file-lane 2.0.5-widget-provider-beta.2 → 2.0.5
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/README.md +247 -247
- package/lib/FileLane.js +71 -71
- package/lib/FileLaneCompilation.d.ts +1 -2
- package/lib/FileLaneCompilation.js +7 -7
- package/lib/enum/FileLaneTriggerType.js +2 -2
- package/lib/event/CompilationEvent.js +2 -2
- package/lib/event/FileEvent.js +2 -2
- package/lib/event/asyncEvent/DataEvent.js +2 -2
- package/lib/utils/FileLaneUtil.js +7 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,247 +1,247 @@
|
|
|
1
|
-
# 项目介绍
|
|
2
|
-
|
|
3
|
-
file-lane模块用于文件转换,可实现文件1对1的转换,也可实现1对多、多对1的文件转换。
|
|
4
|
-
|
|
5
|
-
<img src="./doc/flow-detail.png" style="max-width: 1000px; width: 100%"/>
|
|
6
|
-
|
|
7
|
-
## 安装使用
|
|
8
|
-
|
|
9
|
-
- 安装
|
|
10
|
-
|
|
11
|
-
`npm i file-lane`
|
|
12
|
-
|
|
13
|
-
- 快速上手
|
|
14
|
-
|
|
15
|
-
```javascript
|
|
16
|
-
const { FileLane } = require('file-lane')
|
|
17
|
-
const { UxLoader } = require('aiot-toolkit/aiotpack')
|
|
18
|
-
const Path = require('path')
|
|
19
|
-
|
|
20
|
-
const projectPath = Path.join(__dirname, '../testProject')
|
|
21
|
-
|
|
22
|
-
// 定义项目转换的配置参数,output和module为必要配置内容
|
|
23
|
-
const projectConfig = {
|
|
24
|
-
// output指定转换后项目的存储位置
|
|
25
|
-
get output() {
|
|
26
|
-
const name = Path.basename(projectPath)
|
|
27
|
-
const result = `../.temp_${name}`
|
|
28
|
-
return result
|
|
29
|
-
},
|
|
30
|
-
// 转换过程中使用的转换模块配置
|
|
31
|
-
module: {
|
|
32
|
-
rules: [
|
|
33
|
-
{
|
|
34
|
-
test: [/.+\.ux$/],
|
|
35
|
-
exclude: [/app\.ux/],
|
|
36
|
-
loader: [UxLoader]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 开始执行文件转换
|
|
43
|
-
new FileLane(projectConfig).start()
|
|
44
|
-
// 开启watch模式
|
|
45
|
-
// new FileLane(projectConfig).start({ watch: true })
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## 参数配置
|
|
49
|
-
|
|
50
|
-
- 必填参数
|
|
51
|
-
- [output](#output)
|
|
52
|
-
- [module](#module)
|
|
53
|
-
- 可选参数
|
|
54
|
-
- [fileCollector](#fileCollector)
|
|
55
|
-
- [include](#include)
|
|
56
|
-
- [exclude](#exclude)
|
|
57
|
-
- [plugins](#plugins)
|
|
58
|
-
- [preWorks](#preWorks)
|
|
59
|
-
- [followWorks](#followWorks)
|
|
60
|
-
- [watchIgnores](#watchIgnores)
|
|
61
|
-
|
|
62
|
-
<a id="output">output</a>
|
|
63
|
-
|
|
64
|
-
描述: 输出目录
|
|
65
|
-
|
|
66
|
-
参数类型: string
|
|
67
|
-
|
|
68
|
-
示例:
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
'temp_project'
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
<a id="module">module</a>
|
|
75
|
-
|
|
76
|
-
描述: 文件转换规则集
|
|
77
|
-
|
|
78
|
-
参数类型: { rules: IRule[] } // IRule:转换规则
|
|
79
|
-
|
|
80
|
-
```javascript
|
|
81
|
-
interface IRule {
|
|
82
|
-
// 配置文件
|
|
83
|
-
test: MatchType
|
|
84
|
-
|
|
85
|
-
// 文件的 Loader,从前向后依次执行,前一个 loader 结果做为后一个 loader 的入参
|
|
86
|
-
loader: ILoaderClass[]
|
|
87
|
-
exclude?: MatchType
|
|
88
|
-
include?: MatchType
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
示例:
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
{
|
|
96
|
-
rules: [
|
|
97
|
-
{
|
|
98
|
-
test: [/.+\.ux$/],
|
|
99
|
-
exclude: [/app\.ux/],
|
|
100
|
-
loader: [UxLoader]
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
<a id="fileCollector">fileCollector</a>
|
|
108
|
-
|
|
109
|
-
描述: 文件收集器,输入文件路径,返回待合并的文件路径,常用于多转1,默认值为直接使用源文件
|
|
110
|
-
|
|
111
|
-
参数类型:
|
|
112
|
-
|
|
113
|
-
```
|
|
114
|
-
(file: string) => string[]
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
示例:
|
|
118
|
-
|
|
119
|
-
```javascript
|
|
120
|
-
// src/a.hml -->[src/a.hml, src/a.js, src/a.css]
|
|
121
|
-
(file: string) => {
|
|
122
|
-
const fileList = [file]
|
|
123
|
-
const { dir, name, ext } = path.parse(file)
|
|
124
|
-
|
|
125
|
-
if (ext === '.hml') {
|
|
126
|
-
['.js', '.css'].map((item) => {
|
|
127
|
-
const collectFile = path.join(dir, `${name}${item}`)
|
|
128
|
-
// 若路径真实存在,则push到文件列表中
|
|
129
|
-
if (fs.existsSync(collectFile)) {
|
|
130
|
-
fileList.push(collectFile)
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
return fileList
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
<a id="include">include</a>
|
|
139
|
-
|
|
140
|
-
描述: 指定文件范围
|
|
141
|
-
|
|
142
|
-
参数类型:
|
|
143
|
-
|
|
144
|
-
```
|
|
145
|
-
OneMatchType | OneMatchType[]
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
示例:
|
|
149
|
-
|
|
150
|
-
```javascript
|
|
151
|
-
// 匹配包含有src字符串的文件
|
|
152
|
-
include = ['src']
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
<a id="exclude">exclude</a>
|
|
156
|
-
|
|
157
|
-
描述: 需排除的文件范围
|
|
158
|
-
|
|
159
|
-
参数类型:
|
|
160
|
-
|
|
161
|
-
```
|
|
162
|
-
OneMatchType | OneMatchType[]
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
示例:
|
|
166
|
-
|
|
167
|
-
```javascript
|
|
168
|
-
// 排除路径中包含有node_modules字符串的文件
|
|
169
|
-
exclude = [/node_modules/]
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
<a id="plugins">plugins</a>
|
|
173
|
-
|
|
174
|
-
描述: 插件,在每个文件转换完成前后,所有文件转换完成前后,在打包完成前后会触发
|
|
175
|
-
|
|
176
|
-
参数类型:
|
|
177
|
-
|
|
178
|
-
```
|
|
179
|
-
IPlugin[]
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
示例:
|
|
183
|
-
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
<a id="preWorks">preWorks</a>
|
|
189
|
-
|
|
190
|
-
描述: 前置工作,所有文件转换前的工作
|
|
191
|
-
|
|
192
|
-
参数类型:
|
|
193
|
-
|
|
194
|
-
```
|
|
195
|
-
PreWork[]
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
示例:
|
|
199
|
-
|
|
200
|
-
```javascript
|
|
201
|
-
preWorks = [validateManifest]
|
|
202
|
-
|
|
203
|
-
const validateManifest: PreWork<IJavascriptCompileOption> = async (context) => {
|
|
204
|
-
// 校验manifest.json文件的内容
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
<a id="followWorks">followWorks</a>
|
|
209
|
-
|
|
210
|
-
描述: 后续工作,所有文件转换后的工作
|
|
211
|
-
|
|
212
|
-
参数类型:
|
|
213
|
-
|
|
214
|
-
```
|
|
215
|
-
FollowWoker<O>[]
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
示例:
|
|
219
|
-
|
|
220
|
-
```javascript
|
|
221
|
-
followWorks = [
|
|
222
|
-
{
|
|
223
|
-
worker: toRpk,
|
|
224
|
-
workerDescribe: 'follow work'
|
|
225
|
-
}
|
|
226
|
-
]
|
|
227
|
-
|
|
228
|
-
const toRpk: FollowWork<IJavascriptCompileOption> = async (context, config, compilerOption) => {
|
|
229
|
-
// 生成rpk逻辑
|
|
230
|
-
}
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
<a id="watchIgnores">watchIgnores</a>
|
|
234
|
-
|
|
235
|
-
描述: 配置watch时忽略的文件或者文件夹
|
|
236
|
-
|
|
237
|
-
参数类型:
|
|
238
|
-
|
|
239
|
-
```
|
|
240
|
-
MatchType
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
示例:
|
|
244
|
-
|
|
245
|
-
```javascript
|
|
246
|
-
watchIgnores = [/node_modules/, '/build/', '/dist/']
|
|
247
|
-
```
|
|
1
|
+
# 项目介绍
|
|
2
|
+
|
|
3
|
+
file-lane模块用于文件转换,可实现文件1对1的转换,也可实现1对多、多对1的文件转换。
|
|
4
|
+
|
|
5
|
+
<img src="./doc/flow-detail.png" style="max-width: 1000px; width: 100%"/>
|
|
6
|
+
|
|
7
|
+
## 安装使用
|
|
8
|
+
|
|
9
|
+
- 安装
|
|
10
|
+
|
|
11
|
+
`npm i file-lane`
|
|
12
|
+
|
|
13
|
+
- 快速上手
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const { FileLane } = require('file-lane')
|
|
17
|
+
const { UxLoader } = require('aiot-toolkit/aiotpack')
|
|
18
|
+
const Path = require('path')
|
|
19
|
+
|
|
20
|
+
const projectPath = Path.join(__dirname, '../testProject')
|
|
21
|
+
|
|
22
|
+
// 定义项目转换的配置参数,output和module为必要配置内容
|
|
23
|
+
const projectConfig = {
|
|
24
|
+
// output指定转换后项目的存储位置
|
|
25
|
+
get output() {
|
|
26
|
+
const name = Path.basename(projectPath)
|
|
27
|
+
const result = `../.temp_${name}`
|
|
28
|
+
return result
|
|
29
|
+
},
|
|
30
|
+
// 转换过程中使用的转换模块配置
|
|
31
|
+
module: {
|
|
32
|
+
rules: [
|
|
33
|
+
{
|
|
34
|
+
test: [/.+\.ux$/],
|
|
35
|
+
exclude: [/app\.ux/],
|
|
36
|
+
loader: [UxLoader]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 开始执行文件转换
|
|
43
|
+
new FileLane(projectConfig).start()
|
|
44
|
+
// 开启watch模式
|
|
45
|
+
// new FileLane(projectConfig).start({ watch: true })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 参数配置
|
|
49
|
+
|
|
50
|
+
- 必填参数
|
|
51
|
+
- [output](#output)
|
|
52
|
+
- [module](#module)
|
|
53
|
+
- 可选参数
|
|
54
|
+
- [fileCollector](#fileCollector)
|
|
55
|
+
- [include](#include)
|
|
56
|
+
- [exclude](#exclude)
|
|
57
|
+
- [plugins](#plugins)
|
|
58
|
+
- [preWorks](#preWorks)
|
|
59
|
+
- [followWorks](#followWorks)
|
|
60
|
+
- [watchIgnores](#watchIgnores)
|
|
61
|
+
|
|
62
|
+
<a id="output">output</a>
|
|
63
|
+
|
|
64
|
+
描述: 输出目录
|
|
65
|
+
|
|
66
|
+
参数类型: string
|
|
67
|
+
|
|
68
|
+
示例:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
'temp_project'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
<a id="module">module</a>
|
|
75
|
+
|
|
76
|
+
描述: 文件转换规则集
|
|
77
|
+
|
|
78
|
+
参数类型: { rules: IRule[] } // IRule:转换规则
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
interface IRule {
|
|
82
|
+
// 配置文件
|
|
83
|
+
test: MatchType
|
|
84
|
+
|
|
85
|
+
// 文件的 Loader,从前向后依次执行,前一个 loader 结果做为后一个 loader 的入参
|
|
86
|
+
loader: ILoaderClass[]
|
|
87
|
+
exclude?: MatchType
|
|
88
|
+
include?: MatchType
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
示例:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
{
|
|
96
|
+
rules: [
|
|
97
|
+
{
|
|
98
|
+
test: [/.+\.ux$/],
|
|
99
|
+
exclude: [/app\.ux/],
|
|
100
|
+
loader: [UxLoader]
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
<a id="fileCollector">fileCollector</a>
|
|
108
|
+
|
|
109
|
+
描述: 文件收集器,输入文件路径,返回待合并的文件路径,常用于多转1,默认值为直接使用源文件
|
|
110
|
+
|
|
111
|
+
参数类型:
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
(file: string) => string[]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
示例:
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
// src/a.hml -->[src/a.hml, src/a.js, src/a.css]
|
|
121
|
+
(file: string) => {
|
|
122
|
+
const fileList = [file]
|
|
123
|
+
const { dir, name, ext } = path.parse(file)
|
|
124
|
+
|
|
125
|
+
if (ext === '.hml') {
|
|
126
|
+
['.js', '.css'].map((item) => {
|
|
127
|
+
const collectFile = path.join(dir, `${name}${item}`)
|
|
128
|
+
// 若路径真实存在,则push到文件列表中
|
|
129
|
+
if (fs.existsSync(collectFile)) {
|
|
130
|
+
fileList.push(collectFile)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
return fileList
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
<a id="include">include</a>
|
|
139
|
+
|
|
140
|
+
描述: 指定文件范围
|
|
141
|
+
|
|
142
|
+
参数类型:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
OneMatchType | OneMatchType[]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
示例:
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
// 匹配包含有src字符串的文件
|
|
152
|
+
include = ['src']
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
<a id="exclude">exclude</a>
|
|
156
|
+
|
|
157
|
+
描述: 需排除的文件范围
|
|
158
|
+
|
|
159
|
+
参数类型:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
OneMatchType | OneMatchType[]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
示例:
|
|
166
|
+
|
|
167
|
+
```javascript
|
|
168
|
+
// 排除路径中包含有node_modules字符串的文件
|
|
169
|
+
exclude = [/node_modules/]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
<a id="plugins">plugins</a>
|
|
173
|
+
|
|
174
|
+
描述: 插件,在每个文件转换完成前后,所有文件转换完成前后,在打包完成前后会触发
|
|
175
|
+
|
|
176
|
+
参数类型:
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
IPlugin[]
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
示例:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
<a id="preWorks">preWorks</a>
|
|
189
|
+
|
|
190
|
+
描述: 前置工作,所有文件转换前的工作
|
|
191
|
+
|
|
192
|
+
参数类型:
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
PreWork[]
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
示例:
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
preWorks = [validateManifest]
|
|
202
|
+
|
|
203
|
+
const validateManifest: PreWork<IJavascriptCompileOption> = async (context) => {
|
|
204
|
+
// 校验manifest.json文件的内容
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
<a id="followWorks">followWorks</a>
|
|
209
|
+
|
|
210
|
+
描述: 后续工作,所有文件转换后的工作
|
|
211
|
+
|
|
212
|
+
参数类型:
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
FollowWoker<O>[]
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
示例:
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
followWorks = [
|
|
222
|
+
{
|
|
223
|
+
worker: toRpk,
|
|
224
|
+
workerDescribe: 'follow work'
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
const toRpk: FollowWork<IJavascriptCompileOption> = async (context, config, compilerOption) => {
|
|
229
|
+
// 生成rpk逻辑
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
<a id="watchIgnores">watchIgnores</a>
|
|
234
|
+
|
|
235
|
+
描述: 配置watch时忽略的文件或者文件夹
|
|
236
|
+
|
|
237
|
+
参数类型:
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
MatchType
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
示例:
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
watchIgnores = [/node_modules/, '/build/', '/dist/']
|
|
247
|
+
```
|
package/lib/FileLane.js
CHANGED
|
@@ -15,31 +15,31 @@ var _FileLaneUtil = _interopRequireDefault(require("./utils/FileLaneUtil"));
|
|
|
15
15
|
var _IChangedFile = require("./interface/IChangedFile");
|
|
16
16
|
var _FileLaneTriggerType = _interopRequireDefault(require("./enum/FileLaneTriggerType"));
|
|
17
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
/**
|
|
19
|
-
* FileLane
|
|
20
|
-
*
|
|
21
|
-
* 文件车道,用于将文件进行对应转换,支持1对1、1对N、N对1
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```
|
|
25
|
-
* new FileLane<IJavascriptCompileOption>(
|
|
26
|
-
* fileLaneConfig,
|
|
27
|
-
* projectPath,
|
|
28
|
-
* compilerOption,
|
|
29
|
-
* {
|
|
30
|
-
* onBuildSuccess: (data) => {},
|
|
31
|
-
* onBuildError: (data) => {},
|
|
32
|
-
* onLog: (logs) => {}
|
|
33
|
-
* }).start()
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @description
|
|
18
|
+
/**
|
|
19
|
+
* FileLane
|
|
20
|
+
*
|
|
21
|
+
* 文件车道,用于将文件进行对应转换,支持1对1、1对N、N对1
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```
|
|
25
|
+
* new FileLane<IJavascriptCompileOption>(
|
|
26
|
+
* fileLaneConfig,
|
|
27
|
+
* projectPath,
|
|
28
|
+
* compilerOption,
|
|
29
|
+
* {
|
|
30
|
+
* onBuildSuccess: (data) => {},
|
|
31
|
+
* onBuildError: (data) => {},
|
|
32
|
+
* onLog: (logs) => {}
|
|
33
|
+
* }).start()
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @description
|
|
37
37
|
*/
|
|
38
38
|
class FileLane {
|
|
39
39
|
// 创建监听实例
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
* 每次编译的数据对象
|
|
41
|
+
/**
|
|
42
|
+
* 每次编译的数据对象
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
45
|
changeFileList = [];
|
|
@@ -48,12 +48,12 @@ class FileLane {
|
|
|
48
48
|
nextBuildParam = null;
|
|
49
49
|
fileHashCache = {};
|
|
50
50
|
|
|
51
|
-
/**
|
|
52
|
-
* 实例化FileLane
|
|
53
|
-
* @param config fileLane 配置
|
|
54
|
-
* @param projectPath 项目路径
|
|
55
|
-
* @param compilerOption 编译参数,不同语言的项目具有的参数不同,即使同一项目开发者也会设置不同的参数
|
|
56
|
-
* @param events 事件监听器
|
|
51
|
+
/**
|
|
52
|
+
* 实例化FileLane
|
|
53
|
+
* @param config fileLane 配置
|
|
54
|
+
* @param projectPath 项目路径
|
|
55
|
+
* @param compilerOption 编译参数,不同语言的项目具有的参数不同,即使同一项目开发者也会设置不同的参数
|
|
56
|
+
* @param events 事件监听器
|
|
57
57
|
*/
|
|
58
58
|
constructor(config, projectPath, compilerOption, events) {
|
|
59
59
|
this.config = config;
|
|
@@ -67,10 +67,10 @@ class FileLane {
|
|
|
67
67
|
process.on('SIGINT', this.sigintHandler);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/**
|
|
71
|
-
* 运行
|
|
72
|
-
* @param params
|
|
73
|
-
* @returns
|
|
70
|
+
/**
|
|
71
|
+
* 运行
|
|
72
|
+
* @param params
|
|
73
|
+
* @returns
|
|
74
74
|
*/
|
|
75
75
|
async start(params) {
|
|
76
76
|
const errorList = this.validateConfig();
|
|
@@ -156,11 +156,11 @@ class FileLane {
|
|
|
156
156
|
await this.cleanOutput();
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
/**
|
|
160
|
-
* 触发编译
|
|
161
|
-
*
|
|
162
|
-
* 如果:在编译过程中,则记录统参数,待本次 build 完成后,开始下一次
|
|
163
|
-
* 否则:直接触发编译
|
|
159
|
+
/**
|
|
160
|
+
* 触发编译
|
|
161
|
+
*
|
|
162
|
+
* 如果:在编译过程中,则记录统参数,待本次 build 完成后,开始下一次
|
|
163
|
+
* 否则:直接触发编译
|
|
164
164
|
*/
|
|
165
165
|
async triggerBuild(param) {
|
|
166
166
|
if (this.building) {
|
|
@@ -170,9 +170,9 @@ class FileLane {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
/**
|
|
174
|
-
*
|
|
175
|
-
* @param fileList 原始文件列表
|
|
173
|
+
/**
|
|
174
|
+
*
|
|
175
|
+
* @param fileList 原始文件列表
|
|
176
176
|
*/
|
|
177
177
|
async build(param) {
|
|
178
178
|
const {
|
|
@@ -281,13 +281,13 @@ class FileLane {
|
|
|
281
281
|
return result;
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
/**
|
|
285
|
-
* 处理日志
|
|
286
|
-
* 1. 触发onLog事件
|
|
287
|
-
* 2. 如果有错误日志,则抛出错误
|
|
288
|
-
* @param logs
|
|
289
|
-
* @param onError
|
|
290
|
-
* @returns
|
|
284
|
+
/**
|
|
285
|
+
* 处理日志
|
|
286
|
+
* 1. 触发onLog事件
|
|
287
|
+
* 2. 如果有错误日志,则抛出错误
|
|
288
|
+
* @param logs
|
|
289
|
+
* @param onError
|
|
290
|
+
* @returns
|
|
291
291
|
*/
|
|
292
292
|
handlerLogs(logs, onError) {
|
|
293
293
|
if (!logs?.length) {
|
|
@@ -329,10 +329,10 @@ class FileLane {
|
|
|
329
329
|
return loader.parser(fileList);
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
/**
|
|
333
|
-
* 匹配符合条件的loader
|
|
334
|
-
* @param filePath
|
|
335
|
-
* @returns
|
|
332
|
+
/**
|
|
333
|
+
* 匹配符合条件的loader
|
|
334
|
+
* @param filePath
|
|
335
|
+
* @returns
|
|
336
336
|
*/
|
|
337
337
|
findLoader(filePath) {
|
|
338
338
|
const parse = _path.default.basename(filePath);
|
|
@@ -353,8 +353,8 @@ class FileLane {
|
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
/**
|
|
357
|
-
* start开始时的准备工作
|
|
356
|
+
/**
|
|
357
|
+
* start开始时的准备工作
|
|
358
358
|
*/
|
|
359
359
|
async complyBeforeWorks() {
|
|
360
360
|
const {
|
|
@@ -367,8 +367,8 @@ class FileLane {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
|
|
370
|
-
/**
|
|
371
|
-
* start结束后的收尾工作
|
|
370
|
+
/**
|
|
371
|
+
* start结束后的收尾工作
|
|
372
372
|
*/
|
|
373
373
|
async complyAfterWork() {
|
|
374
374
|
const {
|
|
@@ -381,8 +381,8 @@ class FileLane {
|
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
/**
|
|
385
|
-
* 执行项目转换的前置工作
|
|
384
|
+
/**
|
|
385
|
+
* 执行项目转换的前置工作
|
|
386
386
|
*/
|
|
387
387
|
async complyBeforeCompile() {
|
|
388
388
|
const {
|
|
@@ -400,8 +400,8 @@ class FileLane {
|
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
/**
|
|
404
|
-
* 执行项目转换的后续工作
|
|
403
|
+
/**
|
|
404
|
+
* 执行项目转换的后续工作
|
|
405
405
|
*/
|
|
406
406
|
async complyAfterCompile() {
|
|
407
407
|
const {
|
|
@@ -443,10 +443,10 @@ class FileLane {
|
|
|
443
443
|
this.listenFileChange(onChange);
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
-
/**
|
|
447
|
-
* 采集所有要处理的真实文件路径列表
|
|
448
|
-
* @param entryFileList
|
|
449
|
-
* @returns
|
|
446
|
+
/**
|
|
447
|
+
* 采集所有要处理的真实文件路径列表
|
|
448
|
+
* @param entryFileList
|
|
449
|
+
* @returns
|
|
450
450
|
*/
|
|
451
451
|
collectFile(entryFileList) {
|
|
452
452
|
// 使用include projectPath获取所有要处理的真实文件
|
|
@@ -467,9 +467,9 @@ class FileLane {
|
|
|
467
467
|
return files;
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
/**
|
|
471
|
-
* 监听文件变化
|
|
472
|
-
* @param onChange
|
|
470
|
+
/**
|
|
471
|
+
* 监听文件变化
|
|
472
|
+
* @param onChange
|
|
473
473
|
*/
|
|
474
474
|
listenFileChange(onChange) {
|
|
475
475
|
const watcher = _chokidar.default.watch(this.context.projectPath, {
|
|
@@ -512,16 +512,16 @@ class FileLane {
|
|
|
512
512
|
this.watcher = watcher;
|
|
513
513
|
}
|
|
514
514
|
|
|
515
|
-
/**
|
|
516
|
-
* 清除输出文件夹
|
|
515
|
+
/**
|
|
516
|
+
* 清除输出文件夹
|
|
517
517
|
*/
|
|
518
518
|
async cleanOutput() {
|
|
519
519
|
return _sharedUtils.FileUtil.del(_FileLaneUtil.default.getOutputPath(this.context));
|
|
520
520
|
}
|
|
521
|
-
/**
|
|
522
|
-
* 1. 配置的忽略文件夹
|
|
523
|
-
* 2. 默认应该忽略的文件及文件夹
|
|
524
|
-
* @returns
|
|
521
|
+
/**
|
|
522
|
+
* 1. 配置的忽略文件夹
|
|
523
|
+
* 2. 默认应该忽略的文件及文件夹
|
|
524
|
+
* @returns
|
|
525
525
|
*/
|
|
526
526
|
getIgnoreConfig() {
|
|
527
527
|
let ignoreList = [];
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import FileLaneTriggerType from './enum/FileLaneTriggerType';
|
|
2
2
|
import AsyncEventDispatcher from './event/asyncEvent/AsyncEventDispatcher';
|
|
3
|
-
import IFileParam from './interface/IFileParam';
|
|
4
3
|
/**
|
|
5
4
|
* FileLaneCompilation
|
|
6
5
|
*/
|
|
7
6
|
declare class FileLaneCompilation extends AsyncEventDispatcher {
|
|
8
|
-
buildFileList:
|
|
7
|
+
buildFileList: string[];
|
|
9
8
|
/**
|
|
10
9
|
* 触发方式
|
|
11
10
|
*
|
|
@@ -7,19 +7,19 @@ exports.default = void 0;
|
|
|
7
7
|
var _FileLaneTriggerType = _interopRequireDefault(require("./enum/FileLaneTriggerType"));
|
|
8
8
|
var _AsyncEventDispatcher = _interopRequireDefault(require("./event/asyncEvent/AsyncEventDispatcher"));
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
/**
|
|
11
|
-
* FileLaneCompilation
|
|
10
|
+
/**
|
|
11
|
+
* FileLaneCompilation
|
|
12
12
|
*/
|
|
13
13
|
class FileLaneCompilation extends _AsyncEventDispatcher.default {
|
|
14
14
|
buildFileList = [];
|
|
15
|
-
/**
|
|
16
|
-
* 触发方式
|
|
17
|
-
*
|
|
15
|
+
/**
|
|
16
|
+
* 触发方式
|
|
17
|
+
*
|
|
18
18
|
*/
|
|
19
19
|
trigger = (() => _FileLaneTriggerType.default.START)();
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
* 触发次数
|
|
21
|
+
/**
|
|
22
|
+
* 触发次数
|
|
23
23
|
*/
|
|
24
24
|
triggerCount = 0;
|
|
25
25
|
info = (() => ({
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* FileLaneTriggerType
|
|
7
|
+
/**
|
|
8
|
+
* FileLaneTriggerType
|
|
9
9
|
*/
|
|
10
10
|
var FileLaneTriggerType = /*#__PURE__*/function (FileLaneTriggerType) {
|
|
11
11
|
FileLaneTriggerType[FileLaneTriggerType["START"] = 1] = "START";
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _DataEvent = _interopRequireDefault(require("./asyncEvent/DataEvent"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
/**
|
|
10
|
-
* CompilationEvent
|
|
9
|
+
/**
|
|
10
|
+
* CompilationEvent
|
|
11
11
|
*/
|
|
12
12
|
class CompilationEvent extends _DataEvent.default {
|
|
13
13
|
static PROJECT_START = 'PROJECT_START';
|
package/lib/event/FileEvent.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _DataEvent = _interopRequireDefault(require("./asyncEvent/DataEvent"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
/**
|
|
10
|
-
* FileEvent
|
|
9
|
+
/**
|
|
10
|
+
* FileEvent
|
|
11
11
|
*/
|
|
12
12
|
class FileEvent extends _DataEvent.default {
|
|
13
13
|
static FILE_END_COMPILATION = 'FILE_END_COMPILATION';
|
|
@@ -8,15 +8,15 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
|
8
8
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
/**
|
|
12
|
-
* FileLaneUtil
|
|
11
|
+
/**
|
|
12
|
+
* FileLaneUtil
|
|
13
13
|
*/
|
|
14
14
|
class FileLaneUtil {
|
|
15
|
-
/**
|
|
16
|
-
* 文件路径转换为文件参数
|
|
17
|
-
* @param path 路径
|
|
18
|
-
* @param readContent 是否读取文件内容以设置 content 的值,默认 false
|
|
19
|
-
* @returns
|
|
15
|
+
/**
|
|
16
|
+
* 文件路径转换为文件参数
|
|
17
|
+
* @param path 路径
|
|
18
|
+
* @param readContent 是否读取文件内容以设置 content 的值,默认 false
|
|
19
|
+
* @returns
|
|
20
20
|
*/
|
|
21
21
|
static pathToFileParam(path) {
|
|
22
22
|
let readContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-lane",
|
|
3
|
-
"version": "2.0.5
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "File conversion tool, can be one-to-one, one to N, N to one",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"file",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"test": "node ./__tests__/file-lane.test.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aiot-toolkit/shared-utils": "2.0.5
|
|
23
|
+
"@aiot-toolkit/shared-utils": "2.0.5",
|
|
24
24
|
"chokidar": "^3.6.0",
|
|
25
25
|
"fs-extra": "^11.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/fs-extra": "^11.0.4"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "deb83e8b8fa65191a286690efe3d957d7df772f4"
|
|
31
31
|
}
|