@we-debug/gulp-tool 0.18.1 → 0.19.0
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/CHANGELOG.md +16 -0
- package/index.js +23 -2
- package/lib/constants.js +1 -0
- package/lib/plugin.js +55 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.19.0](https://github.com/dlhandsome/we-debug/compare/v0.18.1...v0.19.0) (2023-11-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* fixed eslint ([c5765fe](https://github.com/dlhandsome/we-debug/commit/c5765fe4495e82f39a88894804b8b55b7ed216c8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **gulp-tool:** support plugins ([7eb8e97](https://github.com/dlhandsome/we-debug/commit/7eb8e97b87e5918026b0ddb27b7beaba30cf3448))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [0.18.1](https://github.com/dlhandsome/we-debug/compare/v0.18.0...v0.18.1) (2023-10-17)
|
|
7
23
|
|
|
8
24
|
|
package/index.js
CHANGED
|
@@ -7,8 +7,8 @@ const { lookupPages } = require('./lib/lookup');
|
|
|
7
7
|
const { belongsPage, belongsApp } = require('./lib/belongs');
|
|
8
8
|
const { getAbsolutePath } = require('./lib/path');
|
|
9
9
|
const injectComponentId = require('./lib/inject-component-id');
|
|
10
|
-
|
|
11
|
-
const PLUGIN_NAME = '
|
|
10
|
+
const plugin = require('./lib/plugin');
|
|
11
|
+
const { PLUGIN_NAME } = require('./lib/constants');
|
|
12
12
|
|
|
13
13
|
let pages = [];
|
|
14
14
|
|
|
@@ -20,6 +20,7 @@ function mpGlobalComp(options = {}) {
|
|
|
20
20
|
let compName = options.compName || 'we-debug';
|
|
21
21
|
let compPath = options.compPath || '@we-debug/core/component/index/index';
|
|
22
22
|
let entryFile = options.entryFile || 'we-debug/index.js';
|
|
23
|
+
const plugins = options.plugins || [];
|
|
23
24
|
|
|
24
25
|
baseDir = getAbsolutePath(baseDir);
|
|
25
26
|
const isModule = compPath.indexOf('@we-debug/core') === 0;
|
|
@@ -39,12 +40,18 @@ function mpGlobalComp(options = {}) {
|
|
|
39
40
|
function init() {
|
|
40
41
|
return through.obj((file, encoding, callback) => {
|
|
41
42
|
if (!mpGlobalComp.init) {
|
|
43
|
+
// 执行 beforeInit 插件钩子
|
|
44
|
+
plugin.execLifecycle('beforeInit', file);
|
|
45
|
+
|
|
42
46
|
try {
|
|
43
47
|
pages = lookupPages(baseDir);
|
|
48
|
+
plugin.initPlugin(plugins, { ...options, pages });
|
|
44
49
|
} catch (e) {
|
|
45
50
|
throw new PluginError(PLUGIN_NAME, 'look up pages failed, please check your configure');
|
|
46
51
|
}
|
|
47
52
|
mpGlobalComp.init = true;
|
|
53
|
+
// 执行 onInit 插件钩子
|
|
54
|
+
plugin.execLifecycle('onInit', file);
|
|
48
55
|
}
|
|
49
56
|
callback(null, file);
|
|
50
57
|
});
|
|
@@ -56,6 +63,8 @@ function mpGlobalComp(options = {}) {
|
|
|
56
63
|
|
|
57
64
|
// 如果不是 wxml 文件, 则跳过
|
|
58
65
|
if (file.extname !== '.wxml') return callback(null, file);
|
|
66
|
+
// 执行 wxml 插件钩子
|
|
67
|
+
plugin.execLifecycle('wxml', file);
|
|
59
68
|
|
|
60
69
|
// 如果命中filter,则跳过
|
|
61
70
|
if (filter) {
|
|
@@ -72,11 +81,15 @@ function mpGlobalComp(options = {}) {
|
|
|
72
81
|
|
|
73
82
|
// 如果属于 Page
|
|
74
83
|
if (belongsPage(file.path, pages)) {
|
|
84
|
+
// 插入 we-debug 片段之前执行
|
|
85
|
+
plugin.execLifecycle('beforeInsertWxml', file);
|
|
75
86
|
let code = file.contents.toString();
|
|
76
87
|
|
|
77
88
|
code += wxmlRaw;
|
|
78
89
|
|
|
79
90
|
file.contents = Buffer.from(code);
|
|
91
|
+
// 插入 we-debug 片段之后执行
|
|
92
|
+
plugin.execLifecycle('afterInsertWxml', file);
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
callback(null, file);
|
|
@@ -105,6 +118,8 @@ function mpGlobalComp(options = {}) {
|
|
|
105
118
|
|
|
106
119
|
// 如果不是 wxml 文件, 则跳过
|
|
107
120
|
if (file.extname !== '.json') return callback(null, file);
|
|
121
|
+
// 检测到项目 json 文件后立即执行
|
|
122
|
+
plugin.execLifecycle('json', file);
|
|
108
123
|
|
|
109
124
|
// 如果是 app.json
|
|
110
125
|
if (belongsApp(file.path, baseDir)) {
|
|
@@ -141,13 +156,19 @@ function mpGlobalComp(options = {}) {
|
|
|
141
156
|
|
|
142
157
|
// 如果不是 JS 文件, 则跳过
|
|
143
158
|
if (file.extname !== '.js') return callback(null, file);
|
|
159
|
+
// 检测到项目 js 文件后立即执行
|
|
160
|
+
plugin.execLifecycle('script', file);
|
|
144
161
|
|
|
145
162
|
// 如果是 app.js
|
|
146
163
|
if (belongsApp(file.path, baseDir) || file.relative === 'app.js') {
|
|
164
|
+
// app.js 插入 we-debug import 片段前执行
|
|
165
|
+
plugin.execLifecycle('beforeInsertScript', file);
|
|
147
166
|
let code = file.contents.toString();
|
|
148
167
|
|
|
149
168
|
code = `require('${entryFile}')\n` + code;
|
|
150
169
|
file.contents = Buffer.from(code);
|
|
170
|
+
// app.js 插入 we-debug import 片段后执行
|
|
171
|
+
plugin.execLifecycle('afterInsertScript', file);
|
|
151
172
|
}
|
|
152
173
|
|
|
153
174
|
callback(null, file);
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports.PLUGIN_NAME = '@we-debug/gulp-tool';
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const PluginError = require('plugin-error');
|
|
2
|
+
|
|
3
|
+
const PLUGIN_NAME = '@we-debug/gulp-tool';
|
|
4
|
+
|
|
5
|
+
class Plugin {
|
|
6
|
+
/** 子插件生命周期 */
|
|
7
|
+
lifecycles = [];
|
|
8
|
+
/** 插件元信息 */
|
|
9
|
+
meta = {};
|
|
10
|
+
|
|
11
|
+
getLifecycles() {
|
|
12
|
+
return this.lifecycles;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
register(options) {
|
|
16
|
+
this.lifecycles.push(options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
execLifecycle(lifetime, file) {
|
|
20
|
+
this.lifecycles.forEach(i => {
|
|
21
|
+
if (typeof i[lifetime] === 'function') {
|
|
22
|
+
i[lifetime].call(this, file);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
loadPlugin(pkg) {
|
|
28
|
+
const pkgType = typeof pkg;
|
|
29
|
+
|
|
30
|
+
switch (pkgType) {
|
|
31
|
+
case 'function':
|
|
32
|
+
// 函数直接返回
|
|
33
|
+
return pkg;
|
|
34
|
+
case 'string':
|
|
35
|
+
// 字符串识别为 npm 包
|
|
36
|
+
return require(pkg);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
initPlugin(packges, meta) {
|
|
41
|
+
this.meta = meta;
|
|
42
|
+
|
|
43
|
+
packges.map(p => {
|
|
44
|
+
try {
|
|
45
|
+
// 加载插件
|
|
46
|
+
let fn = this.loadPlugin(p.package);
|
|
47
|
+
fn.call(this, this, p.options);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
throw new PluginError(PLUGIN_NAME, `load package ${p.package} error: ', ${e}`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = new Plugin();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@we-debug/gulp-tool",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "we-debug, gulp",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"readme": "ERROR: No README data found!",
|
|
29
29
|
"_id": "@we-debug/gulp-tool@0.1.3",
|
|
30
30
|
"_commitid": "f35f53c",
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "91e5d1d55b39be895eabdeffab7508b7d43cabe1"
|
|
32
32
|
}
|