@tmsfe/tmskit 0.0.6 → 0.0.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/README.md +27 -27
- package/dist/index.cjs.js +332 -407
- package/main.js +3 -3
- package/package.json +75 -75
- package/src/config/constant.js +71 -71
- package/src/config/defaultTmsConfig.js +16 -16
- package/src/entry.js +60 -60
- package/src/gulp/build.js +5 -5
- package/src/gulp/compile.js +81 -87
- package/src/gulp/dev.js +102 -102
- package/src/gulp/plugins/less.js +116 -116
- package/src/gulp/plugins/mpCommonDep.js +131 -131
- package/src/gulp/plugins/mpJsonDep.js +108 -108
- package/src/gulp/plugins/mpWxmlDep.js +194 -194
- package/src/gulp/plugins/postcss-font-base64.js +72 -72
- package/src/gulp/plugins/replaceEnv.js +29 -29
- package/src/gulp/plugins/utils/pluginError.js +25 -25
- package/src/index.js +62 -62
- package/src/init.js +33 -33
- package/src/scripts/create/ask.js +63 -63
- package/src/scripts/create/generator.js +25 -25
- package/src/scripts/create/ignoreFiles.js +7 -7
- package/src/scripts/create/index.js +72 -72
- package/src/scripts/create/render.js +19 -19
- package/src/scripts/run/build/index.js +17 -17
- package/src/scripts/run/dev/index.js +84 -84
- package/src/scripts/run/index.js +68 -68
- package/src/scripts/run/init/index.js +87 -87
- package/src/scripts/run/install/index.js +29 -29
- package/src/utils/buildAppJson.js +221 -221
- package/src/utils/checkDependencies.js +77 -77
- package/src/utils/cliUtils.js +35 -35
- package/src/utils/cloneModules.js +116 -116
- package/src/utils/findCssImport.js +30 -30
- package/src/utils/global.js +36 -36
- package/src/utils/handleError.js +16 -16
- package/src/utils/io.js +106 -106
- package/src/utils/log.js +44 -44
- package/src/utils/mpCiUtils.js +73 -73
- package/src/utils/npmUtils.js +166 -166
- package/src/utils/tkitUtils.js +158 -158
- package/src/utils/widgets.js +167 -167
package/src/gulp/dev.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
const watch = require('gulp-watch');
|
|
2
|
-
const { resolve } = require('../utils/widgets');
|
|
3
|
-
const { buildOutputAppJson } = require('../utils/buildAppJson');
|
|
4
|
-
const { DEFAULT_COPY_CONFIG } = require('../config/constant');
|
|
5
|
-
const compile = require('./compile');
|
|
6
|
-
|
|
7
|
-
function excludeGlob(glob) {
|
|
8
|
-
const otherArr = new Set();
|
|
9
|
-
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
10
|
-
Object.keys(glob).forEach((globKey) => {
|
|
11
|
-
if (typeof glob[globKey] === 'string') {
|
|
12
|
-
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
13
|
-
otherArr.add(data);
|
|
14
|
-
} if (Array.isArray(glob[globKey])) {
|
|
15
|
-
glob[globKey].forEach((value) => {
|
|
16
|
-
if (typeof value === 'string') {
|
|
17
|
-
const data = value.startsWith('!') ? value : `!${value}`;
|
|
18
|
-
otherArr.add(data);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return Array.from(otherArr);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
27
|
-
// 监听app.json
|
|
28
|
-
if (isWatch) {
|
|
29
|
-
watch(resolve('app.json'), { ignoreInitial: false, events: ['add', 'change'] }, () => {
|
|
30
|
-
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 监听根目录的文件
|
|
37
|
-
compile(tmsConfig, {
|
|
38
|
-
glob: {
|
|
39
|
-
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
40
|
-
wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
41
|
-
js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
42
|
-
},
|
|
43
|
-
module: { from: '', to: '' },
|
|
44
|
-
destPath: resolve(tmsConfig.outputDir),
|
|
45
|
-
srcOption: { allowEmpty: true },
|
|
46
|
-
isWatch,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// 监听模块的文件
|
|
50
|
-
for (let module of newModules) {
|
|
51
|
-
// 处理默认参数
|
|
52
|
-
module = {
|
|
53
|
-
...{ exclude: [] },
|
|
54
|
-
...module,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
if (isWatch) {
|
|
58
|
-
// 监听模块配置文件
|
|
59
|
-
watch(`${resolve(module.path)}/**/module.config.json`, { events: ['change'] }, () => {
|
|
60
|
-
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
65
|
-
const glob = {
|
|
66
|
-
js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
|
|
67
|
-
json: [`${resolve(module.path)}/**/*.json`, ...excludes],
|
|
68
|
-
wxss: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
|
|
69
|
-
wxml: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
|
|
70
|
-
image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes],
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
compile(tmsConfig, {
|
|
74
|
-
glob: {
|
|
75
|
-
...glob,
|
|
76
|
-
other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)],
|
|
77
|
-
},
|
|
78
|
-
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
79
|
-
module: { from: module.path, to: module.root },
|
|
80
|
-
srcOption: { allowEmpty: true },
|
|
81
|
-
isWatch,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 静态资源目录-拷贝
|
|
86
|
-
if (tmsConfig?.static && tmsConfig?.static.length > 0) {
|
|
87
|
-
for (const item of tmsConfig.static) {
|
|
88
|
-
const from = item?.from.startsWith('/') ? item.from : resolve(item.from);
|
|
89
|
-
const to = item?.to.startsWith('/') ? item.to : resolve(item.to);
|
|
90
|
-
|
|
91
|
-
compile(tmsConfig, {
|
|
92
|
-
glob: {
|
|
93
|
-
other: [from],
|
|
94
|
-
},
|
|
95
|
-
destPath: to,
|
|
96
|
-
module: item,
|
|
97
|
-
srcOption: { allowEmpty: true },
|
|
98
|
-
isWatch,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
1
|
+
const watch = require('gulp-watch');
|
|
2
|
+
const { resolve } = require('../utils/widgets');
|
|
3
|
+
const { buildOutputAppJson } = require('../utils/buildAppJson');
|
|
4
|
+
const { DEFAULT_COPY_CONFIG } = require('../config/constant');
|
|
5
|
+
const compile = require('./compile');
|
|
6
|
+
|
|
7
|
+
function excludeGlob(glob) {
|
|
8
|
+
const otherArr = new Set();
|
|
9
|
+
otherArr.add('!**/*.{ttf,otf,woff,eot}');
|
|
10
|
+
Object.keys(glob).forEach((globKey) => {
|
|
11
|
+
if (typeof glob[globKey] === 'string') {
|
|
12
|
+
const data = glob[globKey].startsWith('!') ? glob[globKey] : `!${glob[globKey]}`;
|
|
13
|
+
otherArr.add(data);
|
|
14
|
+
} if (Array.isArray(glob[globKey])) {
|
|
15
|
+
glob[globKey].forEach((value) => {
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
const data = value.startsWith('!') ? value : `!${value}`;
|
|
18
|
+
otherArr.add(data);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return Array.from(otherArr);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = async (tmsConfig, newModules, isWatch = true) => {
|
|
27
|
+
// 监听app.json
|
|
28
|
+
if (isWatch) {
|
|
29
|
+
watch(resolve('app.json'), { ignoreInitial: false, events: ['add', 'change'] }, () => {
|
|
30
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 监听根目录的文件
|
|
37
|
+
compile(tmsConfig, {
|
|
38
|
+
glob: {
|
|
39
|
+
json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
|
|
40
|
+
wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
|
|
41
|
+
js: ['app.js', 'app.ts'].map(item => resolve(item)),
|
|
42
|
+
},
|
|
43
|
+
module: { from: '', to: '' },
|
|
44
|
+
destPath: resolve(tmsConfig.outputDir),
|
|
45
|
+
srcOption: { allowEmpty: true },
|
|
46
|
+
isWatch,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 监听模块的文件
|
|
50
|
+
for (let module of newModules) {
|
|
51
|
+
// 处理默认参数
|
|
52
|
+
module = {
|
|
53
|
+
...{ exclude: [] },
|
|
54
|
+
...module,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (isWatch) {
|
|
58
|
+
// 监听模块配置文件
|
|
59
|
+
watch(`${resolve(module.path)}/**/module.config.json`, { events: ['change'] }, () => {
|
|
60
|
+
buildOutputAppJson(tmsConfig, newModules, isWatch);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const excludes = module.exclude.map(key => `!${resolve(key)}`);
|
|
65
|
+
const glob = {
|
|
66
|
+
js: [`${resolve(module.path)}/**/*.{js,ts,wxs}`, ...excludes],
|
|
67
|
+
json: [`${resolve(module.path)}/**/*.json`, ...excludes],
|
|
68
|
+
wxss: [`${resolve(module.path)}/**/*.{less,wxss}`, ...excludes],
|
|
69
|
+
wxml: [`${resolve(module.path)}/**/*.wxml`, ...excludes],
|
|
70
|
+
image: [`${resolve(module.path)}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
compile(tmsConfig, {
|
|
74
|
+
glob: {
|
|
75
|
+
...glob,
|
|
76
|
+
other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)],
|
|
77
|
+
},
|
|
78
|
+
destPath: resolve(tmsConfig.outputDir, module.root),
|
|
79
|
+
module: { from: module.path, to: module.root },
|
|
80
|
+
srcOption: { allowEmpty: true },
|
|
81
|
+
isWatch,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 静态资源目录-拷贝
|
|
86
|
+
if (tmsConfig?.static && tmsConfig?.static.length > 0) {
|
|
87
|
+
for (const item of tmsConfig.static) {
|
|
88
|
+
const from = item?.from.startsWith('/') ? item.from : resolve(item.from);
|
|
89
|
+
const to = item?.to.startsWith('/') ? item.to : resolve(item.to);
|
|
90
|
+
|
|
91
|
+
compile(tmsConfig, {
|
|
92
|
+
glob: {
|
|
93
|
+
other: [from],
|
|
94
|
+
},
|
|
95
|
+
destPath: to,
|
|
96
|
+
module: item,
|
|
97
|
+
srcOption: { allowEmpty: true },
|
|
98
|
+
isWatch,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
package/src/gulp/plugins/less.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const less = require('less');
|
|
5
|
-
const through2 = require('through2');
|
|
6
|
-
const replaceExt = require('replace-ext');
|
|
7
|
-
const assign = require('object-assign');
|
|
8
|
-
const applySourceMap = require('vinyl-sourcemaps-apply');
|
|
9
|
-
const PluginError = require('plugin-error');
|
|
10
|
-
const { fail } = require('../../utils/log');
|
|
11
|
-
|
|
12
|
-
function inlineSources(map) {
|
|
13
|
-
if (map.sourcesContent) {
|
|
14
|
-
return Promise.resolve(map);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return Promise.all(map.sources.map(source => new Promise((resolve, reject) => {
|
|
18
|
-
fs.readFile(source, 'utf8', (err, data) => {
|
|
19
|
-
if (err) {
|
|
20
|
-
reject(err);
|
|
21
|
-
} else {
|
|
22
|
-
resolve(data);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}))).then(
|
|
26
|
-
(contents) => {
|
|
27
|
-
map.sourcesContent = contents;
|
|
28
|
-
return map;
|
|
29
|
-
},
|
|
30
|
-
() => map,
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function renderLess(str, opts) {
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
less.render(str, opts, (err, res) => {
|
|
37
|
-
if (err) {
|
|
38
|
-
reject(err);
|
|
39
|
-
} else {
|
|
40
|
-
const obj = {
|
|
41
|
-
result: res.css,
|
|
42
|
-
imports: res.imports,
|
|
43
|
-
};
|
|
44
|
-
if (opts.sourceMap && res.map) {
|
|
45
|
-
obj.sourcemap = JSON.parse(res.map);
|
|
46
|
-
inlineSources(obj.sourcemap).then((map) => {
|
|
47
|
-
obj.sourcemap = map;
|
|
48
|
-
resolve(obj);
|
|
49
|
-
});
|
|
50
|
-
} else {
|
|
51
|
-
resolve(obj);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = function (options) {
|
|
59
|
-
const opts = assign({}, {
|
|
60
|
-
compress: false,
|
|
61
|
-
paths: [],
|
|
62
|
-
isWatch: false,
|
|
63
|
-
}, options);
|
|
64
|
-
|
|
65
|
-
return through2.obj((file, enc, cb) => {
|
|
66
|
-
if (file.isNull()) {
|
|
67
|
-
return cb(null, file);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (file.isStream()) {
|
|
71
|
-
return cb(new PluginError('gulp-less', 'Streaming not supported'));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const str = file.contents.toString();
|
|
75
|
-
|
|
76
|
-
// Injects the path of the current file
|
|
77
|
-
opts.filename = file.path;
|
|
78
|
-
|
|
79
|
-
// Bootstrap source maps
|
|
80
|
-
if (file.sourceMap || opts.sourcemap) {
|
|
81
|
-
opts.sourceMap = true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
renderLess(str, opts).then((res) => {
|
|
85
|
-
file.contents = Buffer.from(res.result);
|
|
86
|
-
file.path = replaceExt(file.path, '.wxss');
|
|
87
|
-
if (res.sourcemap) {
|
|
88
|
-
res.sourcemap.file = file.relative;
|
|
89
|
-
res.sourcemap.sources = res.sourcemap.sources.map(source => path.relative(file.base, source));
|
|
90
|
-
|
|
91
|
-
applySourceMap(file, res.sourcemap);
|
|
92
|
-
}
|
|
93
|
-
return file;
|
|
94
|
-
})
|
|
95
|
-
.then((file) => {
|
|
96
|
-
console.log(`less编译完成${file.path}`);
|
|
97
|
-
cb(null, file);
|
|
98
|
-
})
|
|
99
|
-
.catch((err) => {
|
|
100
|
-
// Convert the keys so PluginError can read them
|
|
101
|
-
err.lineNumber = err.line;
|
|
102
|
-
err.fileName = err.filename;
|
|
103
|
-
|
|
104
|
-
// Add a better error message
|
|
105
|
-
const message = `${err.message} in file ${err.fileName} line no. ${err.lineNumber}`;
|
|
106
|
-
err.message = message;
|
|
107
|
-
if (opts.isWatch) {
|
|
108
|
-
// watch的时候,报错提示,不退出进程
|
|
109
|
-
fail(err);
|
|
110
|
-
return cb(null, file);
|
|
111
|
-
}
|
|
112
|
-
// 不watch的时候,报错退出进程
|
|
113
|
-
return cb(new PluginError('gulp-less', err));
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
};
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const less = require('less');
|
|
5
|
+
const through2 = require('through2');
|
|
6
|
+
const replaceExt = require('replace-ext');
|
|
7
|
+
const assign = require('object-assign');
|
|
8
|
+
const applySourceMap = require('vinyl-sourcemaps-apply');
|
|
9
|
+
const PluginError = require('plugin-error');
|
|
10
|
+
const { fail } = require('../../utils/log');
|
|
11
|
+
|
|
12
|
+
function inlineSources(map) {
|
|
13
|
+
if (map.sourcesContent) {
|
|
14
|
+
return Promise.resolve(map);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return Promise.all(map.sources.map(source => new Promise((resolve, reject) => {
|
|
18
|
+
fs.readFile(source, 'utf8', (err, data) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
reject(err);
|
|
21
|
+
} else {
|
|
22
|
+
resolve(data);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}))).then(
|
|
26
|
+
(contents) => {
|
|
27
|
+
map.sourcesContent = contents;
|
|
28
|
+
return map;
|
|
29
|
+
},
|
|
30
|
+
() => map,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderLess(str, opts) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
less.render(str, opts, (err, res) => {
|
|
37
|
+
if (err) {
|
|
38
|
+
reject(err);
|
|
39
|
+
} else {
|
|
40
|
+
const obj = {
|
|
41
|
+
result: res.css,
|
|
42
|
+
imports: res.imports,
|
|
43
|
+
};
|
|
44
|
+
if (opts.sourceMap && res.map) {
|
|
45
|
+
obj.sourcemap = JSON.parse(res.map);
|
|
46
|
+
inlineSources(obj.sourcemap).then((map) => {
|
|
47
|
+
obj.sourcemap = map;
|
|
48
|
+
resolve(obj);
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
resolve(obj);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = function (options) {
|
|
59
|
+
const opts = assign({}, {
|
|
60
|
+
compress: false,
|
|
61
|
+
paths: [],
|
|
62
|
+
isWatch: false,
|
|
63
|
+
}, options);
|
|
64
|
+
|
|
65
|
+
return through2.obj((file, enc, cb) => {
|
|
66
|
+
if (file.isNull()) {
|
|
67
|
+
return cb(null, file);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (file.isStream()) {
|
|
71
|
+
return cb(new PluginError('gulp-less', 'Streaming not supported'));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const str = file.contents.toString();
|
|
75
|
+
|
|
76
|
+
// Injects the path of the current file
|
|
77
|
+
opts.filename = file.path;
|
|
78
|
+
|
|
79
|
+
// Bootstrap source maps
|
|
80
|
+
if (file.sourceMap || opts.sourcemap) {
|
|
81
|
+
opts.sourceMap = true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
renderLess(str, opts).then((res) => {
|
|
85
|
+
file.contents = Buffer.from(res.result);
|
|
86
|
+
file.path = replaceExt(file.path, '.wxss');
|
|
87
|
+
if (res.sourcemap) {
|
|
88
|
+
res.sourcemap.file = file.relative;
|
|
89
|
+
res.sourcemap.sources = res.sourcemap.sources.map(source => path.relative(file.base, source));
|
|
90
|
+
|
|
91
|
+
applySourceMap(file, res.sourcemap);
|
|
92
|
+
}
|
|
93
|
+
return file;
|
|
94
|
+
})
|
|
95
|
+
.then((file) => {
|
|
96
|
+
console.log(`less编译完成${file.path}`);
|
|
97
|
+
cb(null, file);
|
|
98
|
+
})
|
|
99
|
+
.catch((err) => {
|
|
100
|
+
// Convert the keys so PluginError can read them
|
|
101
|
+
err.lineNumber = err.line;
|
|
102
|
+
err.fileName = err.filename;
|
|
103
|
+
|
|
104
|
+
// Add a better error message
|
|
105
|
+
const message = `${err.message} in file ${err.fileName} line no. ${err.lineNumber}`;
|
|
106
|
+
err.message = message;
|
|
107
|
+
if (opts.isWatch) {
|
|
108
|
+
// watch的时候,报错提示,不退出进程
|
|
109
|
+
fail(err);
|
|
110
|
+
return cb(null, file);
|
|
111
|
+
}
|
|
112
|
+
// 不watch的时候,报错退出进程
|
|
113
|
+
return cb(new PluginError('gulp-less', err));
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|