@tmsfe/tmskit 0.0.5-beta.0 → 0.0.5-beta.1
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/dist/index.cjs.js +476 -268
- package/package.json +3 -2
- package/src/config/defaultTmsConfig.js +2 -0
- package/src/gulp/build.js +3 -75
- package/src/gulp/compile.js +67 -0
- package/src/gulp/dev.js +61 -72
- package/src/gulp/includeDep.js +130 -0
- package/src/gulp/replaceEnv.js +1 -0
- package/src/utils/io.js +45 -0
- package/src/utils/npmUtils.js +4 -1
- package/src/utils/entry.js +0 -150
package/src/utils/entry.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const { resolve, unique } = require('../utils/widgets');
|
|
4
|
-
const { tmsModulesMergeLocalModuleCfg } = require('../utils/tkitUtils');
|
|
5
|
-
const { fail } = require('../utils/log');
|
|
6
|
-
const replaceExt = require('replace-ext');
|
|
7
|
-
|
|
8
|
-
const extensions = ['.js', '.ts'];
|
|
9
|
-
function ext(entry, extensions) {
|
|
10
|
-
let newEntry = entry;
|
|
11
|
-
try {
|
|
12
|
-
const stat = fs.lstatSync(newEntry);
|
|
13
|
-
if (stat.isDirectory()) {
|
|
14
|
-
newEntry += (newEntry[newEntry.length - 1] === '/') ? 'index' : '/index';
|
|
15
|
-
}
|
|
16
|
-
} catch (e) {}
|
|
17
|
-
|
|
18
|
-
for (const ext of extensions) {
|
|
19
|
-
const file = replaceExt(newEntry, ext);
|
|
20
|
-
if (fs.existsSync(file)) {
|
|
21
|
-
return {
|
|
22
|
-
file,
|
|
23
|
-
ext,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 根据用户选择的modules,找到module.config.json的配置信息,找到所有的page
|
|
31
|
-
function getPageEntry(modules, tmsConfig, moduleDir) {
|
|
32
|
-
let entry = [];
|
|
33
|
-
// tms.config.js的modules 合并 module.config.json的配置项
|
|
34
|
-
const newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName, moduleDir);
|
|
35
|
-
newModules.forEach(({ path: relativePath, pages, root }, index) => {
|
|
36
|
-
pages.forEach((page) => {
|
|
37
|
-
const pageJsonPath = `${resolve(relativePath, page)}.json`;
|
|
38
|
-
if (fs.existsSync(pageJsonPath)) {
|
|
39
|
-
const pageJsonContent = JSON.parse(fs.readFileSync(pageJsonPath, 'utf-8'));
|
|
40
|
-
const pageDir = path.dirname(pageJsonPath); // 该页面所在的目录
|
|
41
|
-
const extValue = ext(resolve(relativePath, page), extensions);
|
|
42
|
-
if (!extValue) {
|
|
43
|
-
fail(`当前${page}找不到入口.js或.ts文件`);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const entryKey = `${root}/${page}${extValue.ext}`;
|
|
48
|
-
entry = entry.concat(
|
|
49
|
-
[{
|
|
50
|
-
key: entryKey,
|
|
51
|
-
filePath: extValue.file,
|
|
52
|
-
type: 'page',
|
|
53
|
-
moduleInfo: {
|
|
54
|
-
path: relativePath,
|
|
55
|
-
root,
|
|
56
|
-
},
|
|
57
|
-
}],
|
|
58
|
-
getComponentEntry(pageJsonContent, pageDir, path.dirname(entryKey), newModules[index]),
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
return entry;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 根据pageJson,filePath,获取页面引入的所有component
|
|
67
|
-
function getComponentEntry(pageJson, pagePath, pageKey, moduleInfo) {
|
|
68
|
-
const componentEntry = [];
|
|
69
|
-
function task(json, dir, rootKey) {
|
|
70
|
-
if (!json.usingComponents) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const componentKeys = Object.keys(json.usingComponents);
|
|
75
|
-
|
|
76
|
-
// 如果存在依赖的组件
|
|
77
|
-
componentKeys.forEach((key) => {
|
|
78
|
-
if (json.usingComponents[key].startsWith('.')) {
|
|
79
|
-
// 拼出组件所在位置的绝对路径
|
|
80
|
-
const comValue = path.join(dir, json.usingComponents[key]);
|
|
81
|
-
const extValue = ext(comValue, extensions);
|
|
82
|
-
const comKey = path.resolve('/', rootKey, json.usingComponents[key]);
|
|
83
|
-
if (!extValue) {
|
|
84
|
-
fail(`当前page: ${pagePath} component: ${comValue}找不到入口.js或.ts文件`);
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
componentEntry.push({
|
|
89
|
-
key: `${comKey.slice(1)}${extValue.ext}`,
|
|
90
|
-
filePath: extValue.file,
|
|
91
|
-
type: 'component',
|
|
92
|
-
moduleInfo: {
|
|
93
|
-
path: moduleInfo.path,
|
|
94
|
-
root: moduleInfo.root,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const comJsonPath = `${comValue}.json`;
|
|
99
|
-
if (fs.existsSync(comJsonPath)) {
|
|
100
|
-
const comJsonContent = JSON.parse(fs.readFileSync(comJsonPath, 'utf-8'));
|
|
101
|
-
|
|
102
|
-
const comDir = path.dirname(comJsonPath); // 该页面所在的目录
|
|
103
|
-
task(comJsonContent, comDir, path.dirname(comKey));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
task(pageJson, pagePath, pageKey);
|
|
110
|
-
|
|
111
|
-
return componentEntry;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// 收集依赖在非模块内的目录
|
|
115
|
-
function getDepDirOfNotInModule(modules, tmsConfig, moduleDir) {
|
|
116
|
-
const result = [];
|
|
117
|
-
const pageInfoArr = getPageEntry(modules, tmsConfig, moduleDir);
|
|
118
|
-
// const pageInfoArr = [{
|
|
119
|
-
// type: 'component',
|
|
120
|
-
// filePath: '/Users/odile/workspace/tms-frontend1/miniprogram/modules/home/common/components/favorite/favorite.js',
|
|
121
|
-
// moduleInfo: {
|
|
122
|
-
// root: 'modules/home/welfare',
|
|
123
|
-
// path: '../../miniprogram/modules/home/welfare',
|
|
124
|
-
// },
|
|
125
|
-
// }];
|
|
126
|
-
pageInfoArr.filter(item => item.type === 'component').forEach((item) => {
|
|
127
|
-
const { moduleInfo, filePath } = item;
|
|
128
|
-
// 文件路径 相对于 模块path的路径 ../../common/data
|
|
129
|
-
const moduleFileRelative = path.relative(resolve(moduleInfo.path), filePath);
|
|
130
|
-
|
|
131
|
-
// '../../common/data' => '../../common'
|
|
132
|
-
const fileRelativeDir = moduleFileRelative.match(/^(\.\.\/)+([^/]*)/);
|
|
133
|
-
// eslint-disable-next-line
|
|
134
|
-
if (fileRelativeDir && fileRelativeDir[0]) {
|
|
135
|
-
const fileDir = resolve(moduleInfo.path, fileRelativeDir[0]);
|
|
136
|
-
if (fs.existsSync(fileDir)) {
|
|
137
|
-
result.push({
|
|
138
|
-
from: fileDir,
|
|
139
|
-
to: resolve(tmsConfig.webpack.outputDir, moduleInfo.root, fileRelativeDir[0]),
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
return unique(result, 'from');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
module.exports = {
|
|
149
|
-
getDepDirOfNotInModule,
|
|
150
|
-
};
|