@struggler/cli 1.0.10 → 1.0.12
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/index.js +1 -1
- package/lib/config.js +35 -9
- package/lib/i18n.js +2 -0
- package/package.json +1 -1
- package/test/config.test.js +24 -0
package/index.js
CHANGED
|
@@ -58,7 +58,7 @@ program.configureHelp({
|
|
|
58
58
|
},
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
program.name("struggler-cli").description(locale.appDescription).version(packageJson.version, "-v, --version", locale.options.version).helpOption("-h, --help", locale.options.help).option("-c, --config <path>", locale.options.config, "./command/qiniu.json").option("-d, --dir <path>", locale.options.dir, "./dist").option("--dry-run", locale.options.dryRun).option("--concurrency <number>", locale.options.concurrency, "5").option("--exclude <pattern>", locale.options.exclude).option("--ignore-file <path>", locale.options.ignoreFile, ".strugglerignore").option("--manifest <path>", locale.options.manifest).option("--json", locale.options.json).option("--skip-init", locale.options.skipInit).option("--skip-refresh", locale.options.skipRefresh).option("--no-cache", locale.options.noCache).option("--lang <lang>", locale.options.lang, lang)
|
|
61
|
+
program.name("struggler-cli").description(locale.appDescription).version(packageJson.version, "-v, --version", locale.options.version).helpOption("-h, --help", locale.options.help).option("-c, --config <path>", locale.options.config, "./command/qiniu.json").option("--config-dir [path]", locale.options.configDir).option("-d, --dir <path>", locale.options.dir, "./dist").option("--dry-run", locale.options.dryRun).option("--concurrency <number>", locale.options.concurrency, "5").option("--exclude <pattern>", locale.options.exclude).option("--ignore-file <path>", locale.options.ignoreFile, ".strugglerignore").option("--manifest <path>", locale.options.manifest).option("--json", locale.options.json).option("--skip-init", locale.options.skipInit).option("--skip-refresh", locale.options.skipRefresh).option("--no-cache", locale.options.noCache).option("--lang <lang>", locale.options.lang, lang)
|
|
62
62
|
|
|
63
63
|
program
|
|
64
64
|
.command("init")
|
package/lib/config.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
let path = require('path')
|
|
2
|
+
const { getJsonData } = require('./files');
|
|
2
3
|
|
|
3
4
|
const DEFAULT_QINIU_CONFIG = './command/qiniu.json';
|
|
5
|
+
const DEFAULT_META_DIR = './command';
|
|
4
6
|
const DEFAULT_CONFIG = './command/config.json';
|
|
5
7
|
const DEFAULT_CACHE = './command/upload-cache.json';
|
|
6
8
|
|
|
@@ -12,22 +14,43 @@ function getQiniuConfigPath(options = {}) {
|
|
|
12
14
|
return resolveFromCwd(options.config || DEFAULT_QINIU_CONFIG);
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
function resolveConfigDirOption(options = {}) {
|
|
18
|
+
const value = options.configDir;
|
|
19
|
+
if (value === true || value === '') {
|
|
20
|
+
return DEFAULT_META_DIR;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** config.json / upload-cache.json 所在目录;优先级:CLI --config-dir > qiniu.json configDir > 与 qiniu 同目录 > ./command */
|
|
29
|
+
function getMetaDir(options = {}) {
|
|
30
|
+
const cliConfigDir = resolveConfigDirOption(options);
|
|
31
|
+
if (cliConfigDir) {
|
|
32
|
+
return resolveFromCwd(cliConfigDir);
|
|
18
33
|
}
|
|
19
34
|
|
|
20
35
|
const qiniuConfigPath = getQiniuConfigPath(options);
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
const qiniuConfig = getJsonData(qiniuConfigPath);
|
|
37
|
+
if (qiniuConfig.configDir) {
|
|
38
|
+
return resolveFromCwd(qiniuConfig.configDir);
|
|
39
|
+
}
|
|
23
40
|
|
|
24
|
-
function getCachePath(options = {}) {
|
|
25
41
|
if (!options.config) {
|
|
26
|
-
return resolveFromCwd(
|
|
42
|
+
return resolveFromCwd(DEFAULT_META_DIR);
|
|
27
43
|
}
|
|
28
44
|
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
return path.dirname(qiniuConfigPath);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getConfigPath(options = {}) {
|
|
49
|
+
return path.join(getMetaDir(options), 'config.json');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getCachePath(options = {}) {
|
|
53
|
+
return path.join(getMetaDir(options), 'upload-cache.json');
|
|
31
54
|
}
|
|
32
55
|
|
|
33
56
|
module.exports = {
|
|
@@ -40,6 +63,9 @@ module.exports = {
|
|
|
40
63
|
getCachePath: (options) => {
|
|
41
64
|
return getCachePath(options)
|
|
42
65
|
},
|
|
66
|
+
getMetaDir: (options) => {
|
|
67
|
+
return getMetaDir(options)
|
|
68
|
+
},
|
|
43
69
|
getDir: (options) => {
|
|
44
70
|
return resolveFromCwd(options.dir || './dist')
|
|
45
71
|
},
|
package/lib/i18n.js
CHANGED
|
@@ -38,6 +38,7 @@ const LANGUAGES = {
|
|
|
38
38
|
options: {
|
|
39
39
|
version: '显示版本号。',
|
|
40
40
|
config: '指定上传配置文件路径。',
|
|
41
|
+
configDir: '指定 config.json、upload-cache.json 所在目录;可写 --config-dir ./command,单独写 --config-dir 时默认为 ./command。',
|
|
41
42
|
dir: '指定要上传的目录。',
|
|
42
43
|
dryRun: '仅预览执行计划,不写文件也不调用七牛接口。',
|
|
43
44
|
concurrency: '设置上传并发数。',
|
|
@@ -111,6 +112,7 @@ const LANGUAGES = {
|
|
|
111
112
|
options: {
|
|
112
113
|
version: 'Display the version number.',
|
|
113
114
|
config: 'Specify the path to the upload configuration file.',
|
|
115
|
+
configDir: 'Directory for config.json and upload-cache.json; use --config-dir ./command, or --config-dir alone for ./command.',
|
|
114
116
|
dir: 'Specify the directory to upload.',
|
|
115
117
|
dryRun: 'Preview actions without writing files or calling Qiniu APIs.',
|
|
116
118
|
concurrency: 'Set upload concurrency.',
|
package/package.json
CHANGED
package/test/config.test.js
CHANGED
|
@@ -24,6 +24,30 @@ test('config helpers resolve qiniu and derived config paths together', () => {
|
|
|
24
24
|
);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
test('config-dir overrides default meta directory', () => {
|
|
28
|
+
const options = {
|
|
29
|
+
config: './test/command/qiniu.json',
|
|
30
|
+
configDir: './test/meta',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
assert.equal(
|
|
34
|
+
getConfig(options),
|
|
35
|
+
`${process.cwd()}/test/meta/config.json`
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('config-dir flag without path defaults to ./command', () => {
|
|
40
|
+
const options = {
|
|
41
|
+
config: './test/command/qiniu.json',
|
|
42
|
+
configDir: true,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
assert.equal(
|
|
46
|
+
getConfig(options),
|
|
47
|
+
`${process.cwd()}/command/config.json`
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
27
51
|
test('deploy helpers normalize concurrency and build remote keys', () => {
|
|
28
52
|
assert.equal(normalizeConcurrency('0'), 5);
|
|
29
53
|
assert.equal(normalizeConcurrency('3'), 3);
|