apify-cli 0.19.2-beta.0 → 0.19.2-beta.2
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/package.json +4 -7
- package/src/commands/init.js +14 -3
- package/src/lib/scrapy-wrapper/index.js +2 -2
- package/src/lib/utils.js +14 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apify-cli",
|
|
3
|
-
"version": "0.19.2-beta.
|
|
3
|
+
"version": "0.19.2-beta.2",
|
|
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": {
|
|
7
|
-
"test": "cross-env APIFY_CLI_SKIP_UPDATE_CHECK=1
|
|
8
|
-
"test-python": "
|
|
7
|
+
"test": "cross-env APIFY_CLI_SKIP_UPDATE_CHECK=1 vitest run",
|
|
8
|
+
"test-python": "cross-env APIFY_CLI_SKIP_UPDATE_CHECK=1 vitest run -t '.*\\[python\\]'",
|
|
9
9
|
"lint": "eslint src test",
|
|
10
10
|
"lint:fix": "eslint src test --fix",
|
|
11
11
|
"commands-md": "npm run manifest && oclif-dev readme",
|
|
@@ -98,12 +98,9 @@
|
|
|
98
98
|
"@apify/eslint-config": "^0.4.0",
|
|
99
99
|
"@oclif/dev-cli": "^1.26.0",
|
|
100
100
|
"@oclif/test": "^2.1.0",
|
|
101
|
-
"chai": "^4.3.4",
|
|
102
|
-
"chai-match": "^1.1.1",
|
|
103
101
|
"cross-env": "^7.0.3",
|
|
104
102
|
"eslint": "^8.53.0",
|
|
105
|
-
"
|
|
106
|
-
"sinon": "^17.0.0"
|
|
103
|
+
"vitest": "^1.0.4"
|
|
107
104
|
},
|
|
108
105
|
"oclif": {
|
|
109
106
|
"bin": "apify",
|
package/src/commands/init.js
CHANGED
|
@@ -9,7 +9,7 @@ const { createPrefilledInputFileFromInputSchema } = require('../lib/input_schema
|
|
|
9
9
|
const outputs = require('../lib/outputs');
|
|
10
10
|
const { ProjectAnalyzer } = require('../lib/project_analyzer');
|
|
11
11
|
const { wrapScrapyProject } = require('../lib/scrapy-wrapper');
|
|
12
|
-
const { setLocalConfig, setLocalEnv, getLocalConfig, getLocalConfigOrThrow, detectLocalActorLanguage } = require('../lib/utils');
|
|
12
|
+
const { setLocalConfig, setLocalEnv, getLocalConfig, getLocalConfigOrThrow, detectLocalActorLanguage, validateActorName } = require('../lib/utils');
|
|
13
13
|
|
|
14
14
|
class InitCommand extends ApifyCommand {
|
|
15
15
|
async run() {
|
|
@@ -34,8 +34,19 @@ class InitCommand extends ApifyCommand {
|
|
|
34
34
|
outputs.warning(`Skipping creation of "${LOCAL_CONFIG_PATH}", the file already exists in the current directory.`);
|
|
35
35
|
} else {
|
|
36
36
|
if (!actorName) {
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
|
39
50
|
}
|
|
40
51
|
// Migrate apify.json to .actor/actor.json
|
|
41
52
|
const localConfig = { ...EMPTY_LOCAL_CONFIG, ...await getLocalConfigOrThrow() };
|
|
@@ -9,7 +9,7 @@ const inquirer = require('inquirer');
|
|
|
9
9
|
|
|
10
10
|
const { ScrapyProjectAnalyzer } = require('./ScrapyProjectAnalyzer');
|
|
11
11
|
const outputs = require('../outputs');
|
|
12
|
-
const { downloadAndUnzip } = require('../utils');
|
|
12
|
+
const { downloadAndUnzip, sanitizeActorName } = require('../utils');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Files that should be concatenated instead of copied (and overwritten).
|
|
@@ -86,7 +86,7 @@ async function wrapScrapyProject({ projectPath }) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
const templateBindings = {
|
|
89
|
-
botName: analyzer.settings.BOT_NAME,
|
|
89
|
+
botName: sanitizeActorName(analyzer.settings.BOT_NAME),
|
|
90
90
|
scrapy_settings_module: analyzer.configuration.get('settings', 'default'),
|
|
91
91
|
apify_module_path: `${analyzer.settings.BOT_NAME}.apify`,
|
|
92
92
|
spider_class_name: analyzer.getAvailableSpiders()[spiderIndex].class_name,
|
package/src/lib/utils.js
CHANGED
|
@@ -536,6 +536,19 @@ const validateActorName = (actorName) => {
|
|
|
536
536
|
}
|
|
537
537
|
};
|
|
538
538
|
|
|
539
|
+
const sanitizeActorName = (actorName) => {
|
|
540
|
+
let sanitizedName = actorName
|
|
541
|
+
.replaceAll(/[^a-zA-Z0-9-]/g, '-');
|
|
542
|
+
|
|
543
|
+
if (sanitizedName.length < ACTOR_NAME.MIN_LENGTH) {
|
|
544
|
+
sanitizedName = `${sanitizedName}-apify-actor`;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
sanitizedName = sanitizedName.replaceAll(/^-+/g, '').replaceAll(/-+$/g, '');
|
|
548
|
+
|
|
549
|
+
return sanitizedName.slice(0, ACTOR_NAME.MAX_LENGTH);
|
|
550
|
+
};
|
|
551
|
+
|
|
539
552
|
const getPythonCommand = (directory) => {
|
|
540
553
|
const pythonVenvPath = /^win/.test(process.platform)
|
|
541
554
|
? 'Scripts/python.exe'
|
|
@@ -665,4 +678,5 @@ module.exports = {
|
|
|
665
678
|
detectNpmVersion,
|
|
666
679
|
detectLocalActorLanguage,
|
|
667
680
|
downloadAndUnzip,
|
|
681
|
+
sanitizeActorName,
|
|
668
682
|
};
|