hexo-swpp 1.2.7 → 1.2.9

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 (2) hide show
  1. package/index.js +8 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -18,7 +18,7 @@ if (pluginConfig?.enable) {
18
18
  // 生成 update.json
19
19
  hexo.extend.console.register('swpp', '生成前端更新需要的 json 文件以及相关缓存', {}, async () => {
20
20
  if (!fs.existsSync(config.public_dir))
21
- return logger.info('跳过生成 update.json')
21
+ return logger.info('未检测到发布目录,跳过 swpp 执行')
22
22
  const cachePath = 'cacheList.json'
23
23
  const updatePath = 'update.json'
24
24
  const oldCache = await getJsonFromNetwork(cachePath)
@@ -124,7 +124,7 @@ const buildNewJson = path => {
124
124
  let publicRoot = config.public_dir || 'public/'
125
125
  if (!publicRoot.endsWith('/')) publicRoot += '/'
126
126
  fs.writeFileSync(`${publicRoot}${path}`, JSON.stringify(result), 'utf-8')
127
- logger.info(`SwppGenerated: ${path}`)
127
+ logger.info(`Generated: ${path}`)
128
128
  return result
129
129
  }
130
130
 
@@ -135,6 +135,7 @@ const buildNewJson = path => {
135
135
  const getJsonFromNetwork = async path => {
136
136
  const url = root + path
137
137
  try {
138
+ // noinspection SpellCheckingInspection
138
139
  const result = await fetch(url, {
139
140
  headers: {
140
141
  referer: new URL(url).hostname,
@@ -142,10 +143,10 @@ const getJsonFromNetwork = async path => {
142
143
  }
143
144
  })
144
145
  switch (result.status) {
145
- case 200: case 301: case 302: break
146
- case 404:
147
- logger.error(`拉取 ${url} 时出现 404,如果您是第一次构建请忽略这个错误`)
146
+ case 200: case 301: case 302:
148
147
  break
148
+ case 404:
149
+ return logger.error(`拉取 ${url} 时出现 404,如果您是第一次构建请忽略这个错误`)
149
150
  default:
150
151
  // noinspection ExceptionCaughtLocallyJS
151
152
  throw `拉取 ${url} 时出现 ${result.status},拉取到的内容:\n${result}`
@@ -217,7 +218,7 @@ const buildUpdateJson = (name, dif, oldUpdate) => {
217
218
  /** 将对象写入文件,如果对象为 null 或 undefined 则跳过写入 */
218
219
  const writeJson = json => {
219
220
  if (json) {
220
- logger.info(`SwppGenerated: ${name}`)
221
+ logger.info(`Generated: ${name}`)
221
222
  fs.writeFileSync(`public/${name}`, JSON.stringify(json), 'utf-8')
222
223
  }
223
224
  }
@@ -237,7 +238,7 @@ const buildUpdateJson = (name, dif, oldUpdate) => {
237
238
  }
238
239
  // 整理更新的数据
239
240
  const tidied = tidyDiff(dif, expand)
240
- if (expand.all) return writeJson({
241
+ if (expand?.all) return writeJson({
241
242
  global: (oldUpdate?.global ?? 0) + (tidied.updateGlobal ? 1 : 0),
242
243
  info: [newInfo]
243
244
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",