apify-cli 0.13.1-beta.4 → 0.13.1-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/call.js +0 -1
- package/src/commands/create.js +101 -31
- package/src/commands/push.js +0 -1
- package/src/commands/run.js +46 -21
- package/src/lib/consts.js +4 -0
- package/src/lib/utils.js +39 -0
package/README.md
CHANGED
|
@@ -399,9 +399,12 @@ ARGUMENTS
|
|
|
399
399
|
ACTORNAME Name of the actor and its directory
|
|
400
400
|
|
|
401
401
|
OPTIONS
|
|
402
|
-
-t, --template=template
|
|
403
|
-
|
|
404
|
-
|
|
402
|
+
-t, --template=template Template for the actor. If not provided, the command will prompt for it.
|
|
403
|
+
Visit
|
|
404
|
+
https://raw.githubusercontent.com/apify/actor-templates/master/templates/manifest.json to
|
|
405
|
+
find available template names.
|
|
406
|
+
|
|
407
|
+
--skip-dependency-install Skip installing actor dependencies.
|
|
405
408
|
```
|
|
406
409
|
|
|
407
410
|
_See code: [src/commands/create.js](https://github.com/apify/apify-cli/blob/v0.13.1/src/commands/create.js)_
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.13.1","commands":{"call":{"id":"call","description":"Runs a specific actor remotely on the Apify cloud platform.\nThe actor is run under your current Apify account. Therefore you need to be logged in by calling \"apify login\". It takes input for the actor from the default local key-value store by default.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build","type":"option","char":"b","description":"Tag or number of the build to run (e.g. \"latest\" or \"1.2.34\").","required":false},"timeout":{"name":"timeout","type":"option","char":"t","description":"Timeout for the actor run in seconds. Zero value means there is no timeout.","required":false},"memory":{"name":"memory","type":"option","char":"m","description":"Amount of memory allocated for the actor run, in megabytes.","required":false},"wait-for-finish":{"name":"wait-for-finish","type":"option","char":"w","description":"Seconds for waiting to run to finish, if no value passed, it waits forever.","required":false}},"args":[{"name":"actId","description":"Name or ID of the actor to run (e.g. \"apify/hello-world\" or \"E2jjCZBezvAZnX8Rb\"). If not provided, the command runs the remote actor specified in the \".actor/actor.json\" file.","required":false}]},"check-version":{"id":"check-version","description":"Checks that installed Apify CLI version is up to date.","pluginName":"apify-cli","pluginType":"core","hidden":true,"aliases":["cv"],"flags":{"enforce-update":{"name":"enforce-update","type":"boolean","char":"e","description":"[Optional] Enforce version update from NPM","required":false,"allowNo":false}},"args":[]},"create":{"id":"create","description":"Creates a new actor project directory from a selected boilerplate template.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"template":{"name":"template","type":"option","char":"t","description":"Template for the actor. If not provided, the command will prompt for it.Visit https://raw.githubusercontent.com/apify/actor-templates/master/templates/manifest.json to find available template names.","required":false}},"args":[{"name":"actorName","description":"Name of the actor and its directory","required":false}]},"edit-input-schema":{"id":"edit-input-schema","description":"Lets you edit your input schema that would be used on the platform in a visual input schema editor.","pluginName":"apify-cli","pluginType":"core","hidden":true,"aliases":["eis"],"flags":{},"args":[{"name":"path","description":"Optional path to your INPUT_SCHEMA.json file. If not provided default platform location for input schema is used.","required":false}]},"info":{"id":"info","description":"Displays information about the currently active Apify account.\nThe information is printed to the console.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"init":{"id":"init","description":"Initializes a new actor project in an existing directory.\nThe command only creates the \".actor/actor.json\" file and the \"storage\" directory in the current directory, but will not touch anything else.\n\nWARNING: The directory at \"storage\" will be overwritten if it already exists.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"actorName","description":"Name of the actor. If not provided, you will be prompted for it.","required":false}]},"login":{"id":"login","description":"Logs in to your Apify account using a provided API token.\nThe API token and other account information is stored in the ~/.apify directory, from where it is read by all other \"apify\" commands. To log out, call \"apify logout\".","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"token":{"name":"token","type":"option","char":"t","description":"[Optional] Apify API token","required":false}},"args":[]},"logout":{"id":"logout","description":"Logs out of your Apify account.\nThe command deletes the API token and all other account information stored in the ~/.apify directory. To log in again, call \"apify login\".","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"push":{"id":"push","description":"Uploads the actor to the Apify platform and builds it there.\nThe actor settings are read from the \".actor/actor.json\" file in the current directory, but they can be overridden using command-line options.\nNOTE: If the source files are smaller than 3 MB then they are uploaded as \n\"Multiple source files\", otherwise they are uploaded as \"Zip file\".\n\nWARNING: If the target actor already exists in your Apify account, it will be overwritten!","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"version-number":{"name":"version-number","type":"option","description":"DEPRECATED: Use flag version instead. Actor version number to which the files should be pushed. By default, it is taken from the \".actor/actor.json\" file.","required":false},"version":{"name":"version","type":"option","char":"v","description":"Actor version number to which the files should be pushed. By default, it is taken from the \".actor/actor.json\" file.","required":false},"build-tag":{"name":"build-tag","type":"option","char":"b","description":"Build tag to be applied to the successful actor build. By default, it is taken from the \".actor/actor.json\" file","required":false},"wait-for-finish":{"name":"wait-for-finish","type":"option","char":"w","description":"Seconds for waiting to build to finish, if no value passed, it waits forever.","required":false}},"args":[{"name":"actorId","description":"ID of an existing actor on the Apify platform where the files will be pushed. If not provided, the command will create or modify the actor with the name specified in \".actor/actor.json\" file.","required":false}]},"run":{"id":"run","description":"Runs the actor locally in the current directory by executing \"npm start\".\nIt sets various APIFY_XYZ environment variables in order to provide a working execution environment for the actor. For example, this causes the actor input, as well as all other data in key-value stores, datasets or request queues to be stored in the \"storage\" directory, rather than on the Apify platform.\n\nNOTE: You can override the command's default behavior by overriding the npm start script value in a package.json file. You can set up your own main file or environment variables by changing it.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"purge":{"name":"purge","type":"boolean","char":"p","description":"Shortcut that combines the --purge-queue, --purge-dataset and --purge-key-value-store options.","required":false,"allowNo":false},"purge-queue":{"name":"purge-queue","type":"boolean","description":"Deletes the local directory containing the default request queue before the run starts.","required":false,"allowNo":false},"purge-dataset":{"name":"purge-dataset","type":"boolean","description":"Deletes the local directory containing the default dataset before the run starts.","required":false,"allowNo":false},"purge-key-value-store":{"name":"purge-key-value-store","type":"boolean","description":"Deletes all records from the default key-value store in the local directory before the run starts, except for the \"INPUT\" key.","required":false,"allowNo":false}},"args":[]},"vis":{"id":"vis","description":"Validates input schema and prints errors found.\nThe input schema for the actor is used from these locations in order of preference.\nThe first one found is validated as it would be the one used on the Apify platform.\n1. Directly embedded object in \".actor/actor.json\" under 'input' key\n2. Path to JSON file referenced in \".actor/actor.json\" under 'input' key\n3. JSON file at .actor/INPUT_SCHEMA.json\n4. JSON file at INPUT_SCHEMA.json\n\nYou can also pass any custom path to your input schema to have it validated instead.\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"path","description":"Optional path to your INPUT_SCHEMA.json file. If not provided ./INPUT_SCHEMA.json is used.","required":false}]},"actor:get-input":{"id":"actor:get-input","description":"Gets the actor input value from the default key-value store associated with the actor run.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"actor:get-value":{"id":"actor:get-value","description":"Gets a value from the default key-value store associated with the actor run.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"key","description":"Key of the record in key-value store","required":true}]},"actor":{"id":"actor","description":"Commands are designed to be used in actor runs. All commands are in PoC state, do not use in production environments.\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"actor:push-data":{"id":"actor:push-data","description":"Stores an object or an array of objects to the default dataset of the actor run.\nIt is possible to pass data using item argument or stdin.\nPassing data using argument:\n$ apify actor:push-data {\"foo\": \"bar\"}\nPassing data using stdin with pipe:\n$ cat ./test.json | apify actor:push-data\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"item","description":"JSON string with one object or array of objects containing data to be stored in the default dataset.","required":false}]},"actor:set-value":{"id":"actor:set-value","description":"Sets or removes record into the default KeyValueStore associated with the actor run.\nIt is possible to pass data using argument or stdin.\nPassing data using argument:\n$ apify actor:set-value KEY my-value\nPassing data using stdin with pipe:\n$ cat ./my-text-file.txt | apify actor:set-value KEY --contentType text/plain\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"contentType":{"name":"contentType","type":"option","char":"c","description":"Specifies a custom MIME content type of the record. By default \"application/json\" is used.","required":false}},"args":[{"name":"key","description":"Key of the record in key-value store.","required":true},{"name":"value","description":"Record data, which can be one of the following values:\n- If empty, the record in the key-value store is deleted.\n- If no `contentType` flag is specified, value is expected to be any JSON string value.\n- If options.contentType is set, value is taken as is.","required":false}]},"secrets:add":{"id":"secrets:add","description":"Adds a new secret value.\nThe secrets are stored to a file at ~/.apify","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"name","description":"Name of the secret","required":true},{"name":"value","description":"Value of the secret","required":true}]},"secrets":{"id":"secrets","description":"Manages secret values for actor environment variables.\n\nExample:\n$ apify secrets:add mySecret TopSecretValue123\n\nNow the \"mySecret\" value can be used in an environment variable defined in \".actor/actor.json\" file by adding the \"@\" prefix:\n\n{\n \"actorSpecification\": 1,\n \"name\": \"my_actor\",\n \"environmentVariables\": { \"SECRET_ENV_VAR\": \"@mySecret\" },\n \"version\": \"0.1\n}\n\nWhen the actor is pushed to Apify cloud, the \"SECRET_ENV_VAR\" and its value is stored as a secret environment variable of the actor.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"secrets:rm":{"id":"secrets:rm","description":"Removes the secret.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"name","description":"Name of the secret","required":true}]}}}
|
|
1
|
+
{"version":"0.13.1","commands":{"call":{"id":"call","description":"Runs a specific actor remotely on the Apify cloud platform.\nThe actor is run under your current Apify account. Therefore you need to be logged in by calling \"apify login\". It takes input for the actor from the default local key-value store by default.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build","type":"option","char":"b","description":"Tag or number of the build to run (e.g. \"latest\" or \"1.2.34\").","required":false},"timeout":{"name":"timeout","type":"option","char":"t","description":"Timeout for the actor run in seconds. Zero value means there is no timeout.","required":false},"memory":{"name":"memory","type":"option","char":"m","description":"Amount of memory allocated for the actor run, in megabytes.","required":false},"wait-for-finish":{"name":"wait-for-finish","type":"option","char":"w","description":"Seconds for waiting to run to finish, if no value passed, it waits forever.","required":false}},"args":[{"name":"actId","description":"Name or ID of the actor to run (e.g. \"apify/hello-world\" or \"E2jjCZBezvAZnX8Rb\"). If not provided, the command runs the remote actor specified in the \".actor/actor.json\" file.","required":false}]},"check-version":{"id":"check-version","description":"Checks that installed Apify CLI version is up to date.","pluginName":"apify-cli","pluginType":"core","hidden":true,"aliases":["cv"],"flags":{"enforce-update":{"name":"enforce-update","type":"boolean","char":"e","description":"[Optional] Enforce version update from NPM","required":false,"allowNo":false}},"args":[]},"create":{"id":"create","description":"Creates a new actor project directory from a selected boilerplate template.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"template":{"name":"template","type":"option","char":"t","description":"Template for the actor. If not provided, the command will prompt for it.\nVisit https://raw.githubusercontent.com/apify/actor-templates/master/templates/manifest.json to find available template names.","required":false},"skip-dependency-install":{"name":"skip-dependency-install","type":"boolean","description":"Skip installing actor dependencies.","required":false,"allowNo":false},"template-archive-url":{"name":"template-archive-url","type":"option","description":"Actor template archive url. Useful for developing new templates.","hidden":true,"required":false}},"args":[{"name":"actorName","description":"Name of the actor and its directory","required":false}]},"edit-input-schema":{"id":"edit-input-schema","description":"Lets you edit your input schema that would be used on the platform in a visual input schema editor.","pluginName":"apify-cli","pluginType":"core","hidden":true,"aliases":["eis"],"flags":{},"args":[{"name":"path","description":"Optional path to your INPUT_SCHEMA.json file. If not provided default platform location for input schema is used.","required":false}]},"info":{"id":"info","description":"Displays information about the currently active Apify account.\nThe information is printed to the console.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"init":{"id":"init","description":"Initializes a new actor project in an existing directory.\nThe command only creates the \".actor/actor.json\" file and the \"storage\" directory in the current directory, but will not touch anything else.\n\nWARNING: The directory at \"storage\" will be overwritten if it already exists.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"actorName","description":"Name of the actor. If not provided, you will be prompted for it.","required":false}]},"login":{"id":"login","description":"Logs in to your Apify account using a provided API token.\nThe API token and other account information is stored in the ~/.apify directory, from where it is read by all other \"apify\" commands. To log out, call \"apify logout\".","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"token":{"name":"token","type":"option","char":"t","description":"[Optional] Apify API token","required":false}},"args":[]},"logout":{"id":"logout","description":"Logs out of your Apify account.\nThe command deletes the API token and all other account information stored in the ~/.apify directory. To log in again, call \"apify login\".","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"push":{"id":"push","description":"Uploads the actor to the Apify platform and builds it there.\nThe actor settings are read from the \".actor/actor.json\" file in the current directory, but they can be overridden using command-line options.\nNOTE: If the source files are smaller than 3 MB then they are uploaded as \n\"Multiple source files\", otherwise they are uploaded as \"Zip file\".\n\nWARNING: If the target actor already exists in your Apify account, it will be overwritten!","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"version-number":{"name":"version-number","type":"option","description":"DEPRECATED: Use flag version instead. Actor version number to which the files should be pushed. By default, it is taken from the \".actor/actor.json\" file.","required":false},"version":{"name":"version","type":"option","char":"v","description":"Actor version number to which the files should be pushed. By default, it is taken from the \".actor/actor.json\" file.","required":false},"build-tag":{"name":"build-tag","type":"option","char":"b","description":"Build tag to be applied to the successful actor build. By default, it is taken from the \".actor/actor.json\" file","required":false},"wait-for-finish":{"name":"wait-for-finish","type":"option","char":"w","description":"Seconds for waiting to build to finish, if no value passed, it waits forever.","required":false}},"args":[{"name":"actorId","description":"ID of an existing actor on the Apify platform where the files will be pushed. If not provided, the command will create or modify the actor with the name specified in \".actor/actor.json\" file.","required":false}]},"run":{"id":"run","description":"Runs the actor locally in the current directory by executing \"npm start\".\nIt sets various APIFY_XYZ environment variables in order to provide a working execution environment for the actor. For example, this causes the actor input, as well as all other data in key-value stores, datasets or request queues to be stored in the \"storage\" directory, rather than on the Apify platform.\n\nNOTE: You can override the command's default behavior by overriding the npm start script value in a package.json file. You can set up your own main file or environment variables by changing it.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"purge":{"name":"purge","type":"boolean","char":"p","description":"Shortcut that combines the --purge-queue, --purge-dataset and --purge-key-value-store options.","required":false,"allowNo":false},"purge-queue":{"name":"purge-queue","type":"boolean","description":"Deletes the local directory containing the default request queue before the run starts.","required":false,"allowNo":false},"purge-dataset":{"name":"purge-dataset","type":"boolean","description":"Deletes the local directory containing the default dataset before the run starts.","required":false,"allowNo":false},"purge-key-value-store":{"name":"purge-key-value-store","type":"boolean","description":"Deletes all records from the default key-value store in the local directory before the run starts, except for the \"INPUT\" key.","required":false,"allowNo":false}},"args":[]},"vis":{"id":"vis","description":"Validates input schema and prints errors found.\nThe input schema for the actor is used from these locations in order of preference.\nThe first one found is validated as it would be the one used on the Apify platform.\n1. Directly embedded object in \".actor/actor.json\" under 'input' key\n2. Path to JSON file referenced in \".actor/actor.json\" under 'input' key\n3. JSON file at .actor/INPUT_SCHEMA.json\n4. JSON file at INPUT_SCHEMA.json\n\nYou can also pass any custom path to your input schema to have it validated instead.\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"path","description":"Optional path to your INPUT_SCHEMA.json file. If not provided ./INPUT_SCHEMA.json is used.","required":false}]},"actor:get-input":{"id":"actor:get-input","description":"Gets the actor input value from the default key-value store associated with the actor run.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"actor:get-value":{"id":"actor:get-value","description":"Gets a value from the default key-value store associated with the actor run.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"key","description":"Key of the record in key-value store","required":true}]},"actor":{"id":"actor","description":"Commands are designed to be used in actor runs. All commands are in PoC state, do not use in production environments.\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"actor:push-data":{"id":"actor:push-data","description":"Stores an object or an array of objects to the default dataset of the actor run.\nIt is possible to pass data using item argument or stdin.\nPassing data using argument:\n$ apify actor:push-data {\"foo\": \"bar\"}\nPassing data using stdin with pipe:\n$ cat ./test.json | apify actor:push-data\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"item","description":"JSON string with one object or array of objects containing data to be stored in the default dataset.","required":false}]},"actor:set-value":{"id":"actor:set-value","description":"Sets or removes record into the default KeyValueStore associated with the actor run.\nIt is possible to pass data using argument or stdin.\nPassing data using argument:\n$ apify actor:set-value KEY my-value\nPassing data using stdin with pipe:\n$ cat ./my-text-file.txt | apify actor:set-value KEY --contentType text/plain\n","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{"contentType":{"name":"contentType","type":"option","char":"c","description":"Specifies a custom MIME content type of the record. By default \"application/json\" is used.","required":false}},"args":[{"name":"key","description":"Key of the record in key-value store.","required":true},{"name":"value","description":"Record data, which can be one of the following values:\n- If empty, the record in the key-value store is deleted.\n- If no `contentType` flag is specified, value is expected to be any JSON string value.\n- If options.contentType is set, value is taken as is.","required":false}]},"secrets:add":{"id":"secrets:add","description":"Adds a new secret value.\nThe secrets are stored to a file at ~/.apify","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"name","description":"Name of the secret","required":true},{"name":"value","description":"Value of the secret","required":true}]},"secrets":{"id":"secrets","description":"Manages secret values for actor environment variables.\n\nExample:\n$ apify secrets:add mySecret TopSecretValue123\n\nNow the \"mySecret\" value can be used in an environment variable defined in \".actor/actor.json\" file by adding the \"@\" prefix:\n\n{\n \"actorSpecification\": 1,\n \"name\": \"my_actor\",\n \"environmentVariables\": { \"SECRET_ENV_VAR\": \"@mySecret\" },\n \"version\": \"0.1\n}\n\nWhen the actor is pushed to Apify cloud, the \"SECRET_ENV_VAR\" and its value is stored as a secret environment variable of the actor.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[]},"secrets:rm":{"id":"secrets:rm","description":"Removes the secret.","pluginName":"apify-cli","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"name","description":"Name of the secret","required":true}]}}}
|
package/package.json
CHANGED
package/src/commands/call.js
CHANGED
package/src/commands/create.js
CHANGED
|
@@ -9,14 +9,25 @@ const { ApifyCommand } = require('../lib/apify_command');
|
|
|
9
9
|
const execWithLog = require('../lib/exec');
|
|
10
10
|
const outputs = require('../lib/outputs');
|
|
11
11
|
const { updateLocalJson } = require('../lib/files');
|
|
12
|
-
const {
|
|
13
|
-
|
|
12
|
+
const {
|
|
13
|
+
setLocalConfig,
|
|
14
|
+
setLocalEnv,
|
|
15
|
+
getNpmCmd,
|
|
16
|
+
validateActorName,
|
|
17
|
+
getJsonFileContent,
|
|
18
|
+
detectPythonVersion,
|
|
19
|
+
isPythonVersionSupported,
|
|
20
|
+
getPythonCommand,
|
|
21
|
+
} = require('../lib/utils');
|
|
22
|
+
const { EMPTY_LOCAL_CONFIG, LOCAL_CONFIG_PATH, PYTHON_VENV_PATH } = require('../lib/consts');
|
|
14
23
|
|
|
15
24
|
class CreateCommand extends ApifyCommand {
|
|
16
25
|
async run() {
|
|
17
26
|
const { flags, args } = this.parse(CreateCommand);
|
|
18
27
|
let { actorName } = args;
|
|
19
|
-
let templateName = flags
|
|
28
|
+
let { templateArchiveUrl, template: templateName } = flags;
|
|
29
|
+
const { skipDependencyInstall } = flags;
|
|
30
|
+
let skipOptionalDeps = false;
|
|
20
31
|
|
|
21
32
|
// Check proper format of actorName
|
|
22
33
|
if (!actorName) {
|
|
@@ -38,24 +49,30 @@ class CreateCommand extends ApifyCommand {
|
|
|
38
49
|
validateActorName(actorName);
|
|
39
50
|
}
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
if (!templateArchiveUrl) {
|
|
53
|
+
const manifest = await actorTemplates.fetchManifest();
|
|
54
|
+
if (!templateName) {
|
|
55
|
+
const choices = manifest.templates.map((t) => ({
|
|
56
|
+
value: t.name,
|
|
57
|
+
name: t.description,
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
const answer = await inquirer.prompt([{
|
|
61
|
+
type: 'list',
|
|
62
|
+
name: 'template',
|
|
63
|
+
message: 'Please select the template for your new actor',
|
|
64
|
+
default: choices[0],
|
|
65
|
+
choices,
|
|
66
|
+
loop: false,
|
|
67
|
+
pageSize: 8, // Due to the answers wrapping, the prompt looks best if the `pageSize` is a multiple of 2
|
|
68
|
+
}]);
|
|
69
|
+
templateName = answer.template;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const templateObj = manifest.templates.find((t) => t.name === templateName);
|
|
73
|
+
({ archiveUrl: templateArchiveUrl, skipOptionalDeps } = templateObj);
|
|
58
74
|
}
|
|
75
|
+
|
|
59
76
|
const cwd = process.cwd();
|
|
60
77
|
const actFolderDir = path.join(cwd, actorName);
|
|
61
78
|
|
|
@@ -70,11 +87,9 @@ class CreateCommand extends ApifyCommand {
|
|
|
70
87
|
}
|
|
71
88
|
throw err;
|
|
72
89
|
}
|
|
73
|
-
const templateObj = manifest.templates.find((t) => t.name === templateName);
|
|
74
|
-
const { archiveUrl } = templateObj;
|
|
75
90
|
|
|
76
91
|
const zipStream = await gotScraping({
|
|
77
|
-
url:
|
|
92
|
+
url: templateArchiveUrl,
|
|
78
93
|
isStream: true,
|
|
79
94
|
});
|
|
80
95
|
const unzip = unzipper.Extract({ path: actFolderDir });
|
|
@@ -84,15 +99,61 @@ class CreateCommand extends ApifyCommand {
|
|
|
84
99
|
const localConfig = await getJsonFileContent(path.join(actFolderDir, LOCAL_CONFIG_PATH));
|
|
85
100
|
await setLocalConfig(Object.assign(localConfig || EMPTY_LOCAL_CONFIG, { name: actorName }), actFolderDir);
|
|
86
101
|
await setLocalEnv(actFolderDir);
|
|
87
|
-
await updateLocalJson(path.join(actFolderDir, 'package.json'), { name: actorName });
|
|
88
102
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const cmdArgs = ['install'];
|
|
92
|
-
if (templateObj.skipOptionalDeps) cmdArgs.push('--no-optional');
|
|
93
|
-
await execWithLog(getNpmCmd(), cmdArgs, { cwd: actFolderDir });
|
|
103
|
+
const packageJsonPath = path.join(actFolderDir, 'package.json');
|
|
104
|
+
const requirementsTxtPath = path.join(actFolderDir, 'requirements.txt');
|
|
94
105
|
|
|
95
|
-
|
|
106
|
+
let dependenciesInstalled = false;
|
|
107
|
+
if (!skipDependencyInstall) {
|
|
108
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
109
|
+
// If the actor is a Node.js actor (has package.json), run `npm install`
|
|
110
|
+
await updateLocalJson(packageJsonPath, { name: actorName });
|
|
111
|
+
// Run npm install in actor dir.
|
|
112
|
+
// For efficiency, don't install Puppeteer for templates that don't use it
|
|
113
|
+
const cmdArgs = ['install'];
|
|
114
|
+
if (skipOptionalDeps) cmdArgs.push('--no-optional');
|
|
115
|
+
await execWithLog(getNpmCmd(), cmdArgs, { cwd: actFolderDir });
|
|
116
|
+
dependenciesInstalled = true;
|
|
117
|
+
} else if (fs.existsSync(requirementsTxtPath)) {
|
|
118
|
+
const pythonVersion = detectPythonVersion(actFolderDir);
|
|
119
|
+
if (pythonVersion) {
|
|
120
|
+
if (isPythonVersionSupported(pythonVersion)) {
|
|
121
|
+
const venvPath = path.join(actFolderDir, '.venv');
|
|
122
|
+
outputs.info(`Python version ${pythonVersion} detected.`);
|
|
123
|
+
outputs.info(`Creating a virtual environment in "${venvPath}" and installing dependencies from "requirements.txt"...`);
|
|
124
|
+
let pythonCommand = getPythonCommand(actFolderDir);
|
|
125
|
+
if (!process.env.VIRTUAL_ENV) {
|
|
126
|
+
// If Python is not running in a virtual environment, create a new one
|
|
127
|
+
await execWithLog(pythonCommand, ['-m', 'venv', '--prompt', '.', PYTHON_VENV_PATH], { cwd: actFolderDir });
|
|
128
|
+
// regenerate the `pythonCommand` after we create the virtual environment
|
|
129
|
+
pythonCommand = getPythonCommand(actFolderDir);
|
|
130
|
+
}
|
|
131
|
+
await execWithLog(
|
|
132
|
+
pythonCommand,
|
|
133
|
+
['-m', 'pip', 'install', '--no-cache-dir', '--no-warn-script-location', '--upgrade', 'pip'],
|
|
134
|
+
{ cwd: actFolderDir },
|
|
135
|
+
);
|
|
136
|
+
await execWithLog(
|
|
137
|
+
pythonCommand,
|
|
138
|
+
['-m', 'pip', 'install', '--no-cache-dir', '--no-warn-script-location', '-r', 'requirements.txt'],
|
|
139
|
+
{ cwd: actFolderDir },
|
|
140
|
+
);
|
|
141
|
+
dependenciesInstalled = true;
|
|
142
|
+
} else {
|
|
143
|
+
outputs.warning(`Python actors require Python 3.8 or higher, but you have Python ${pythonVersion}!`);
|
|
144
|
+
outputs.warning('Please install Python 3.8 or higher to be able to run Python actors locally.');
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
outputs.warning('No Python detected! Please install Python 3.8 or higher to be able to run Python actors locally.');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (dependenciesInstalled) {
|
|
153
|
+
outputs.success(`Actor '${actorName}' was created. To run it, run "cd ${actorName}" and "apify run".`);
|
|
154
|
+
} else {
|
|
155
|
+
outputs.success(`Actor '${actorName}' was created. Please install its dependencies to be able to run it using "apify run".`);
|
|
156
|
+
}
|
|
96
157
|
}
|
|
97
158
|
}
|
|
98
159
|
|
|
@@ -101,10 +162,19 @@ CreateCommand.description = 'Creates a new actor project directory from a select
|
|
|
101
162
|
CreateCommand.flags = {
|
|
102
163
|
template: flagsHelper.string({
|
|
103
164
|
char: 't',
|
|
104
|
-
description: 'Template for the actor. If not provided, the command will prompt for it
|
|
165
|
+
description: 'Template for the actor. If not provided, the command will prompt for it.\n'
|
|
105
166
|
+ `Visit ${actorTemplates.manifestUrl} to find available template names.`,
|
|
106
167
|
required: false,
|
|
107
168
|
}),
|
|
169
|
+
'skip-dependency-install': flagsHelper.boolean({
|
|
170
|
+
description: 'Skip installing actor dependencies.',
|
|
171
|
+
required: false,
|
|
172
|
+
}),
|
|
173
|
+
'template-archive-url': flagsHelper.string({
|
|
174
|
+
description: 'Actor template archive url. Useful for developing new templates.',
|
|
175
|
+
required: false,
|
|
176
|
+
hidden: true,
|
|
177
|
+
}),
|
|
108
178
|
};
|
|
109
179
|
|
|
110
180
|
CreateCommand.args = [
|
package/src/commands/push.js
CHANGED
package/src/commands/run.js
CHANGED
|
@@ -10,8 +10,9 @@ const { ApifyCommand } = require('../lib/apify_command');
|
|
|
10
10
|
const {
|
|
11
11
|
getLocalUserInfo, purgeDefaultQueue, purgeDefaultKeyValueStore,
|
|
12
12
|
purgeDefaultDataset, getLocalConfigOrThrow, getNpmCmd, checkIfStorageIsEmpty,
|
|
13
|
+
detectPythonVersion, isPythonVersionSupported, getPythonCommand,
|
|
13
14
|
} = require('../lib/utils');
|
|
14
|
-
const { info, warning } = require('../lib/outputs');
|
|
15
|
+
const { error, info, warning } = require('../lib/outputs');
|
|
15
16
|
const { replaceSecretsValue } = require('../lib/secrets');
|
|
16
17
|
|
|
17
18
|
class RunCommand extends ApifyCommand {
|
|
@@ -22,14 +23,16 @@ class RunCommand extends ApifyCommand {
|
|
|
22
23
|
const cwd = process.cwd();
|
|
23
24
|
|
|
24
25
|
const packageJsonPath = path.join(cwd, 'package.json');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
throw new Error(
|
|
32
|
-
|
|
26
|
+
const mainPyPath = path.join(cwd, 'src/__main__.py');
|
|
27
|
+
|
|
28
|
+
const packageJsonExists = fs.existsSync(packageJsonPath);
|
|
29
|
+
const mainPyExists = fs.existsSync(mainPyPath);
|
|
30
|
+
|
|
31
|
+
if (!packageJsonExists && !mainPyExists) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
'Actor is of an uknown format.'
|
|
34
|
+
+ ` Make sure either the 'package.json' file or 'src/__main__.py' file exists.`,
|
|
35
|
+
);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
if (fs.existsSync(LEGACY_LOCAL_STORAGE_DIR) && !fs.existsSync(DEFAULT_LOCAL_STORAGE_DIR)) {
|
|
@@ -82,19 +85,41 @@ class RunCommand extends ApifyCommand {
|
|
|
82
85
|
warning('You are not logged in with your Apify Account. Some features like Apify Proxy will not work. Call "apify login" to fix that.');
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
if (packageJsonExists) { // Actor is written in Node.js
|
|
89
|
+
const serverJsFile = path.join(cwd, 'server.js');
|
|
90
|
+
const packageJson = await loadJson(packageJsonPath);
|
|
91
|
+
if ((!packageJson.scripts || !packageJson.scripts.start) && !fs.existsSync(serverJsFile)) {
|
|
92
|
+
throw new Error('The "npm start" script was not found in package.json. Please set it up for your project. '
|
|
93
|
+
+ 'For more information about that call "apify help run".');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// --max-http-header-size=80000
|
|
97
|
+
// Increases default size of headers. The original limit was 80kb, but from node 10+ they decided to lower it to 8kb.
|
|
98
|
+
// However they did not think about all the sites there with large headers,
|
|
99
|
+
// so we put back the old limit of 80kb, which seems to work just fine.
|
|
100
|
+
const currentNodeVersion = process.versions.node;
|
|
101
|
+
const lastSupportedVersion = semver.minVersion(SUPPORTED_NODEJS_VERSION);
|
|
102
|
+
if (semver.gte(currentNodeVersion, lastSupportedVersion)) {
|
|
103
|
+
env.NODE_OPTIONS = env.NODE_OPTIONS ? `${env.NODE_OPTIONS} --max-http-header-size=80000` : '--max-http-header-size=80000';
|
|
104
|
+
} else {
|
|
105
|
+
warning(`You are running Node.js version ${currentNodeVersion}, which is no longer supported. `
|
|
106
|
+
+ `Please upgrade to Node.js version ${lastSupportedVersion} or later.`);
|
|
107
|
+
}
|
|
108
|
+
await execWithLog(getNpmCmd(), ['start'], { env });
|
|
109
|
+
} else if (mainPyExists) {
|
|
110
|
+
const pythonVersion = detectPythonVersion(cwd);
|
|
111
|
+
if (pythonVersion) {
|
|
112
|
+
if (isPythonVersionSupported(pythonVersion)) {
|
|
113
|
+
const pythonCommand = getPythonCommand(cwd);
|
|
114
|
+
await execWithLog(pythonCommand, ['-m', 'src'], { env });
|
|
115
|
+
} else {
|
|
116
|
+
error(`Python actors require Python 3.8 or higher, but you have Python ${pythonVersion}!`);
|
|
117
|
+
error('Please install Python 3.8 or higher to be able to run Python actors locally.');
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
error('No Python detected! Please install Python 3.8 or higher to be able to run Python actors locally.');
|
|
121
|
+
}
|
|
96
122
|
}
|
|
97
|
-
await execWithLog(getNpmCmd(), ['start'], { env });
|
|
98
123
|
}
|
|
99
124
|
}
|
|
100
125
|
|
package/src/lib/consts.js
CHANGED
|
@@ -43,3 +43,7 @@ exports.UPLOADS_STORE_NAME = 'apify-cli-deployments';
|
|
|
43
43
|
exports.SUPPORTED_NODEJS_VERSION = require('../../package.json').engines.node; // eslint-disable-line;
|
|
44
44
|
|
|
45
45
|
exports.APIFY_CLIENT_DEFAULT_HEADERS = { 'X-Apify-Request-Origin': META_ORIGINS.CLI };
|
|
46
|
+
|
|
47
|
+
exports.MINIMUM_SUPPORTED_PYTHON_VERSION = '3.8.0';
|
|
48
|
+
|
|
49
|
+
exports.PYTHON_VENV_PATH = '.venv';
|
package/src/lib/utils.js
CHANGED
|
@@ -21,6 +21,7 @@ const { ApifyClient } = require('apify-client');
|
|
|
21
21
|
const {
|
|
22
22
|
execSync,
|
|
23
23
|
} = require('child_process');
|
|
24
|
+
const semver = require('semver');
|
|
24
25
|
const {
|
|
25
26
|
GLOBAL_CONFIGS_FOLDER,
|
|
26
27
|
AUTH_FILE_PATH,
|
|
@@ -30,6 +31,7 @@ const {
|
|
|
30
31
|
DEPRECATED_LOCAL_CONFIG_NAME,
|
|
31
32
|
ACTOR_SPECIFICATION_VERSION,
|
|
32
33
|
APIFY_CLIENT_DEFAULT_HEADERS,
|
|
34
|
+
MINIMUM_SUPPORTED_PYTHON_VERSION,
|
|
33
35
|
} = require('./consts');
|
|
34
36
|
const {
|
|
35
37
|
ensureFolderExistsSync,
|
|
@@ -488,6 +490,40 @@ const validateActorName = (actorName) => {
|
|
|
488
490
|
}
|
|
489
491
|
};
|
|
490
492
|
|
|
493
|
+
const getPythonCommand = (directory) => {
|
|
494
|
+
const pythonVenvPath = /^win/.test(process.platform)
|
|
495
|
+
? 'Scripts/python.exe'
|
|
496
|
+
: 'bin/python3';
|
|
497
|
+
|
|
498
|
+
let fullPythonVenvPath;
|
|
499
|
+
if (process.env.VIRTUAL_ENV) {
|
|
500
|
+
fullPythonVenvPath = path.join(process.env.VIRTUAL_ENV, pythonVenvPath);
|
|
501
|
+
} else {
|
|
502
|
+
fullPythonVenvPath = path.join(directory, '.venv', pythonVenvPath);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (fs.existsSync(fullPythonVenvPath)) {
|
|
506
|
+
return fullPythonVenvPath;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return /^win/.test(process.platform)
|
|
510
|
+
? 'python'
|
|
511
|
+
: 'python3';
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
const detectPythonVersion = (directory) => {
|
|
515
|
+
const pythonCommand = getPythonCommand(directory);
|
|
516
|
+
try {
|
|
517
|
+
return execSync(`${pythonCommand} -c "import platform; print(platform.python_version(), end='')"`, { encoding: 'utf-8' });
|
|
518
|
+
} catch {
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
const isPythonVersionSupported = (installedPythonVersion) => {
|
|
524
|
+
return semver.satisfies(installedPythonVersion, `^${MINIMUM_SUPPORTED_PYTHON_VERSION}`);
|
|
525
|
+
};
|
|
526
|
+
|
|
491
527
|
module.exports = {
|
|
492
528
|
getLoggedClientOrThrow,
|
|
493
529
|
getLocalConfig,
|
|
@@ -515,4 +551,7 @@ module.exports = {
|
|
|
515
551
|
validateActorName,
|
|
516
552
|
getJsonFileContent,
|
|
517
553
|
getApifyClientOptions,
|
|
554
|
+
detectPythonVersion,
|
|
555
|
+
isPythonVersionSupported,
|
|
556
|
+
getPythonCommand,
|
|
518
557
|
};
|