@tmsfe/tmskit 0.0.5-beta.4 → 0.0.6

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/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.5-beta.4",
3
+ "version": "0.0.6",
4
4
  "description": "tmskit",
5
5
  "main": "main.js",
6
6
  "bin": {
7
7
  "tmskit": "main.js"
8
8
  },
9
- "files": ["src", "dist", "main.js", "package.json"],
9
+ "files": [
10
+ "src",
11
+ "dist",
12
+ "main.js",
13
+ "package.json"
14
+ ],
10
15
  "scripts": {
11
16
  "dev": "rollup -wc --environment TARGET:tmskit",
12
17
  "build": "rollup -c --environment TARGET:tmskit"
@@ -36,6 +41,7 @@
36
41
  "copy-webpack-plugin": "^9.1.0",
37
42
  "download-git-repo": "^3.0.2",
38
43
  "ejs": "^3.1.5",
44
+ "fs-extra": "^10.0.1",
39
45
  "glob-ignore": "^1.0.2",
40
46
  "gulp": "^4.0.2",
41
47
  "gulp-cache": "^1.1.3",
@@ -21,6 +21,7 @@ const TMS_NAME = 'tmskit';
21
21
  // 脚手架的配置名称
22
22
  const TMS_CONFIG_FILENAME = 'tms.config.js';
23
23
 
24
+ const TMS_PRIVATE_FILENAME = 'tms.private.config.js';
24
25
 
25
26
  // 模块代码的默认在modules子目录
26
27
  const DEFAULT_MODULE_DIR = 'modules';
@@ -38,7 +39,6 @@ const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json'];
38
39
 
39
40
  // 开发模式
40
41
  const MODE = {
41
- main: 'tkitmain',
42
42
  all: 'all',
43
43
  multi: 'multi',
44
44
  };
@@ -58,6 +58,7 @@ export {
58
58
  TEMPLATE_PATH,
59
59
  TMS_NAME,
60
60
  TMS_CONFIG_FILENAME,
61
+ TMS_PRIVATE_FILENAME,
61
62
  DEFAULT_MODULE_DIR,
62
63
  MODULE_CONFIG_FILENAME,
63
64
  DEFAULT_WEBPACK_ENTRY,
@@ -5,14 +5,12 @@ module.exports = {
5
5
  // 模块配置信息
6
6
  modules: [],
7
7
  cloudDir: 'cloud',
8
- gulp: {
9
- // 第三方依赖代码需要拷贝到本项目的
10
- dependencies: {},
11
- /** 编译输出文件夹位置 */
12
- outputDir: 'dist',
13
- /** 源码监听路径 */
14
- sourceDir: './',
15
- /** 静态资源目录 */
16
- static: [],
17
- },
8
+ // 第三方依赖代码需要拷贝到本项目的
9
+ dependencies: {},
10
+ /** 编译输出文件夹位置 */
11
+ outputDir: 'dist',
12
+ /** 源码监听路径 */
13
+ sourceDir: './',
14
+ /** 静态资源目录 */
15
+ static: [],
18
16
  };
package/src/gulp/build.js CHANGED
@@ -1,8 +1,5 @@
1
- const shelljs = require('shelljs');
2
1
  const dev = require('./dev');
3
2
 
4
3
  module.exports = async (tmsConfig, newModules) => {
5
- shelljs.rm('-rf', tmsConfig.gulp.outputDir);
6
-
7
4
  dev(tmsConfig, newModules, false);
8
5
  };
@@ -2,9 +2,9 @@ const { src, dest, lastRun } = require('gulp');
2
2
  const px2rpx = require('gulp-px-to-rpx');
3
3
  const postcss = require('gulp-postcss');
4
4
  const watch = require('gulp-watch');
5
- const cache = require('gulp-cache');
6
- const image = require('gulp-image');
7
- const replaceEnv = require('./replaceEnv');
5
+ // const cache = require('gulp-cache');
6
+ // const image = require('gulp-image');
7
+ const replaceEnv = require('./plugins/replaceEnv');
8
8
  const { mpCommonDep } = require('./plugins/mpCommonDep');
9
9
  const { mpJsonDep } = require('./plugins/mpJsonDep');
10
10
  const { mpWxmlDep } = require('./plugins/mpWxmlDep');
@@ -70,10 +70,10 @@ module.exports = function (
70
70
  break;
71
71
  case 'image':
72
72
  srcPipe
73
- .pipe(cache(image()))
74
- .on('error', (err) => {
75
- fail(`image编译报错${err}`);
76
- })
73
+ // .pipe(cache(image()))
74
+ // .on('error', (err) => {
75
+ // fail(`image编译报错${err}`);
76
+ // })
77
77
  .pipe(dest(destPath));
78
78
  break;
79
79
  case 'other':
package/src/gulp/dev.js CHANGED
@@ -27,10 +27,10 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
27
27
  // 监听app.json
28
28
  if (isWatch) {
29
29
  watch(resolve('app.json'), { ignoreInitial: false, events: ['add', 'change'] }, () => {
30
- buildOutputAppJson(tmsConfig, newModules);
30
+ buildOutputAppJson(tmsConfig, newModules, isWatch);
31
31
  });
32
32
  } else {
33
- buildOutputAppJson(tmsConfig, newModules);
33
+ buildOutputAppJson(tmsConfig, newModules, isWatch);
34
34
  }
35
35
 
36
36
  // 监听根目录的文件
@@ -41,7 +41,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
41
41
  js: ['app.js', 'app.ts'].map(item => resolve(item)),
42
42
  },
43
43
  module: { from: '', to: '' },
44
- destPath: resolve(tmsConfig.gulp.outputDir),
44
+ destPath: resolve(tmsConfig.outputDir),
45
45
  srcOption: { allowEmpty: true },
46
46
  isWatch,
47
47
  });
@@ -57,7 +57,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
57
57
  if (isWatch) {
58
58
  // 监听模块配置文件
59
59
  watch(`${resolve(module.path)}/**/module.config.json`, { events: ['change'] }, () => {
60
- buildOutputAppJson(tmsConfig, newModules);
60
+ buildOutputAppJson(tmsConfig, newModules, isWatch);
61
61
  });
62
62
  }
63
63
 
@@ -75,30 +75,24 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
75
75
  ...glob,
76
76
  other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)],
77
77
  },
78
- destPath: resolve(tmsConfig.gulp.outputDir, module.root),
78
+ destPath: resolve(tmsConfig.outputDir, module.root),
79
79
  module: { from: module.path, to: module.root },
80
80
  srcOption: { allowEmpty: true },
81
81
  isWatch,
82
82
  });
83
83
  }
84
84
 
85
- // 监听copy模块
86
- if (tmsConfig?.gulp?.static && tmsConfig?.gulp?.static.length > 0) {
87
- for (const item of tmsConfig.gulp?.static) {
88
- const glob = {
89
- js: `${item.from}/**/*.{js,ts,wxs}`,
90
- json: `${item.from}/**/*.json`,
91
- wxss: `${item.from}/**/*.{less,wxss}`,
92
- wxml: `${item.from}/**/*.wxml`,
93
- image: `${item.from}/**/*.{png,jpg,jpeg,gif,svg}`,
94
- };
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);
95
90
 
96
91
  compile(tmsConfig, {
97
92
  glob: {
98
- ...glob,
99
- other: [`${item.from}/**/*`, ...excludeGlob(glob)],
93
+ other: [from],
100
94
  },
101
- destPath: item.to,
95
+ destPath: to,
102
96
  module: item,
103
97
  srcOption: { allowEmpty: true },
104
98
  isWatch,
@@ -60,15 +60,15 @@ function mpCommonDep(tmsConfig, module, extensions = [], isWatch = true) {
60
60
  // 依赖分析的文件
61
61
  const anaFileOriginFile = file.history[0];
62
62
  const anaFileRelativeModule = path.relative(resolve(module.from), anaFileOriginFile);
63
- const anaFileDestFile = resolve(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
63
+ const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
64
64
 
65
65
  if (file.isBuffer()) {
66
66
  let contents = String(file.contents);
67
67
  const deps = cssFilter.indexOf(path.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
68
68
 
69
69
  const copyModules = new Map();
70
- Object.keys(tmsConfig.gulp.dependencies).forEach((includeName) => {
71
- const includePath = tmsConfig.gulp.dependencies[includeName];
70
+ Object.keys(tmsConfig.dependencies).forEach((includeName) => {
71
+ const includePath = tmsConfig.dependencies[includeName];
72
72
  deps.forEach((depItem) => {
73
73
  if (depItem.indexOf(includeName) > -1) {
74
74
  // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
@@ -88,14 +88,14 @@ function mpCommonDep(tmsConfig, module, extensions = [], isWatch = true) {
88
88
  const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
89
89
  const regRes = depItem.match(reg) || [];
90
90
  if (regRes[2]) {
91
- const depDestPath = resolve(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
91
+ const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
92
92
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
93
93
  if (!copyModules.has(depDestFile)) {
94
94
  copyModules.set(depDestFile, {
95
95
  depOriginFile,
96
96
  depDestFile,
97
97
  beforeDepPath: depItem,
98
- afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath),
98
+ afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/'),
99
99
  });
100
100
  }
101
101
  }
@@ -116,7 +116,7 @@ function mpCommonDep(tmsConfig, module, extensions = [], isWatch = true) {
116
116
  // console.log('mpCommonDep defs', defs);
117
117
  });
118
118
 
119
- file.contents = new Buffer(contents);
119
+ file.contents = Buffer.from(contents);
120
120
  }
121
121
  this.push(file);
122
122
  cb();
@@ -18,7 +18,7 @@ function mpJsonDep(
18
18
  // 当前分析的文件的路径
19
19
  const anaFileOriginFile = file.history[0];
20
20
  const anaFileRelativeModule = path.relative(resolve(module.from), anaFileOriginFile);
21
- const anaFileDestFile = resolve(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
21
+ const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
22
22
 
23
23
  if (file.isBuffer()) {
24
24
  const copyModules = new Map();
@@ -26,8 +26,8 @@ function mpJsonDep(
26
26
  try {
27
27
  contents = JSON.parse(contents);
28
28
  if (contents.usingComponents) {
29
- Object.keys(tmsConfig.gulp.dependencies).forEach((includeName) => {
30
- const includePath = tmsConfig.gulp.dependencies[includeName];
29
+ Object.keys(tmsConfig.dependencies).forEach((includeName) => {
30
+ const includePath = tmsConfig.dependencies[includeName];
31
31
  Object.keys(contents.usingComponents).forEach((componentKey) => {
32
32
  const componentPath = contents.usingComponents[componentKey];
33
33
  if (componentPath.indexOf(includeName) > -1) {
@@ -48,7 +48,7 @@ function mpJsonDep(
48
48
  const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
49
49
  const regRes = componentPath.match(reg) || [];
50
50
  if (regRes[2]) {
51
- const depDestPath = resolve(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
51
+ const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
52
52
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
53
53
 
54
54
  if (!copyModules.has(depDestFile)) {
@@ -57,7 +57,7 @@ function mpJsonDep(
57
57
  depOriginExt: extAlias,
58
58
  depDestFile,
59
59
  beforeDepPath: componentPath,
60
- afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath),
60
+ afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestPath).replace(/\\/g, '/'),
61
61
  });
62
62
  }
63
63
  }
@@ -93,7 +93,7 @@ function mpJsonDep(
93
93
  contents = contents.replace(reg, `"${afterDepPath}"`);
94
94
  });
95
95
  contents = typeof contents === 'object' ? JSON.stringify(contents, null, 2) : contents;
96
- file.contents = new Buffer(contents);
96
+ file.contents = Buffer.from(contents);
97
97
  }
98
98
 
99
99
  this.push(file);
@@ -107,7 +107,7 @@ function mpWxmlDep(tmsConfig, module, isWatch) {
107
107
  // 依赖分析的文件
108
108
  const anaFileOriginFile = file.history[0];
109
109
  const anaFileRelativeModule = path.relative(resolve(module.from), anaFileOriginFile);
110
- const anaFileDestFile = resolve(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
110
+ const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
111
111
 
112
112
  if (file.isBuffer()) {
113
113
  let contents = String(file.contents);
@@ -120,9 +120,9 @@ function mpWxmlDep(tmsConfig, module, isWatch) {
120
120
  // 处理后缀(源码引入依赖时,后缀不全的情况)
121
121
  const { ext, file: depOriginFile, extPath } = extFile(name, depOriginPath);
122
122
 
123
- Object.keys(tmsConfig.gulp.dependencies).forEach((includeName) => {
123
+ Object.keys(tmsConfig.dependencies).forEach((includeName) => {
124
124
  if (attributes.src.indexOf(includeName) > -1) {
125
- const includePath = tmsConfig.gulp.dependencies[includeName];
125
+ const includePath = tmsConfig.dependencies[includeName];
126
126
 
127
127
  if (!fileInDir(includePath, depOriginFile)) {
128
128
  pluginError(
@@ -136,14 +136,14 @@ function mpWxmlDep(tmsConfig, module, isWatch) {
136
136
  const reg = new RegExp(`^(\.\.\/)+.*\/${includeName}\/(.*)`);
137
137
  const regRes = attributes.src.match(reg) || [];
138
138
  if (regRes[2]) {
139
- const depDestPath = resolve(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
139
+ const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
140
140
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
141
141
  if (!copyModules.has(depDestFile)) {
142
142
  copyModules.set(depDestFile, {
143
143
  depOriginFile,
144
144
  depDestFile,
145
145
  beforeDepPath: attributes.src,
146
- afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestFile),
146
+ afterDepPath: path.relative(path.dirname(anaFileDestFile), depDestFile).replace(/\\/g, '/'),
147
147
  });
148
148
  }
149
149
  }
@@ -178,7 +178,7 @@ function mpWxmlDep(tmsConfig, module, isWatch) {
178
178
  }
179
179
  });
180
180
 
181
- file.contents = new Buffer(contents);
181
+ file.contents = Buffer.from(contents);
182
182
  }
183
183
 
184
184
  this.push(file);
@@ -66,7 +66,7 @@ module.exports = postcss.plugin('postcss-font-base64', (options) => {
66
66
 
67
67
  function readAndEncodeFile(file) {
68
68
  const bitmap = fs.readFileSync(file);
69
- return new Buffer(bitmap).toString('base64');
69
+ return Buffer.from(bitmap).toString('base64');
70
70
  }
71
71
  };
72
72
  });
@@ -16,7 +16,7 @@ function replaceEnv(reg = /process\.env(\.(\w*))?/g, envData) {
16
16
  }
17
17
 
18
18
  // eslint-disable-next-line
19
- file.contents = new Buffer(contents);
19
+ file.contents = Buffer.from(contents);
20
20
  }
21
21
 
22
22
  this.push(file);
package/src/index.js CHANGED
@@ -37,7 +37,6 @@ function registerCommand(program, commands) {
37
37
 
38
38
  registerCommand(program, commands);
39
39
 
40
-
41
40
  program.on('--help', () => {
42
41
  log();
43
42
  log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
@@ -5,9 +5,10 @@ const gulpBuild = require('../../../gulp/build');
5
5
 
6
6
  async function build(tmsConfig, targetModules, env) {
7
7
  // 开始构建前,清理输出目录
8
- await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
8
+ await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
9
9
 
10
- const { targetModules: newModules } = await init(tmsConfig, targetModules);
10
+ const isDev = false;
11
+ const { targetModules: newModules } = await init(tmsConfig, targetModules, isDev);
11
12
 
12
13
  gulpBuild(tmsConfig, newModules, env);
13
14
  }
@@ -2,12 +2,14 @@ const gulpDev = require('../../../gulp/dev');
2
2
  const fs = require('fs');
3
3
  const { resolve } = require('../../../utils/widgets');
4
4
  const init = require('../init/index');
5
- const { DEFAULT_MODULE_DIR } = require('../../../config/constant');
5
+ const { MODULE_CONFIG_FILENAME } = require('../../../config/constant');
6
6
  const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
7
7
  const { checkDependencies } = require('../../../utils/checkDependencies');
8
8
  const { fail } = require('../../../utils/log');
9
+ const shelljs = require('shelljs');
10
+ // const io = require('../../../utils/io');
9
11
 
10
- function isInit(tmsConfig, targetModules, contextDir) {
12
+ function isInit(tmsConfig, targetModules, contextDir, isDev) {
11
13
  // 判断是否存在dist目录
12
14
  if (!fs.existsSync(contextDir)) {
13
15
  return true;
@@ -33,8 +35,8 @@ function isInit(tmsConfig, targetModules, contextDir) {
33
35
  if (!item.root) {
34
36
  return true;
35
37
  }
36
- // 判断编译目录是否有该模块
37
- if (!fs.existsSync(`${contextDir}/${item.root}`)) {
38
+ // 判断dist目录是否有该模块
39
+ if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
38
40
  return true;
39
41
  }
40
42
  // 判断源码目录是否有该模块
@@ -45,21 +47,36 @@ function isInit(tmsConfig, targetModules, contextDir) {
45
47
  }
46
48
 
47
49
  // 判断package.json的版本是否有新的版本
48
- return checkDependencies(targetModules, resolve('./'), tmsConfig.gulp.outputDir);
50
+ return checkDependencies(targetModules, resolve('./'), tmsConfig.outputDir, isDev);
51
+ }
52
+
53
+ // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
54
+ function delOtherModule(tmsConfig, targetModules) {
55
+ const modules = tmsModulesMergeLocalModuleCfg(tmsConfig.modules, tmsConfig.appName);
56
+ const targetModulesName = targetModules.map(item => item.name);
57
+ modules.forEach((item) => {
58
+ if (item.root && targetModulesName.indexOf(item.name) === -1) {
59
+ const moduleRootDir = resolve(`dist/${item.root}`);
60
+ shelljs.rm('-rf', `${moduleRootDir}/*`, { silent: true });
61
+ // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
62
+ // io.ensureDirExist(moduleRootDir);
63
+ }
64
+ });
49
65
  }
50
66
 
51
67
  async function dev(tmsConfig, targetModules, env) {
52
- // tms.config.js的modules 合并 module.config.json的配置项
53
- let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR);
68
+ let newModules = targetModules;
69
+ const isDev = true;
54
70
 
55
71
  // 判断是否进行init命令
56
- if (isInit(tmsConfig, newModules, resolve('dist'))) {
57
- // init函数会将 最新的tms.config.js的modules 合并 module.config.json的配置项 返回,不需要再做重复工作
58
- const initData = await init(tmsConfig, targetModules);
72
+ if (isInit(tmsConfig, targetModules, resolve('dist'), isDev)) {
73
+ // init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
74
+ const initData = await init(tmsConfig, newModules, isDev);
59
75
  newModules = initData.targetModules;
60
76
  }
61
77
 
62
- console.log('当前dev启动的有效模块', newModules.map(item => item.name));
78
+ console.log('当前dev启动的有效模块', newModules.map(item => item.name).sort());
79
+ delOtherModule(tmsConfig, newModules);
63
80
  gulpDev(tmsConfig, newModules, env);
64
81
  }
65
82
 
@@ -4,56 +4,61 @@ const build = require('./build/index');
4
4
  const install = require('./install/index');
5
5
  const { createTask } = require('../../utils/widgets');
6
6
  const { MODE } = require('../../config/constant');
7
- const { readTmsConfig, checkModules } = require('../../utils/tkitUtils');
7
+ const { readTmsConfig, readTmsPrivateCf, checkModules } = require('../../utils/tkitUtils');
8
+ const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../utils/tkitUtils');
8
9
 
9
- const handleModulesArg = (cmd) => {
10
- // 主模块开发
11
- if (cmd.module === MODE.main) {
12
- return MODE.main;
13
- }
14
- // 单模块 或 多模块开发
15
- const { argv } = process;
16
- const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
10
+ const handleModulesArg = (cmd, tmsPrivateCg) => {
11
+ // 单模块或多模块开发-用户通过脚手架参数指定的模块
17
12
  if (cmd.module) {
13
+ const { argv } = process;
14
+ const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
18
15
  return [
19
16
  cmd.module,
20
17
  ...reset,
21
18
  ];
22
19
  }
20
+ // 单模块或多模块开发-用户在tms.private.js指定的模块
21
+ if (tmsPrivateCg?.modules && tmsPrivateCg?.modules.length > 0) {
22
+ return tmsPrivateCg?.modules;
23
+ }
23
24
  // 全量模块
24
25
  return MODE.all;
25
26
  };
26
27
 
27
28
  async function run(commandName, cmd) {
28
- const moduleArg = handleModulesArg(cmd);
29
- const { env } = cmd;
30
-
29
+ // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
30
+ const tmsPrivateCg = readTmsPrivateCf();
31
+ // 处理module参数
32
+ const moduleArg = handleModulesArg(cmd, tmsPrivateCg);
33
+ const { env = tmsPrivateCg?.env } = cmd;
31
34
  const tmsConfig = await createTask(readTmsConfig, '开始读取脚手架的配置项', '读取脚手架的配置项完成')(env);
32
35
 
33
36
  let modules;
34
- // 主模块
35
- if (moduleArg === MODE.main) {
36
- modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages])]);;
37
- } else if (moduleArg === MODE.all) {
37
+ if (moduleArg === MODE.all) {
38
38
  // 全量模块
39
39
  modules = tmsConfig.modules;
40
40
  } else {
41
41
  // 检查用户输入modules的有效性
42
- modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...moduleArg])]);;
42
+ modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...moduleArg])]);
43
43
  }
44
44
 
45
+ // tms.config.js的modules 合并 module.config.json的配置项
46
+ let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName);
47
+ // A分包依赖了B分包的代码, merge B分包进行编译;
48
+ newModules = subModulesMergeDepModules(tmsConfig, newModules);
49
+
45
50
  switch (commandName) {
46
51
  case 'init':
47
- init(tmsConfig, modules, env);
52
+ init(tmsConfig, newModules, env);
48
53
  return;
49
54
  case 'dev':
50
- dev(tmsConfig, modules, env);
55
+ dev(tmsConfig, newModules, env);
51
56
  return;
52
57
  case 'install':
53
- install(tmsConfig, modules, env);
58
+ install(tmsConfig, newModules, env);
54
59
  return;
55
60
  case 'build':
56
- build(tmsConfig, modules, env);
61
+ build(tmsConfig, newModules, env);
57
62
  return;
58
63
  default:
59
64
  return;
@@ -3,9 +3,9 @@ const fs = require('fs');
3
3
  const io = require('../../../utils/io');
4
4
  const { resolve, createTask } = require('../../../utils/widgets');
5
5
  const { buildOutputAppJson } = require('../../../utils/buildAppJson');
6
- const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG, DEFAULT_MODULE_DIR } = require('../../../config/constant');
6
+ const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG } = require('../../../config/constant');
7
7
  const { cloneModules } = require('../../../utils/cloneModules');
8
- const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
8
+ const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../../utils/tkitUtils');
9
9
  const { fail } = require('../../../utils/log');
10
10
  const install = require('../install');
11
11
 
@@ -17,17 +17,17 @@ const install = require('../install');
17
17
  * @returns
18
18
  */
19
19
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
20
- const outputDir = resolve(tmsConfig.gulp.outputDir);
20
+ const outputDir = resolve(tmsConfig.outputDir);
21
21
  io.ensureDirExist(outputDir);
22
22
  defaultFiles.forEach((item) => {
23
23
  if (fs.existsSync(resolve(item))) {
24
- shelljs.cp('-rf', resolve(item), resolve(tmsConfig.gulp.outputDir, item));
24
+ shelljs.cp('-rf', resolve(item), resolve(tmsConfig.outputDir, item));
25
25
  }
26
26
  });
27
27
 
28
28
  // 拷贝模块的package.json到编译输出目录
29
29
  targetModules.forEach((item) => {
30
- const outputModuleDir = resolve(`${tmsConfig.gulp.outputDir}/${item.root}`);
30
+ const outputModuleDir = resolve(`${tmsConfig.outputDir}/${item.root}`);
31
31
  if (!fs.existsSync(resolve(item.path))) {
32
32
  fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
33
33
  process.exit(1);
@@ -38,17 +38,18 @@ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
38
38
  });
39
39
  };
40
40
 
41
- async function task(tmsConfig, targetModules) {
41
+ async function task(tmsConfig, targetModules, isDev) {
42
42
  // 下载和移动代码
43
43
  await createTask(
44
44
  cloneModules,
45
45
  '开始下载模块代码完成',
46
46
  '下载模块代码码完成',
47
- )(MODULE_CODE_DIR, resolve('./'), targetModules);
47
+ )(MODULE_CODE_DIR, resolve('./'), targetModules, isDev);
48
48
 
49
49
  // tms.config.js的modules 合并 module.config.json的配置项
50
- const newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName, DEFAULT_MODULE_DIR);
51
- console.log('当前init的有效模块', newModules.map(item => item.name));
50
+ let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName);
51
+ // A分包依赖了B分包的代码, merge B分包进行编译;
52
+ newModules = subModulesMergeDepModules(tmsConfig, newModules);
52
53
 
53
54
  // 拷贝相关配置文件到输出目录
54
55
  await createTask(
@@ -65,16 +66,22 @@ async function task(tmsConfig, targetModules) {
65
66
  buildOutputAppJson,
66
67
  '开始生成编译后的app.json',
67
68
  '生成编译后的app.json完成',
68
- )(tmsConfig, newModules);
69
+ )(tmsConfig, newModules, isDev);
69
70
 
70
71
  return newModules;
71
72
  }
72
- async function bootstrap(tmsConfig, targetModules) {
73
- const newModules = await task(tmsConfig, targetModules);
73
+ async function init(tmsConfig, targetModules, isDev) {
74
+ try {
75
+ const newModules = await task(tmsConfig, targetModules, isDev);
74
76
 
75
- return {
76
- targetModules: newModules,
77
- };
77
+ return {
78
+ targetModules: newModules,
79
+ };
80
+ } catch (error) {
81
+ const errMsg = typeof error === 'object' ? error.message : error;
82
+ fail(`init流程出现错误${errMsg}`);
83
+ process.exit(1);
84
+ }
78
85
  }
79
86
 
80
- module.exports = bootstrap;
87
+ module.exports = init;
@@ -1,17 +1,15 @@
1
1
  const { createTask, resolve } = require('../../../utils/widgets');
2
2
  const { buildMpNpm } = require('../../../utils/mpCiUtils');
3
- const { CACHE_DIR, DEFAULT_MODULE_DIR } = require('../../../config/constant');
3
+ const { CACHE_DIR } = require('../../../config/constant');
4
4
  const { cloudNpmInstall, mpNpmInstallAll } = require('../../../utils/npmUtils');
5
- const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
6
5
 
7
- async function install(tmsConfig, modules, isCloud = true) {
8
- const newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName, DEFAULT_MODULE_DIR);
6
+ async function install(tmsConfig, modules, isCloud = false) {
9
7
  // 小程序npm install
10
8
  await createTask(
11
9
  mpNpmInstallAll,
12
10
  '小程序 开始npm install',
13
11
  '小程序npm install 完成',
14
- )(newModules, resolve(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`);
12
+ )(modules, resolve(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
15
13
 
16
14
  // 构建miniprograme_npm
17
15
  await createTask(