@tmsfe/tmskit 0.0.10 → 0.0.13

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/main.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
4
4
  "description": "tmskit",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {
@@ -43,9 +43,6 @@
43
43
  "fs-extra": "^10.0.1",
44
44
  "glob-ignore": "^1.0.2",
45
45
  "gulp": "^4.0.2",
46
- "gulp-cache": "^1.1.3",
47
- "gulp-postcss": "^9.0.1",
48
- "gulp-px-to-rpx": "^1.0.7",
49
46
  "gulp-watch": "^5.0.1",
50
47
  "htmlparser2": "^7.2.0",
51
48
  "inquirer": "^7.3.3",
@@ -53,6 +50,7 @@
53
50
  "lodash": "^4.17.21",
54
51
  "metalsmith": "^2.3.0",
55
52
  "miniprogram-ci": "1.4.13",
53
+ "moment": "^2.29.1",
56
54
  "object-assign": "^4.0.1",
57
55
  "ora": "^5.1.0",
58
56
  "plugin-error": "^1.0.0",
@@ -1,6 +1,5 @@
1
- const { src, dest, lastRun } = require('gulp');
2
- const px2rpx = require('gulp-px-to-rpx');
3
- const watch = require('gulp-watch');
1
+ const { src, dest } = require('gulp');
2
+ // const px2rpx = require('gulp-px-to-rpx');
4
3
  // const cache = require('gulp-cache');
5
4
  // const image = require('gulp-image');
6
5
  // const replaceEnv = require('./plugins/replaceEnv');
@@ -11,7 +10,7 @@ const { mpWxmlDep } = require('./plugins/mpWxmlDep');
11
10
  // const base64 = require('./plugins/postcss-font-base64');
12
11
  const { fail } = require('../utils/log');
13
12
 
14
- const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
13
+ // const since = task => file => (lastRun(task) > file.stat.ctime ? lastRun(task) : 0);
15
14
  module.exports = function (
16
15
  tmsConfig,
17
16
  {
@@ -19,72 +18,133 @@ module.exports = function (
19
18
  destPath,
20
19
  srcOption,
21
20
  module,
22
- watchOption = { events: ['change', 'add', 'unlink'] },
23
21
  isWatch,
24
22
  },
25
23
  ) {
24
+ const compileTasksMap = new Map();
26
25
  Object.keys(glob).forEach((globKey) => {
27
26
  const globValue = glob[globKey];
28
- const task = () => src(globValue, { ...srcOption, since: since(task) });
29
- let srcPipe = task();
30
-
31
- if (isWatch) {
32
- srcPipe = srcPipe.pipe(watch(globValue, watchOption));
33
- }
34
27
 
35
28
  switch (globKey) {
36
29
  case 'js':
37
- srcPipe
38
- // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
39
- .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch))
40
- .pipe(dest(destPath))
41
- .on('error', (err) => {
42
- fail(`js编译报错${err}`);
43
- });
30
+ compileTasksMap.set(
31
+ globValue,
32
+ {
33
+ module,
34
+ taskFn: () => {
35
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
36
+ // const srcPipe = srcTask();
37
+ const srcPipe = src(globValue, { ...srcOption });
38
+ return srcPipe
39
+ // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
40
+ .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch))
41
+ .pipe(dest(destPath))
42
+ .on('error', (err) => {
43
+ fail(`js编译报错${err}`);
44
+ });
45
+ },
46
+ },
47
+ );
44
48
  break;
45
49
  case 'wxss':
46
- srcPipe
47
- .pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch))
48
- .on('error', (err) => {
49
- fail(`mpCommonDep编译报错${err}`);
50
- })
51
- // .pipe(postcss([base64()]))
52
- // .on('error', (err) => {
53
- // fail(`postcss编译报错${err}`);
54
- // })
55
- .pipe(px2rpx({
56
- designWidth: 375, // 设计稿宽度,默认为750
57
- precision: 2, // 小数最大精度,默认为6
58
- }))
59
- .pipe(dest(destPath));
50
+ compileTasksMap.set(
51
+ globValue,
52
+ {
53
+ module,
54
+ taskFn: () => {
55
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
56
+ // const srcPipe = srcTask();
57
+ const srcPipe = src(globValue, { ...srcOption });
58
+ return srcPipe
59
+ .pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch))
60
+ .on('error', (err) => {
61
+ fail(`mpCommonDep编译报错${err}`);
62
+ })
63
+ // .pipe(postcss([base64()]))
64
+ // .on('error', (err) => {
65
+ // fail(`postcss编译报错${err}`);
66
+ // })
67
+ // .pipe(px2rpx({
68
+ // designWidth: 375, // 设计稿宽度,默认为750
69
+ // precision: 2, // 小数最大精度,默认为6
70
+ // }))
71
+ .pipe(dest(destPath));
72
+ },
73
+ },
74
+ );
60
75
  break;
61
76
  case 'json':
62
- srcPipe
63
- .pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch))
64
- .on('error', (err) => {
65
- fail(`mpJsonDep编译报错${err}`);
66
- })
67
- .pipe(dest(destPath));
77
+ compileTasksMap.set(
78
+ globValue,
79
+ {
80
+ module,
81
+ taskFn: () => {
82
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
83
+ // const srcPipe = srcTask();
84
+ const srcPipe = src(globValue, { ...srcOption });
85
+ return srcPipe
86
+ .pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch))
87
+ .on('error', (err) => {
88
+ fail(`mpJsonDep编译报错${err}`);
89
+ })
90
+ .pipe(dest(destPath));
91
+ },
92
+ },
93
+ );
68
94
  break;
69
95
  case 'wxml':
70
- srcPipe
71
- .pipe(mpWxmlDep(tmsConfig, module, isWatch))
72
- .pipe(dest(destPath));
96
+ compileTasksMap.set(
97
+ globValue,
98
+ {
99
+ module,
100
+ taskFn: () => {
101
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
102
+ // const srcPipe = srcTask();
103
+ const srcPipe = src(globValue, { ...srcOption });
104
+ return srcPipe
105
+ .pipe(mpWxmlDep(tmsConfig, module, isWatch))
106
+ .pipe(dest(destPath));
107
+ },
108
+ },
109
+ );
73
110
  break;
74
111
  case 'image':
75
- srcPipe
76
- // .pipe(cache(image()))
77
- // .on('error', (err) => {
78
- // fail(`image编译报错${err}`);
79
- // })
80
- .pipe(dest(destPath));
112
+ compileTasksMap.set(
113
+ globValue,
114
+ {
115
+ module,
116
+ taskFn: () => {
117
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
118
+ // const srcPipe = srcTask();
119
+ const srcPipe = src(globValue, { ...srcOption });
120
+ return srcPipe
121
+ // .pipe(cache(image()))
122
+ // .on('error', (err) => {
123
+ // fail(`image编译报错${err}`);
124
+ // })
125
+ .pipe(dest(destPath));
126
+ },
127
+ },
128
+ );
81
129
  break;
82
130
  case 'other':
83
- srcPipe
84
- .pipe(dest(destPath));
131
+ compileTasksMap.set(
132
+ globValue,
133
+ {
134
+ module,
135
+ taskFn: () => {
136
+ // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
137
+ // const srcPipe = srcTask();
138
+ const srcPipe = src(globValue, { ...srcOption });
139
+ return srcPipe
140
+ .pipe(dest(destPath));
141
+ },
142
+ },
143
+ );
85
144
  break;
86
145
  default:
87
146
  break;
88
147
  }
89
148
  });
149
+ return compileTasksMap;
90
150
  };
@@ -1,11 +1,15 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
- const watch = require('gulp-watch');
4
- const { resolve } = require('../utils/widgets');
3
+ const ora = require('ora');
4
+ const { parallel, series } = require('gulp');
5
+ const { resolve, mergeMap } = require('../utils/widgets');
5
6
  const { buildOutputAppJson } = require('../core/buildAppJson');
6
7
  const { DEFAULT_COPY_CONFIG } = require('../config/constant');
7
8
  const compile = require('./compile');
9
+ const watch = require('./watch');
10
+ const { info } = require('../utils/log');
8
11
 
12
+ const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
9
13
  function excludeGlob(glob) {
10
14
  const otherArr = new Set();
11
15
  otherArr.add('!**/*.{ttf,otf,woff,eot}');
@@ -31,19 +35,21 @@ function adaptPath(pathDir) {
31
35
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
32
36
  return newPath;
33
37
  }
34
-
35
38
  module.exports = async (tmsConfig, newModules, isWatch = true) => {
39
+ const compileTasksMap = new Map();
36
40
  // 监听app.json
37
41
  if (isWatch) {
38
- watch(resolve('app.json'), { ignoreInitial: false, events: ['add', 'change'] }, () => {
39
- buildOutputAppJson(tmsConfig, newModules, isWatch);
40
- });
42
+ watch(
43
+ [resolve('app.json')],
44
+ { ignoreInitial: false, events: watchEvents },
45
+ () => buildOutputAppJson(tmsConfig, newModules, isWatch),
46
+ );
41
47
  } else {
42
48
  buildOutputAppJson(tmsConfig, newModules, isWatch);
43
49
  }
44
50
 
45
51
  // 监听根目录的文件
46
- compile(tmsConfig, {
52
+ mergeMap(compileTasksMap, compile(tmsConfig, {
47
53
  glob: {
48
54
  json: DEFAULT_COPY_CONFIG.map(item => resolve(item)),
49
55
  // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
@@ -53,7 +59,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
53
59
  destPath: resolve(tmsConfig.outputDir),
54
60
  srcOption: { allowEmpty: true },
55
61
  isWatch,
56
- });
62
+ }));
57
63
 
58
64
  // 监听模块的文件
59
65
  for (let module of newModules) {
@@ -65,22 +71,24 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
65
71
 
66
72
  if (isWatch) {
67
73
  // 监听模块配置文件
68
- watch(`${resolve(module.path)}/**/module.config.json`, { events: ['change'] }, () => {
69
- buildOutputAppJson(tmsConfig, newModules, isWatch);
70
- });
74
+ watch(
75
+ [`${resolve(module.path)}/**/module.config.json`],
76
+ { events: watchEvents },
77
+ () => buildOutputAppJson(tmsConfig, newModules, isWatch),
78
+ );
71
79
  }
72
80
 
73
81
  const excludes = module.exclude.map(key => `!${resolve(key)}`);
74
82
  const modulePath = adaptPath(module.path);
75
83
  const glob = {
76
84
  js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
77
- json: [`${modulePath}/**/*.json`, ...excludes],
85
+ json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
78
86
  wxss: [`${modulePath}/**/*.{less,wxss}`, ...excludes],
79
87
  wxml: [`${modulePath}/**/*.wxml`, ...excludes],
80
88
  image: [`${modulePath}/**/*.{png,jpg,jpeg,gif,svg}`, ...excludes],
81
89
  };
82
90
 
83
- compile(tmsConfig, {
91
+ mergeMap(compileTasksMap, compile(tmsConfig, {
84
92
  glob: {
85
93
  ...glob,
86
94
  other: [`${modulePath}/**/*`, ...excludeGlob(glob)],
@@ -89,7 +97,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
89
97
  module: { from: module.path, to: module.root },
90
98
  srcOption: { allowEmpty: true },
91
99
  isWatch,
92
- });
100
+ }));
93
101
  }
94
102
 
95
103
  // 静态资源目录-拷贝
@@ -114,7 +122,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
114
122
  }
115
123
 
116
124
  const from = fs.lstatSync(item.from).isFile() ? path.dirname(item.from) : item.from;
117
- compile(tmsConfig, {
125
+ mergeMap(compileTasksMap, compile(tmsConfig, {
118
126
  glob,
119
127
  destPath: item.to,
120
128
  module: {
@@ -123,7 +131,35 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
123
131
  },
124
132
  srcOption: { allowEmpty: true },
125
133
  isWatch,
134
+ }));
135
+ }
136
+ }
137
+
138
+ let sTime;
139
+ let eTime;
140
+ const spinner = ora();
141
+ function end(cb) {
142
+ if (isWatch) {
143
+ compileTasksMap.forEach(({ taskFn, module }, globValue) => {
144
+ watch(globValue, { ignoreInitial: true, events: watchEvents }, taskFn, module);
126
145
  });
127
146
  }
147
+ eTime = new Date().getTime() - sTime;
148
+ spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
149
+ spinner.stop();
150
+ cb();
151
+ }
152
+
153
+ function start(cb) {
154
+ info('启动编译...');
155
+ spinner.start();
156
+ sTime = new Date().getTime();
157
+ cb();
128
158
  }
159
+
160
+ const compileTasks = [];
161
+ compileTasksMap.forEach(({ taskFn }) => {
162
+ compileTasks.push(taskFn);
163
+ });
164
+ series(start, parallel(...compileTasks), end)();
129
165
  };
@@ -0,0 +1,29 @@
1
+ const watch = require('gulp-watch');
2
+ const path = require('path');
3
+ const shellJs = require('shelljs');
4
+ const { info } = require('../utils/log');
5
+ const { resolve } = require('../utils/widgets');
6
+ const { global } = require('../utils/global');
7
+
8
+ module.exports = function (glob, watchOptions, callback, module) {
9
+ watch(glob, {
10
+ readDelay: 100,
11
+ ...watchOptions,
12
+ }, (vinyl) => {
13
+ const file = vinyl.history[0];
14
+ const fileDirArr = file.replace(/\\/g, '/').split('/');
15
+ const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
16
+
17
+ if (vinyl.event === 'unlink' || vinyl.event === 'unlinkDir') {
18
+ const tmsConfig = global.getData('tmsConfig');
19
+ const anaFileRelativeModule = path.relative(resolve(module.from), file);
20
+ const anaFileDestFile = resolve(tmsConfig.outputDir, module.to, anaFileRelativeModule);
21
+ info(`删除${fileName}`);
22
+ shellJs.rm('-rf', anaFileDestFile);
23
+ return;
24
+ }
25
+
26
+ info(`更新${fileName}`);
27
+ return callback(vinyl);
28
+ });
29
+ };
@@ -21,7 +21,9 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
21
21
  const tmsPrivateCf = global.getData('tmsPrivateCf');
22
22
 
23
23
  let gitUrl = httpRepoUrl;
24
- const { username = '', pass = '' } = tmsPrivateCf?.gitAccout?.[moduleName] || {};
24
+ const { username = '', pass = '' } = tmsPrivateCf?.gitAccout?.[moduleName]
25
+ || tmsPrivateCf?.gitAccount?.[moduleName]
26
+ || {};
25
27
 
26
28
  const urlPrefixReg = /http(s)?:\/\//;
27
29
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -74,6 +76,7 @@ function md5ByGitUrlBranch(gitUrl, branch) {
74
76
  * @returns { array } modules 描述模块的列表
75
77
  */
76
78
  async function cloneModules(sourceDir, targetDir, modules) {
79
+ const cwd = process.cwd();
77
80
  // 收集下载模块代码的任务
78
81
  const downloadTasksMap = collectDownLoadTasksMap(sourceDir, targetDir, modules);
79
82
 
@@ -94,6 +97,7 @@ async function cloneModules(sourceDir, targetDir, modules) {
94
97
  });
95
98
 
96
99
  await Promise.all(arrPromises);
100
+ shelljs.cd(cwd);
97
101
  }
98
102
 
99
103
  /**
@@ -154,12 +158,12 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
154
158
  let promiseTask;
155
159
  if (fs.existsSync(sourcePath) && fs.existsSync(`${sourcePath}/.git`)) {
156
160
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
157
- info(`git pull仓库:${httpRepoUrl}`);
161
+ info(`git pull:${httpRepoUrl}`);
158
162
  return pullRepoForGit(sourcePath, branch);
159
163
  };
160
164
  } else {
161
165
  promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
162
- info(`git clone仓库: ${httpRepoUrl}`);
166
+ info(`git clone: ${httpRepoUrl}`);
163
167
  return downloadRepoForGit(gitUrl, sourcePath, branch);
164
168
  };
165
169
  }
@@ -1,21 +1,17 @@
1
1
  const fs = require('fs');
2
2
  const { resolve } = require('../utils/widgets');
3
- const { MODULE_CONFIG_FILENAME, MODULE_CODE_DIR } = require('../config/constant');
3
+ const { MODULE_CODE_DIR } = require('../config/constant');
4
4
  const { checkRemoteModGitUrlBranch } = require('./cloneModules');
5
5
  const { checkDependencies } = require('./checkDependencies');
6
6
  const { fail } = require('../utils/log');
7
7
 
8
- function checkModule(targetModules, contextDir) {
8
+ function checkModule(targetModules) {
9
9
  // 判断\源码\dist\是否存在用户指定的模块
10
10
  for (const item of targetModules) {
11
11
  // 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
12
12
  if (!item.root) {
13
13
  return true;
14
14
  }
15
- // 判断dist目录是否有该模块
16
- if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
17
- return true;
18
- }
19
15
 
20
16
  // 判断第三方远程模块git地址与branch是否有更新
21
17
  if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
package/src/core/npm.js CHANGED
@@ -10,7 +10,6 @@ const glob = require('glob-ignore');
10
10
  const log = require('../utils/log');
11
11
  const { npmInstall } = require('../utils/widgets');
12
12
  const { handleError } = require('./handleError');
13
- const { info } = require('console');
14
13
 
15
14
  const shellJsOption = { async: false, silent: true };
16
15
  const dirPath = process.cwd(); // 项目根目录
@@ -52,8 +51,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
52
51
  ...shellJsOption,
53
52
  cwd: packageJsonDir,
54
53
  };
55
- shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', newShellJsOption);
56
- shell.exec('rm -rf ./node_modules.tar.gz', newShellJsOption);
54
+ shell.exec('tar -xvf ./node_modules.tar.gz -C ./', newShellJsOption);
55
+ shell.rm('-rf', './node_modules');
57
56
  },
58
57
  };
59
58
 
@@ -70,14 +69,14 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
70
69
  promiseTask = (packageJsonPath, cacheNMPath, shell) => {
71
70
  fsExtra.emptydirSync(cacheNMPath);
72
71
  shell.cp('-f', packageJsonPath, cacheNMPath);
73
- info(`npm install: ${packageJsonPath}`);
72
+ log.info(`npm install: ${packageJsonPath}`);
74
73
  return npmInstall(cacheNMPath).then(() => {
75
74
  const newShellJsOption = {
76
75
  ...shellJsOption,
77
76
  cwd: cacheNMPath,
78
77
  };
79
- shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
80
- shell.exec('rm -rf ./node_modules', newShellJsOption);
78
+ shell.exec('tar -cvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
79
+ shell.rm('-rf', './node_modules');
81
80
  });
82
81
  };
83
82
  }
@@ -99,6 +98,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
99
98
 
100
99
  // 遍历安装指定目录下所有项目的npm依赖
101
100
  const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
101
+ const cwd = process.cwd();
102
102
  const packageJsonFiles = await findAllPackageJson(modules, contextDir);
103
103
 
104
104
  // 收集npm install的任务
@@ -121,6 +121,7 @@ const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
121
121
  });
122
122
 
123
123
  await Promise.all(arrPromises);
124
+ shell.cd(cwd);
124
125
  };
125
126
 
126
127
  /**
@@ -11,7 +11,12 @@ const symLink = (tmsConfig) => {
11
11
  try {
12
12
  if (tmsConfig.cloudModules) {
13
13
  tmsConfig.cloudModules.forEach((item) => {
14
- fs.symlinkSync(resolve(item.path), resolve(DEFAULT_CLOUD_MODULE_DIR, item.name));
14
+ const path = resolve(DEFAULT_CLOUD_MODULE_DIR, item.name);
15
+ fs.access(path, fs.constants.F_OK, (res) => {
16
+ if (res) {
17
+ fs.symlinkSync(resolve(item.path), path);
18
+ }
19
+ });
15
20
  });
16
21
  }
17
22
  } catch (e) {
@@ -3,7 +3,7 @@
3
3
  */
4
4
  const loadash = require('lodash');
5
5
  const fs = require('fs');
6
- const { TMS_NAME, TMS_CONFIG_FILENAME, MODULE_CONFIG_FILENAME, TMS_PRIVATE_FILENAME } = require('../config/constant');
6
+ const { TMS_CONFIG_FILENAME, MODULE_CONFIG_FILENAME, TMS_PRIVATE_FILENAME } = require('../config/constant');
7
7
  const { resolve, isObject, isArray } = require('../utils/widgets');
8
8
  const defaultTmsConfig = require('../config/defaultTmsConfig');
9
9
  const { fail } = require('../utils/log');
@@ -77,15 +77,18 @@ const readTmsPrivateCf = function () {
77
77
  * @param { array } modules
78
78
  * @returns
79
79
  */
80
- const checkModules = function (tmsConfig, modules) {
80
+ const checkModules = function (tmsConfig, modules, isQuit = false) {
81
81
  const targetModules = [];
82
82
  modules.forEach((moduleName) => {
83
83
  const module = tmsConfig.modules.find(module => module.name === moduleName);
84
84
  module && targetModules.push(module);
85
85
  });
86
+
87
+
86
88
  if (targetModules.length === 0) {
87
- fail(`你启动的模块无效,尝试 ${TMS_NAME} -m moduleName`);
88
- process.exit(1);
89
+ fail(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
90
+ >name字段与module.config.json的name字段是否一致`);
91
+ isQuit && process.exit(1);
89
92
  }
90
93
  return targetModules;
91
94
  };
@@ -175,7 +178,7 @@ const tmsModulesMergeLocalModuleCfg = (modules, appName) => {
175
178
  }
176
179
  });
177
180
  if (!findModule) {
178
- fail(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
181
+ fail(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
179
182
  process.exit(1);
180
183
  }
181
184
  } catch (e) {
@@ -213,10 +216,12 @@ const subModulesMergeDepModules = (tmsConfig, modules) => {
213
216
  // 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
214
217
  // 否则递归处理,根据name找到相关配置加到modules里
215
218
  if (moduleNames.indexOf(item) === -1) {
216
- isOver = false;
217
219
  const tmpModules = checkModules(tmsConfig, [...new Set([item])]);
218
- mergeModules = [...mergeModules, ...tmpModules];
219
- mergeModules = tmsModulesMergeLocalModuleCfg(mergeModules, tmsConfig.appName);
220
+ if (tmpModules.length > 0) {
221
+ isOver = false;
222
+ mergeModules = [...mergeModules, ...tmpModules];
223
+ mergeModules = tmsModulesMergeLocalModuleCfg(mergeModules, tmsConfig.appName);
224
+ }
220
225
  }
221
226
  });
222
227
  });
package/src/index.js CHANGED
@@ -39,9 +39,7 @@ function registerCommand(program, commands) {
39
39
  registerCommand(program, commands);
40
40
 
41
41
  program.on('--help', () => {
42
- info();
43
42
  info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
44
- info();
45
43
  });
46
44
 
47
45
  // 捕获未注册的命令
@@ -49,8 +47,7 @@ program
49
47
  .arguments('<command>')
50
48
  .action((cmd) => {
51
49
  program.outputHelp();
52
- info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
53
- info();
50
+ info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
54
51
  suggestCommands(cmd);
55
52
  process.exitCode = 1;
56
53
  });
@@ -55,12 +55,16 @@ async function run(commandName, cmd) {
55
55
  tmsConfig.modules,
56
56
  );
57
57
 
58
- const modules = checkModules(tmsConfig, [
59
- ...new Set([
60
- ...tmsConfig.mainPackages,
61
- ...specificModules,
62
- ]),
63
- ]);
58
+ const modules = checkModules(
59
+ tmsConfig,
60
+ [
61
+ ...new Set([
62
+ ...tmsConfig.mainPackages,
63
+ ...specificModules,
64
+ ]),
65
+ ],
66
+ true,
67
+ );
64
68
 
65
69
  // tms.config.js的modules 合并 module.config.json的配置项
66
70
  let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName);
@@ -72,6 +76,7 @@ async function run(commandName, cmd) {
72
76
  env,
73
77
  cmd,
74
78
  tmsPrivateCf,
79
+ tmsConfig,
75
80
  });
76
81
 
77
82
  switch (commandName) {
package/src/utils/io.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { info } = require('../utils/log');
4
+ const { relativeCwdPath } = require('../utils/widgets');
4
5
  /**
5
6
  * 判断目录是否为空
6
7
  * @param {string} dirname 目录名
@@ -44,11 +45,11 @@ function diffContentCopyFile(originFile, destFile) {
44
45
  const depDestContent = fs.readFileSync(destFile, 'utf8');
45
46
  const depOriginContent = fs.readFileSync(originFile, 'utf8');
46
47
  if (depDestContent !== depOriginContent) {
47
- info(`拷贝${originFile}内容到${destFile}`);
48
+ info(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
48
49
  copyFile(originFile, destFile);
49
50
  }
50
51
  } else {
51
- info(`拷贝${originFile}内容到${destFile}`);
52
+ info(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
52
53
  copyFile(originFile, destFile);
53
54
  }
54
55
  }