@tmsfe/tmskit 0.0.5-beta.5 → 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.
Files changed (42) hide show
  1. package/README.md +27 -25
  2. package/dist/index.cjs.js +779 -664
  3. package/main.js +3 -3
  4. package/package.json +75 -69
  5. package/src/config/constant.js +71 -70
  6. package/src/config/defaultTmsConfig.js +16 -16
  7. package/src/entry.js +60 -60
  8. package/src/gulp/build.js +5 -8
  9. package/src/gulp/compile.js +81 -87
  10. package/src/gulp/dev.js +102 -108
  11. package/src/gulp/plugins/less.js +116 -116
  12. package/src/gulp/plugins/mpCommonDep.js +131 -131
  13. package/src/gulp/plugins/mpJsonDep.js +108 -108
  14. package/src/gulp/plugins/mpWxmlDep.js +194 -194
  15. package/src/gulp/plugins/postcss-font-base64.js +72 -72
  16. package/src/gulp/{replaceEnv.js → plugins/replaceEnv.js} +29 -29
  17. package/src/gulp/plugins/utils/pluginError.js +25 -25
  18. package/src/index.js +62 -62
  19. package/src/init.js +33 -33
  20. package/src/scripts/create/ask.js +63 -63
  21. package/src/scripts/create/generator.js +25 -25
  22. package/src/scripts/create/ignoreFiles.js +7 -7
  23. package/src/scripts/create/index.js +72 -72
  24. package/src/scripts/create/render.js +19 -19
  25. package/src/scripts/run/build/index.js +17 -16
  26. package/src/scripts/run/dev/index.js +84 -67
  27. package/src/scripts/run/index.js +68 -63
  28. package/src/scripts/run/init/index.js +87 -80
  29. package/src/scripts/run/install/index.js +29 -31
  30. package/src/utils/buildAppJson.js +221 -200
  31. package/src/utils/checkDependencies.js +77 -77
  32. package/src/utils/cliUtils.js +35 -35
  33. package/src/utils/cloneModules.js +116 -91
  34. package/src/utils/findCssImport.js +30 -30
  35. package/src/utils/global.js +36 -36
  36. package/src/utils/handleError.js +16 -0
  37. package/src/utils/io.js +106 -106
  38. package/src/utils/log.js +44 -44
  39. package/src/utils/mpCiUtils.js +73 -74
  40. package/src/utils/npmUtils.js +166 -148
  41. package/src/utils/tkitUtils.js +158 -84
  42. package/src/utils/widgets.js +167 -173
@@ -1,131 +1,131 @@
1
- /* eslint-disable no-param-reassign */
2
- const through = require('through2');
3
- const precinct = require('precinct');
4
- const path = require('path');
5
- const { findCssImports } = require('../../utils/findCssImport');
6
- const { ext, fileInDir, diffContentCopyFile } = require('../../utils/io');
7
- const { resolve } = require('../../utils/widgets');
8
- const fs = require('fs');
9
- const { pluginError } = require('./utils/pluginError');
10
-
11
- const cssFilter = ['.less', '.wxss'];
12
- const dfsFindCommonDep = function (anaFileOriginFile, anaFileDestFile, extensions, isWatch = true) {
13
- const resDep = new Map();
14
- function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
15
- let contents = '';
16
- try {
17
- contents = fs.readFileSync(anaFileOriginFile, 'utf8');
18
- } catch (e) {
19
- pluginError(e, isWatch);
20
- }
21
- const deps = cssFilter.indexOf(path.extname(anaFileOriginFile)) > -1
22
- ? findCssImports(contents)
23
- : precinct(contents);
24
- deps.forEach((depItem) => {
25
- if (depItem.startsWith('.')) {
26
- // 被依赖文件的存在的绝对路径
27
- const depOriginPath = path.join(path.dirname(anaFileOriginFile), depItem);
28
- // 被依赖文件加上后缀
29
- const { ext: extAlias, file: depOriginFile, extPath } = ext(depOriginPath, extensions);
30
-
31
- if (!fs.existsSync(depOriginFile)) {
32
- pluginError(
33
- new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`),
34
- isWatch,
35
- );
36
- return;
37
- }
38
-
39
- const depDestPath = resolve(path.dirname(anaFileDestFile), depItem);
40
- const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
41
- if (!resDep.has(depDestFile)) {
42
- resDep.set(depDestFile, {
43
- anaFileOriginFile,
44
- anaFileDestFile,
45
- depDestFile,
46
- depOriginFile,
47
- });
48
- dfs(depOriginFile, depDestFile, extensions);
49
- }
50
- }
51
- });
52
- }
53
- dfs(anaFileOriginFile, anaFileDestFile, extensions);
54
-
55
- return resDep;
56
- };
57
-
58
- function mpCommonDep(tmsConfig, module, extensions = [], isWatch = true) {
59
- const stream = through.obj(function (file, enc, cb) {
60
- // 依赖分析的文件
61
- const anaFileOriginFile = file.history[0];
62
- const anaFileRelativeModule = path.relative(resolve(module.from), anaFileOriginFile);
63
- const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
64
-
65
- if (file.isBuffer()) {
66
- let contents = String(file.contents);
67
- const deps = cssFilter.indexOf(path.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
68
-
69
- const copyModules = new Map();
70
- Object.keys(tmsConfig.dependencies).forEach((includeName) => {
71
- const includePath = tmsConfig.dependencies[includeName];
72
- deps.forEach((depItem) => {
73
- if (depItem.indexOf(includeName) > -1) {
74
- // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
75
- const depOriginPath = path.join(path.dirname(anaFileOriginFile), depItem);
76
- // 被依赖文件加上后缀
77
- const { ext: extAlias, file: depOriginFile, extPath } = ext(depOriginPath, extensions);
78
-
79
- if (!fileInDir(includePath, depOriginFile)) {
80
- pluginError(
81
- new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`),
82
- isWatch,
83
- );
84
- return;
85
- }
86
-
87
- // eslint-disable-next-line
88
- const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
89
- const regRes = depItem.match(reg) || [];
90
- if (regRes[2]) {
91
- const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
92
- const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
93
- if (!copyModules.has(depDestFile)) {
94
- copyModules.set(depDestFile, {
95
- depOriginFile,
96
- depDestFile,
97
- beforeDepPath: depItem,
98
- afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath),
99
- });
100
- }
101
- }
102
- }
103
- });
104
- });
105
-
106
- // console.log('mpCommonDep copyModules', copyModules);
107
- copyModules.forEach(({ depOriginFile, depDestFile, beforeDepPath, afterDepPath }) => {
108
- diffContentCopyFile(depOriginFile, depDestFile);
109
- const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
110
- contents = contents.replace(reg, `"${afterDepPath}"`);
111
-
112
- const defs = dfsFindCommonDep(depOriginFile, depDestFile, extensions, isWatch);
113
- defs.forEach((item) => {
114
- diffContentCopyFile(item.depOriginFile, item.depDestFile);
115
- });
116
- // console.log('mpCommonDep defs', defs);
117
- });
118
-
119
- file.contents = new Buffer(contents);
120
- }
121
- this.push(file);
122
- cb();
123
- });
124
-
125
- return stream;
126
- }
127
-
128
- module.exports = {
129
- mpCommonDep,
130
- dfsFindCommonDep,
131
- };
1
+ /* eslint-disable no-param-reassign */
2
+ const through = require('through2');
3
+ const precinct = require('precinct');
4
+ const path = require('path');
5
+ const { findCssImports } = require('../../utils/findCssImport');
6
+ const { ext, fileInDir, diffContentCopyFile } = require('../../utils/io');
7
+ const { resolve } = require('../../utils/widgets');
8
+ const fs = require('fs');
9
+ const { pluginError } = require('./utils/pluginError');
10
+
11
+ const cssFilter = ['.less', '.wxss'];
12
+ const dfsFindCommonDep = function (anaFileOriginFile, anaFileDestFile, extensions, isWatch = true) {
13
+ const resDep = new Map();
14
+ function dfs(anaFileOriginFile, anaFileDestFile, extensions) {
15
+ let contents = '';
16
+ try {
17
+ contents = fs.readFileSync(anaFileOriginFile, 'utf8');
18
+ } catch (e) {
19
+ pluginError(e, isWatch);
20
+ }
21
+ const deps = cssFilter.indexOf(path.extname(anaFileOriginFile)) > -1
22
+ ? findCssImports(contents)
23
+ : precinct(contents);
24
+ deps.forEach((depItem) => {
25
+ if (depItem.startsWith('.')) {
26
+ // 被依赖文件的存在的绝对路径
27
+ const depOriginPath = path.join(path.dirname(anaFileOriginFile), depItem);
28
+ // 被依赖文件加上后缀
29
+ const { ext: extAlias, file: depOriginFile, extPath } = ext(depOriginPath, extensions);
30
+
31
+ if (!fs.existsSync(depOriginFile)) {
32
+ pluginError(
33
+ new Error(`${anaFileOriginFile}引用路径${depOriginFile}文件不存在, 请检查应用路径`),
34
+ isWatch,
35
+ );
36
+ return;
37
+ }
38
+
39
+ const depDestPath = resolve(path.dirname(anaFileDestFile), depItem);
40
+ const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
41
+ if (!resDep.has(depDestFile)) {
42
+ resDep.set(depDestFile, {
43
+ anaFileOriginFile,
44
+ anaFileDestFile,
45
+ depDestFile,
46
+ depOriginFile,
47
+ });
48
+ dfs(depOriginFile, depDestFile, extensions);
49
+ }
50
+ }
51
+ });
52
+ }
53
+ dfs(anaFileOriginFile, anaFileDestFile, extensions);
54
+
55
+ return resDep;
56
+ };
57
+
58
+ function mpCommonDep(tmsConfig, module, extensions = [], isWatch = true) {
59
+ const stream = through.obj(function (file, enc, cb) {
60
+ // 依赖分析的文件
61
+ const anaFileOriginFile = file.history[0];
62
+ const anaFileRelativeModule = path.relative(resolve(module.from), anaFileOriginFile);
63
+ const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
64
+
65
+ if (file.isBuffer()) {
66
+ let contents = String(file.contents);
67
+ const deps = cssFilter.indexOf(path.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
68
+
69
+ const copyModules = new Map();
70
+ Object.keys(tmsConfig.dependencies).forEach((includeName) => {
71
+ const includePath = tmsConfig.dependencies[includeName];
72
+ deps.forEach((depItem) => {
73
+ if (depItem.indexOf(includeName) > -1) {
74
+ // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
75
+ const depOriginPath = path.join(path.dirname(anaFileOriginFile), depItem);
76
+ // 被依赖文件加上后缀
77
+ const { ext: extAlias, file: depOriginFile, extPath } = ext(depOriginPath, extensions);
78
+
79
+ if (!fileInDir(includePath, depOriginFile)) {
80
+ pluginError(
81
+ new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`),
82
+ isWatch,
83
+ );
84
+ return;
85
+ }
86
+
87
+ // eslint-disable-next-line
88
+ const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
89
+ const regRes = depItem.match(reg) || [];
90
+ if (regRes[2]) {
91
+ const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
92
+ const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
93
+ if (!copyModules.has(depDestFile)) {
94
+ copyModules.set(depDestFile, {
95
+ depOriginFile,
96
+ depDestFile,
97
+ beforeDepPath: depItem,
98
+ afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/'),
99
+ });
100
+ }
101
+ }
102
+ }
103
+ });
104
+ });
105
+
106
+ // console.log('mpCommonDep copyModules', copyModules);
107
+ copyModules.forEach(({ depOriginFile, depDestFile, beforeDepPath, afterDepPath }) => {
108
+ diffContentCopyFile(depOriginFile, depDestFile);
109
+ const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
110
+ contents = contents.replace(reg, `"${afterDepPath}"`);
111
+
112
+ const defs = dfsFindCommonDep(depOriginFile, depDestFile, extensions, isWatch);
113
+ defs.forEach((item) => {
114
+ diffContentCopyFile(item.depOriginFile, item.depDestFile);
115
+ });
116
+ // console.log('mpCommonDep defs', defs);
117
+ });
118
+
119
+ file.contents = Buffer.from(contents);
120
+ }
121
+ this.push(file);
122
+ cb();
123
+ });
124
+
125
+ return stream;
126
+ }
127
+
128
+ module.exports = {
129
+ mpCommonDep,
130
+ dfsFindCommonDep,
131
+ };
@@ -1,108 +1,108 @@
1
- /* eslint-disable no-param-reassign */
2
- const through = require('through2');
3
- const path = require('path');
4
- const { ext, fileInDir, diffContentCopyFile } = require('../../utils/io');
5
- const { resolve } = require('../../utils/widgets');
6
- const fs = require('fs');
7
- const { pluginError } = require('./utils/pluginError');
8
- const { dfsFindCommonDep } = require('./mpCommonDep');
9
-
10
- function mpJsonDep(
11
- tmsConfig,
12
- module,
13
- extensions = ['.json'],
14
- filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'],
15
- isWatch,
16
- ) {
17
- const stream = through.obj(function (file, enc, cb) {
18
- // 当前分析的文件的路径
19
- const anaFileOriginFile = file.history[0];
20
- const anaFileRelativeModule = path.relative(resolve(module.from), anaFileOriginFile);
21
- const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
22
-
23
- if (file.isBuffer()) {
24
- const copyModules = new Map();
25
- let contents = String(file.contents);
26
- try {
27
- contents = JSON.parse(contents);
28
- if (contents.usingComponents) {
29
- Object.keys(tmsConfig.dependencies).forEach((includeName) => {
30
- const includePath = tmsConfig.dependencies[includeName];
31
- Object.keys(contents.usingComponents).forEach((componentKey) => {
32
- const componentPath = contents.usingComponents[componentKey];
33
- if (componentPath.indexOf(includeName) > -1) {
34
- const depOriginPath = path.join(path.dirname(anaFileOriginFile), componentPath);
35
- // 被依赖文件加上后缀
36
- const { ext: extAlias, file: depOriginFile, extPath } = ext(depOriginPath, extensions);
37
-
38
- const isFileInDir = fileInDir(includePath, depOriginFile);
39
- if (!isFileInDir) {
40
- pluginError(
41
- new Error(`${anaFileOriginFile}引用的路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`),
42
- isWatch,
43
- );
44
- return;
45
- }
46
-
47
- // eslint-disable-next-line
48
- const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
49
- const regRes = componentPath.match(reg) || [];
50
- if (regRes[2]) {
51
- const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
52
- const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
53
-
54
- if (!copyModules.has(depDestFile)) {
55
- copyModules.set(depDestFile, {
56
- depOriginFile,
57
- depOriginExt: extAlias,
58
- depDestFile,
59
- beforeDepPath: componentPath,
60
- afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath),
61
- });
62
- }
63
- }
64
- }
65
- });
66
- });
67
- }
68
- } catch (e) {
69
- pluginError(e, isWatch);
70
- }
71
- // console.log('json copyModules', copyModules);
72
- copyModules.forEach(({ depOriginFile, depOriginExt, depDestFile, beforeDepPath, afterDepPath }) => {
73
- // 拷贝当前依赖组件几个部分 wxml、wxss、wxs、json
74
- filesExt.forEach((extKey) => {
75
- const originFile = depOriginFile.replace(depOriginExt, extKey);
76
- const destFile = depDestFile.replace(depOriginExt, extKey);
77
-
78
- if (fs.existsSync(originFile)) {
79
- diffContentCopyFile(originFile, destFile);
80
-
81
- const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
82
- if (extensionsFilter.indexOf(extKey) > -1) {
83
- const defs = dfsFindCommonDep(originFile, destFile, extensionsFilter);
84
- // console.log('json defs', defs);
85
- defs.forEach((item) => {
86
- diffContentCopyFile(item.depOriginFile, item.depDestFile);
87
- });
88
- }
89
- }
90
- });
91
- contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
92
- const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
93
- contents = contents.replace(reg, `"${afterDepPath}"`);
94
- });
95
- contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
96
- file.contents = new Buffer(contents);
97
- }
98
-
99
- this.push(file);
100
- cb();
101
- });
102
-
103
- return stream;
104
- }
105
-
106
- module.exports = {
107
- mpJsonDep,
108
- };
1
+ /* eslint-disable no-param-reassign */
2
+ const through = require('through2');
3
+ const path = require('path');
4
+ const { ext, fileInDir, diffContentCopyFile } = require('../../utils/io');
5
+ const { resolve } = require('../../utils/widgets');
6
+ const fs = require('fs');
7
+ const { pluginError } = require('./utils/pluginError');
8
+ const { dfsFindCommonDep } = require('./mpCommonDep');
9
+
10
+ function mpJsonDep(
11
+ tmsConfig,
12
+ module,
13
+ extensions = ['.json'],
14
+ filesExt = ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'],
15
+ isWatch,
16
+ ) {
17
+ const stream = through.obj(function (file, enc, cb) {
18
+ // 当前分析的文件的路径
19
+ const anaFileOriginFile = file.history[0];
20
+ const anaFileRelativeModule = path.relative(resolve(module.from), anaFileOriginFile);
21
+ const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
22
+
23
+ if (file.isBuffer()) {
24
+ const copyModules = new Map();
25
+ let contents = String(file.contents);
26
+ try {
27
+ contents = JSON.parse(contents);
28
+ if (contents.usingComponents) {
29
+ Object.keys(tmsConfig.dependencies).forEach((includeName) => {
30
+ const includePath = tmsConfig.dependencies[includeName];
31
+ Object.keys(contents.usingComponents).forEach((componentKey) => {
32
+ const componentPath = contents.usingComponents[componentKey];
33
+ if (componentPath.indexOf(includeName) > -1) {
34
+ const depOriginPath = path.join(path.dirname(anaFileOriginFile), componentPath);
35
+ // 被依赖文件加上后缀
36
+ const { ext: extAlias, file: depOriginFile, extPath } = ext(depOriginPath, extensions);
37
+
38
+ const isFileInDir = fileInDir(includePath, depOriginFile);
39
+ if (!isFileInDir) {
40
+ pluginError(
41
+ new Error(`${anaFileOriginFile}引用的路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`),
42
+ isWatch,
43
+ );
44
+ return;
45
+ }
46
+
47
+ // eslint-disable-next-line
48
+ const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
49
+ const regRes = componentPath.match(reg) || [];
50
+ if (regRes[2]) {
51
+ const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
52
+ const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
53
+
54
+ if (!copyModules.has(depDestFile)) {
55
+ copyModules.set(depDestFile, {
56
+ depOriginFile,
57
+ depOriginExt: extAlias,
58
+ depDestFile,
59
+ beforeDepPath: componentPath,
60
+ afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/'),
61
+ });
62
+ }
63
+ }
64
+ }
65
+ });
66
+ });
67
+ }
68
+ } catch (e) {
69
+ pluginError(e, isWatch);
70
+ }
71
+ // console.log('json copyModules', copyModules);
72
+ copyModules.forEach(({ depOriginFile, depOriginExt, depDestFile, beforeDepPath, afterDepPath }) => {
73
+ // 拷贝当前依赖组件几个部分 wxml、wxss、wxs、json
74
+ filesExt.forEach((extKey) => {
75
+ const originFile = depOriginFile.replace(depOriginExt, extKey);
76
+ const destFile = depDestFile.replace(depOriginExt, extKey);
77
+
78
+ if (fs.existsSync(originFile)) {
79
+ diffContentCopyFile(originFile, destFile);
80
+
81
+ const extensionsFilter = ['.js', '.ts', '.wxss', '.less'];
82
+ if (extensionsFilter.indexOf(extKey) > -1) {
83
+ const defs = dfsFindCommonDep(originFile, destFile, extensionsFilter);
84
+ // console.log('json defs', defs);
85
+ defs.forEach((item) => {
86
+ diffContentCopyFile(item.depOriginFile, item.depDestFile);
87
+ });
88
+ }
89
+ }
90
+ });
91
+ contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
92
+ const reg = new RegExp(`['"]${beforeDepPath}["']`, 'g');
93
+ contents = contents.replace(reg, `"${afterDepPath}"`);
94
+ });
95
+ contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
96
+ file.contents = Buffer.from(contents);
97
+ }
98
+
99
+ this.push(file);
100
+ cb();
101
+ });
102
+
103
+ return stream;
104
+ }
105
+
106
+ module.exports = {
107
+ mpJsonDep,
108
+ };