swpp-backends 3.1.2 → 3.1.3
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/dist/swpp/cli.d.ts +2 -2
- package/dist/swpp/cli.js +13 -1
- package/package.json +1 -1
package/dist/swpp/cli.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export interface SwppCliConfig {
|
|
2
|
-
/**
|
|
2
|
+
/** 网站根目录,可以是绝对路径也可以是相对路径(相对于 swpp.cli.json 所在目录) */
|
|
3
3
|
webRoot: string;
|
|
4
|
-
/**
|
|
4
|
+
/** 配置文件所在的相对路径(相对于 swpp.cli.json 所在目录,越靠前优先级越高) */
|
|
5
5
|
configFiles: string[] | string;
|
|
6
6
|
/** dom js 的相对路径(相对于网站根目录,`.js` 结尾) */
|
|
7
7
|
domJsPath?: string;
|
package/dist/swpp/cli.js
CHANGED
|
@@ -39,10 +39,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.initCommand = initCommand;
|
|
40
40
|
const commander_1 = require("commander");
|
|
41
41
|
const fs_1 = __importDefault(require("fs"));
|
|
42
|
+
const path_1 = __importDefault(require("path"));
|
|
42
43
|
const index_1 = require("../index");
|
|
43
44
|
const BasicActions_1 = require("./BasicActions");
|
|
44
45
|
const untils_1 = require("./untils");
|
|
45
46
|
const HTMLParser = __importStar(require("node-html-parser"));
|
|
47
|
+
function resolveCliConfigFiles(configFiles, cliJsonPath) {
|
|
48
|
+
const cliDir = path_1.default.dirname(cliJsonPath);
|
|
49
|
+
const resolveItem = (item) => path_1.default.isAbsolute(item) ? item : path_1.default.resolve(cliDir, item);
|
|
50
|
+
return typeof configFiles === 'string' ? resolveItem(configFiles) : configFiles.map(resolveItem);
|
|
51
|
+
}
|
|
52
|
+
function resolveCliConfigDirPath(filePath, cliJsonPath) {
|
|
53
|
+
return path_1.default.isAbsolute(filePath) ? filePath : path_1.default.resolve(path_1.default.dirname(cliJsonPath), filePath);
|
|
54
|
+
}
|
|
46
55
|
async function initCommand() {
|
|
47
56
|
commander_1.program.version(index_1.swppVersion, '-v, --version', '查看当前 swpp backends 的版本号');
|
|
48
57
|
commander_1.program.addHelpText('after', ' 每行显示一条指令信息,指令后跟方括号表示可选参数,尖括号表示必填参数');
|
|
@@ -88,13 +97,16 @@ async function runBuild(cliJsonPath = './swpp.cli.json', context) {
|
|
|
88
97
|
if (!cliJsonPath.endsWith('.json')) {
|
|
89
98
|
throw new untils_1.RuntimeException(untils_1.exceptionNames.unsupportedFileType, 'CLI 配置文件仅支持 JSON 格式', { yourPath: cliJsonPath });
|
|
90
99
|
}
|
|
100
|
+
cliJsonPath = path_1.default.resolve(cliJsonPath);
|
|
91
101
|
const cliConfig = JSON.parse(await untils_1.utils.readFileUtf8(cliJsonPath));
|
|
102
|
+
cliConfig.webRoot = resolveCliConfigDirPath(cliConfig.webRoot, cliJsonPath);
|
|
103
|
+
cliConfig.configFiles = resolveCliConfigFiles(cliConfig.configFiles, cliJsonPath);
|
|
92
104
|
await checkAndInitConfig(cliConfig);
|
|
93
105
|
const actions = await BasicActions_1.BasicActions.build({
|
|
94
106
|
context,
|
|
95
107
|
publicPath: cliConfig.webRoot,
|
|
96
108
|
isServiceWorker: cliConfig.serviceWorker ?? true,
|
|
97
|
-
domJsPath: cliConfig.gen_dom ? cliConfig.domJsPath : undefined,
|
|
109
|
+
domJsPath: cliConfig.gen_dom ? (cliConfig.domJsPath ?? '/sw-dom.js') : undefined,
|
|
98
110
|
diffJsonPath: cliConfig.diffJsonPath
|
|
99
111
|
});
|
|
100
112
|
await actions.loadConfigs(Array.isArray(cliConfig.configFiles) ? cliConfig.configFiles : [cliConfig.configFiles]);
|