apify-cli 0.19.3-beta.4 → 1.0.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.
Files changed (231) hide show
  1. package/README.md +87 -63
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +16 -0
  4. package/bin/run.js +16 -0
  5. package/dist/.tsbuildinfo +1 -0
  6. package/dist/commands/actor/get-input.d.ts +6 -0
  7. package/dist/commands/actor/get-input.d.ts.map +1 -0
  8. package/dist/commands/actor/get-input.js +14 -0
  9. package/dist/commands/actor/get-input.js.map +1 -0
  10. package/dist/commands/actor/get-value.d.ts +9 -0
  11. package/dist/commands/actor/get-value.d.ts.map +1 -0
  12. package/dist/commands/actor/get-value.js +27 -0
  13. package/dist/commands/actor/get-value.js.map +1 -0
  14. package/dist/commands/actor/index.d.ts +6 -0
  15. package/dist/commands/actor/index.d.ts.map +1 -0
  16. package/dist/commands/actor/index.js +13 -0
  17. package/dist/commands/actor/index.js.map +1 -0
  18. package/dist/commands/actor/push-data.d.ts +11 -0
  19. package/dist/commands/actor/push-data.d.ts.map +1 -0
  20. package/dist/commands/actor/push-data.js +56 -0
  21. package/dist/commands/actor/push-data.js.map +1 -0
  22. package/dist/commands/actor/set-value.d.ts +15 -0
  23. package/dist/commands/actor/set-value.d.ts.map +1 -0
  24. package/dist/commands/actor/set-value.js +76 -0
  25. package/dist/commands/actor/set-value.js.map +1 -0
  26. package/dist/commands/call.d.ts +15 -0
  27. package/dist/commands/call.d.ts.map +1 -0
  28. package/dist/commands/call.js +142 -0
  29. package/dist/commands/call.js.map +1 -0
  30. package/dist/commands/check-version.d.ts +11 -0
  31. package/dist/commands/check-version.d.ts.map +1 -0
  32. package/dist/commands/check-version.js +39 -0
  33. package/dist/commands/check-version.js.map +1 -0
  34. package/dist/commands/create.d.ts +14 -0
  35. package/dist/commands/create.d.ts.map +1 -0
  36. package/dist/commands/create.js +181 -0
  37. package/dist/commands/create.js.map +1 -0
  38. package/dist/commands/edit-input-schema.d.ts +11 -0
  39. package/dist/commands/edit-input-schema.d.ts.map +1 -0
  40. package/{src → dist}/commands/edit-input-schema.js +81 -85
  41. package/dist/commands/edit-input-schema.js.map +1 -0
  42. package/dist/commands/info.d.ts +6 -0
  43. package/dist/commands/info.d.ts.map +1 -0
  44. package/dist/commands/info.js +26 -0
  45. package/dist/commands/info.js.map +1 -0
  46. package/dist/commands/init-wrap-scrapy.d.ts +10 -0
  47. package/dist/commands/init-wrap-scrapy.d.ts.map +1 -0
  48. package/dist/commands/init-wrap-scrapy.js +41 -0
  49. package/dist/commands/init-wrap-scrapy.js.map +1 -0
  50. package/dist/commands/init.d.ts +12 -0
  51. package/dist/commands/init.d.ts.map +1 -0
  52. package/dist/commands/init.js +88 -0
  53. package/dist/commands/init.js.map +1 -0
  54. package/dist/commands/login-new.d.ts +10 -0
  55. package/dist/commands/login-new.d.ts.map +1 -0
  56. package/{src → dist}/commands/login-new.js +79 -82
  57. package/dist/commands/login-new.js.map +1 -0
  58. package/dist/commands/login.d.ts +9 -0
  59. package/dist/commands/login.d.ts.map +1 -0
  60. package/dist/commands/login.js +43 -0
  61. package/dist/commands/login.js.map +1 -0
  62. package/dist/commands/logout.d.ts +6 -0
  63. package/dist/commands/logout.d.ts.map +1 -0
  64. package/dist/commands/logout.js +20 -0
  65. package/dist/commands/logout.js.map +1 -0
  66. package/dist/commands/pull.d.ts +12 -0
  67. package/dist/commands/pull.d.ts.map +1 -0
  68. package/dist/commands/pull.js +148 -0
  69. package/dist/commands/pull.js.map +1 -0
  70. package/dist/commands/push.d.ts +16 -0
  71. package/dist/commands/push.d.ts.map +1 -0
  72. package/dist/commands/push.js +242 -0
  73. package/dist/commands/push.js.map +1 -0
  74. package/dist/commands/run.d.ts +12 -0
  75. package/dist/commands/run.d.ts.map +1 -0
  76. package/{src → dist}/commands/run.js +96 -109
  77. package/dist/commands/run.js.map +1 -0
  78. package/dist/commands/secrets/add.d.ts +10 -0
  79. package/dist/commands/secrets/add.d.ts.map +1 -0
  80. package/dist/commands/secrets/add.js +31 -0
  81. package/dist/commands/secrets/add.js.map +1 -0
  82. package/dist/commands/secrets/index.d.ts +6 -0
  83. package/dist/commands/secrets/index.d.ts.map +1 -0
  84. package/dist/commands/secrets/index.js +24 -0
  85. package/dist/commands/secrets/index.js.map +1 -0
  86. package/dist/commands/secrets/rm.d.ts +9 -0
  87. package/dist/commands/secrets/rm.d.ts.map +1 -0
  88. package/dist/commands/secrets/rm.js +27 -0
  89. package/dist/commands/secrets/rm.js.map +1 -0
  90. package/dist/commands/vis.d.ts +9 -0
  91. package/dist/commands/vis.d.ts.map +1 -0
  92. package/dist/commands/vis.js +52 -0
  93. package/dist/commands/vis.js.map +1 -0
  94. package/dist/hooks/init.d.ts +7 -0
  95. package/dist/hooks/init.d.ts.map +1 -0
  96. package/dist/hooks/init.js +17 -0
  97. package/dist/hooks/init.js.map +1 -0
  98. package/dist/index.d.ts +2 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +3 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/lib/actor.d.ts +27 -0
  103. package/dist/lib/actor.d.ts.map +1 -0
  104. package/{src → dist}/lib/actor.js +21 -44
  105. package/dist/lib/actor.js.map +1 -0
  106. package/dist/lib/apify-oclif-help.d.ts +15 -0
  107. package/dist/lib/apify-oclif-help.d.ts.map +1 -0
  108. package/dist/lib/apify-oclif-help.js +19 -0
  109. package/dist/lib/apify-oclif-help.js.map +1 -0
  110. package/dist/lib/apify_command.d.ts +22 -0
  111. package/dist/lib/apify_command.d.ts.map +1 -0
  112. package/dist/lib/apify_command.js +103 -0
  113. package/dist/lib/apify_command.js.map +1 -0
  114. package/dist/lib/community.d.ts +2 -0
  115. package/dist/lib/community.d.ts.map +1 -0
  116. package/dist/lib/community.js +4 -0
  117. package/dist/lib/community.js.map +1 -0
  118. package/dist/lib/consts.d.ts +45 -0
  119. package/dist/lib/consts.d.ts.map +1 -0
  120. package/dist/lib/consts.js +54 -0
  121. package/dist/lib/consts.js.map +1 -0
  122. package/dist/lib/create-utils.d.ts +8 -0
  123. package/dist/lib/create-utils.d.ts.map +1 -0
  124. package/{src → dist}/lib/create-utils.js +74 -113
  125. package/dist/lib/create-utils.js.map +1 -0
  126. package/dist/lib/exec.d.ts +4 -0
  127. package/dist/lib/exec.d.ts.map +1 -0
  128. package/{src → dist}/lib/exec.js +15 -16
  129. package/dist/lib/exec.js.map +1 -0
  130. package/dist/lib/files.d.ts +14 -0
  131. package/dist/lib/files.d.ts.map +1 -0
  132. package/dist/lib/files.js +58 -0
  133. package/dist/lib/files.js.map +1 -0
  134. package/dist/lib/input_schema.d.ts +26 -0
  135. package/dist/lib/input_schema.d.ts.map +1 -0
  136. package/{src → dist}/lib/input_schema.js +34 -55
  137. package/dist/lib/input_schema.js.map +1 -0
  138. package/dist/lib/local_state.d.ts +11 -0
  139. package/dist/lib/local_state.d.ts.map +1 -0
  140. package/dist/lib/local_state.js +27 -0
  141. package/dist/lib/local_state.js.map +1 -0
  142. package/dist/lib/outputs.d.ts +7 -0
  143. package/dist/lib/outputs.d.ts.map +1 -0
  144. package/{src → dist}/lib/outputs.js +8 -15
  145. package/dist/lib/outputs.js.map +1 -0
  146. package/dist/lib/project_analyzer.d.ts +4 -0
  147. package/dist/lib/project_analyzer.d.ts.map +1 -0
  148. package/{src → dist}/lib/project_analyzer.js +6 -11
  149. package/dist/lib/project_analyzer.js.map +1 -0
  150. package/dist/lib/projects/CrawleeAnalyzer.d.ts +4 -0
  151. package/dist/lib/projects/CrawleeAnalyzer.d.ts.map +1 -0
  152. package/{src → dist}/lib/projects/CrawleeAnalyzer.js +7 -24
  153. package/dist/lib/projects/CrawleeAnalyzer.js.map +1 -0
  154. package/dist/lib/projects/OldApifySDKAnalyzer.d.ts +4 -0
  155. package/dist/lib/projects/OldApifySDKAnalyzer.d.ts.map +1 -0
  156. package/{src → dist}/lib/projects/OldApifySDKAnalyzer.js +9 -32
  157. package/dist/lib/projects/OldApifySDKAnalyzer.js.map +1 -0
  158. package/dist/lib/projects/scrapy/ScrapyProjectAnalyzer.d.ts +17 -0
  159. package/dist/lib/projects/scrapy/ScrapyProjectAnalyzer.d.ts.map +1 -0
  160. package/{src/lib/scrapy-wrapper → dist/lib/projects/scrapy}/ScrapyProjectAnalyzer.js +33 -36
  161. package/dist/lib/projects/scrapy/ScrapyProjectAnalyzer.js.map +1 -0
  162. package/dist/lib/projects/scrapy/Spider.d.ts +14 -0
  163. package/dist/lib/projects/scrapy/Spider.d.ts.map +1 -0
  164. package/dist/lib/projects/scrapy/Spider.js +33 -0
  165. package/dist/lib/projects/scrapy/Spider.js.map +1 -0
  166. package/dist/lib/projects/scrapy/SpiderFileAnalyzer.d.ts +7 -0
  167. package/dist/lib/projects/scrapy/SpiderFileAnalyzer.d.ts.map +1 -0
  168. package/dist/lib/projects/scrapy/SpiderFileAnalyzer.js +25 -0
  169. package/dist/lib/projects/scrapy/SpiderFileAnalyzer.js.map +1 -0
  170. package/dist/lib/projects/scrapy/wrapScrapyProject.d.ts +4 -0
  171. package/dist/lib/projects/scrapy/wrapScrapyProject.d.ts.map +1 -0
  172. package/{src/lib/scrapy-wrapper/index.js → dist/lib/projects/scrapy/wrapScrapyProject.js} +43 -73
  173. package/dist/lib/projects/scrapy/wrapScrapyProject.js.map +1 -0
  174. package/dist/lib/projects/shared.d.ts +2 -0
  175. package/dist/lib/projects/shared.d.ts.map +1 -0
  176. package/dist/lib/projects/shared.js +13 -0
  177. package/dist/lib/projects/shared.js.map +1 -0
  178. package/dist/lib/secrets.d.ts +22 -0
  179. package/dist/lib/secrets.d.ts.map +1 -0
  180. package/{src → dist}/lib/secrets.js +32 -40
  181. package/dist/lib/secrets.js.map +1 -0
  182. package/dist/lib/telemetry.d.ts +21 -0
  183. package/dist/lib/telemetry.d.ts.map +1 -0
  184. package/dist/lib/telemetry.js +87 -0
  185. package/dist/lib/telemetry.js.map +1 -0
  186. package/dist/lib/types.d.ts +11 -0
  187. package/dist/lib/types.d.ts.map +1 -0
  188. package/dist/lib/types.js +2 -0
  189. package/dist/lib/types.js.map +1 -0
  190. package/dist/lib/utils.d.ts +106 -0
  191. package/dist/lib/utils.d.ts.map +1 -0
  192. package/{src → dist}/lib/utils.js +235 -347
  193. package/dist/lib/utils.js.map +1 -0
  194. package/dist/lib/version_check.d.ts +14 -0
  195. package/dist/lib/version_check.d.ts.map +1 -0
  196. package/{src → dist}/lib/version_check.js +25 -54
  197. package/dist/lib/version_check.js.map +1 -0
  198. package/oclif.manifest.json +722 -1
  199. package/package.json +137 -113
  200. package/index.js +0 -1
  201. package/src/bin/run +0 -16
  202. package/src/commands/actor/get-input.js +0 -12
  203. package/src/commands/actor/get-value.js +0 -23
  204. package/src/commands/actor/index.js +0 -13
  205. package/src/commands/actor/push-data.js +0 -44
  206. package/src/commands/actor/set-value.js +0 -63
  207. package/src/commands/call.js +0 -131
  208. package/src/commands/check-version.js +0 -28
  209. package/src/commands/create.js +0 -203
  210. package/src/commands/info.js +0 -24
  211. package/src/commands/init-wrap-scrapy.js +0 -34
  212. package/src/commands/init.js +0 -83
  213. package/src/commands/login.js +0 -40
  214. package/src/commands/logout.js +0 -18
  215. package/src/commands/pull.js +0 -154
  216. package/src/commands/push.js +0 -234
  217. package/src/commands/secrets/add.js +0 -28
  218. package/src/commands/secrets/index.js +0 -24
  219. package/src/commands/secrets/rm.js +0 -23
  220. package/src/commands/vis.js +0 -50
  221. package/src/hooks/init.js +0 -16
  222. package/src/lib/apify-oclif-help.js +0 -23
  223. package/src/lib/apify_command.js +0 -82
  224. package/src/lib/community.js +0 -3
  225. package/src/lib/consts.js +0 -69
  226. package/src/lib/files.js +0 -76
  227. package/src/lib/local_state.js +0 -39
  228. package/src/lib/scrapy-wrapper/Spider.js +0 -10
  229. package/src/lib/scrapy-wrapper/SpiderFileAnalyzer.js +0 -26
  230. package/src/lib/telemetry.js +0 -104
  231. /package/{src/bin → bin}/run.cmd +0 -0
@@ -1,203 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const actorTemplates = require('@apify/actor-templates');
5
- const { flags: flagsHelper } = require('@oclif/command');
6
- const semver = require('semver');
7
-
8
- const { ApifyCommand } = require('../lib/apify_command');
9
- const { EMPTY_LOCAL_CONFIG, LOCAL_CONFIG_PATH, PYTHON_VENV_PATH, SUPPORTED_NODEJS_VERSION } = require('../lib/consts');
10
- const {
11
- ensureValidActorName,
12
- getTemplateDefinition,
13
- enhanceReadmeWithLocalSuffix,
14
- } = require('../lib/create-utils');
15
- const execWithLog = require('../lib/exec');
16
- const { updateLocalJson } = require('../lib/files');
17
- const { createPrefilledInputFileFromInputSchema } = require('../lib/input_schema');
18
- const outputs = require('../lib/outputs');
19
- const {
20
- setLocalConfig,
21
- setLocalEnv,
22
- getNpmCmd,
23
- getJsonFileContent,
24
- detectPythonVersion,
25
- isPythonVersionSupported,
26
- getPythonCommand,
27
- detectNodeVersion,
28
- isNodeVersionSupported,
29
- detectNpmVersion,
30
- downloadAndUnzip,
31
- } = require('../lib/utils');
32
-
33
- class CreateCommand extends ApifyCommand {
34
- async run() {
35
- const { flags, args } = this.parse(CreateCommand);
36
- let { actorName } = args;
37
- const {
38
- template: templateName,
39
- skipDependencyInstall,
40
- } = flags;
41
-
42
- // --template-archive-url is an internal, undocumented flag that's used
43
- // for testing of templates that are not yet published in the manifest
44
- let { templateArchiveUrl } = flags;
45
- let skipOptionalDeps = false;
46
-
47
- // Start fetching manifest immediately to prevent
48
- // annoying delays that sometimes happen on CLI startup.
49
- const manifestPromise = actorTemplates.fetchManifest().catch((err) => {
50
- return new Error(`Could not fetch template list from server. Cause: ${err?.message}`);
51
- });
52
-
53
- actorName = await ensureValidActorName(actorName);
54
- let messages = null;
55
-
56
- this.telemetryData.fromArchiveUrl = !!templateArchiveUrl;
57
-
58
- if (!templateArchiveUrl) {
59
- const templateDefinition = await getTemplateDefinition(templateName, manifestPromise);
60
- ({ archiveUrl: templateArchiveUrl, skipOptionalDeps, messages } = templateDefinition);
61
- this.telemetryData.templateId = templateDefinition.id;
62
- this.telemetryData.templateName = templateDefinition.name;
63
- this.telemetryData.templateLanguage = templateDefinition.category;
64
- }
65
-
66
- const cwd = process.cwd();
67
- const actFolderDir = path.join(cwd, actorName);
68
-
69
- // Create actor directory structure
70
- try {
71
- fs.mkdirSync(actFolderDir);
72
- } catch (err) {
73
- if (err?.code === 'EEXIST') {
74
- outputs.error(`Cannot create new Actor, directory '${actorName}' already exists. `
75
- + 'You can use "apify init" to create a local Actor environment inside an existing directory.');
76
- return;
77
- }
78
- throw err;
79
- }
80
-
81
- await downloadAndUnzip({ url: templateArchiveUrl, pathTo: actFolderDir });
82
-
83
- // There may be .actor/actor.json file in used template - let's try to load it and change the name prop value to actorName
84
- const localConfig = await getJsonFileContent(path.join(actFolderDir, LOCAL_CONFIG_PATH));
85
- await setLocalConfig(Object.assign(localConfig || EMPTY_LOCAL_CONFIG, { name: actorName }), actFolderDir);
86
- await setLocalEnv(actFolderDir);
87
-
88
- // Create prefilled INPUT.json file from the input schema prefills
89
- await createPrefilledInputFileFromInputSchema(actFolderDir);
90
-
91
- const packageJsonPath = path.join(actFolderDir, 'package.json');
92
- const requirementsTxtPath = path.join(actFolderDir, 'requirements.txt');
93
- const readmePath = path.join(actFolderDir, 'README.md');
94
-
95
- // Add localReadmeSuffix which is fetched from manifest to README.md
96
- // The suffix contains local development instructions
97
- await enhanceReadmeWithLocalSuffix(readmePath, manifestPromise);
98
-
99
- let dependenciesInstalled = false;
100
- if (!skipDependencyInstall) {
101
- if (fs.existsSync(packageJsonPath)) {
102
- const currentNodeVersion = detectNodeVersion();
103
- const minimumSupportedNodeVersion = semver.minVersion(SUPPORTED_NODEJS_VERSION);
104
- if (currentNodeVersion) {
105
- if (!isNodeVersionSupported(currentNodeVersion)) {
106
- outputs.warning(`You are running Node.js version ${currentNodeVersion}, which is no longer supported. `
107
- + `Please upgrade to Node.js version ${minimumSupportedNodeVersion} or later.`);
108
- }
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) {
115
- const currentNpmVersion = detectNpmVersion();
116
- if (semver.gte(currentNpmVersion, '7.0.0')) {
117
- cmdArgs.push('--omit=optional');
118
- } else {
119
- cmdArgs.push('--no-optional');
120
- }
121
- }
122
- await execWithLog(getNpmCmd(), cmdArgs, { cwd: actFolderDir });
123
- dependenciesInstalled = true;
124
- } else {
125
- outputs.error(`No Node.js detected! Please install Node.js ${minimumSupportedNodeVersion} or higher`
126
- + ' to be able to run Node.js actors locally.');
127
- }
128
- } else if (fs.existsSync(requirementsTxtPath)) {
129
- const pythonVersion = detectPythonVersion(actFolderDir);
130
- if (pythonVersion) {
131
- if (isPythonVersionSupported(pythonVersion)) {
132
- const venvPath = path.join(actFolderDir, '.venv');
133
- outputs.info(`Python version ${pythonVersion} detected.`);
134
- outputs.info(`Creating a virtual environment in "${venvPath}" and installing dependencies from "requirements.txt"...`);
135
- let pythonCommand = getPythonCommand(actFolderDir);
136
- if (!process.env.VIRTUAL_ENV) {
137
- // If Python is not running in a virtual environment, create a new one
138
- await execWithLog(pythonCommand, ['-m', 'venv', '--prompt', '.', PYTHON_VENV_PATH], { cwd: actFolderDir });
139
- // regenerate the `pythonCommand` after we create the virtual environment
140
- pythonCommand = getPythonCommand(actFolderDir);
141
- }
142
- await execWithLog(
143
- pythonCommand,
144
- ['-m', 'pip', 'install', '--no-cache-dir', '--no-warn-script-location', '--upgrade', 'pip', 'setuptools', 'wheel'],
145
- { cwd: actFolderDir },
146
- );
147
- await execWithLog(
148
- pythonCommand,
149
- ['-m', 'pip', 'install', '--no-cache-dir', '--no-warn-script-location', '-r', 'requirements.txt'],
150
- { cwd: actFolderDir },
151
- );
152
- dependenciesInstalled = true;
153
- } else {
154
- outputs.warning(`Python actors require Python 3.8 or higher, but you have Python ${pythonVersion}!`);
155
- outputs.warning('Please install Python 3.8 or higher to be able to run Python actors locally.');
156
- }
157
- } else {
158
- outputs.warning('No Python detected! Please install Python 3.8 or higher to be able to run Python actors locally.');
159
- }
160
- }
161
- }
162
-
163
- if (dependenciesInstalled) {
164
- outputs.success(`Actor '${actorName}' was created. To run it, run "cd ${actorName}" and "apify run".`);
165
- outputs.success('To run your code in the cloud, run "apify push" and deploy your code to Apify Console.');
166
- if (messages?.postCreate) {
167
- outputs.info(messages?.postCreate);
168
- }
169
- } else {
170
- outputs.success(`Actor '${actorName}' was created. Please install its dependencies to be able to run it using "apify run".`);
171
- }
172
- }
173
- }
174
-
175
- CreateCommand.description = 'Creates a new Actor project directory from a selected boilerplate template.';
176
-
177
- CreateCommand.flags = {
178
- template: flagsHelper.string({
179
- char: 't',
180
- description: 'Template for the Actor. If not provided, the command will prompt for it.\n'
181
- + `Visit ${actorTemplates.manifestUrl} to find available template names.`,
182
- required: false,
183
- }),
184
- 'skip-dependency-install': flagsHelper.boolean({
185
- description: 'Skip installing Actor dependencies.',
186
- required: false,
187
- }),
188
- 'template-archive-url': flagsHelper.string({
189
- description: 'Actor template archive url. Useful for developing new templates.',
190
- required: false,
191
- hidden: true,
192
- }),
193
- };
194
-
195
- CreateCommand.args = [
196
- {
197
- name: 'actorName',
198
- required: false,
199
- description: 'Name of the Actor and its directory',
200
- },
201
- ];
202
-
203
- module.exports = CreateCommand;
@@ -1,24 +0,0 @@
1
- const chalk = require('chalk');
2
-
3
- const { ApifyCommand } = require('../lib/apify_command');
4
- const { getLoggedClientOrThrow, getLocalUserInfo } = require('../lib/utils');
5
-
6
- class InfoCommand extends ApifyCommand {
7
- async run() {
8
- await getLoggedClientOrThrow();
9
- const info = await getLocalUserInfo();
10
-
11
- if (info) {
12
- const niceInfo = {
13
- username: info.username,
14
- userId: info.id,
15
- };
16
- Object.keys(niceInfo).forEach((key) => console.log(`${chalk.gray(key)}: ${chalk.bold(niceInfo[key])}`));
17
- }
18
- }
19
- }
20
-
21
- InfoCommand.description = 'Displays information about the currently active Apify account.\n'
22
- + 'The information is printed to the console.';
23
-
24
- module.exports = InfoCommand;
@@ -1,34 +0,0 @@
1
- const { ApifyCommand } = require('../lib/apify_command');
2
- const { info } = require('../lib/outputs');
3
- const { wrapScrapyProject } = require('../lib/scrapy-wrapper/index');
4
-
5
- class WrapScrapyCommand extends ApifyCommand {
6
- async run() {
7
- const { args } = this.parse(WrapScrapyCommand);
8
-
9
- await wrapScrapyProject({ projectPath: args.path });
10
-
11
- info('Scrapy project wrapped successfully.');
12
- }
13
- }
14
-
15
- WrapScrapyCommand.hidden = true;
16
-
17
- WrapScrapyCommand.description = `Wraps your existing Scrapy project to work like an Apify Actor.
18
-
19
- It adds the following features:
20
- - Automatic retry of failed requests
21
- - Automatic proxy rotation
22
- - Automatic user agent rotation
23
- ...
24
- `;
25
-
26
- WrapScrapyCommand.args = [
27
- {
28
- name: 'path',
29
- required: false,
30
- description: 'Optional path to your scrapy project. If not provided, the current directory is used.',
31
- },
32
- ];
33
-
34
- module.exports = WrapScrapyCommand;
@@ -1,83 +0,0 @@
1
- const path = require('path');
2
-
3
- const { flags: flagsHelper } = require('@oclif/command');
4
- const inquirer = require('inquirer');
5
-
6
- const { ApifyCommand } = require('../lib/apify_command');
7
- const { EMPTY_LOCAL_CONFIG, DEFAULT_LOCAL_STORAGE_DIR, LOCAL_CONFIG_PATH, LANGUAGE, PROJECT_TYPES } = require('../lib/consts');
8
- const { createPrefilledInputFileFromInputSchema } = require('../lib/input_schema');
9
- const outputs = require('../lib/outputs');
10
- const { ProjectAnalyzer } = require('../lib/project_analyzer');
11
- const { wrapScrapyProject } = require('../lib/scrapy-wrapper');
12
- const { setLocalConfig, setLocalEnv, getLocalConfig, getLocalConfigOrThrow, detectLocalActorLanguage, validateActorName } = require('../lib/utils');
13
-
14
- class InitCommand extends ApifyCommand {
15
- async run() {
16
- const { args, flags } = this.parse(InitCommand);
17
- let { actorName } = args;
18
- const cwd = process.cwd();
19
-
20
- if (ProjectAnalyzer.getProjectType(cwd) === PROJECT_TYPES.SCRAPY) {
21
- outputs.info('The current directory looks like a Scrapy project. Using automatic project wrapping.');
22
- this.telemetryData.actorWrapper = PROJECT_TYPES.SCRAPY;
23
-
24
- return wrapScrapyProject({ projectPath: cwd });
25
- }
26
-
27
- if (!flags.yes && detectLocalActorLanguage(cwd).language === LANGUAGE.UNKNOWN) {
28
- outputs.warning('The current directory does not look like a Node.js or Python project.');
29
- const { c } = await inquirer.prompt([{ name: 'c', message: 'Do you want to continue?', type: 'confirm' }]);
30
- if (!c) return;
31
- }
32
-
33
- if (getLocalConfig()) {
34
- outputs.warning(`Skipping creation of "${LOCAL_CONFIG_PATH}", the file already exists in the current directory.`);
35
- } else {
36
- if (!actorName) {
37
- let response = null;
38
-
39
- while (!response) {
40
- try {
41
- const answer = await inquirer.prompt([{ name: 'actName', message: 'Actor name:', default: path.basename(cwd) }]);
42
- validateActorName(answer.actName);
43
- response = answer;
44
- } catch (err) {
45
- outputs.error(err.message);
46
- }
47
- }
48
-
49
- ({ actName: actorName } = response);
50
- }
51
- // Migrate apify.json to .actor/actor.json
52
- const localConfig = { ...EMPTY_LOCAL_CONFIG, ...await getLocalConfigOrThrow() };
53
- await setLocalConfig(Object.assign(localConfig, { name: actorName }), cwd);
54
- }
55
- await setLocalEnv(cwd);
56
- // Create prefilled INPUT.json file from the input schema prefills
57
- await createPrefilledInputFileFromInputSchema(cwd);
58
- outputs.success('The Actor has been initialized in the current directory.');
59
- }
60
- }
61
-
62
- InitCommand.description = 'Initializes a new Actor project in an existing directory.\n'
63
- + `The command only creates the "${LOCAL_CONFIG_PATH}" file and the "${DEFAULT_LOCAL_STORAGE_DIR}" directory in the current directory, `
64
- + 'but will not touch anything else.\n\n'
65
- + `WARNING: The directory at "${DEFAULT_LOCAL_STORAGE_DIR}" will be overwritten if it already exists.`;
66
-
67
- InitCommand.args = [
68
- {
69
- name: 'actorName',
70
- required: false,
71
- description: 'Name of the Actor. If not provided, you will be prompted for it.',
72
- },
73
- ];
74
-
75
- InitCommand.flags = {
76
- yes: flagsHelper.boolean({
77
- char: 'y',
78
- description: 'Automatic yes to prompts; assume "yes" as answer to all prompts. Note that in some cases, the command may still ask for confirmation.',
79
- required: false,
80
- }),
81
- };
82
-
83
- module.exports = InitCommand;
@@ -1,40 +0,0 @@
1
- const { flags: flagsHelper } = require('@oclif/command');
2
- const inquirer = require('inquirer');
3
-
4
- const { ApifyCommand } = require('../lib/apify_command');
5
- const { success, error } = require('../lib/outputs');
6
- const { useApifyIdentity } = require('../lib/telemetry');
7
- const { getLoggedClient } = require('../lib/utils');
8
- const { getLocalUserInfo } = require('../lib/utils');
9
-
10
- class LoginCommand extends ApifyCommand {
11
- async run() {
12
- const { flags } = this.parse(LoginCommand);
13
- let { token } = flags;
14
- if (!token) {
15
- console.log('Enter your Apify API token. You can find it at https://console.apify.com/account#/integrations');
16
- const tokenPrompt = await inquirer.prompt([{ name: 'token', message: 'token:', type: 'password' }]);
17
- ({ token } = tokenPrompt);
18
- }
19
- const isUserLogged = await getLoggedClient(token);
20
- const userInfo = getLocalUserInfo();
21
- await useApifyIdentity(userInfo.id);
22
- return isUserLogged
23
- ? success(`You are logged in to Apify as ${userInfo.username || userInfo.id}!`)
24
- : error('Login to Apify failed, the provided API token is not valid.');
25
- }
26
- }
27
-
28
- LoginCommand.description = 'Logs in to your Apify account using a provided API token.\nThe API token and other account '
29
- + 'information is stored in the ~/.apify directory, from where it is read by all other "apify" commands. '
30
- + 'To log out, call "apify logout".';
31
-
32
- LoginCommand.flags = {
33
- token: flagsHelper.string({
34
- char: 't',
35
- description: '[Optional] Apify API token',
36
- required: false,
37
- }),
38
- };
39
-
40
- module.exports = LoginCommand;
@@ -1,18 +0,0 @@
1
- const { ApifyCommand } = require('../lib/apify_command');
2
- const { AUTH_FILE_PATH } = require('../lib/consts');
3
- const { rimrafPromised } = require('../lib/files');
4
- const { success } = require('../lib/outputs');
5
- const { regenerateLocalDistinctId } = require('../lib/telemetry');
6
-
7
- class LogoutCommand extends ApifyCommand {
8
- async run() {
9
- await rimrafPromised(AUTH_FILE_PATH);
10
- regenerateLocalDistinctId();
11
- success('You are logged out from your Apify account.');
12
- }
13
- }
14
-
15
- LogoutCommand.description = 'Logs out of your Apify account.\nThe command deletes the API token and all other '
16
- + 'account information stored in the ~/.apify directory. To log in again, call "apify login".';
17
-
18
- module.exports = LogoutCommand;
@@ -1,154 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const { flags: flagsHelper } = require('@oclif/command');
5
- const AdmZip = require('adm-zip');
6
- const { get } = require('axios');
7
- const jju = require('jju');
8
- const semverGt = require('semver/functions/gt');
9
- const tiged = require('tiged');
10
-
11
- const { ApifyCommand } = require('../lib/apify_command');
12
- const { LOCAL_CONFIG_PATH } = require('../lib/consts');
13
- const { success, error } = require('../lib/outputs');
14
- const { getLoggedClientOrThrow, getLocalConfigOrThrow, getLocalUserInfo } = require('../lib/utils');
15
-
16
- const extractGitHubZip = async (url, directoryPath) => {
17
- const { data } = await get(url, { responseType: 'arraybuffer' });
18
-
19
- const zipFile = new AdmZip(Buffer.from(data, 'binary'));
20
-
21
- zipFile.extractEntryTo(zipFile.getEntries()[0].entryName, directoryPath, false);
22
- };
23
-
24
- class PullCommand extends ApifyCommand {
25
- async run() {
26
- const { args, flags } = this.parse(PullCommand);
27
- const localConfig = await getLocalConfigOrThrow();
28
- const userInfo = await getLocalUserInfo();
29
- const apifyClient = await getLoggedClientOrThrow();
30
- const cwd = process.cwd();
31
-
32
- const isActorAutomaticallyDetected = !args?.actorId;
33
- const usernameOrId = userInfo.username || userInfo.id;
34
-
35
- const actorId = args?.actorId || localConfig?.id || (localConfig.name ? `${usernameOrId}/${localConfig.name}` : undefined);
36
-
37
- if (!actorId) throw new Error('Cannot find Actor in this directory.');
38
-
39
- let actor;
40
- try {
41
- actor = await apifyClient.actor(actorId).get();
42
- } catch {
43
- throw new Error(`Cannot find Actor with ID/name '${actorId}' in your account.`);
44
- }
45
-
46
- if (!actor) throw new Error(`Cannot find Actor with ID/name '${actorId}' in your account.`);
47
-
48
- const { name, versions } = actor;
49
-
50
- let correctVersion = null;
51
- if (flags?.version) {
52
- correctVersion = versions.find((version) => version.versionNumber === flags?.version);
53
- if (!correctVersion) {
54
- throw new Error(`Cannot find version ${flags?.version} of Actor ${actorId}.`);
55
- }
56
- }
57
-
58
- if (!correctVersion) {
59
- correctVersion = versions.reduce((match, curr) => {
60
- if (semverGt(`${curr.versionNumber}.0`, `${match.versionNumber}.0`)) return curr;
61
- return match;
62
- });
63
- }
64
-
65
- const dirpath = isActorAutomaticallyDetected ? cwd : path.join(cwd, name);
66
- fs.mkdirSync(dirpath, { recursive: true });
67
-
68
- if (!isActorAutomaticallyDetected && !(fs.readdirSync(dirpath).length === 0)) {
69
- error(`Directory ${dirpath} is not empty. Please empty it or choose another directory.`);
70
- return;
71
- }
72
-
73
- switch (correctVersion.sourceType) {
74
- case 'TARBALL': {
75
- await extractGitHubZip(correctVersion.tarballUrl, dirpath);
76
-
77
- break;
78
- }
79
- case 'SOURCE_FILES': {
80
- const { sourceFiles } = correctVersion;
81
- for (const file of sourceFiles) {
82
- const folderPath = path.dirname(file.name);
83
- fs.mkdirSync(`${dirpath}/${folderPath}`, { recursive: true }, null);
84
-
85
- if (!file.folder) {
86
- const fileContent = file.format === 'BASE64' ? Buffer.from(file.content, 'base64') : file.content;
87
-
88
- if (file.name === LOCAL_CONFIG_PATH) {
89
- const actorJson = jju.parse(fileContent);
90
- actorJson.name = actor.name;
91
- fs.writeFileSync(`${dirpath}/${file.name}`, jju.update(fileContent, actorJson));
92
- } else {
93
- fs.writeFileSync(`${dirpath}/${file.name}`, fileContent);
94
- }
95
- }
96
- }
97
-
98
- break;
99
- }
100
- case 'GIT_REPO': {
101
- // e.g. https://github.com/jakubbalada/Datasety.git#master:RejstrikPolitickychStran
102
- const { gitRepoUrl } = correctVersion;
103
- const [repoUrl, branchDirPart] = gitRepoUrl.split('#');
104
-
105
- let branch;
106
- let dir;
107
- if (branchDirPart) [branch, dir] = branchDirPart.split(':');
108
- let branchDirRepoUrl = repoUrl;
109
- if (dir) branchDirRepoUrl += `/${dir}`;
110
- if (branch) branchDirRepoUrl += `#${branch}`;
111
-
112
- const emitter = tiged(branchDirRepoUrl);
113
- try {
114
- await emitter.clone(dirpath);
115
- } catch (err) {
116
- throw new Error(`Failed to pull Actor from ${gitRepoUrl}. ${err.message}`);
117
- }
118
-
119
- break;
120
- }
121
- case 'GITHUB_GIST': {
122
- await extractGitHubZip(`${correctVersion.gitHubGistUrl}/archive/master.zip`, dirpath);
123
-
124
- break;
125
- }
126
- default:
127
- throw new Error(`Unknown source type: ${correctVersion.sourceType}`);
128
- }
129
-
130
- success(isActorAutomaticallyDetected ? `Actor ${name} updated at ${dirpath}/` : `Pulled to ${dirpath}/`);
131
- }
132
- }
133
-
134
- PullCommand.description = 'Pulls an Actor from the Apify platform to the current directory. '
135
- + 'If it is defined as Git repository, it will be cloned. If it is defined as Web IDE, it will fetch the files.';
136
-
137
- PullCommand.flags = {
138
- version: flagsHelper.string({
139
- char: 'v',
140
- description: 'Actor version number which will be pulled, e.g. 1.2. Default: the highest version',
141
- required: false,
142
- }),
143
- };
144
-
145
- PullCommand.args = [
146
- {
147
- name: 'actorId',
148
- required: false,
149
- description: 'Name or ID of the actor to run (e.g. "apify/hello-world" or "E2jjCZBezvAZnX8Rb"). '
150
- + 'If not provided, the command will update the Actor in the current directory based on its name in ".actor/actor.json" file.',
151
- },
152
- ];
153
-
154
- module.exports = PullCommand;