apify-cli 0.10.0-beta.2 → 0.11.0-beta.0

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.
@@ -1 +1 @@
1
- {"version":"0.10.0","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 \"apify.json\" file.","required":false}]},"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 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 ./INPUT_SCHEMA.json 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 \"apify.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 \"apify.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 \"apify.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 \"apify.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 \"apify.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 \"apify.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 default behaviour of command overriding 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.json file and prints errors found.","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 \"apify.json\" file by adding the \"@\" prefix:\n\n{\n \"name\": \"my_actor\",\n \"env\": { \"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.11.0","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}]},"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}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-cli",
3
- "version": "0.10.0-beta.2",
3
+ "version": "0.11.0-beta.0",
4
4
  "description": "Apify command-line interface helps you create, develop, build and run Apify actors, and manage the Apify cloud platform.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,6 +5,7 @@ const { ApifyCommand } = require('../lib/apify_command');
5
5
  const { getLocalConfig, getLoggedClientOrThrow,
6
6
  getLocalUserInfo, getLocalInput, outputJobLog } = require('../lib/utils');
7
7
  const outputs = require('../lib/outputs');
8
+ const { LOCAL_CONFIG_PATH } = require('../lib/consts');
8
9
 
9
10
  // TODO: Show full error messages and HTTP codes, this is not great:
10
11
  // jan:testx$ apify call help
@@ -90,7 +91,7 @@ class CallCommand extends ApifyCommand {
90
91
  }
91
92
 
92
93
  CallCommand.description = 'Runs a specific actor remotely on the Apify cloud platform.\n'
93
- + 'The actor is run under your current Apify account, therefore you need to be logged in by calling "apify login". '
94
+ + 'The actor is run under your current Apify account. Therefore you need to be logged in by calling "apify login". '
94
95
  + 'It takes input for the actor from the default local key-value store by default.';
95
96
 
96
97
  CallCommand.flags = {
@@ -123,7 +124,7 @@ CallCommand.args = [
123
124
  name: 'actId',
124
125
  required: false,
125
126
  description: 'Name or ID of the actor to run (e.g. "apify/hello-world" or "E2jjCZBezvAZnX8Rb"). '
126
- + 'If not provided, the command runs the remote actor specified in the "apify.json" file.',
127
+ + `If not provided, the command runs the remote actor specified in the "${LOCAL_CONFIG_PATH}" file.`,
127
128
  },
128
129
  ];
129
130
 
@@ -9,7 +9,7 @@ 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 { setLocalConfig, setLocalEnv, getNpmCmd, validateActorName } = require('../lib/utils');
12
+ const { setLocalConfig, setLocalEnv, getNpmCmd, validateActorName, getLocalConfig } = require('../lib/utils');
13
13
  const { EMPTY_LOCAL_CONFIG } = require('../lib/consts');
14
14
 
15
15
  class CreateCommand extends ApifyCommand {
@@ -78,7 +78,9 @@ class CreateCommand extends ApifyCommand {
78
78
  const unzip = unzipper.Extract({ path: actFolderDir });
79
79
  await zipStream.pipe(unzip).promise();
80
80
 
81
- await setLocalConfig(Object.assign(EMPTY_LOCAL_CONFIG, { name: actorName, template: templateName }), actFolderDir);
81
+ // There may be .actor/actor.json file in used template - let's try to load it and change the name prop value to actorName
82
+ const localConfig = await getLocalConfig();
83
+ await setLocalConfig(Object.assign(localConfig || EMPTY_LOCAL_CONFIG, { name: actorName }), actFolderDir);
82
84
  await setLocalEnv(actFolderDir);
83
85
  await updateLocalJson(path.join(actFolderDir, 'package.json'), { name: actorName });
84
86
 
@@ -1,4 +1,5 @@
1
1
  const fs = require('fs');
2
+ const path = require('path');
2
3
 
3
4
  const cors = require('cors');
4
5
  const detectIndent = require('detect-indent');
@@ -9,22 +10,30 @@ const { cryptoRandomObjectId } = require('@apify/utilities');
9
10
 
10
11
  const { ApifyCommand } = require('../lib/apify_command');
11
12
  const outputs = require('../lib/outputs');
13
+ const { readInputSchema } = require('../lib/input_schema');
14
+ const { LOCAL_CONFIG_PATH } = require('../lib/consts');
12
15
 
13
16
  const INPUT_SCHEMA_EDITOR_BASE_URL = 'https://apify.github.io/input-schema-editor-react/';
14
17
  const INPUT_SCHEMA_EDITOR_ORIGIN = new URL(INPUT_SCHEMA_EDITOR_BASE_URL).origin;
15
18
 
16
- const DEFAULT_INPUT_SCHEMA_PATH = './INPUT_SCHEMA.json';
17
-
18
19
  // Not really checked right now, but it might come useful if we ever need to do some breaking changes
19
20
  const API_VERSION = 'v1';
20
21
 
21
22
  class EditInputSchemaCommand extends ApifyCommand {
22
23
  async run() {
23
24
  const { args } = this.parse(EditInputSchemaCommand);
24
- const { path = DEFAULT_INPUT_SCHEMA_PATH } = args;
25
+
26
+ // This call fails if no input schema is found on any of the default locations
27
+ const { inputSchema: existingSchema, inputSchemaPath } = await readInputSchema(args.path);
28
+
29
+ if (existingSchema && !inputSchemaPath) {
30
+ // If path is not returned, it means the input schema must be directly embedded as object in actor.json
31
+ // TODO - allow editing input schema embedded in actor.json
32
+ throw new Error(`Editing an input schema directly embedded in "${LOCAL_CONFIG_PATH}" is not yet supported.`);
33
+ }
25
34
 
26
35
  outputs.warning('This command is still experimental and might break at any time. Use at your own risk.\n');
27
- outputs.info(`Editing input schema at "${path}"...`);
36
+ outputs.info(`Editing input schema at "${inputSchemaPath}"...`);
28
37
 
29
38
  let server;
30
39
  const app = express();
@@ -76,14 +85,18 @@ class EditInputSchemaCommand extends ApifyCommand {
76
85
  apiRouter.get('/input-schema', (req, res) => {
77
86
  let inputSchemaStr;
78
87
  try {
79
- inputSchemaStr = fs.readFileSync(path, { encoding: 'utf-8', flag: 'a+' });
80
- if (inputSchemaStr.length > 2) {
88
+ inputSchemaStr = fs.existsSync(inputSchemaPath) ? fs.readFileSync(inputSchemaPath, { encoding: 'utf-8' }) : '{}\n';
89
+ if (inputSchemaStr.length > 3) {
81
90
  jsonIndentation = detectIndent(inputSchemaStr).indent || jsonIndentation;
82
91
  }
83
92
  if (inputSchemaStr) {
84
93
  appendFinalNewline = inputSchemaStr[inputSchemaStr.length - 1] === '\n';
85
94
  }
86
- outputs.info('Input schema loaded from disk.');
95
+ if (fs.existsSync(inputSchemaPath)) {
96
+ outputs.info(`Input schema loaded from "${inputSchemaPath}"`);
97
+ } else {
98
+ outputs.info(`Empty input schema initialized.`);
99
+ }
87
100
  } catch (err) {
88
101
  const errorMessage = `Reading input schema from disk failed with: ${err.message}`;
89
102
  outputs.error(errorMessage);
@@ -113,7 +126,13 @@ class EditInputSchemaCommand extends ApifyCommand {
113
126
  const inputSchemaObj = req.body;
114
127
  let inputSchemaStr = JSON.stringify(inputSchemaObj, null, jsonIndentation);
115
128
  if (appendFinalNewline) inputSchemaStr += '\n';
116
- fs.writeFileSync(path, inputSchemaStr, { encoding: 'utf-8', flag: 'w+' });
129
+
130
+ const inputSchemaDir = path.dirname(inputSchemaPath);
131
+ if (!fs.existsSync(inputSchemaDir)) {
132
+ fs.mkdirSync(inputSchemaDir, { recursive: true });
133
+ }
134
+
135
+ fs.writeFileSync(inputSchemaPath, inputSchemaStr, { encoding: 'utf-8', flag: 'w+' });
117
136
  res.end();
118
137
  outputs.info('Input schema saved to disk.');
119
138
  } catch (err) {
@@ -145,13 +164,13 @@ class EditInputSchemaCommand extends ApifyCommand {
145
164
  }
146
165
  }
147
166
 
148
- EditInputSchemaCommand.description = 'Lets you edit your input schema in a visual input schema editor.';
167
+ EditInputSchemaCommand.description = 'Lets you edit your input schema that would be used on the platform in a visual input schema editor.';
149
168
 
150
169
  EditInputSchemaCommand.args = [
151
170
  {
152
171
  name: 'path',
153
172
  required: false,
154
- description: 'Optional path to your INPUT_SCHEMA.json file. If not provided ./INPUT_SCHEMA.json is used.',
173
+ description: 'Optional path to your INPUT_SCHEMA.json file. If not provided default platform location for input schema is used.',
155
174
  },
156
175
  ];
157
176
 
@@ -2,8 +2,8 @@ const inquirer = require('inquirer');
2
2
  const path = require('path');
3
3
  const { ApifyCommand } = require('../lib/apify_command');
4
4
  const outputs = require('../lib/outputs');
5
- const { setLocalConfig, setLocalEnv, getLocalConfig } = require('../lib/utils');
6
- const { EMPTY_LOCAL_CONFIG, DEFAULT_LOCAL_STORAGE_DIR } = require('../lib/consts');
5
+ const { setLocalConfig, setLocalEnv, getLocalConfig, getLocalConfigOrThrow } = require('../lib/utils');
6
+ const { EMPTY_LOCAL_CONFIG, DEFAULT_LOCAL_STORAGE_DIR, LOCAL_CONFIG_PATH } = require('../lib/consts');
7
7
 
8
8
  class InitCommand extends ApifyCommand {
9
9
  async run() {
@@ -12,13 +12,15 @@ class InitCommand extends ApifyCommand {
12
12
  const cwd = process.cwd();
13
13
 
14
14
  if (getLocalConfig()) {
15
- outputs.warning('Skipping creation of apify.json, the file already exists in the current directory.');
15
+ outputs.warning(`Skipping creation of "${LOCAL_CONFIG_PATH}", the file already exists in the current directory.`);
16
16
  } else {
17
17
  if (!actorName) {
18
18
  const answer = await inquirer.prompt([{ name: 'actName', message: 'Actor name:', default: path.basename(cwd) }]);
19
19
  ({ actName: actorName } = answer);
20
20
  }
21
- await setLocalConfig(Object.assign(EMPTY_LOCAL_CONFIG, { name: actorName }), cwd);
21
+ // Migrate apify.json to .actor/actor.json
22
+ const localConfig = { ...EMPTY_LOCAL_CONFIG, ...await getLocalConfigOrThrow() };
23
+ await setLocalConfig(Object.assign(localConfig, { name: actorName }), cwd);
22
24
  }
23
25
  await setLocalEnv(cwd);
24
26
  outputs.success('The Apify actor has been initialized in the current directory.');
@@ -26,7 +28,7 @@ class InitCommand extends ApifyCommand {
26
28
  }
27
29
 
28
30
  InitCommand.description = 'Initializes a new actor project in an existing directory.\n'
29
- + `The command only creates the "apify.json" file and the "${DEFAULT_LOCAL_STORAGE_DIR}" directory in the current directory, `
31
+ + `The command only creates the "${LOCAL_CONFIG_PATH}" file and the "${DEFAULT_LOCAL_STORAGE_DIR}" directory in the current directory, `
30
32
  + 'but will not touch anything else.\n\n'
31
33
  + `WARNING: The directory at "${DEFAULT_LOCAL_STORAGE_DIR}" will be overwritten if it already exists.`;
32
34
 
@@ -8,7 +8,7 @@ const { createActZip, getLoggedClientOrThrow,
8
8
  outputJobLog, getLocalUserInfo, getActorLocalFilePaths,
9
9
  createSourceFiles, getLocalConfigOrThrow } = require('../lib/utils');
10
10
  const { sumFilesSizeInBytes } = require('../lib/files');
11
- const { UPLOADS_STORE_NAME } = require('../lib/consts');
11
+ const { UPLOADS_STORE_NAME, LOCAL_CONFIG_PATH } = require('../lib/consts');
12
12
  const { transformEnvToEnvVars } = require('../lib/secrets');
13
13
  const outputs = require('../lib/outputs');
14
14
 
@@ -94,15 +94,17 @@ class PushCommand extends ApifyCommand {
94
94
  contentType: 'application/zip',
95
95
  });
96
96
  fs.unlinkSync(TEMP_ZIP_FILE_NAME);
97
- tarballUrl = `https://api.apify.com/v2/key-value-stores/${store.id}/records/${key}?disableRedirect=true`;
97
+ tarballUrl = `${apifyClient.baseUrl}/key-value-stores/${store.id}/records/${key}?disableRedirect=true`;
98
98
  sourceType = ACT_SOURCE_TYPES.TARBALL;
99
99
  }
100
100
 
101
101
  // Update actor version
102
102
  const actorCurrentVersion = await actorClient.version(version).get();
103
+ const envVars = localConfig.environmentVariables
104
+ ? transformEnvToEnvVars(localConfig.environmentVariables)
105
+ : undefined;
103
106
  if (actorCurrentVersion) {
104
- const actorVersionModifier = { tarballUrl, sourceFiles, buildTag, sourceType };
105
- if (localConfig.env) actorVersionModifier.envVars = transformEnvToEnvVars(localConfig.env);
107
+ const actorVersionModifier = { tarballUrl, sourceFiles, buildTag, sourceType, envVars };
106
108
  await actorClient.version(version).update(actorVersionModifier);
107
109
  outputs.run(`Updated version ${version} for ${actor.name} actor.`);
108
110
  } else {
@@ -112,8 +114,8 @@ class PushCommand extends ApifyCommand {
112
114
  sourceFiles,
113
115
  buildTag,
114
116
  sourceType,
117
+ envVars,
115
118
  };
116
- if (localConfig.env) actorNewVersion.envVars = transformEnvToEnvVars(localConfig.env);
117
119
  await actorClient.versions().create({
118
120
  versionNumber: version,
119
121
  ...actorNewVersion,
@@ -150,7 +152,7 @@ class PushCommand extends ApifyCommand {
150
152
  }
151
153
 
152
154
  PushCommand.description = 'Uploads the actor to the Apify platform and builds it there.\n'
153
- + 'The actor settings are read from the "apify.json" file in the current directory, but they can be overridden using command-line options.\n'
155
+ + `The actor settings are read from the "${LOCAL_CONFIG_PATH}" file in the current directory, but they can be overridden using command-line options.\n`
154
156
  + `NOTE: If the source files are smaller than ${MAX_MULTIFILE_BYTES / (1024 ** 2)} MB then they are uploaded as \n`
155
157
  + '"Multiple source files", otherwise they are uploaded as "Zip file".\n\n'
156
158
  + 'WARNING: If the target actor already exists in your Apify account, it will be overwritten!';
@@ -158,17 +160,17 @@ PushCommand.description = 'Uploads the actor to the Apify platform and builds it
158
160
  PushCommand.flags = {
159
161
  'version-number': flagsHelper.string({
160
162
  description: 'DEPRECATED: Use flag version instead. Actor version number to which the files should be pushed. '
161
- + 'By default, it is taken from the "apify.json" file.',
163
+ + `By default, it is taken from the "${LOCAL_CONFIG_PATH}" file.`,
162
164
  required: false,
163
165
  }),
164
166
  version: flagsHelper.string({
165
167
  char: 'v',
166
- description: 'Actor version number to which the files should be pushed. By default, it is taken from the "apify.json" file.',
168
+ description: `Actor version number to which the files should be pushed. By default, it is taken from the "${LOCAL_CONFIG_PATH}" file.`,
167
169
  required: false,
168
170
  }),
169
171
  'build-tag': flagsHelper.string({
170
172
  char: 'b',
171
- description: 'Build tag to be applied to the successful actor build. By default, it is taken from the "apify.json" file',
173
+ description: `Build tag to be applied to the successful actor build. By default, it is taken from the "${LOCAL_CONFIG_PATH}" file`,
172
174
  required: false,
173
175
  }),
174
176
  'wait-for-finish': flagsHelper.string({
@@ -183,7 +185,7 @@ PushCommand.args = [
183
185
  name: 'actorId',
184
186
  required: false,
185
187
  description: 'ID of an existing actor on the Apify platform where the files will be pushed. '
186
- + 'If not provided, the command will create or modify the actor with the name specified in "apify.json" file.',
188
+ + `If not provided, the command will create or modify the actor with the name specified in "${LOCAL_CONFIG_PATH}" file.`,
187
189
  },
188
190
  ];
189
191
 
@@ -71,8 +71,8 @@ class RunCommand extends ApifyCommand {
71
71
  if (proxy && proxy.password) localEnvVars[ENV_VARS.PROXY_PASSWORD] = proxy.password;
72
72
  if (userId) localEnvVars[ENV_VARS.USER_ID] = userId;
73
73
  if (token) localEnvVars[ENV_VARS.TOKEN] = token;
74
- if (localConfig.env) {
75
- const updatedEnv = replaceSecretsValue(localConfig.env);
74
+ if (localConfig.environmentVariables) {
75
+ const updatedEnv = replaceSecretsValue(localConfig.environmentVariables);
76
76
  Object.assign(localEnvVars, updatedEnv);
77
77
  }
78
78
  // NOTE: User can overwrite env vars
@@ -106,7 +106,7 @@ RunCommand.description = 'Runs the actor locally in the current directory by exe
106
106
  + 'the actor input, as well as all other data in key-value stores, '
107
107
  + `datasets or request queues to be stored in the "${DEFAULT_LOCAL_STORAGE_DIR}" directory, `
108
108
  + 'rather than on the Apify platform.\n\n'
109
- + 'NOTE: You can override the default behaviour of command overriding npm start script value in a package.json file. '
109
+ + 'NOTE: You can override the command\'s default behavior by overriding the npm start script value in a package.json file. '
110
110
  + 'You can set up your own main file or environment variables by changing it.';
111
111
 
112
112
  RunCommand.flags = {
@@ -1,4 +1,5 @@
1
1
  const { Command } = require('@oclif/command');
2
+ const { LOCAL_CONFIG_PATH } = require('../../lib/consts');
2
3
  const { showHelpForCommand } = require('../../lib/utils');
3
4
 
4
5
  class SecretsIndexCommand extends Command {
@@ -10,10 +11,11 @@ class SecretsIndexCommand extends Command {
10
11
  SecretsIndexCommand.description = 'Manages secret values for actor environment variables.\n\n'
11
12
  + 'Example:\n'
12
13
  + '$ apify secrets:add mySecret TopSecretValue123\n\n'
13
- + 'Now the "mySecret" value can be used in an environment variable defined in "apify.json" file by adding the "@" prefix:\n\n'
14
+ + `Now the "mySecret" value can be used in an environment variable defined in "${LOCAL_CONFIG_PATH}" file by adding the "@" prefix:\n\n`
14
15
  + '{\n'
16
+ + ' "actorSpecification": 1,\n'
15
17
  + ' "name": "my_actor",\n'
16
- + ' "env": { "SECRET_ENV_VAR": "@mySecret" },\n'
18
+ + ' "environmentVariables": { "SECRET_ENV_VAR": "@mySecret" },\n'
17
19
  + ' "version": "0.1\n'
18
20
  + '}\n\n'
19
21
  + 'When the actor is pushed to Apify cloud, the "SECRET_ENV_VAR" and its value is stored as a secret environment variable of the actor.';
@@ -1,32 +1,42 @@
1
1
  const { validateInputSchema } = require('@apify/input_schema');
2
2
  const Ajv = require('ajv');
3
- const fs = require('fs');
4
3
  const { ApifyCommand } = require('../lib/apify_command');
4
+ const { LOCAL_CONFIG_PATH } = require('../lib/consts');
5
+ const { readInputSchema } = require('../lib/input_schema');
5
6
  const outputs = require('../lib/outputs');
6
7
 
7
- const DEFAULT_INPUT_SCHEMA_PATH = './INPUT_SCHEMA.json';
8
-
9
8
  class ValidateInputSchemaCommand extends ApifyCommand {
10
9
  async run() {
11
10
  const { args } = this.parse(ValidateInputSchemaCommand);
12
- const { path = DEFAULT_INPUT_SCHEMA_PATH } = args;
13
- const validator = new Ajv({ strict: false });
14
11
 
15
- let inputSchemaObj;
12
+ const { inputSchema, inputSchemaPath } = await readInputSchema(args.path);
13
+
14
+ if (!inputSchema) {
15
+ throw new Error(`Input schema has not been found at ${inputSchemaPath}.`);
16
+ }
16
17
 
17
- try {
18
- const inputSchemaStr = fs.readFileSync(path).toString();
19
- inputSchemaObj = JSON.parse(inputSchemaStr);
20
- } catch (err) {
21
- throw new Error(`Input schema is not a valid JSON (${err})`);
18
+ if (inputSchemaPath) {
19
+ outputs.info(`Validating input schema stored at ${inputSchemaPath}`);
20
+ } else {
21
+ outputs.info(`Validating input schema embedded in "${LOCAL_CONFIG_PATH}"`);
22
22
  }
23
23
 
24
- validateInputSchema(validator, inputSchemaObj); // This one throws an error in a case of invalid schema.
24
+ const validator = new Ajv({ strict: false });
25
+ validateInputSchema(validator, inputSchema); // This one throws an error in a case of invalid schema.
25
26
  outputs.success('Input schema is valid.');
26
27
  }
27
28
  }
28
29
 
29
- ValidateInputSchemaCommand.description = 'Validates INPUT_SCHEMA.json file and prints errors found.';
30
+ ValidateInputSchemaCommand.description = `Validates input schema and prints errors found.
31
+ The input schema for the actor is used from these locations in order of preference.
32
+ The first one found is validated as it would be the one used on the Apify platform.
33
+ 1. Directly embedded object in "${LOCAL_CONFIG_PATH}" under 'input' key
34
+ 2. Path to JSON file referenced in "${LOCAL_CONFIG_PATH}" under 'input' key
35
+ 3. JSON file at .actor/INPUT_SCHEMA.json
36
+ 4. JSON file at INPUT_SCHEMA.json
37
+
38
+ You can also pass any custom path to your input schema to have it validated instead.
39
+ `;
30
40
 
31
41
  ValidateInputSchemaCommand.args = [
32
42
  {
package/src/lib/consts.js CHANGED
@@ -6,11 +6,14 @@ exports.DEFAULT_LOCAL_STORAGE_DIR = 'storage';
6
6
 
7
7
  exports.LEGACY_LOCAL_STORAGE_DIR = 'apify_storage';
8
8
 
9
+ exports.ACTOR_SPECIFICATION_VERSION = 1;
10
+
9
11
  exports.EMPTY_LOCAL_CONFIG = {
12
+ actorSpecification: exports.ACTOR_SPECIFICATION_VERSION,
10
13
  name: null,
11
14
  version: '0.0',
12
15
  buildTag: 'latest',
13
- env: null,
16
+ environmentVariables: {},
14
17
  };
15
18
 
16
19
  exports.GLOBAL_CONFIGS_FOLDER = path.join(os.homedir(), '.apify');
@@ -19,7 +22,13 @@ exports.AUTH_FILE_PATH = path.join(exports.GLOBAL_CONFIGS_FOLDER, 'auth.json');
19
22
 
20
23
  exports.SECRETS_FILE_PATH = path.join(exports.GLOBAL_CONFIGS_FOLDER, 'secrets.json');
21
24
 
22
- exports.LOCAL_CONFIG_NAME = 'apify.json';
25
+ exports.DEPRECATED_LOCAL_CONFIG_NAME = 'apify.json';
26
+
27
+ exports.ACTOR_SPECIFICATION_FOLDER = '.actor';
28
+
29
+ exports.LOCAL_CONFIG_NAME = 'actor.json';
30
+
31
+ exports.LOCAL_CONFIG_PATH = path.join(exports.ACTOR_SPECIFICATION_FOLDER, exports.LOCAL_CONFIG_NAME);
23
32
 
24
33
  exports.INPUT_FILE_REG_EXP = new RegExp(`^${KEY_VALUE_STORE_KEYS.INPUT}\\..*`);
25
34
 
@@ -0,0 +1,70 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { ACTOR_SPECIFICATION_FOLDER } = require('./consts');
4
+ const { getLocalConfig, getJsonFileContent } = require('./utils');
5
+
6
+ const DEFAULT_INPUT_SCHEMA_PATHS = [
7
+ '.actor/INPUT_SCHEMA.json',
8
+ './INPUT_SCHEMA.json',
9
+ ];
10
+
11
+ /**
12
+ * Return the input schema from the default location.
13
+ *
14
+ * When the input schema does not exist, null is returned for schema.
15
+ * In such a acase, path would be set to the location
16
+ * where the input schema would be expected to be found (and e.g. can be created there).
17
+ *
18
+ * @param {string} forcePath
19
+ * @returns {{inputSchema: object, inputSchemaPath: string | null}}
20
+ */
21
+ const readInputSchema = async (forcePath) => {
22
+ if (forcePath) {
23
+ return {
24
+ inputSchema: await getJsonFileContent(forcePath),
25
+ inputSchemaPath: forcePath,
26
+ };
27
+ }
28
+
29
+ const localConfig = getLocalConfig();
30
+
31
+ if (typeof localConfig?.input === 'object') {
32
+ return {
33
+ inputSchema: localConfig.input,
34
+ inputSchemaPath: null,
35
+ };
36
+ }
37
+
38
+ if (typeof localConfig?.input === 'string') {
39
+ const fullPath = path.join(ACTOR_SPECIFICATION_FOLDER, localConfig.input);
40
+ return {
41
+ inputSchema: await getJsonFileContent(fullPath),
42
+ inputSchemaPath: fullPath,
43
+ };
44
+ }
45
+
46
+ if (fs.existsSync(DEFAULT_INPUT_SCHEMA_PATHS[0])) {
47
+ return {
48
+ inputSchema: await getJsonFileContent(DEFAULT_INPUT_SCHEMA_PATHS[0]),
49
+ inputSchemaPath: DEFAULT_INPUT_SCHEMA_PATHS[0],
50
+ };
51
+ }
52
+
53
+ if (fs.existsSync(DEFAULT_INPUT_SCHEMA_PATHS[1])) {
54
+ return {
55
+ inputSchema: await getJsonFileContent(DEFAULT_INPUT_SCHEMA_PATHS[1]),
56
+ inputSchemaPath: DEFAULT_INPUT_SCHEMA_PATHS[1],
57
+ };
58
+ }
59
+
60
+ // If not input schema has been found so far, return the first default path
61
+ // where the input schema would be expected.
62
+ return {
63
+ inputSchema: null,
64
+ inputSchemaPath: DEFAULT_INPUT_SCHEMA_PATHS[0],
65
+ };
66
+ };
67
+
68
+ module.exports = {
69
+ readInputSchema,
70
+ };