file-lane 2.0.3-beta.5 → 2.0.3-beta.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/FileLane.d.ts +15 -5
- package/lib/FileLane.js +49 -13
- package/lib/interface/IFileLaneEvents.d.ts +5 -0
- package/package.json +3 -3
package/lib/FileLane.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import IFileLaneConfig from './interface/IFileLaneConfig';
|
|
2
|
+
import FileLaneTriggerType from './enum/FileLaneTriggerType';
|
|
2
3
|
import IFileLaneEvents from './interface/IFileLaneEvents';
|
|
4
|
+
export interface IBuilderParam {
|
|
5
|
+
fileList: string[];
|
|
6
|
+
trigger: FileLaneTriggerType;
|
|
7
|
+
}
|
|
3
8
|
/**
|
|
4
9
|
* FileLane
|
|
5
10
|
*
|
|
6
11
|
* 文件车道,用于将文件进行对应转换,支持1对1、1对N、N对1
|
|
7
12
|
*
|
|
8
|
-
* 打包过程中,有以下事件
|
|
9
|
-
* 1. 打包成功:onBuildSuccess
|
|
10
|
-
* 2. 打包失败: onBuildError
|
|
11
|
-
* 3. 产生日志: onLog
|
|
12
|
-
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```
|
|
15
15
|
* new FileLane<IJavascriptCompileOption>(
|
|
@@ -37,11 +37,14 @@ declare class FileLane<O = any> {
|
|
|
37
37
|
private compilation?;
|
|
38
38
|
private changeFileList;
|
|
39
39
|
private triggerCount;
|
|
40
|
+
private building;
|
|
41
|
+
private nextBuildParam;
|
|
40
42
|
/**
|
|
41
43
|
* 实例化FileLane
|
|
42
44
|
* @param config fileLane 配置
|
|
43
45
|
* @param projectPath 项目路径
|
|
44
46
|
* @param compilerOption 编译参数,不同语言的项目具有的参数不同,即使同一项目开发者也会设置不同的参数
|
|
47
|
+
* @param events 事件监听器
|
|
45
48
|
*/
|
|
46
49
|
constructor(config: IFileLaneConfig<O>, projectPath?: string, compilerOption?: O | undefined, events?: IFileLaneEvents | undefined);
|
|
47
50
|
private addProcessListener;
|
|
@@ -62,6 +65,13 @@ declare class FileLane<O = any> {
|
|
|
62
65
|
private processBeforeExitHandler;
|
|
63
66
|
private sigintHandler;
|
|
64
67
|
dispose(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* 触发编译
|
|
70
|
+
*
|
|
71
|
+
* 如果:在编译过程中,则记录统参数,待本次 build 完成后,开始下一次
|
|
72
|
+
* 否则:直接触发编译
|
|
73
|
+
*/
|
|
74
|
+
private triggerBuild;
|
|
65
75
|
/**
|
|
66
76
|
*
|
|
67
77
|
* @param fileList 原始文件列表
|
package/lib/FileLane.js
CHANGED
|
@@ -28,11 +28,6 @@ const FileLaneTriggerType_1 = __importDefault(require("./enum/FileLaneTriggerTyp
|
|
|
28
28
|
*
|
|
29
29
|
* 文件车道,用于将文件进行对应转换,支持1对1、1对N、N对1
|
|
30
30
|
*
|
|
31
|
-
* 打包过程中,有以下事件
|
|
32
|
-
* 1. 打包成功:onBuildSuccess
|
|
33
|
-
* 2. 打包失败: onBuildError
|
|
34
|
-
* 3. 产生日志: onLog
|
|
35
|
-
*
|
|
36
31
|
* @example
|
|
37
32
|
* ```
|
|
38
33
|
* new FileLane<IJavascriptCompileOption>(
|
|
@@ -54,6 +49,7 @@ class FileLane {
|
|
|
54
49
|
* @param config fileLane 配置
|
|
55
50
|
* @param projectPath 项目路径
|
|
56
51
|
* @param compilerOption 编译参数,不同语言的项目具有的参数不同,即使同一项目开发者也会设置不同的参数
|
|
52
|
+
* @param events 事件监听器
|
|
57
53
|
*/
|
|
58
54
|
constructor(config, projectPath, compilerOption, events) {
|
|
59
55
|
this.config = config;
|
|
@@ -61,6 +57,8 @@ class FileLane {
|
|
|
61
57
|
this.events = events;
|
|
62
58
|
this.changeFileList = [];
|
|
63
59
|
this.triggerCount = 0;
|
|
60
|
+
this.building = false;
|
|
61
|
+
this.nextBuildParam = null;
|
|
64
62
|
this.processBeforeExitHandler = () => {
|
|
65
63
|
this.dispose();
|
|
66
64
|
};
|
|
@@ -102,7 +100,10 @@ class FileLane {
|
|
|
102
100
|
if (params === null || params === void 0 ? void 0 : params.watch) {
|
|
103
101
|
this.watch();
|
|
104
102
|
}
|
|
105
|
-
yield this.build(
|
|
103
|
+
yield this.build({
|
|
104
|
+
fileList,
|
|
105
|
+
trigger: FileLaneTriggerType_1.default.START
|
|
106
|
+
});
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
109
|
validateConfig() {
|
|
@@ -162,16 +163,35 @@ class FileLane {
|
|
|
162
163
|
yield this.cleanOutput();
|
|
163
164
|
});
|
|
164
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* 触发编译
|
|
168
|
+
*
|
|
169
|
+
* 如果:在编译过程中,则记录统参数,待本次 build 完成后,开始下一次
|
|
170
|
+
* 否则:直接触发编译
|
|
171
|
+
*/
|
|
172
|
+
triggerBuild(param) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
if (this.building) {
|
|
175
|
+
this.nextBuildParam = param;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.build(param);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
165
182
|
/**
|
|
166
183
|
*
|
|
167
184
|
* @param fileList 原始文件列表
|
|
168
185
|
*/
|
|
169
|
-
build(
|
|
186
|
+
build(param) {
|
|
170
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
188
|
var _a;
|
|
172
|
-
const {
|
|
173
|
-
const
|
|
189
|
+
const { fileList, trigger } = param;
|
|
190
|
+
const { onBuildSuccess, onBuildError, onBuildStart } = this.events || {};
|
|
191
|
+
const timeStart = Date.now();
|
|
174
192
|
this.initCompilation(trigger);
|
|
193
|
+
this.building = true;
|
|
194
|
+
onBuildStart === null || onBuildStart === void 0 ? void 0 : onBuildStart();
|
|
175
195
|
try {
|
|
176
196
|
yield this.complyBeforeCompile();
|
|
177
197
|
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.PROJECT_START));
|
|
@@ -185,12 +205,18 @@ class FileLane {
|
|
|
185
205
|
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.FLLOW_WORK_START));
|
|
186
206
|
yield this.complyAfterCompile();
|
|
187
207
|
this.triggerPlugins(new CompilationEvent_1.default(CompilationEvent_1.default.FLLOW_WORK_END));
|
|
208
|
+
const costTime = Date.now() - timeStart;
|
|
188
209
|
if (onBuildSuccess) {
|
|
189
|
-
onBuildSuccess
|
|
190
|
-
costTime
|
|
210
|
+
onBuildSuccess({
|
|
211
|
+
costTime,
|
|
191
212
|
info: (_a = this.compilation) === null || _a === void 0 ? void 0 : _a.info
|
|
192
213
|
});
|
|
193
214
|
}
|
|
215
|
+
else {
|
|
216
|
+
shared_utils_1.ColorConsole.success({
|
|
217
|
+
word: 'build success:'
|
|
218
|
+
}, `${costTime}ms`);
|
|
219
|
+
}
|
|
194
220
|
}
|
|
195
221
|
catch (error) {
|
|
196
222
|
if (onBuildError) {
|
|
@@ -200,6 +226,13 @@ class FileLane {
|
|
|
200
226
|
shared_utils_1.ColorConsole.throw(`ERROR: `, { word: 'build error' }, `, ${error || 'unknown error'}`);
|
|
201
227
|
}
|
|
202
228
|
}
|
|
229
|
+
finally {
|
|
230
|
+
this.building = false;
|
|
231
|
+
if (this.nextBuildParam) {
|
|
232
|
+
this.build(this.nextBuildParam);
|
|
233
|
+
this.nextBuildParam = null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
203
236
|
});
|
|
204
237
|
}
|
|
205
238
|
initCompilation(trigger) {
|
|
@@ -405,7 +438,7 @@ class FileLane {
|
|
|
405
438
|
]);
|
|
406
439
|
}
|
|
407
440
|
catch (error) {
|
|
408
|
-
throw new Error(`FollowWork: ${item.workerDescribe} error
|
|
441
|
+
throw new Error(`FollowWork: ${item.workerDescribe} error: ${error}`);
|
|
409
442
|
}
|
|
410
443
|
}
|
|
411
444
|
}
|
|
@@ -420,7 +453,10 @@ class FileLane {
|
|
|
420
453
|
: this.collectFile();
|
|
421
454
|
// 开始编译前,记录列表置空
|
|
422
455
|
this.changeFileList = [];
|
|
423
|
-
yield this.
|
|
456
|
+
yield this.triggerBuild({
|
|
457
|
+
fileList,
|
|
458
|
+
trigger: FileLaneTriggerType_1.default.UPDATE
|
|
459
|
+
});
|
|
424
460
|
});
|
|
425
461
|
this.listenFileChange(onChange);
|
|
426
462
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-lane",
|
|
3
|
-
"version": "2.0.3-beta.
|
|
3
|
+
"version": "2.0.3-beta.7",
|
|
4
4
|
"description": "File conversion tool, can be one-to-one, one to N, N to one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"file",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"test": "node ./__tests__/file-lane.test.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aiot-toolkit/shared-utils": "2.0.3-beta.
|
|
23
|
+
"@aiot-toolkit/shared-utils": "2.0.3-beta.7",
|
|
24
24
|
"chokidar": "^3.6.0",
|
|
25
25
|
"fs-extra": "^11.2.0",
|
|
26
26
|
"lodash": "^4.17.21"
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/fs-extra": "^11.0.4"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "9621c52866d7bb1dc23110c4c9cc772b6169b682"
|
|
32
32
|
}
|