Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(create): merge local development instructions into README #372

Merged
merged 10 commits into from
Jun 21, 2023
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ USAGE
$ apify actor
```

_See code: [src/commands/actor/index.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/actor/index.js)_
_See code: [src/commands/actor/index.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/actor/index.js)_

## `apify actor:get-input`

Expand All @@ -310,7 +310,7 @@ USAGE
$ apify actor:get-input
```

_See code: [src/commands/actor/get-input.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/actor/get-input.js)_
_See code: [src/commands/actor/get-input.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/actor/get-input.js)_

## `apify actor:get-value KEY`

Expand All @@ -324,7 +324,7 @@ ARGUMENTS
KEY Key of the record in key-value store
```

_See code: [src/commands/actor/get-value.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/actor/get-value.js)_
_See code: [src/commands/actor/get-value.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/actor/get-value.js)_

## `apify actor:push-data [ITEM]`

Expand All @@ -345,7 +345,7 @@ DESCRIPTION
$ cat ./test.json | apify actor:push-data
```

_See code: [src/commands/actor/push-data.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/actor/push-data.js)_
_See code: [src/commands/actor/push-data.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/actor/push-data.js)_

## `apify actor:set-value KEY [VALUE]`

Expand Down Expand Up @@ -375,7 +375,7 @@ DESCRIPTION
$ cat ./my-text-file.txt | apify actor:set-value KEY --contentType text/plain
```

_See code: [src/commands/actor/set-value.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/actor/set-value.js)_
_See code: [src/commands/actor/set-value.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/actor/set-value.js)_

## `apify call [ACTID]`

Expand All @@ -400,7 +400,7 @@ DESCRIPTION
takes input for the actor from the default local key-value store by default.
```

_See code: [src/commands/call.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/call.js)_
_See code: [src/commands/call.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/call.js)_

## `apify create [ACTORNAME]`

Expand All @@ -422,7 +422,7 @@ OPTIONS
--skip-dependency-install Skip installing actor dependencies.
```

_See code: [src/commands/create.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/create.js)_
_See code: [src/commands/create.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/create.js)_

## `apify info`

Expand All @@ -436,7 +436,7 @@ DESCRIPTION
The information is printed to the console.
```

_See code: [src/commands/info.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/info.js)_
_See code: [src/commands/info.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/info.js)_

## `apify init [ACTORNAME]`

Expand All @@ -456,7 +456,7 @@ DESCRIPTION
WARNING: The directory at "storage" will be overwritten if it already exists.
```

_See code: [src/commands/init.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/init.js)_
_See code: [src/commands/init.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/init.js)_

## `apify login`

Expand All @@ -474,7 +474,7 @@ DESCRIPTION
"apify" commands. To log out, call "apify logout".
```

_See code: [src/commands/login.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/login.js)_
_See code: [src/commands/login.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/login.js)_

## `apify logout`

Expand All @@ -489,7 +489,7 @@ DESCRIPTION
call "apify login".
```

_See code: [src/commands/logout.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/logout.js)_
_See code: [src/commands/logout.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/logout.js)_

## `apify pull [ACTORID]`

Expand All @@ -507,7 +507,7 @@ OPTIONS
-v, --version=version Actor version number which will be pulled, e.g. 1.2. Default: the highest version
```

_See code: [src/commands/pull.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/pull.js)_
_See code: [src/commands/pull.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/pull.js)_

## `apify push [ACTORID]`

Expand Down Expand Up @@ -545,7 +545,7 @@ DESCRIPTION
WARNING: If the target Actor already exists in your Apify account, it will be overwritten!
```

_See code: [src/commands/push.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/push.js)_
_See code: [src/commands/push.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/push.js)_

## `apify run`

Expand Down Expand Up @@ -575,7 +575,7 @@ DESCRIPTION
package.json file. You can set up your own main file or environment variables by changing it.
```

_See code: [src/commands/run.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/run.js)_
_See code: [src/commands/run.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/run.js)_

## `apify secrets`

Expand Down Expand Up @@ -603,7 +603,7 @@ DESCRIPTION
of the actor.
```

_See code: [src/commands/secrets/index.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/secrets/index.js)_
_See code: [src/commands/secrets/index.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/secrets/index.js)_

## `apify secrets:add NAME VALUE`

Expand All @@ -621,7 +621,7 @@ DESCRIPTION
The secrets are stored to a file at ~/.apify
```

_See code: [src/commands/secrets/add.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/secrets/add.js)_
_See code: [src/commands/secrets/add.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/secrets/add.js)_

## `apify secrets:rm NAME`

Expand All @@ -635,7 +635,7 @@ ARGUMENTS
NAME Name of the secret
```

_See code: [src/commands/secrets/rm.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/secrets/rm.js)_
_See code: [src/commands/secrets/rm.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/secrets/rm.js)_

## `apify vis [PATH]`

Expand All @@ -659,5 +659,5 @@ DESCRIPTION
You can also pass any custom path to your input schema to have it validated instead.
```

_See code: [src/commands/vis.js](https://github.com/apify/apify-cli/blob/v0.16.2/src/commands/vis.js)_
_See code: [src/commands/vis.js](https://github.com/apify/apify-cli/blob/v0.17.0/src/commands/vis.js)_
<!-- commandsstop -->
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion oclif.manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apify-cli",
"version": "0.16.3",
"version": "0.17.0",
"description": "Apify command-line interface helps you create, develop, build and run Apify actors, and manage the Apify cloud platform.",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 11 additions & 7 deletions src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
detectNpmVersion,
} = require('../lib/utils');
const { EMPTY_LOCAL_CONFIG, LOCAL_CONFIG_PATH, PYTHON_VENV_PATH, SUPPORTED_NODEJS_VERSION } = require('../lib/consts');
const { httpsGet, ensureValidActorName, getTemplateDefinition } = require('../lib/create-utils');
const { httpsGet, ensureValidActorName, getTemplateDefinition, enhanceReadmeWithLocalSuffix } = require('../lib/create-utils');

class CreateCommand extends ApifyCommand {
async run() {
Expand All @@ -41,15 +41,14 @@ class CreateCommand extends ApifyCommand {

// Start fetching manifest immediately to prevent
// annoying delays that sometimes happen on CLI startup.
const manifestPromise = templateArchiveUrl
? undefined // not fetching manifest when we have direct template URL
: actorTemplates.fetchManifest().catch((err) => {
return new Error(`Could not fetch template list from server. Cause: ${err?.message}`);
});
const manifestPromise = actorTemplates.fetchManifest().catch((err) => {
return new Error(`Could not fetch template list from server. Cause: ${err?.message}`);
});

actorName = await ensureValidActorName(actorName);
let messages = null;
if (manifestPromise) {

if (!templateArchiveUrl) {
({ archiveUrl: templateArchiveUrl, skipOptionalDeps, messages } = await getTemplateDefinition(templateName, manifestPromise));
}

Expand Down Expand Up @@ -82,6 +81,11 @@ class CreateCommand extends ApifyCommand {

const packageJsonPath = path.join(actFolderDir, 'package.json');
const requirementsTxtPath = path.join(actFolderDir, 'requirements.txt');
const readmePath = path.join(actFolderDir, 'README.md');

// Add localReadmeSuffix which is fetched from manifest to README.md
// The suffix contains local development instructions
await enhanceReadmeWithLocalSuffix(readmePath, manifestPromise);

let dependenciesInstalled = false;
if (!skipDependencyInstall) {
Expand Down
34 changes: 34 additions & 0 deletions src/lib/create-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const chalk = require('chalk');
const inquirer = require('inquirer');
const https = require('https');
const { finished } = require('stream');
const { promisify } = require('util');
const { validateActorName } = require('./utils');
const {
warning,
} = require('./outputs');
const fs = require('fs');

const PROGRAMMING_LANGUAGES = ['JavaScript', 'TypeScript', 'Python'];

Expand Down Expand Up @@ -58,6 +64,34 @@ exports.getTemplateDefinition = async (maybeTemplateName, manifestPromise) => {
return executePrompts(manifest);
};

/**
* Fetch local readme suffix from the manifest and append it to the readme.
* @param {string} readmePath
* @param {Promise<object>} manifestPromise
*/
exports.enhanceReadmeWithLocalSuffix = async (readmePath, manifestPromise) => {
const manifest = await manifestPromise;
// If the fetch failed earlier, the resolve value of
// the promise will be the error from fetching the manifest.
if (manifest instanceof Error) throw manifest;

try {
let localReadmeSuffix = '';
monkey-denky marked this conversation as resolved.
Show resolved Hide resolved
const suffixStream = await this.httpsGet(manifest.localReadmeSuffixUrl);

suffixStream.on('data', (chunk) => {
localReadmeSuffix += chunk;
});

await promisify(finished)(suffixStream);

const readmeContent = fs.readFileSync(readmePath, 'utf8');
fs.writeFileSync(readmePath, `${readmeContent}\n\n${localReadmeSuffix}`);
} catch (err) {
warning(`Could not append local development instructions to README.md. Cause: ${err.message}`);
}
};

/**
* Inquirer does not have a native way to "go back" between prompts.
* @param {object} manifest
Expand Down