pug-site-core 2.0.5 → 2.0.7
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/lib/generate.js +11 -8
- package/package.json +2 -2
package/lib/generate.js
CHANGED
|
@@ -44,7 +44,7 @@ export async function compilePagesPugToFn(pugPath) {
|
|
|
44
44
|
pagesPugFilePathArr.filter(
|
|
45
45
|
(fileName) => !pugPath || pathIsSame(pugPath, fileName)
|
|
46
46
|
),
|
|
47
|
-
|
|
47
|
+
12, // 限制并发数为10
|
|
48
48
|
async (fileName) => {
|
|
49
49
|
const filePath = paths.resolveRoot(paths.template.pages, fileName);
|
|
50
50
|
const funName = fileName.split(pathSymbol).join("_").slice(0, -4);
|
|
@@ -139,6 +139,9 @@ export async function generateGetDataFn() {
|
|
|
139
139
|
*/
|
|
140
140
|
export async function fetchDataToJsonFile(args) {
|
|
141
141
|
try {
|
|
142
|
+
console.log("开始获取数据...");
|
|
143
|
+
let starTime = Date.now();
|
|
144
|
+
|
|
142
145
|
// 解析过滤参数,使用对象解构使代码更清晰
|
|
143
146
|
const { filterFun, filterLang } = args.reduce(
|
|
144
147
|
(acc, item) => {
|
|
@@ -201,7 +204,7 @@ export async function fetchDataToJsonFile(args) {
|
|
|
201
204
|
// 创建一个全局任务队列控制整体并发数
|
|
202
205
|
const queue = async.queue(async (task) => {
|
|
203
206
|
await task();
|
|
204
|
-
}, fetchDataConcurrencyLimit ||
|
|
207
|
+
}, fetchDataConcurrencyLimit || 12);
|
|
205
208
|
|
|
206
209
|
// 收集所有需要执行的任务
|
|
207
210
|
const allTasks = [];
|
|
@@ -260,8 +263,8 @@ export async function fetchDataToJsonFile(args) {
|
|
|
260
263
|
const regex = /^\[.+\]$/;
|
|
261
264
|
if (regex.test(name)) {
|
|
262
265
|
let property = name.slice(1, -1);
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
// 使用async.eachLimit替换for循环,并发写入
|
|
267
|
+
await async.eachLimit(data, 12, async (dataItem, index) => {
|
|
265
268
|
let fileName = dataItem[property];
|
|
266
269
|
if (!fileName) {
|
|
267
270
|
return Promise.reject(
|
|
@@ -274,7 +277,7 @@ export async function fetchDataToJsonFile(args) {
|
|
|
274
277
|
paths.join(language, outPutPath.replace(name, fileName)),
|
|
275
278
|
dataItem
|
|
276
279
|
);
|
|
277
|
-
}
|
|
280
|
+
});
|
|
278
281
|
} else {
|
|
279
282
|
await saveJsonData(paths.join(language, outPutPath), data);
|
|
280
283
|
}
|
|
@@ -304,8 +307,7 @@ export async function fetchDataToJsonFile(args) {
|
|
|
304
307
|
let data = await getData[funName](language);
|
|
305
308
|
await checkData(data, language, funName);
|
|
306
309
|
if (Array.isArray(data)) {
|
|
307
|
-
|
|
308
|
-
const item = data[index];
|
|
310
|
+
await async.eachLimit(data, 12, async (item, index) => {
|
|
309
311
|
let lastJsonFilePath;
|
|
310
312
|
if (item.page_name) {
|
|
311
313
|
lastJsonFilePath = paths.join(
|
|
@@ -323,7 +325,7 @@ export async function fetchDataToJsonFile(args) {
|
|
|
323
325
|
}
|
|
324
326
|
item._template = fileName;
|
|
325
327
|
await saveJsonData(lastJsonFilePath, item);
|
|
326
|
-
}
|
|
328
|
+
});
|
|
327
329
|
} else {
|
|
328
330
|
if (data.page_name) {
|
|
329
331
|
jsonFilePath = paths.join(
|
|
@@ -347,6 +349,7 @@ export async function fetchDataToJsonFile(args) {
|
|
|
347
349
|
// 等待所有任务完成
|
|
348
350
|
return new Promise((resolve, reject) => {
|
|
349
351
|
queue.drain(() => {
|
|
352
|
+
console.log("获取数据并写入完成花费:", (Date.now() - starTime) / 1000, "s");
|
|
350
353
|
resolve();
|
|
351
354
|
});
|
|
352
355
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pug-site-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"axios": "^1.7.7"
|
|
38
38
|
},
|
|
39
39
|
"license": "ISC",
|
|
40
|
-
"description": "
|
|
40
|
+
"description": "增加获取数据的log",
|
|
41
41
|
"files": [
|
|
42
42
|
"lib/",
|
|
43
43
|
"index.js"
|