@ywal123456/jskim 0.4.0 → 0.5.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.
- package/README.md +16 -7
- package/bin/jskim.js +32 -29
- package/docs/configuration.md +20 -2
- package/docs/create-jskim.md +3 -3
- package/package.json +1 -1
- package/scripts/build.js +14 -2
- package/scripts/commands/build-command.js +113 -3
- package/scripts/commands/dev-command.js +10 -1
- package/scripts/commands/help-text.js +23 -11
- package/scripts/commands/serve-command.js +20 -4
- package/scripts/commands/serve-errors.js +30 -4
- package/scripts/commands/watch-command.js +1 -1
- package/scripts/dev.js +16 -2
- package/scripts/lib/apply-serve-cli-overrides.js +96 -0
- package/scripts/lib/assert-output-dirs-compatible.js +88 -0
- package/scripts/lib/create-watch-runtime.js +70 -9
- package/scripts/lib/open-browser.js +102 -0
- package/scripts/lib/parse-cli-args.js +216 -0
- package/scripts/lib/select-project-name.js +64 -0
- package/scripts/serve.js +21 -2
- package/scripts/watch.js +13 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* config.projects のキーを定義順で返します。
|
|
5
|
+
* @param {object} config
|
|
6
|
+
* @returns {string[]}
|
|
7
|
+
*/
|
|
8
|
+
function listProjectNames(config) {
|
|
9
|
+
const projects = config && config.projects;
|
|
10
|
+
if (!projects || typeof projects !== 'object') {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
return Object.keys(projects);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* positional project が無い場合の自動選択、または明示名を返します。
|
|
18
|
+
*
|
|
19
|
+
* @param {object} options
|
|
20
|
+
* @param {object} options.config
|
|
21
|
+
* @param {string|undefined} options.projectName
|
|
22
|
+
* @param {string} [options.commandName]
|
|
23
|
+
* @param {string} [options.usageLine]
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
function selectProjectName({
|
|
27
|
+
config,
|
|
28
|
+
projectName,
|
|
29
|
+
commandName = 'build',
|
|
30
|
+
usageLine,
|
|
31
|
+
}) {
|
|
32
|
+
const names = listProjectNames(config);
|
|
33
|
+
const usage =
|
|
34
|
+
usageLine || `jskim ${commandName} [<project>]`;
|
|
35
|
+
|
|
36
|
+
if (projectName && String(projectName).trim() !== '') {
|
|
37
|
+
return String(projectName).trim();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (names.length === 0) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`[JSKim] 設定にprojectがありません。\n` +
|
|
43
|
+
`jskim.config.js の projects に1件以上定義してください。\n` +
|
|
44
|
+
`使用方法: ${usage}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (names.length === 1) {
|
|
49
|
+
return names[0];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const list = names.map((name) => `- ${name}`).join('\n');
|
|
53
|
+
throw new Error(
|
|
54
|
+
`[JSKim] projectを指定してください。\n` +
|
|
55
|
+
`使用方法: ${usage}\n\n` +
|
|
56
|
+
`利用可能なproject:\n` +
|
|
57
|
+
list
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
listProjectNames,
|
|
63
|
+
selectProjectName,
|
|
64
|
+
};
|
package/scripts/serve.js
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { parseCommandArgv } = require('./lib/parse-cli-args');
|
|
3
4
|
const { runServeCommand } = require('./commands/serve-command');
|
|
4
5
|
|
|
6
|
+
let parsed;
|
|
7
|
+
try {
|
|
8
|
+
parsed = parseCommandArgv('serve', process.argv.slice(2));
|
|
9
|
+
} catch (err) {
|
|
10
|
+
const message = err && err.message ? err.message : String(err);
|
|
11
|
+
console.error(message);
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const projectName = parsed.projectName;
|
|
17
|
+
const buildHint = projectName
|
|
18
|
+
? `jskim build ${projectName}`
|
|
19
|
+
: 'jskim build [<project>]';
|
|
20
|
+
|
|
5
21
|
runServeCommand({
|
|
6
|
-
projectName
|
|
22
|
+
projectName,
|
|
7
23
|
workspaceRoot: process.cwd(),
|
|
8
|
-
usageLine: '
|
|
24
|
+
usageLine: 'jskim serve [<project>] [--host <host>] [--port <port>]',
|
|
25
|
+
buildHint,
|
|
26
|
+
host: parsed.options.host,
|
|
27
|
+
port: parsed.options.port,
|
|
9
28
|
}).catch((err) => {
|
|
10
29
|
const message = err && err.message ? err.message : String(err);
|
|
11
30
|
console.error(message);
|
package/scripts/watch.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { parseCommandArgv } = require('./lib/parse-cli-args');
|
|
3
4
|
const { runWatchCommand } = require('./commands/watch-command');
|
|
4
5
|
|
|
6
|
+
let parsed;
|
|
7
|
+
try {
|
|
8
|
+
parsed = parseCommandArgv('watch', process.argv.slice(2));
|
|
9
|
+
} catch (err) {
|
|
10
|
+
const message = err && err.message ? err.message : String(err);
|
|
11
|
+
console.error(message);
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
5
16
|
runWatchCommand({
|
|
6
|
-
projectName:
|
|
17
|
+
projectName: parsed.projectName,
|
|
7
18
|
workspaceRoot: process.cwd(),
|
|
8
|
-
usageLine: '
|
|
19
|
+
usageLine: 'jskim watch [<project>]',
|
|
9
20
|
}).catch((err) => {
|
|
10
21
|
const message = err && err.message ? err.message : String(err);
|
|
11
22
|
console.error(message);
|