@hyext/builder-revues 1.0.51 → 1.0.53

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/index.js CHANGED
@@ -14,6 +14,7 @@ var os = require('os');
14
14
  var chalk = require('chalk');
15
15
  var util = require('util');
16
16
  var download = require('download');
17
+ var chokidar = require('chokidar');
17
18
  var glob = require('glob');
18
19
  var handlebars = require('handlebars');
19
20
  var tapable = require('tapable');
@@ -29,6 +30,7 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
29
30
  var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
30
31
  var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
31
32
  var download__default = /*#__PURE__*/_interopDefaultLegacy(download);
33
+ var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
32
34
  var handlebars__default = /*#__PURE__*/_interopDefaultLegacy(handlebars);
33
35
  var liveServer__default = /*#__PURE__*/_interopDefaultLegacy(liveServer);
34
36
  var archiver__default = /*#__PURE__*/_interopDefaultLegacy(archiver);
@@ -279,6 +281,116 @@ function resolvePluginConfig(pluginDir, key, props) {
279
281
  return resolvedConfig;
280
282
  }
281
283
 
284
+ class CollectQueue {
285
+ constructor(handler, opts) {
286
+ this.timer = null;
287
+ this.debounceTime = 50;
288
+ this.actionQueue = [];
289
+ this.handler = handler;
290
+ Object.assign(this, opts);
291
+ }
292
+ collect(action) {
293
+ this.actionQueue.push(action);
294
+ this.timer && clearTimeout(this.timer);
295
+ this.timer = setTimeout(() => {
296
+ this.flush();
297
+ }, this.debounceTime);
298
+ }
299
+ flush() {
300
+ const queue = this.actionQueue;
301
+ this.actionQueue = [];
302
+ this.handler(queue);
303
+ }
304
+ }
305
+
306
+ function normalizePath(filePath = '') {
307
+ const format = path__default["default"].posix.normalize(filePath.replace(/\\/g, '/'));
308
+ const hasSlash = (!filePath.startsWith('//') && !filePath.startsWith('\\\\')) ||
309
+ format.startsWith('//');
310
+ return hasSlash ? format : '/' + format;
311
+ }
312
+
313
+ const defaultIgnoreRules = [/node_modules/, /(^|[\/\\])\../, 'dist/build-result/**', 'release/**'];
314
+ function watchFiles(opts, cb) {
315
+ let isReady = false;
316
+ chokidar__default["default"]
317
+ .watch(opts.pattern, {
318
+ cwd: opts.projectPath,
319
+ ignored: opts.ignored
320
+ ? [...defaultIgnoreRules, ...opts.ignored]
321
+ : defaultIgnoreRules
322
+ })
323
+ .on('all', (type, filePath) => {
324
+ if (isReady) {
325
+ // filePath 需要遵循posix规范
326
+ cb && cb(type, normalizePath(filePath));
327
+ }
328
+ })
329
+ .on('error', (e) => {
330
+ console.error(e);
331
+ })
332
+ .on('ready', () => {
333
+ isReady = true;
334
+ logger.success('file watcher ready.');
335
+ });
336
+ }
337
+
338
+ const maxCompileFilesCount = 5;
339
+ function watchProject(opts, done) {
340
+ const { compilerManager, compileFn, graphId } = opts;
341
+ function compileOne(type, filePath) {
342
+ return __awaiter(this, void 0, void 0, function* () {
343
+ if (compilerManager.isFileChange({ type, filePath })) {
344
+ console.log('\n\n');
345
+ logger.log('正在编译:' + filePath);
346
+ try {
347
+ yield compilerManager.compileSingleCode({ graphId, filePath, type });
348
+ done && done();
349
+ }
350
+ catch (error) {
351
+ const msg = `热编译文件 '${filePath}' 失败,原因:\n\n ${error.message}`;
352
+ error.message = msg;
353
+ console.log(error);
354
+ }
355
+ }
356
+ });
357
+ }
358
+ function restart() {
359
+ return __awaiter(this, void 0, void 0, function* () {
360
+ console.log('\n\n');
361
+ logger.log('重启编译器');
362
+ compilerManager.destroy();
363
+ yield compileFn(true);
364
+ done && done();
365
+ });
366
+ }
367
+ function flush(queue) {
368
+ return __awaiter(this, void 0, void 0, function* () {
369
+ if (queue.length > maxCompileFilesCount) {
370
+ // 重启编译器
371
+ yield restart();
372
+ }
373
+ else {
374
+ {
375
+ while (queue.length) {
376
+ const item = queue.shift();
377
+ if (item != null) {
378
+ yield compileOne(item.type, item.filePath);
379
+ }
380
+ }
381
+ }
382
+ }
383
+ });
384
+ }
385
+ const collectFileQueue = new CollectQueue(flush);
386
+ watchFiles({
387
+ pattern: '**/**',
388
+ projectPath: compilerManager.projectPath
389
+ }, (type, filePath) => {
390
+ collectFileQueue.collect({ type, filePath });
391
+ });
392
+ }
393
+
282
394
  function compile(mode, projectPath, outputPath) {
283
395
  return __awaiter(this, void 0, void 0, function* () {
284
396
  const isProd = mode === 'prod';
@@ -290,17 +402,21 @@ function compile(mode, projectPath, outputPath) {
290
402
  } : {};
291
403
  const { plugins, } = yield tryLoadPlugins(projectPath);
292
404
  initCacheDir();
293
- yield codeCompiler.compilerManager.init({
294
- projectPath,
295
- outputPath,
296
- cachePath: cacheDir,
297
- compileSettings,
298
- plugins,
299
- mode
405
+ const run = (keep) => __awaiter(this, void 0, void 0, function* () {
406
+ yield codeCompiler.compilerManager.init({
407
+ projectPath,
408
+ outputPath,
409
+ cachePath: cacheDir,
410
+ compileSettings,
411
+ plugins,
412
+ mode
413
+ });
414
+ const action = isProd ? 'compile' : 'compileDev';
415
+ yield codeCompiler.compilerManager[action](isProd ? undefined : keep);
300
416
  });
301
- const action = isProd ? 'compile' : 'compileDev';
302
- yield codeCompiler.compilerManager[action]();
417
+ yield run(false);
303
418
  copyProjectConfigJSON(projectPath, outputPath);
419
+ return run;
304
420
  });
305
421
  }
306
422
  function compileDevPluginForProd(projectPath, outputPath) {
@@ -358,15 +474,12 @@ function watchGame(opts) {
358
474
  function watchMiniProgram(opts) {
359
475
  return __awaiter(this, void 0, void 0, function* () {
360
476
  const { projectPath, outputPath, cb } = opts;
361
- yield compile('dev', projectPath, outputPath);
362
- codeCompiler.compilerManager.watch({ graphId: 'miniprogram' }, (type, filePath) => __awaiter(this, void 0, void 0, function* () {
363
- yield codeCompiler.compilerManager.compileSingleCode({
364
- type,
365
- filePath,
366
- graphId: 'miniprogram'
367
- });
368
- cb && cb();
369
- }));
477
+ const run = yield compile('dev', projectPath, outputPath);
478
+ watchProject({
479
+ compilerManager: codeCompiler.compilerManager,
480
+ graphId: 'miniprogram',
481
+ compileFn: run
482
+ }, cb);
370
483
  });
371
484
  }
372
485
  function watchDevPlugin(opts) {
@@ -525,10 +638,12 @@ function mergeSubPackagesToMainPackage(packagePath, main, subList, onMoveBefore)
525
638
  subList.forEach(conf => {
526
639
  const subRoot = path__default["default"].join(packagePath, conf.name);
527
640
  const subPath = path__default["default"].join(subRoot, conf.root);
528
- const dest = path__default["default"].join(mainPath, conf.root);
529
- onMoveBefore && onMoveBefore(subRoot, mainPath, conf);
530
- fs__default["default"].moveSync(subPath, dest, { overwrite: true });
531
- fs__default["default"].removeSync(path__default["default"].join(packagePath, conf.name));
641
+ if (fs__default["default"].existsSync(subPath)) {
642
+ const dest = path__default["default"].join(mainPath, conf.root);
643
+ onMoveBefore && onMoveBefore(subRoot, mainPath, conf);
644
+ fs__default["default"].moveSync(subPath, dest, { overwrite: true });
645
+ fs__default["default"].removeSync(subRoot);
646
+ }
532
647
  });
533
648
  }
534
649
 
@@ -855,9 +970,9 @@ function startLiveServer(opts) {
855
970
  open: false,
856
971
  ignore: opts.ignore,
857
972
  file: "index.html",
858
- wait: 1000,
973
+ wait: 200,
859
974
  mount: opts.mount,
860
- logLevel: 1,
975
+ logLevel: 0,
861
976
  https: httpsConf
862
977
  };
863
978
  // @ts-expect-error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyext/builder-revues",
3
- "version": "1.0.51",
3
+ "version": "1.0.53",
4
4
  "description": "> TODO: description",
5
5
  "author": "loler",
6
6
  "homepage": "",
@@ -24,14 +24,15 @@
24
24
  "minify": "node scripts/minify"
25
25
  },
26
26
  "dependencies": {
27
- "@revues/cocos-web-adapter": "1.0.51",
28
- "@revues/code-compiler": "1.0.51",
29
- "@revues/hyext-adapter": "1.0.51",
30
- "@revues/web-frame": "1.0.51",
31
- "@revues/web-sdk-core": "1.0.51",
27
+ "@revues/cocos-web-adapter": "1.0.53",
28
+ "@revues/code-compiler": "1.0.53",
29
+ "@revues/hyext-adapter": "1.0.53",
30
+ "@revues/web-frame": "1.0.53",
31
+ "@revues/web-sdk-core": "1.0.53",
32
32
  "archiver": "^7.0.1",
33
33
  "axios": "^1.7.1",
34
34
  "chalk": "^2.4.2",
35
+ "chokidar": "^3.6.0",
35
36
  "download": "^8.0.0",
36
37
  "fs-extra": "8.1.0",
37
38
  "glob": "^10.3.10",
@@ -45,8 +46,7 @@
45
46
  "@types/archiver": "^6.0.2",
46
47
  "@types/live-server": "^1.2.3",
47
48
  "@types/ramda": "^0.29.11",
48
- "chokidar": "^3.6.0",
49
49
  "terser": "^5.31.0"
50
50
  },
51
- "gitHead": "8e60b83b2a9fc4ea7490643f06afbf47d0033d35"
51
+ "gitHead": "e42b19e3ef7e2e29b03b1633f5e2b5cc316caf9f"
52
52
  }