file-lane 2.0.2-beta.16 → 2.0.2-beta.18

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/FileLane.d.ts CHANGED
@@ -13,6 +13,7 @@ declare class FileLane<O = any> {
13
13
  private context;
14
14
  private watcher?;
15
15
  private compilation?;
16
+ private changeFileList;
16
17
  /**
17
18
  * 实例化FileLane
18
19
  * @param config fileLane 配置
@@ -20,9 +21,9 @@ declare class FileLane<O = any> {
20
21
  * @param compilerOption 编译参数,不同语言的项目具有的参数不同,即使同一项目开发者也会设置不同的参数
21
22
  */
22
23
  constructor(config: IFileLaneConfig<O>, projectPath?: string, compilerOption?: O | undefined, events?: {
23
- onBuildSuccess?: ((data: {
24
+ onBuildSuccess?: (data: {
24
25
  costTime: number;
25
- }) => void) | undefined;
26
+ }) => void;
26
27
  } | undefined);
27
28
  /**
28
29
  * 运行
package/lib/FileLane.js CHANGED
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const shared_utils_1 = require("@aiot-toolkit/shared-utils");
16
16
  const chokidar_1 = __importDefault(require("chokidar"));
17
- const del_1 = __importDefault(require("del"));
18
17
  const fs_extra_1 = __importDefault(require("fs-extra"));
19
18
  const lodash_1 = __importDefault(require("lodash"));
20
19
  const path_1 = __importDefault(require("path"));
@@ -22,6 +21,7 @@ const FileLaneCompilation_1 = __importDefault(require("./FileLaneCompilation"));
22
21
  const CompilationEvent_1 = __importDefault(require("./event/CompilationEvent"));
23
22
  const FileEvent_1 = __importDefault(require("./event/FileEvent"));
24
23
  const FileLaneUtil_1 = __importDefault(require("./utils/FileLaneUtil"));
24
+ const IChangedFile_1 = require("./interface/IChangedFile");
25
25
  /**
26
26
  * FileLane
27
27
  *
@@ -40,6 +40,7 @@ class FileLane {
40
40
  this.config = config;
41
41
  this.compilerOption = compilerOption;
42
42
  this.events = events;
43
+ this.changeFileList = [];
43
44
  this.processExitHandler = () => {
44
45
  this.dispose();
45
46
  };
@@ -136,7 +137,7 @@ class FileLane {
136
137
  const t1 = Date.now();
137
138
  this.initCompilation();
138
139
  try {
139
- yield this.complyBeforeCompile(fileList);
140
+ yield this.complyBeforeCompile();
140
141
  this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.PROJECT_START));
141
142
  for (let item of fileList) {
142
143
  this.triggerPlugins(new FileEvent_1.default(FileEvent_1.default.FILE_START_COMPILATION, FileLaneUtil_1.default.pathToFileParam(item)));
@@ -212,6 +213,9 @@ class FileLane {
212
213
  return;
213
214
  }
214
215
  const buildPath = FileLaneUtil_1.default.getOutputPath(this.context);
216
+ if (!fs_extra_1.default.existsSync(buildPath)) {
217
+ shared_utils_1.FileUtil.mkdirSync(buildPath, { hidden: true });
218
+ }
215
219
  return Promise.all(fileList.map((item) => {
216
220
  const resolvePath = path_1.default.relative(this.context.projectPath, item.path);
217
221
  // 将相对路径与输出路径拼接,形成最新的文件路径
@@ -283,12 +287,17 @@ class FileLane {
283
287
  /**
284
288
  * 执行项目转换的前置工作
285
289
  */
286
- complyBeforeCompile(fileList) {
290
+ complyBeforeCompile() {
287
291
  return __awaiter(this, void 0, void 0, function* () {
288
292
  const { beforeCompile } = this.config;
289
293
  if (beforeCompile) {
290
294
  for (let item of beforeCompile) {
291
- yield item(this.context, fileList, this.config, this.compilerOption);
295
+ yield item({
296
+ context: this.context,
297
+ config: this.config,
298
+ compilerOption: this.compilerOption,
299
+ compalition: this.compilation
300
+ });
292
301
  }
293
302
  }
294
303
  });
@@ -303,7 +312,12 @@ class FileLane {
303
312
  for (let item of afterCompile) {
304
313
  try {
305
314
  shared_utils_1.ColorConsole.info(`FollowWork: ${item.workerDescribe} start`);
306
- yield item.worker(this.context, this.config, this.compilerOption);
315
+ yield item.worker({
316
+ context: this.context,
317
+ config: this.config,
318
+ compilerOption: this.compilerOption,
319
+ compalition: this.compilation
320
+ });
307
321
  shared_utils_1.ColorConsole.info(`FollowWork: ${item.workerDescribe} end`);
308
322
  }
309
323
  catch (error) {
@@ -317,8 +331,12 @@ class FileLane {
317
331
  watch() {
318
332
  return __awaiter(this, void 0, void 0, function* () {
319
333
  // 监听文件变化,并触发 build
320
- const onChange = (changedFileList) => __awaiter(this, void 0, void 0, function* () {
321
- const fileList = this.config.collectFile ? this.config.collectFile() : this.collectFile();
334
+ const onChange = () => __awaiter(this, void 0, void 0, function* () {
335
+ const fileList = this.config.collectFile
336
+ ? this.config.collectFile(this.changeFileList)
337
+ : this.collectFile();
338
+ // 开始编译前,记录列表置空
339
+ this.changeFileList = [];
322
340
  yield this.build(fileList);
323
341
  });
324
342
  this.listenFileChange(onChange);
@@ -357,14 +375,16 @@ class FileLane {
357
375
  ignored: this.getIgnoreConfig()
358
376
  });
359
377
  const throttledOnChange = lodash_1.default.throttle(onChange, 1000, {
360
- leading: true,
361
- trailing: false
378
+ leading: false,
379
+ trailing: true
362
380
  });
363
- const handler = (filePath) => {
381
+ const handler = (path, type) => {
364
382
  const { exclude, include } = this.config;
365
383
  // 执行onChange回调
366
- if (shared_utils_1.FileUtil.include(filePath, include, exclude)) {
367
- throttledOnChange([filePath]);
384
+ const validFile = shared_utils_1.FileUtil.include(path, include, exclude);
385
+ if (validFile) {
386
+ this.changeFileList.push({ path, type });
387
+ throttledOnChange();
368
388
  }
369
389
  };
370
390
  watcher
@@ -373,15 +393,15 @@ class FileLane {
373
393
  watcher
374
394
  .on('add', (path) => {
375
395
  // 监听文件添加事件
376
- handler(path);
396
+ handler(path, IChangedFile_1.HandlerType.ADD);
377
397
  })
378
398
  .on('change', (path) => {
379
399
  // 监听文件修改事件
380
- handler(path);
400
+ handler(path, IChangedFile_1.HandlerType.CHANGE);
381
401
  })
382
402
  .on('unlink', (filePath) => {
383
403
  // 监听文件删除事件
384
- handler(filePath);
404
+ handler(filePath, IChangedFile_1.HandlerType.UNLINK);
385
405
  });
386
406
  })
387
407
  .on('error', (error) => {
@@ -399,7 +419,7 @@ class FileLane {
399
419
  */
400
420
  cleanOutput() {
401
421
  return __awaiter(this, void 0, void 0, function* () {
402
- yield (0, del_1.default)(FileLaneUtil_1.default.getOutputPath(this.context), { force: true });
422
+ shared_utils_1.FileUtil.del(FileLaneUtil_1.default.getOutputPath(this.context));
403
423
  });
404
424
  }
405
425
  /**
@@ -1,7 +1,10 @@
1
1
  import AsyncEventDispatcher from './event/asyncEvent/AsyncEventDispatcher';
2
+ import IFileParam from './interface/IFileParam';
2
3
  /**
3
4
  * FileLaneCompilation
4
5
  */
5
6
  declare class FileLaneCompilation extends AsyncEventDispatcher {
7
+ buildFileList: IFileParam<any>[];
8
+ diffJson: string[];
6
9
  }
7
10
  export default FileLaneCompilation;
@@ -8,5 +8,10 @@ const AsyncEventDispatcher_1 = __importDefault(require("./event/asyncEvent/Async
8
8
  * FileLaneCompilation
9
9
  */
10
10
  class FileLaneCompilation extends AsyncEventDispatcher_1.default {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.buildFileList = [];
14
+ this.diffJson = [];
15
+ }
11
16
  }
12
17
  exports.default = FileLaneCompilation;
@@ -0,0 +1,9 @@
1
+ export interface IChangedFile {
2
+ path: string;
3
+ type: HandlerType;
4
+ }
5
+ export declare enum HandlerType {
6
+ ADD = 0,
7
+ CHANGE = 1,
8
+ UNLINK = 2
9
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HandlerType = void 0;
4
+ var HandlerType;
5
+ (function (HandlerType) {
6
+ HandlerType[HandlerType["ADD"] = 0] = "ADD";
7
+ HandlerType[HandlerType["CHANGE"] = 1] = "CHANGE";
8
+ HandlerType[HandlerType["UNLINK"] = 2] = "UNLINK";
9
+ })(HandlerType || (exports.HandlerType = HandlerType = {}));
@@ -2,6 +2,8 @@ import { MatchType } from '@aiot-toolkit/shared-utils';
2
2
  import IFileLaneContext from './IFileLaneContext';
3
3
  import ILoader from './ILoader';
4
4
  import IPlugin from './IPlugin';
5
+ import FileLaneCompilation from '../FileLaneCompilation';
6
+ import { IChangedFile } from './IChangedFile';
5
7
  export type ILoaderClass = (new (...args: any[]) => ILoader) & {
6
8
  raw?: boolean;
7
9
  };
@@ -30,7 +32,7 @@ export default interface IFileLaneConfig<O = any> {
30
32
  *
31
33
  * @description 用于采集所有要处理的真实文件路径列表,或者输入文件列表中要处理的真实文件路径列表
32
34
  */
33
- collectFile?: (entryFileList?: string[]) => string[];
35
+ collectFile?: (entryFileList?: IChangedFile[]) => string[];
34
36
  /**
35
37
  * 文件收集器
36
38
  *
@@ -106,12 +108,14 @@ type FollowWoker<O> = {
106
108
  worker: FollowWork<O>;
107
109
  workerDescribe?: string;
108
110
  };
109
- export type FollowWork<O = any> = (context: IFileLaneContext, config?: IFileLaneConfig, compilerOption?: O) => Promise<any>;
110
- /**
111
- * context 上下文
112
- * fileList 待转换的文件列表
113
- */
114
- export type PreWork<O = any> = (context: IFileLaneContext, fileList: string[], config: IFileLaneConfig, compilerOption: O) => Promise<any>;
111
+ type CompileParam<O = any> = {
112
+ context: IFileLaneContext;
113
+ config: IFileLaneConfig;
114
+ compilerOption?: O;
115
+ compalition?: FileLaneCompilation;
116
+ };
115
117
  export type BeforeWork = (context: IFileLaneContext) => Promise<any>;
118
+ export type PreWork<O = any> = (preWorkParams: CompileParam<O>) => Promise<any>;
119
+ export type FollowWork<O = any> = (followParams: CompileParam<O>) => Promise<any>;
116
120
  export type AfterWork = (context: IFileLaneContext) => Promise<any>;
117
121
  export {};
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * IFileParam
4
3
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-lane",
3
- "version": "2.0.2-beta.16",
3
+ "version": "2.0.2-beta.18",
4
4
  "description": "File conversion tool, can be one-to-one, one to N, N to one",
5
5
  "keywords": [
6
6
  "file",
@@ -20,14 +20,13 @@
20
20
  "test": "node ./__tests__/file-lane.test.js"
21
21
  },
22
22
  "dependencies": {
23
- "@aiot-toolkit/shared-utils": "2.0.2-beta.16",
23
+ "@aiot-toolkit/shared-utils": "2.0.2-beta.18",
24
24
  "chokidar": "^3.6.0",
25
- "del": "^4.1.0",
26
25
  "fs-extra": "^11.2.0",
27
26
  "lodash": "^4.17.21"
28
27
  },
29
28
  "devDependencies": {
30
29
  "@types/fs-extra": "^11.0.4"
31
30
  },
32
- "gitHead": "785701c64914f50acd18ab71ea41b2f5a2cd161c"
31
+ "gitHead": "e39f0ad4fe3bfe8e733499742c5a39ab80fa2cd0"
33
32
  }