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

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.
Files changed (3) hide show
  1. package/README.md +247 -247
  2. package/lib/FileLane.js +0 -1
  3. 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
@@ -156,7 +156,6 @@ class FileLane {
156
156
  });
157
157
  }
158
158
  catch (error) {
159
- console.log('FileLane error', error);
160
159
  shared_utils_1.ColorConsole.throw(`ERROR: `, { word: 'build error' }, `, ${error || 'unknown error'}`);
161
160
  // 结束任务
162
161
  process.exit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-lane",
3
- "version": "2.0.2-beta.18",
3
+ "version": "2.0.2-beta.19",
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.2-beta.18",
23
+ "@aiot-toolkit/shared-utils": "2.0.2-beta.19",
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": "e39f0ad4fe3bfe8e733499742c5a39ab80fa2cd0"
31
+ "gitHead": "7c6ed600fe84ee9de9b00c6e95dfabf3bfb3ad65"
32
32
  }