swpp-backends 1.2.3 → 2.0.1

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.
@@ -1,50 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getShorthand = exports.buildNewInfo = exports.readUpdateJson = exports.loadUpdateJson = exports.submitChange = void 0;
4
- const FileAnalyzer_1 = require("./FileAnalyzer");
5
- const SwppRules_1 = require("./SwppRules");
3
+ exports.getShorthand = exports.loadUpdateJson = exports.submitChange = exports.buildUpdateJson = void 0;
6
4
  const Utils_1 = require("./Utils");
7
- let _oldJson = undefined;
8
- let externalChange = [];
9
- /** 提交修改 */
10
- function submitChange(...change) {
11
- if (!externalChange) {
12
- (0, Utils_1.error)('SubmitChange', '版本文件已经构建完成,调用该函数无意义!');
13
- throw 'submitChange 调用时机错误';
14
- }
15
- externalChange.push(...change);
16
- }
17
- exports.submitChange = submitChange;
18
- /**
19
- * 加载版本文件
20
- *
21
- * + **调用该函数前必须调用过 [loadRules]**
22
- */
23
- async function loadUpdateJson(url) {
24
- if (_oldJson !== undefined)
25
- return _oldJson;
26
- const response = await (0, Utils_1.fetchFile)(url).catch(err => err);
27
- if (response?.status === 404 || response.code === 'ENOTFOUND') {
28
- (0, Utils_1.warn)('LoadUpdateJson', `拉取 ${url} 时出现 404 错误,如果您是第一次构建请忽略这个警告。`);
29
- return _oldJson = null;
30
- }
31
- return _oldJson = (await response.json());
32
- }
33
- exports.loadUpdateJson = loadUpdateJson;
34
- /**
35
- * 读取最后一次加载的版本文件
36
- *
37
- * + **调用该函数前必须调用过 [loadRules]**
38
- * + **调用该函数前必须调用过 [loadUpdateJson]**
39
- */
40
- function readUpdateJson() {
41
- if (_oldJson === undefined) {
42
- (0, Utils_1.error)('UpdateJsonReader', 'UpdateJson 尚未初始化');
43
- throw 'UpdateJson 未初始化';
44
- }
45
- return _oldJson;
46
- }
47
- exports.readUpdateJson = readUpdateJson;
5
+ const Variant_1 = require("./Variant");
48
6
  /**
49
7
  * 构建新的 update json
50
8
  *
@@ -56,34 +14,50 @@ exports.readUpdateJson = readUpdateJson;
56
14
  * @param root 网站根路径(包括网络协议)
57
15
  * @param dif 网站文件变化
58
16
  */
59
- function buildNewInfo(root, dif) {
60
- const config = (0, SwppRules_1.readRules)().config.json;
17
+ function buildUpdateJson(root, dif) {
18
+ const rules = (0, Variant_1.readRules)();
19
+ const config = rules.config.json;
61
20
  if (!config) {
62
- (0, Utils_1.error)('NewInfoBuilder', '功能未开启');
21
+ (0, Utils_1.error)('UpdateJsonBuilder', '功能未开启');
63
22
  throw '功能未开启';
64
23
  }
65
- const old = readUpdateJson();
24
+ const externalChange = (0, Variant_1.readEvent)('swppSubmitChange');
25
+ (0, Variant_1.writeVariant)('swppSubmitChange', false);
26
+ const old = (0, Variant_1.readUpdateJson)();
66
27
  let global = old?.global ?? 0;
67
- if (dif.force)
28
+ let userUpdate = rules.update;
29
+ if (userUpdate) {
30
+ if (!userUpdate.flag) {
31
+ (0, Utils_1.error)('UpdateJsonBuilder', '规则文件的 update 项目必须包含 flag 值!');
32
+ throw '规则文件的 update 不合规';
33
+ }
34
+ if (userUpdate.flag === (0, Variant_1.readOldVersionJson)()?.external?.flag)
35
+ userUpdate = undefined;
36
+ }
37
+ // 如果需要强制刷新直接返回
38
+ if (dif.force || userUpdate?.force)
68
39
  return {
69
40
  global: global + 1,
70
41
  info: [{
71
42
  version: old ? old.info[0].version + 1 : 0
72
43
  }]
73
44
  };
74
- const change = [];
45
+ if (root.endsWith('/'))
46
+ root = root.substring(0, root.length - 1);
47
+ const change = userUpdate?.change ?? [];
75
48
  const info = {
76
49
  version: old ? old.info[0].version + 1 : 0,
77
50
  change
78
51
  };
79
- const list = [...dif.refresh, ...dif.deleted, ...dif.variational, ...dif.rules.remove];
52
+ const list = [...dif.refresh, ...dif.deleted, ...dif.variational, ...dif.rules.remove, ...(userUpdate?.refresh ?? [])];
80
53
  const records = {
54
+ // 记录要合并的值
81
55
  merge: new Set(),
56
+ // 记录 HTML 值
82
57
  html: new Set()
83
58
  };
84
59
  for (let url of list) {
85
- if (url.startsWith('/')) {
86
- // 本地链接
60
+ if (url.startsWith('/')) { // 本地链接
87
61
  const merge = config.merge.find(it => url.startsWith(`/${it}/`));
88
62
  if (merge) {
89
63
  records.merge.add(merge);
@@ -119,13 +93,33 @@ function buildNewInfo(root, dif) {
119
93
  });
120
94
  }
121
95
  change.push(...externalChange);
122
- externalChange = null;
123
96
  return zipJson({
124
97
  global,
125
98
  info: [info, ...(old?.info ?? [])]
126
99
  });
127
100
  }
128
- exports.buildNewInfo = buildNewInfo;
101
+ exports.buildUpdateJson = buildUpdateJson;
102
+ (0, Variant_1.writeVariant)('swppSubmitChange', []);
103
+ /** 提交修改 */
104
+ function submitChange(...change) {
105
+ (0, Variant_1.readEvent)('swppSubmitChange').push(...change);
106
+ }
107
+ exports.submitChange = submitChange;
108
+ /**
109
+ * 加载版本文件
110
+ *
111
+ * + **调用该函数前必须调用过 [loadRules]**
112
+ */
113
+ async function loadUpdateJson(url) {
114
+ const key = 'oldUpdateJson';
115
+ const response = await (0, Utils_1.fetchFile)(url).catch(err => err);
116
+ if (response?.status === 404 || response.code === 'ENOTFOUND') {
117
+ (0, Utils_1.warn)('LoadUpdateJson', `拉取 ${url} 时出现 404 错误,如果您是第一次构建请忽略这个警告。`);
118
+ return (0, Variant_1.writeVariant)(key, null);
119
+ }
120
+ return (0, Variant_1.writeVariant)(key, await response.json());
121
+ }
122
+ exports.loadUpdateJson = loadUpdateJson;
129
123
  function zipJson(json) {
130
124
  const record = new Map();
131
125
  /** 合并同名项目 */
@@ -243,7 +237,7 @@ function zipJson(json) {
243
237
  }
244
238
  }
245
239
  function limit(json) {
246
- const charLimit = (0, SwppRules_1.readRules)().config.json.charLimit;
240
+ const charLimit = (0, Variant_1.readRules)().config.json.charLimit;
247
241
  for (let i = 0; i !== -1; ++i) {
248
242
  if (i === 999) {
249
243
  (0, Utils_1.error)('UpdateJsonLimit', `JSON 输出长度异常:${JSON.stringify(json, null, 4)}`);
@@ -278,7 +272,7 @@ function zipJson(json) {
278
272
  * + **执行该函数前必须调用过 [calcEjectValues]**
279
273
  */
280
274
  function getShorthand(url, offset = 0) {
281
- const map = (0, FileAnalyzer_1.readMergeVersionMap)();
275
+ const map = (0, Variant_1.readMergeVersionMap)();
282
276
  let collide = new Set();
283
277
  for (let mapKey in map) {
284
278
  collide.add(mapKey);
package/dist/Utils.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.deepFreeze = exports.replaceDevRequest = exports.fetchFile = exports.getSource = exports.readEjectData = exports.calcEjectValues = exports.warn = exports.error = void 0;
7
7
  const node_fetch_1 = __importDefault(require("node-fetch"));
8
- const SwppRules_1 = require("./SwppRules");
8
+ const Variant_1 = require("./Variant");
9
9
  const logger = require('hexo-log').default({
10
10
  debug: false,
11
11
  silent: false
@@ -18,7 +18,6 @@ function warn(type, message) {
18
18
  logger.warn(`[SWPP ${type}] ${message}`);
19
19
  }
20
20
  exports.warn = warn;
21
- let ejectData = undefined;
22
21
  /**
23
22
  * 获取 eject values
24
23
  *
@@ -27,9 +26,9 @@ let ejectData = undefined;
27
26
  * @param framework 框架对象
28
27
  */
29
28
  function calcEjectValues(framework) {
30
- const rules = (0, SwppRules_1.readRules)();
29
+ const rules = (0, Variant_1.readRules)();
31
30
  if (!('ejectValues' in rules)) {
32
- ejectData = null;
31
+ (0, Variant_1.writeVariant)('swppEjectData', false);
33
32
  return;
34
33
  }
35
34
  // noinspection JSUnresolvedReference
@@ -51,10 +50,10 @@ function calcEjectValues(framework) {
51
50
  ejectStr += ` ${data.prefix} ${key} = ${str}\n`;
52
51
  nodeEject[key] = data.value;
53
52
  }
54
- ejectData = {
53
+ (0, Variant_1.writeVariant)('swppEjectData', {
55
54
  strValue: ejectStr,
56
55
  nodeEject
57
- };
56
+ });
58
57
  }
59
58
  exports.calcEjectValues = calcEjectValues;
60
59
  /**
@@ -64,11 +63,12 @@ exports.calcEjectValues = calcEjectValues;
64
63
  * + **执行该函数前必须调用过 [calcEjectValues]**
65
64
  */
66
65
  function readEjectData() {
66
+ const ejectData = (0, Variant_1.readVariant)('swppEjectData');
67
67
  if (ejectData === undefined) {
68
68
  error('EjectReader', 'eject data 尚未初始化');
69
69
  throw 'eject data 尚未初始化';
70
70
  }
71
- return ejectData;
71
+ return ejectData || null;
72
72
  }
73
73
  exports.readEjectData = readEjectData;
74
74
  /**
@@ -140,7 +140,7 @@ exports.getSource = getSource;
140
140
  * **调用该函数前必须调用过 [loadRules]**
141
141
  */
142
142
  async function fetchFile(link) {
143
- const config = (0, SwppRules_1.readRules)().config;
143
+ const config = (0, Variant_1.readRules)().config;
144
144
  const url = replaceDevRequest(link);
145
145
  const opts = {
146
146
  headers: {
@@ -151,7 +151,7 @@ async function fetchFile(link) {
151
151
  };
152
152
  try {
153
153
  if (typeof url === 'string') {
154
- return await (0, node_fetch_1.default)(url, opts);
154
+ return await fetch(url, opts);
155
155
  }
156
156
  else {
157
157
  return await fetchSpeed(url);
@@ -174,14 +174,40 @@ exports.fetchFile = fetchFile;
174
174
  * **调用该函数前必须调用过 [loadRules]**
175
175
  */
176
176
  function replaceDevRequest(link) {
177
- const config = (0, SwppRules_1.readRules)().config;
177
+ const config = (0, Variant_1.readRules)().config;
178
178
  return config.external?.replacer(link) ?? link;
179
179
  }
180
180
  exports.replaceDevRequest = replaceDevRequest;
181
+ let fetchActiveCount = 0;
182
+ const waitList = [];
183
+ /**
184
+ * 拉取一个文件
185
+ *
186
+ * 拉取时有数量限制,当活跃的 fetch 超过数量限制后会进入队列等待,后进入的优先执行
187
+ */
188
+ function fetch(url, opts) {
189
+ const limit = (0, Variant_1.readRules)().config.external?.concurrencyLimit ?? 100;
190
+ const start = (url, opts) => (0, node_fetch_1.default)(url, opts)
191
+ .then(response => {
192
+ if (waitList.length !== 0) {
193
+ const { url, opts, resolve, reject } = waitList.pop();
194
+ start(url, opts).then(it => resolve(it))
195
+ .catch(err => reject(err));
196
+ }
197
+ return response;
198
+ }).finally(() => --fetchActiveCount);
199
+ if (fetchActiveCount < limit) {
200
+ ++fetchActiveCount;
201
+ return start(url, opts);
202
+ }
203
+ return new Promise((resolve, reject) => {
204
+ waitList.push({ url, opts, resolve, reject });
205
+ });
206
+ }
181
207
  /** 通过 CDN 竞速的方式拉取文件 */
182
208
  async function fetchSpeed(list) {
183
209
  const controllers = new Array(list.length);
184
- const result = await Promise.any(list.map((it, index) => (0, node_fetch_1.default)(it, {
210
+ const result = await Promise.any(list.map((it, index) => fetch(it, {
185
211
  signal: (controllers[index] = new AbortController()).signal
186
212
  }).then(response => [200, 301, 302, 307, 308].includes(response.status) ? { index, response } : Promise.reject())));
187
213
  for (let i = 0; i < controllers.length; i++) {
@@ -193,12 +219,13 @@ async function fetchSpeed(list) {
193
219
  /** 深度冻结一个对象,这将使得无法修改对象中的任何值,也无法添加新的值 */
194
220
  function deepFreeze(obj) {
195
221
  if (!obj)
196
- return;
222
+ return obj;
197
223
  Object.freeze(obj);
198
224
  for (let key in obj) {
199
225
  const value = obj[key];
200
226
  if (typeof value === 'object')
201
227
  deepFreeze(value);
202
228
  }
229
+ return obj;
203
230
  }
204
231
  exports.deepFreeze = deepFreeze;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readEvent = exports.readAnalyzeResult = exports.readUpdateJson = exports.readMergeVersionMap = exports.readNewVersionJson = exports.readOldVersionJson = exports.readRules = exports.deleteVariant = exports.readVariant = exports.writeVariant = void 0;
4
+ const Utils_1 = require("./Utils");
5
+ const map = new Map();
6
+ /** 创建一个变量 */
7
+ function writeVariant(key, value) {
8
+ map.set(key, value);
9
+ return value;
10
+ }
11
+ exports.writeVariant = writeVariant;
12
+ /** 读取一个变量 */
13
+ function readVariant(key) {
14
+ return map.get(key);
15
+ }
16
+ exports.readVariant = readVariant;
17
+ /** 移除一个变量 */
18
+ function deleteVariant(key) {
19
+ map.delete(key);
20
+ }
21
+ exports.deleteVariant = deleteVariant;
22
+ /**
23
+ * 读取最后一次构建的 rules
24
+ *
25
+ * **执行该函数前必须调用过 [loadRules]**
26
+ */
27
+ function readRules() {
28
+ return readLoadedData('swppRules', 'RulesReader', '规则文件');
29
+ }
30
+ exports.readRules = readRules;
31
+ /**
32
+ * 读取最后一次加载的 version json
33
+ *
34
+ * + **执行该函数前必须调用过 [loadRules]**
35
+ * + **调用该函数前必须调用过 [loadCacheJson]**
36
+ */
37
+ function readOldVersionJson() {
38
+ return readLoadedData('oldVersionJson', 'OldVersionReader', 'version json');
39
+ }
40
+ exports.readOldVersionJson = readOldVersionJson;
41
+ /**
42
+ * 读取最后一次构建的 VersionJson
43
+ *
44
+ * + **执行该函数前必须调用过 [loadRules]**
45
+ * + **调用该函数前必须调用过 [loadCacheJson]**
46
+ * + **执行该函数前必须调用过 [buildVersionJson]**
47
+ * + **执行该函数前必须调用过 [calcEjectValues]**
48
+ */
49
+ function readNewVersionJson() {
50
+ return readLoadedData('newVersionJson', 'NewVersionReader', 'version json');
51
+ }
52
+ exports.readNewVersionJson = readNewVersionJson;
53
+ /**
54
+ * 读取新旧版本文件合并后的版本地图
55
+ *
56
+ * + **执行该函数前必须调用过 [loadRules]**
57
+ * + **调用该函数前必须调用过 [loadCacheJson]**
58
+ * + **执行该函数前必须调用过 [buildVersionJson]**
59
+ * + **执行该函数前必须调用过 [calcEjectValues]**
60
+ */
61
+ function readMergeVersionMap() {
62
+ const key = 'mergeVersionMap';
63
+ const cache = readVariant(key);
64
+ if (cache)
65
+ return cache;
66
+ const map = {};
67
+ Object.assign(map, readOldVersionJson()?.list ?? {});
68
+ Object.assign(map, readNewVersionJson().list);
69
+ writeVariant(key, (0, Utils_1.deepFreeze)(map));
70
+ return map;
71
+ }
72
+ exports.readMergeVersionMap = readMergeVersionMap;
73
+ /**
74
+ * 读取最后一次加载的版本文件
75
+ *
76
+ * + **调用该函数前必须调用过 [loadRules]**
77
+ * + **调用该函数前必须调用过 [loadUpdateJson]**
78
+ */
79
+ function readUpdateJson() {
80
+ return readLoadedData('oldUpdateJson', 'OldUpdateJsonReader', 'update json');
81
+ }
82
+ exports.readUpdateJson = readUpdateJson;
83
+ /**
84
+ * 读取分析结果
85
+ *
86
+ * + **执行该函数前必须调用过 [loadRules]**
87
+ * + **调用该函数前必须调用过 [loadCacheJson]**
88
+ * + **调用该函数前必须调用过 [analyze]**
89
+ */
90
+ function readAnalyzeResult() {
91
+ return readLoadedData('swppAnalyze', 'AnalyzeResultReader', 'analyze result');
92
+ }
93
+ exports.readAnalyzeResult = readAnalyzeResult;
94
+ /** 读取一个事件 */
95
+ function readEvent(key) {
96
+ return readLoadedData(key, key[0].toUpperCase() + key.substring(1), key);
97
+ }
98
+ exports.readEvent = readEvent;
99
+ function readLoadedData(key, type, name) {
100
+ const item = readVariant(key);
101
+ switch (item) {
102
+ case undefined:
103
+ (0, Utils_1.error)(type, `${name} 尚未初始化`);
104
+ throw name;
105
+ case false:
106
+ (0, Utils_1.error)(type, `${name} 事件周期已经结束`);
107
+ throw name;
108
+ default:
109
+ return item;
110
+ }
111
+ }
@@ -1,19 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refreshUrl = exports.analyze = void 0;
4
- const FileAnalyzer_1 = require("./FileAnalyzer");
3
+ exports.refreshUrl = exports.analyzeVersion = void 0;
5
4
  const Utils_1 = require("./Utils");
6
- let extraUrl = new Set();
5
+ const Variant_1 = require("./Variant");
7
6
  /**
8
7
  * 分析两个版本信息的不同
9
8
  *
10
9
  * + **执行该函数前必须调用过 [loadRules]**
11
10
  * + **调用该函数前必须调用过 [loadCacheJson]**
12
- *
13
- * @param version 新的版本信息
11
+ * + **调用该函数前必须调用过 [buildVersionJson]**
14
12
  */
15
- function analyze(version) {
16
- const oldVersion = (0, FileAnalyzer_1.readOldVersionJson)();
13
+ function analyzeVersion() {
14
+ const extraUrl = (0, Variant_1.readEvent)('refreshUrl');
15
+ (0, Variant_1.writeVariant)('refreshUrl', false);
16
+ const newVersion = (0, Variant_1.readNewVersionJson)();
17
+ const oldVersion = (0, Variant_1.readOldVersionJson)();
17
18
  const result = {
18
19
  force: false,
19
20
  deleted: [],
@@ -26,7 +27,7 @@ function analyze(version) {
26
27
  };
27
28
  if (!oldVersion)
28
29
  return result;
29
- if (version.version !== oldVersion.version) {
30
+ if (newVersion.version !== oldVersion.version) {
30
31
  result.force = true;
31
32
  return result;
32
33
  }
@@ -37,7 +38,7 @@ function analyze(version) {
37
38
  continue;
38
39
  }
39
40
  const oldValue = oldVersion.list[url];
40
- const newValue = version.list[url];
41
+ const newValue = newVersion.list[url];
41
42
  if (!newValue) {
42
43
  result.deleted.push(url);
43
44
  continue;
@@ -55,16 +56,12 @@ function analyze(version) {
55
56
  }
56
57
  }
57
58
  extraUrl.forEach(url => result.refresh.push(url));
58
- extraUrl = null;
59
- return result;
59
+ return (0, Variant_1.writeVariant)('swppAnalyze', (0, Utils_1.deepFreeze)(result));
60
60
  }
61
- exports.analyze = analyze;
61
+ exports.analyzeVersion = analyzeVersion;
62
+ (0, Variant_1.writeVariant)('refreshUrl', new Set());
62
63
  /** 手动添加一个要刷新的 URL */
63
64
  function refreshUrl(url) {
64
- if (!extraUrl) {
65
- (0, Utils_1.error)('RefreshUrl', '版本信息已经分析完成,调用该函数无意义!');
66
- throw 'refreshUrl 调用时机错误';
67
- }
68
- extraUrl.add(url);
65
+ (0, Variant_1.readEvent)('refreshUrl').add(url);
69
66
  }
70
67
  exports.refreshUrl = refreshUrl;
package/dist/index.js CHANGED
@@ -5,21 +5,25 @@ const FileAnalyzer_1 = require("./FileAnalyzer");
5
5
  const ServiceWorkerBuilder_1 = require("./ServiceWorkerBuilder");
6
6
  const SwppRules_1 = require("./SwppRules");
7
7
  const UpdateJsonBuilder_1 = require("./UpdateJsonBuilder");
8
+ const Variant_1 = require("./Variant");
8
9
  const VersionAnalyzer_1 = require("./VersionAnalyzer");
10
+ const DomBuilder_1 = require("./DomBuilder");
9
11
  // noinspection JSUnusedGlobalSymbols
10
12
  exports.default = {
11
- version: '1.2.3',
13
+ version: '2.0.1',
12
14
  cache: {
13
- readEjectData: Utils_1.readEjectData, readUpdateJson: UpdateJsonBuilder_1.readUpdateJson,
14
- readRules: SwppRules_1.readRules, readMergeVersionMap: FileAnalyzer_1.readMergeVersionMap,
15
- readOldVersionJson: FileAnalyzer_1.readOldVersionJson, readNewVersionJson: FileAnalyzer_1.readNewVersionJson
15
+ readEjectData: Utils_1.readEjectData, readUpdateJson: Variant_1.readUpdateJson,
16
+ readRules: Variant_1.readRules, readMergeVersionMap: Variant_1.readMergeVersionMap,
17
+ readOldVersionJson: Variant_1.readOldVersionJson, readNewVersionJson: Variant_1.readNewVersionJson,
18
+ readAnalyzeResult: Variant_1.readAnalyzeResult
16
19
  },
17
20
  builder: {
18
21
  buildServiceWorker: ServiceWorkerBuilder_1.buildServiceWorker,
22
+ buildDomJs: DomBuilder_1.buildDomJs,
19
23
  buildVersionJson: FileAnalyzer_1.buildVersionJson,
20
- buildNewInfo: UpdateJsonBuilder_1.buildNewInfo,
24
+ buildUpdateJson: UpdateJsonBuilder_1.buildUpdateJson,
21
25
  calcEjectValues: Utils_1.calcEjectValues,
22
- analyze: VersionAnalyzer_1.analyze
26
+ analyzeVersion: VersionAnalyzer_1.analyzeVersion
23
27
  },
24
28
  loader: {
25
29
  loadRules: SwppRules_1.loadRules, loadUpdateJson: UpdateJsonBuilder_1.loadUpdateJson, loadVersionJson: FileAnalyzer_1.loadVersionJson
@@ -31,6 +35,6 @@ exports.default = {
31
35
  getSource: Utils_1.getSource, getShorthand: UpdateJsonBuilder_1.getShorthand, findCache: FileAnalyzer_1.findCache,
32
36
  fetchFile: Utils_1.fetchFile, replaceDevRequest: Utils_1.replaceDevRequest, replaceRequest: FileAnalyzer_1.replaceRequest,
33
37
  isStable: FileAnalyzer_1.isStable, isExclude: FileAnalyzer_1.isExclude, findFileHandler: FileAnalyzer_1.findFileHandler,
34
- eachAllLinkInUrl: FileAnalyzer_1.eachAllLinkInUrl, deepFreeze: Utils_1.deepFreeze
38
+ eachAllLinkInUrl: FileAnalyzer_1.eachAllLinkInUrl, deepFreeze: Utils_1.deepFreeze, writeVariant: Variant_1.writeVariant, readVariant: Variant_1.readVariant, deleteVariant: Variant_1.deleteVariant
35
39
  }
36
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "1.2.3",
3
+ "version": "2.0.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 构建 DOM 端的 JS 文件
3
+ *
4
+ * + **执行该函数前必须调用过 [loadRules]**
5
+ */
6
+ export declare function buildDomJs(): string;
@@ -1,3 +1,15 @@
1
+ /**
2
+ * 构建一个 version json
3
+ *
4
+ * + **执行该函数前必须调用过 [loadRules]**
5
+ * + **调用该函数前必须调用过 [loadCacheJson]**
6
+ * + **执行该函数前必须调用过 [calcEjectValues]**
7
+ *
8
+ * @param protocol 网站的网络协议
9
+ * @param domain 网站域名(包括二级域名)
10
+ * @param root 网页根目录(首页 index.html 所在目录)
11
+ */
12
+ export declare function buildVersionJson(protocol: ('https://' | 'http://'), domain: string, root: string): Promise<VersionJson>;
1
13
  /**
2
14
  * 版本信息(可以用 JSON 序列化)
3
15
  * @see VersionMap
@@ -44,43 +56,6 @@ export declare function loadVersionJson(url: string): Promise<VersionJson | null
44
56
  export declare function submitCacheInfo(key: string, value: any): void;
45
57
  /** 添加一个要监听的 URL */
46
58
  export declare function submitExternalUrl(url: string): void;
47
- /**
48
- * 读取最后一次加载的 version json
49
- *
50
- * + **执行该函数前必须调用过 [loadRules]**
51
- * + **调用该函数前必须调用过 [loadCacheJson]**
52
- */
53
- export declare function readOldVersionJson(): VersionJson | null;
54
- /**
55
- * 读取最后一次构建的 VersionJson
56
- *
57
- * + **执行该函数前必须调用过 [loadRules]**
58
- * + **调用该函数前必须调用过 [loadCacheJson]**
59
- * + **执行该函数前必须调用过 [buildVersionJson]**
60
- * + **执行该函数前必须调用过 [calcEjectValues]**
61
- */
62
- export declare function readNewVersionJson(): VersionJson;
63
- /**
64
- * 读取新旧版本文件合并后的版本地图
65
- *
66
- * + **执行该函数前必须调用过 [loadRules]**
67
- * + **调用该函数前必须调用过 [loadCacheJson]**
68
- * + **执行该函数前必须调用过 [buildVersionJson]**
69
- * + **执行该函数前必须调用过 [calcEjectValues]**
70
- */
71
- export declare function readMergeVersionMap(): VersionMap;
72
- /**
73
- * 构建一个 version json
74
- *
75
- * + **执行该函数前必须调用过 [loadRules]**
76
- * + **调用该函数前必须调用过 [loadCacheJson]**
77
- * + **执行该函数前必须调用过 [calcEjectValues]**
78
- *
79
- * @param protocol 网站的网络协议
80
- * @param domain 网站域名(包括二级域名)
81
- * @param root 网页根目录(首页 index.html 所在目录)
82
- */
83
- export declare function buildVersionJson(protocol: ('https://' | 'http://'), domain: string, root: string): Promise<VersionJson>;
84
59
  /** 注册一个文件处理器 */
85
60
  export declare function registryFileHandler(handler: FileHandler): void;
86
61
  /** 查询一个文件处理器 */
@@ -52,6 +52,8 @@ export interface VersionJsonConfig {
52
52
  export interface ExternalMonitorConfig {
53
53
  /** 拉取网络文件的超时时间 */
54
54
  timeout: number;
55
+ /** 拉取文件时的并发限制 */
56
+ concurrencyLimit: number;
55
57
  /** 匹配 JS 代码中的 URL */
56
58
  js: ({
57
59
  head: string;
@@ -112,6 +114,8 @@ export interface SwppConfigTemplate {
112
114
  external?: boolean | {
113
115
  /** 拉取网络文件的超时时间 */
114
116
  timeout?: number;
117
+ /** 拉取文件时的并发限制 */
118
+ concurrencyLimit: number;
115
119
  /** 匹配 JS 代码中的 URL */
116
120
  js?: ({
117
121
  head: string;
@@ -1,24 +1,18 @@
1
1
  import { Request, Response } from 'node-fetch';
2
2
  import { SwppConfig } from './SwppConfig';
3
3
  /**
4
- * 读取最后一次构建的 rules
5
- *
6
- * **执行该函数前必须调用过 [loadRules]**
4
+ * 加载 rules 文件
5
+ * @param root 项目根目录
6
+ * @param fileName rules 文件名称
7
+ * @param selects 附加的可选目录,优先级低于 [root]
7
8
  */
8
- export declare function readRules(): SwppRules;
9
+ export declare function loadRules(root: string, fileName: string, selects: string[]): SwppRules;
9
10
  /**
10
11
  * 添加一个 rules 映射事件,这个事件允许用户修改 rules 的内容
11
12
  *
12
13
  * 执行时按照注册的顺序执行
13
14
  */
14
15
  export declare function addRulesMapEvent(mapper: (rules: any) => void): void;
15
- /**
16
- * 加载 rules 文件
17
- * @param root 项目根目录
18
- * @param fileName rules 文件名称
19
- * @param selects 附加的可选目录,优先级低于 [root]
20
- */
21
- export declare function loadRules(root: string, fileName: string, selects: string[]): SwppRules;
22
16
  export interface SwppRules {
23
17
  /** 配置项 */
24
18
  config: SwppConfig;
@@ -1,19 +1,4 @@
1
1
  import { AnalyzeResult } from './VersionAnalyzer';
2
- /** 提交修改 */
3
- export declare function submitChange(...change: ChangeExpression[]): void;
4
- /**
5
- * 加载版本文件
6
- *
7
- * + **调用该函数前必须调用过 [loadRules]**
8
- */
9
- export declare function loadUpdateJson(url: string): Promise<UpdateJson | null>;
10
- /**
11
- * 读取最后一次加载的版本文件
12
- *
13
- * + **调用该函数前必须调用过 [loadRules]**
14
- * + **调用该函数前必须调用过 [loadUpdateJson]**
15
- */
16
- export declare function readUpdateJson(): UpdateJson | null;
17
2
  /**
18
3
  * 构建新的 update json
19
4
  *
@@ -25,7 +10,15 @@ export declare function readUpdateJson(): UpdateJson | null;
25
10
  * @param root 网站根路径(包括网络协议)
26
11
  * @param dif 网站文件变化
27
12
  */
28
- export declare function buildNewInfo(root: string, dif: AnalyzeResult): UpdateJson;
13
+ export declare function buildUpdateJson(root: string, dif: AnalyzeResult): UpdateJson;
14
+ /** 提交修改 */
15
+ export declare function submitChange(...change: ChangeExpression[]): void;
16
+ /**
17
+ * 加载版本文件
18
+ *
19
+ * + **调用该函数前必须调用过 [loadRules]**
20
+ */
21
+ export declare function loadUpdateJson(url: string): Promise<UpdateJson | null>;
29
22
  /**
30
23
  * 获取 URL 的缩写形式
31
24
  *