hexo-swpp 4.0.3 → 4.0.4

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.
Files changed (3) hide show
  1. package/README.md +6 -2
  2. package/dist/index.js +26 -0
  3. package/package.json +37 -35
package/README.md CHANGED
@@ -90,8 +90,12 @@ swpp:
90
90
  1. 适配 `swpp-backends@3` \[4.0.0]
91
91
  2. 修复无法与 `hexo8` 一同工作的问题 \[4.0.0]
92
92
  3. 修复不支持 `swpp-backends@3.1.0+` 的问题 \[4.0.1]
93
- 4. 修复 `gen_dom` 默认值处理错误的问题 \[4.0.2]
94
- 5. 移除 `-t/-test` 命令 \[4.0.2]
93
+ 4. 删除 `track_link` 配置项 \[4.0.2]
94
+ 5. 修复 `gen_dom` 默认值处理错误的问题 \[4.0.3]
95
+ 6. 移除 `-t/-test` 命令 \[4.0.3]
96
+ 7. 重新添加 `-t/-test` 命令 \[4.0.4]
97
+ 8. 修复 `swpp` 命令没有携带任何参数时不触发构建的问题 \[4.0.4]
98
+ 9. 修复 `-t/-test` 执行时不通过配置中的函数判定请求是否成功的问题 \[4.0.4]
95
99
 
96
100
  + 3.3+
97
101
  1. 版本检查改为仅在执行 `hexo server` 时执行 \[3.3.0]
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ const path_1 = __importDefault(require("path"));
31
31
  const swpp_backends_1 = require("swpp-backends");
32
32
  const logger = require('hexo-log').default();
33
33
  const CONSOLE_OPTIONS = [
34
+ { name: '-t, --test', desc: '尝试拉取指定链接' },
34
35
  { name: '-b, --build', desc: '构建 swpp,留空参数与使用该参数效果一致' }
35
36
  ];
36
37
  let actions;
@@ -93,12 +94,37 @@ async function start(hexo) {
93
94
  hexo.extend.console.register('swpp', 'Hexo Swpp 的相关指令', {
94
95
  options: CONSOLE_OPTIONS
95
96
  }, async (args) => {
97
+ const test = args.t ?? args.test;
96
98
  // noinspection JSUnresolvedReference
97
99
  const build = args.b ?? args.build;
100
+ if (test) {
101
+ if (typeof test == 'boolean' || Array.isArray(test) || !/^(https?):\/\/(\S*?)\.(\S*?)(\S*)$/i.test(test)) {
102
+ logger.error('[SWPP][CONSOLE] --test/-t 后应跟随一个有效 URL');
103
+ }
104
+ else {
105
+ await initRules(hexo, pluginConfig);
106
+ try {
107
+ const compilationData = actions.compilationData;
108
+ const isSuccessful = compilationData.crossDep.read('isFetchSuccessful');
109
+ const response = await fetchUrl(compilationData, test);
110
+ if (isSuccessful.runOnNode(response)) {
111
+ logger.info('[SWPP][LINK TEST] 资源拉取成功,状态码:' + response.status);
112
+ }
113
+ else {
114
+ logger.warn('[SWPP][LINK TEST] 资源拉取失败,状态码:' + response.status);
115
+ }
116
+ }
117
+ catch (e) {
118
+ logger.warn('[SWPP][LINK TEST] 资源拉取失败', e);
119
+ }
120
+ }
121
+ }
98
122
  if (build) {
99
123
  if (typeof build !== 'boolean') {
100
124
  logger.warn('[SWPP][CONSOLE] -build/-b 后方不应跟随参数');
101
125
  }
126
+ }
127
+ if (build || !test) {
102
128
  try {
103
129
  await runSwpp(hexo, pluginConfig);
104
130
  }
package/package.json CHANGED
@@ -1,36 +1,38 @@
1
- {
2
- "name": "hexo-swpp",
3
- "version": "4.0.3",
4
- "main": "dist/index.js",
5
- "types": "types/index.d.ts",
6
- "files": [
7
- "dist",
8
- "types"
9
- ],
10
- "keywords": [
11
- "hexo",
12
- "sw",
13
- "ServiceWorker",
14
- "json",
15
- "auto"
16
- ],
17
- "author": "kmar",
18
- "license": "AGPL-3.0",
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/EmptyDreams/hexo-swpp.git"
22
- },
23
- "homepage": "https://swpp.kmar.top/",
24
- "devDependencies": {
25
- "@types/node": "^22.0.2",
26
- "hexo": "^7.3.0",
27
- "typescript": "^5.5.4"
28
- },
29
- "dependencies": {
30
- "hexo-log": "^4.1.0"
31
- },
32
- "peerDependencies": {
33
- "swpp-backends": "^3.1.0"
34
- },
35
- "scripts": {}
1
+ {
2
+ "name": "hexo-swpp",
3
+ "version": "4.0.4",
4
+ "main": "dist/index.js",
5
+ "types": "types/index.d.ts",
6
+ "scripts": {
7
+ "prepublishOnly": "tsc"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "types"
12
+ ],
13
+ "keywords": [
14
+ "hexo",
15
+ "sw",
16
+ "ServiceWorker",
17
+ "json",
18
+ "auto"
19
+ ],
20
+ "author": "kmar",
21
+ "license": "AGPL-3.0",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/EmptyDreams/hexo-swpp.git"
25
+ },
26
+ "homepage": "https://swpp.kmar.top/",
27
+ "devDependencies": {
28
+ "@types/node": "^22.0.2",
29
+ "hexo": "^7.3.0",
30
+ "typescript": "^5.5.4"
31
+ },
32
+ "dependencies": {
33
+ "hexo-log": "^4.1.0"
34
+ },
35
+ "peerDependencies": {
36
+ "swpp-backends": "^3.1.0"
37
+ }
36
38
  }