swpp-backends 3.1.1 → 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/cli-index.js CHANGED
File without changes
@@ -168,8 +168,9 @@ class BasicActions {
168
168
  throw new untils_1.RuntimeException(untils_1.exceptionNames.fileDuplicate, `指定文件[${item.path.absPath}]已存在`);
169
169
  }
170
170
  }
171
- await Promise.all(fileList.map(it => {
172
- it.path.mkdirs().then(() => untils_1.utils.writeFile(it.path.absPath, it.content));
171
+ await Promise.all(fileList.map(async (it) => {
172
+ await it.path.mkdirs();
173
+ await untils_1.utils.writeFile(it.path.absPath, it.content);
173
174
  }));
174
175
  }
175
176
  }
@@ -1,7 +1,7 @@
1
1
  export interface SwppCliConfig {
2
- /** 网站根目录,可以是绝对路径也可以是相对路径,swpp 根据系统规则进行判断 */
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 ? undefined : cliConfig.domJsPath,
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]);
@@ -52,12 +52,12 @@ class KeyValueDatabase {
52
52
  let value = item.manual ?? item.default;
53
53
  let isNoCache = false;
54
54
  if (SpecialConfig_1.SpecialConfig.isRuntimeSpecialConfig(value)) {
55
- this.runtime.debugCallChain.push(this.namespace, key);
56
- value = value.get(this.runtime, this.compilation);
57
- this.runtime.debugCallChain.pop(this.namespace, key);
58
55
  if (SpecialConfig_1.SpecialConfig.isNoCacheConfig(value)) {
59
56
  isNoCache = true;
60
57
  }
58
+ this.runtime.debugCallChain.push(this.namespace, key);
59
+ value = value.get(this.runtime, this.compilation);
60
+ this.runtime.debugCallChain.pop(this.namespace, key);
61
61
  }
62
62
  // 进行类型预检
63
63
  if (!(item.default === null || item.default === undefined || value === null || value === undefined) && typeof value != typeof item.default) {
package/package.json CHANGED
@@ -1,35 +1,37 @@
1
- {
2
- "name": "swpp-backends",
3
- "version": "3.1.1",
4
- "main": "dist/index.js",
5
- "typings": "dist/index.d.ts",
6
- "description": "Generate a powerful ServiceWorker for your website.",
7
- "author": "kmar",
8
- "license": "AGPL-3.0",
9
- "files": [
10
- "dist",
11
- "types"
12
- ],
13
- "bin": {
14
- "swpp-cli": "dist/cli-index.js"
15
- },
16
- "devDependencies": {
17
- "@types/node": "^22.9.3",
18
- "typescript": "^5.7.2"
19
- },
20
- "dependencies": {
21
- "commander": "^12.1.0",
22
- "jiti": "^2.4.2",
23
- "node-html-parser": "^7.0.1"
24
- },
25
- "repository": {
26
- "type": "git",
27
- "url": "git+ssh://git@github.com/EmptyDreams/swpp-backends.git"
28
- },
29
- "homepage": "https://swpp.kmar.top/",
30
- "keywords": [
31
- "ServiceWorker",
32
- "sw"
33
- ],
34
- "scripts": {}
1
+ {
2
+ "name": "swpp-backends",
3
+ "version": "3.1.3",
4
+ "main": "dist/index.js",
5
+ "typings": "dist/index.d.ts",
6
+ "scripts": {
7
+ "prepublishOnly": "tsc"
8
+ },
9
+ "description": "Generate a powerful ServiceWorker for your website.",
10
+ "author": "kmar",
11
+ "license": "AGPL-3.0",
12
+ "files": [
13
+ "dist",
14
+ "types"
15
+ ],
16
+ "bin": {
17
+ "swpp-cli": "dist/cli-index.js"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^22.9.3",
21
+ "typescript": "^5.7.2"
22
+ },
23
+ "dependencies": {
24
+ "commander": "^12.1.0",
25
+ "jiti": "^2.4.2",
26
+ "node-html-parser": "^7.0.1"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+ssh://git@github.com/EmptyDreams/swpp-backends.git"
31
+ },
32
+ "homepage": "https://swpp.kmar.top/",
33
+ "keywords": [
34
+ "ServiceWorker",
35
+ "sw"
36
+ ]
35
37
  }