@struggler/cli 1.0.10 → 1.0.11
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 +23 -9
- package/lib/i18n.js +2 -0
- package/package.json +1 -1
- package/test/config.test.js +12 -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,31 @@ function getQiniuConfigPath(options = {}) {
|
|
|
12
14
|
return resolveFromCwd(options.config || DEFAULT_QINIU_CONFIG);
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
/** config.json / upload-cache.json 所在目录;优先级:CLI --config-dir > qiniu.json configDir > 与 qiniu 同目录 > ./command */
|
|
18
|
+
function getMetaDir(options = {}) {
|
|
19
|
+
if (options.configDir) {
|
|
20
|
+
return resolveFromCwd(options.configDir);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
const qiniuConfigPath = getQiniuConfigPath(options);
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const qiniuConfig = getJsonData(qiniuConfigPath);
|
|
25
|
+
if (qiniuConfig.configDir) {
|
|
26
|
+
return resolveFromCwd(qiniuConfig.configDir);
|
|
27
|
+
}
|
|
23
28
|
|
|
24
|
-
function getCachePath(options = {}) {
|
|
25
29
|
if (!options.config) {
|
|
26
|
-
return resolveFromCwd(
|
|
30
|
+
return resolveFromCwd(DEFAULT_META_DIR);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
return path.dirname(qiniuConfigPath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getConfigPath(options = {}) {
|
|
37
|
+
return path.join(getMetaDir(options), 'config.json');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getCachePath(options = {}) {
|
|
41
|
+
return path.join(getMetaDir(options), 'upload-cache.json');
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
module.exports = {
|
|
@@ -40,6 +51,9 @@ module.exports = {
|
|
|
40
51
|
getCachePath: (options) => {
|
|
41
52
|
return getCachePath(options)
|
|
42
53
|
},
|
|
54
|
+
getMetaDir: (options) => {
|
|
55
|
+
return getMetaDir(options)
|
|
56
|
+
},
|
|
43
57
|
getDir: (options) => {
|
|
44
58
|
return resolveFromCwd(options.dir || './dist')
|
|
45
59
|
},
|
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 所在目录(默认与 -c 同目录,未传 -c 时为 ./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 (default: same dir as -c, or ./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,18 @@ 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
|
+
|
|
27
39
|
test('deploy helpers normalize concurrency and build remote keys', () => {
|
|
28
40
|
assert.equal(normalizeConcurrency('0'), 5);
|
|
29
41
|
assert.equal(normalizeConcurrency('3'), 3);
|