@tmsfe/tmskit 0.0.13 → 0.0.15-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.13",
3
+ "version": "0.0.15-beta.1",
4
4
  "description": "tmskit",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {
@@ -14,7 +14,11 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "dev": "rollup -wc --environment TARGET:tmskit",
17
- "build": "rollup -c --environment TARGET:tmskit"
17
+ "build": "rollup -c --environment TARGET:tmskit",
18
+ "pub:patch": "sh build/publish.sh patch",
19
+ "pub:minor": "sh build/publish.sh minor",
20
+ "pub:major": "sh build/publish.sh major",
21
+ "postinstall": "cd node_modules/gulp-watch && npm install chokidar@3.5.3"
18
22
  },
19
23
  "author": "tms·web",
20
24
  "license": "ISC",
@@ -53,6 +57,7 @@
53
57
  "moment": "^2.29.1",
54
58
  "object-assign": "^4.0.1",
55
59
  "ora": "^5.1.0",
60
+ "patch-package": "^6.4.7",
56
61
  "plugin-error": "^1.0.0",
57
62
  "postcss": "^8.4.6",
58
63
  "precinct": "^8.3.1",
@@ -18,7 +18,7 @@ module.exports = function (
18
18
  destPath,
19
19
  srcOption,
20
20
  module,
21
- isWatch,
21
+ isDev,
22
22
  },
23
23
  ) {
24
24
  const compileTasksMap = new Map();
@@ -31,14 +31,17 @@ module.exports = function (
31
31
  globValue,
32
32
  {
33
33
  module,
34
- taskFn: () => {
35
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
36
- // const srcPipe = srcTask();
37
- const srcPipe = src(globValue, { ...srcOption });
34
+ taskFn: (sourceFile, targetPath) => {
35
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
36
+ const newDestPath = targetPath ? targetPath : destPath;
37
+ const srcPipe = src(newGlobValue, { ...srcOption });
38
38
  return srcPipe
39
39
  // .pipe(replaceEnv(/process\.env(\.(\w*))?/g, tmsConfig.envData))
40
- .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isWatch))
41
- .pipe(dest(destPath))
40
+ .pipe(mpCommonDep(tmsConfig, module, ['.js', '.ts', '.wxs', '.json'], isDev))
41
+ .on('error', (err) => {
42
+ fail(`mpCommonDep编译报错${err}`);
43
+ })
44
+ .pipe(dest(newDestPath, { overwrite: true }))
42
45
  .on('error', (err) => {
43
46
  fail(`js编译报错${err}`);
44
47
  });
@@ -51,12 +54,12 @@ module.exports = function (
51
54
  globValue,
52
55
  {
53
56
  module,
54
- taskFn: () => {
55
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
56
- // const srcPipe = srcTask();
57
- const srcPipe = src(globValue, { ...srcOption });
57
+ taskFn: (sourceFile, targetPath) => {
58
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
59
+ const newDestPath = targetPath ? targetPath : destPath;
60
+ const srcPipe = src(newGlobValue, { ...srcOption });
58
61
  return srcPipe
59
- .pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isWatch))
62
+ .pipe(mpCommonDep(tmsConfig, module, ['.wxss', '.less'], isDev))
60
63
  .on('error', (err) => {
61
64
  fail(`mpCommonDep编译报错${err}`);
62
65
  })
@@ -68,7 +71,10 @@ module.exports = function (
68
71
  // designWidth: 375, // 设计稿宽度,默认为750
69
72
  // precision: 2, // 小数最大精度,默认为6
70
73
  // }))
71
- .pipe(dest(destPath));
74
+ .pipe(dest(newDestPath))
75
+ .on('error', (err) => {
76
+ fail(`wxss编译报错${err}`);
77
+ });
72
78
  },
73
79
  },
74
80
  );
@@ -78,16 +84,19 @@ module.exports = function (
78
84
  globValue,
79
85
  {
80
86
  module,
81
- taskFn: () => {
82
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
83
- // const srcPipe = srcTask();
84
- const srcPipe = src(globValue, { ...srcOption });
87
+ taskFn: (sourceFile, targetPath) => {
88
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
89
+ const newDestPath = targetPath ? targetPath : destPath;
90
+ const srcPipe = src(newGlobValue, { ...srcOption });
85
91
  return srcPipe
86
- .pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isWatch))
92
+ .pipe(mpJsonDep(tmsConfig, module, ['.json'], ['.wxml', '.json', '.js', '.ts', '.wxss', '.less'], isDev))
87
93
  .on('error', (err) => {
88
94
  fail(`mpJsonDep编译报错${err}`);
89
95
  })
90
- .pipe(dest(destPath));
96
+ .pipe(dest(newDestPath))
97
+ .on('error', (err) => {
98
+ fail(`json编译报错${err}`);
99
+ });
91
100
  },
92
101
  },
93
102
  );
@@ -97,13 +106,19 @@ module.exports = function (
97
106
  globValue,
98
107
  {
99
108
  module,
100
- taskFn: () => {
101
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
102
- // const srcPipe = srcTask();
103
- const srcPipe = src(globValue, { ...srcOption });
109
+ taskFn: (sourceFile, targetPath) => {
110
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
111
+ const newDestPath = targetPath ? targetPath : destPath;
112
+ const srcPipe = src(newGlobValue, { ...srcOption });
104
113
  return srcPipe
105
- .pipe(mpWxmlDep(tmsConfig, module, isWatch))
106
- .pipe(dest(destPath));
114
+ .pipe(mpWxmlDep(tmsConfig, module, isDev))
115
+ .on('error', (err) => {
116
+ fail(`mpWxmlDep编译报错${err}`);
117
+ })
118
+ .pipe(dest(newDestPath))
119
+ .on('error', (err) => {
120
+ fail(`wxml编译报错${err}`);
121
+ });
107
122
  },
108
123
  },
109
124
  );
@@ -113,16 +128,19 @@ module.exports = function (
113
128
  globValue,
114
129
  {
115
130
  module,
116
- taskFn: () => {
117
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
118
- // const srcPipe = srcTask();
119
- const srcPipe = src(globValue, { ...srcOption });
131
+ taskFn: (sourceFile, targetPath) => {
132
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
133
+ const newDestPath = targetPath ? targetPath : destPath;
134
+ const srcPipe = src(newGlobValue, { ...srcOption });
120
135
  return srcPipe
121
136
  // .pipe(cache(image()))
122
137
  // .on('error', (err) => {
123
138
  // fail(`image编译报错${err}`);
124
139
  // })
125
- .pipe(dest(destPath));
140
+ .pipe(dest(newDestPath))
141
+ .on('error', (err) => {
142
+ fail(`image编译报错${err}`);
143
+ });
126
144
  },
127
145
  },
128
146
  );
@@ -132,12 +150,15 @@ module.exports = function (
132
150
  globValue,
133
151
  {
134
152
  module,
135
- taskFn: () => {
136
- // const srcTask = () => src(globValue, { ...srcOption, since: since(srcTask) });
137
- // const srcPipe = srcTask();
138
- const srcPipe = src(globValue, { ...srcOption });
153
+ taskFn: (sourceFile, targetPath) => {
154
+ const newGlobValue = Array.isArray(sourceFile) ? sourceFile : globValue;
155
+ const newDestPath = targetPath ? targetPath : destPath;
156
+ const srcPipe = src(newGlobValue, { ...srcOption });
139
157
  return srcPipe
140
- .pipe(dest(destPath));
158
+ .pipe(dest(newDestPath))
159
+ .on('error', (err) => {
160
+ fail(`编译报错${err}`);
161
+ });
141
162
  },
142
163
  },
143
164
  );
@@ -35,17 +35,18 @@ function adaptPath(pathDir) {
35
35
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
36
36
  return newPath;
37
37
  }
38
- module.exports = async (tmsConfig, newModules, isWatch = true) => {
38
+ module.exports = async (tmsConfig, newModules, isDev = true) => {
39
39
  const compileTasksMap = new Map();
40
40
  // 监听app.json
41
- if (isWatch) {
41
+ if (isDev) {
42
42
  watch(
43
43
  [resolve('app.json')],
44
44
  { ignoreInitial: false, events: watchEvents },
45
- () => buildOutputAppJson(tmsConfig, newModules, isWatch),
45
+ () => buildOutputAppJson(tmsConfig, newModules, isDev),
46
+ { from: resolve(), to: resolve(tmsConfig.outputDir) },
46
47
  );
47
48
  } else {
48
- buildOutputAppJson(tmsConfig, newModules, isWatch);
49
+ buildOutputAppJson(tmsConfig, newModules, isDev);
49
50
  }
50
51
 
51
52
  // 监听根目录的文件
@@ -55,10 +56,10 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
55
56
  // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
56
57
  // js: ['app.js', 'app.ts'].map(item => resolve(item)),
57
58
  },
58
- module: { from: '', to: '' },
59
+ module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
59
60
  destPath: resolve(tmsConfig.outputDir),
60
61
  srcOption: { allowEmpty: true },
61
- isWatch,
62
+ isDev,
62
63
  }));
63
64
 
64
65
  // 监听模块的文件
@@ -68,18 +69,19 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
68
69
  ...{ exclude: [] },
69
70
  ...module,
70
71
  };
72
+ const modulePath = adaptPath(module.path);
71
73
 
72
- if (isWatch) {
74
+ if (isDev) {
73
75
  // 监听模块配置文件
74
76
  watch(
75
- [`${resolve(module.path)}/**/module.config.json`],
77
+ [`${modulePath}/**/module.config.json`],
76
78
  { events: watchEvents },
77
- () => buildOutputAppJson(tmsConfig, newModules, isWatch),
79
+ () => buildOutputAppJson(tmsConfig, newModules, isDev),
80
+ { from: modulePath, to: modulePath },
78
81
  );
79
82
  }
80
83
 
81
84
  const excludes = module.exclude.map(key => `!${resolve(key)}`);
82
- const modulePath = adaptPath(module.path);
83
85
  const glob = {
84
86
  js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
85
87
  json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
@@ -96,7 +98,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
96
98
  destPath: resolve(tmsConfig.outputDir, module.root),
97
99
  module: { from: module.path, to: module.root },
98
100
  srcOption: { allowEmpty: true },
99
- isWatch,
101
+ isDev,
100
102
  }));
101
103
  }
102
104
 
@@ -130,7 +132,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
130
132
  to: item.to,
131
133
  },
132
134
  srcOption: { allowEmpty: true },
133
- isWatch,
135
+ isDev,
134
136
  }));
135
137
  }
136
138
  }
@@ -138,25 +140,27 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
138
140
  let sTime;
139
141
  let eTime;
140
142
  const spinner = ora();
143
+ function start(cb) {
144
+ info('启动编译...');
145
+ spinner.start();
146
+ sTime = new Date().getTime();
147
+ cb();
148
+ }
141
149
  function end(cb) {
142
- if (isWatch) {
150
+ if (isDev) {
143
151
  compileTasksMap.forEach(({ taskFn, module }, globValue) => {
144
152
  watch(globValue, { ignoreInitial: true, events: watchEvents }, taskFn, module);
145
153
  });
146
154
  }
147
155
  eTime = new Date().getTime() - sTime;
148
- spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
156
+ if (typeof tmsConfig?.hooks?.afterCompile === 'function') {
157
+ tmsConfig?.hooks?.afterCompile({ isDev, tmsConfig, modules: newModules });
158
+ }
159
+ spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
149
160
  spinner.stop();
150
161
  cb();
151
162
  }
152
163
 
153
- function start(cb) {
154
- info('启动编译...');
155
- spinner.start();
156
- sTime = new Date().getTime();
157
- cb();
158
- }
159
-
160
164
  const compileTasks = [];
161
165
  compileTasksMap.forEach(({ taskFn }) => {
162
166
  compileTasks.push(taskFn);
@@ -1,29 +1,46 @@
1
1
  const watch = require('gulp-watch');
2
2
  const path = require('path');
3
3
  const shellJs = require('shelljs');
4
- const { info } = require('../utils/log');
4
+ const { info, warn } = require('../utils/log');
5
5
  const { resolve } = require('../utils/widgets');
6
6
  const { global } = require('../utils/global');
7
7
 
8
- module.exports = function (glob, watchOptions, callback, module) {
9
- watch(glob, {
10
- readDelay: 100,
8
+ const TIP_MAP = {
9
+ 'package.json': '若依赖有变动,请重新执行tmskit run dev',
10
+ 'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效',
11
+ };
12
+
13
+ const logTip = (fileName, tipMap) => {
14
+ // eslint-disable-next-line
15
+ for (const item in tipMap) {
16
+ if (fileName.indexOf(item) > -1) {
17
+ warn(`${fileName}有更新, ${tipMap[item]}`);
18
+ return;
19
+ }
20
+ }
21
+ info(`${fileName}有更新`);
22
+ };
23
+
24
+ module.exports = function (globValue, watchOptions, callback, module) {
25
+ watch(globValue, {
26
+ // readDelay: 100,
11
27
  ...watchOptions,
12
28
  }, (vinyl) => {
13
- const file = vinyl.history[0];
14
- const fileDirArr = file.replace(/\\/g, '/').split('/');
15
- const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
29
+ const sourceFile = vinyl.history[0];
30
+ const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
31
+ const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
32
+
33
+ const tmsConfig = global.getData('tmsConfig');
34
+ const sourceFileRelativeModule = path.relative(resolve(module.from), sourceFile);
35
+ const targetFile = resolve(tmsConfig.outputDir, module.to, sourceFileRelativeModule);
16
36
 
17
37
  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);
38
+ info(`删除${sourceFileName}`);
39
+ shellJs.rm('-rf', targetFile);
23
40
  return;
24
41
  }
25
42
 
26
- info(`更新${fileName}`);
27
- return callback(vinyl);
43
+ logTip(sourceFileName, TIP_MAP);
44
+ return callback([sourceFile], path.dirname(targetFile));
28
45
  });
29
46
  };
@@ -154,6 +154,9 @@ function buildOutputAppJson(tmsConfig, modules) {
154
154
  updateMainPackages(appJson, tmsConfig.mainPackages);
155
155
 
156
156
  fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
157
+ if (typeof tmsConfig?.hooks?.updateAppJson === 'function') {
158
+ tmsConfig?.hooks?.updateAppJson(appJson);
159
+ }
157
160
 
158
161
  return appJson;
159
162
  } catch (e) {
package/src/core/mpCi.js CHANGED
@@ -14,7 +14,7 @@ const getMpCi = ({ appId, projectPath, type = 'miniProgram', privateKey = 'TODO'
14
14
  privateKey,
15
15
  type,
16
16
  projectPath,
17
- ignores: ['node_modules/**/*', ...ignores],
17
+ ignores: ['node_modules/**/*', 'cloud/**/*', ...ignores],
18
18
  });
19
19
  };
20
20
 
package/src/core/npm.js CHANGED
@@ -51,8 +51,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
51
51
  ...shellJsOption,
52
52
  cwd: packageJsonDir,
53
53
  };
54
+ shell.cd(packageJsonDir);
54
55
  shell.exec('tar -xvf ./node_modules.tar.gz -C ./', newShellJsOption);
55
- shell.rm('-rf', './node_modules');
56
+ shell.rm('-rf', './node_modules.tar.gz');
56
57
  },
57
58
  };
58
59
 
@@ -75,6 +76,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
75
76
  ...shellJsOption,
76
77
  cwd: cacheNMPath,
77
78
  };
79
+ shell.cd(cacheNMPath);
78
80
  shell.exec('tar -cvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
79
81
  shell.rm('-rf', './node_modules');
80
82
  });
@@ -1,7 +1,8 @@
1
1
  const fs = require('fs');
2
2
  const { resolve } = require('../utils/widgets');
3
3
  const { handleError } = require('./handleError');
4
- const { DEFAULT_CLOUD_MODULE_DIR } = require('../config/constant');
4
+ const { ensureDirExist } = require('../utils/io');
5
+ const { warn } = require('../utils/log');
5
6
 
6
7
  /**
7
8
  * 根据相关配置创建软链接
@@ -9,14 +10,19 @@ const { DEFAULT_CLOUD_MODULE_DIR } = require('../config/constant');
9
10
  */
10
11
  const symLink = (tmsConfig) => {
11
12
  try {
13
+ ensureDirExist(resolve(tmsConfig.cloudDir));
12
14
  if (tmsConfig.cloudModules) {
13
15
  tmsConfig.cloudModules.forEach((item) => {
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
- });
16
+ const sourcePath = resolve(item.path);
17
+ const targetPath = resolve(tmsConfig.cloudDir, item.name);
18
+
19
+ if (!fs.existsSync(sourcePath)) {
20
+ warn(`云函数${sourcePath}不存在`);
21
+ return;
22
+ }
23
+ if (!fs.existsSync(targetPath)) {
24
+ fs.symlinkSync(sourcePath, targetPath);
25
+ }
20
26
  });
21
27
  }
22
28
  } catch (e) {
package/src/entry.js CHANGED
@@ -28,7 +28,7 @@ module.exports = [
28
28
  options: [
29
29
  ['-m, --module [moduleName]', '模块名称'],
30
30
  ['-e, --env [env]', '环境变量'],
31
- ['-latest, --latest', '下载最新第三方模块代码、安装最新依赖'],
31
+ ['-noCache, --noCache', '不使用缓存功能'],
32
32
  ],
33
33
  action: (cmd) => {
34
34
  require('./scripts/run/index')('dev', cmd);
@@ -2,10 +2,10 @@ const shelljs = require('shelljs');
2
2
  const compileDev = require('../../../compile/dev');
3
3
  const { resolve } = require('../../../utils/widgets');
4
4
  const init = require('../init/index');
5
- const { isInit } = require('../../../core/isInIt');
6
5
  const { tmsModulesMergeLocalModuleCfg } = require('../../../core/tmsMpconfig');
7
6
  const { info } = require('../../../utils/log');
8
7
  const { global } = require('../../../utils/global');
8
+ const { CACHE_DIR } = require('../../../config/constant');
9
9
 
10
10
 
11
11
  // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
@@ -24,16 +24,20 @@ function delOtherModule(tmsConfig, targetModules) {
24
24
 
25
25
  async function dev(tmsConfig, targetModules, env) {
26
26
  let newModules = targetModules;
27
- const isLatest = global.getData('cmd').latest;
28
-
29
- // 判断是否进行init命令
30
- if (isLatest || isInit(tmsConfig, targetModules, resolve('dist'))) {
31
- // init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
32
- const initData = await init(tmsConfig, newModules);
33
- newModules = initData.targetModules;
27
+ const { noCache } = global.getData('cmd');
28
+ if (noCache) {
29
+ shelljs.rm('-rf', resolve('dist'));
30
+ shelljs.rm('-rf', CACHE_DIR);
34
31
  }
35
32
 
33
+ // 初始化操作
34
+ const initData = await init(tmsConfig, newModules);
35
+ newModules = initData.targetModules;
36
+
36
37
  info('当前dev启动的有效模块', newModules.map(item => item.name).sort());
38
+ if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
39
+ tmsConfig?.hooks?.beforeCompile({ isDev: true, tmsConfig, modules: newModules });
40
+ };
37
41
  delOtherModule(tmsConfig, newModules);
38
42
  compileDev(tmsConfig, newModules, env);
39
43
  }
@@ -3,12 +3,12 @@ const fs = require('fs');
3
3
  const io = require('../../../utils/io');
4
4
  const { resolve, createTask } = require('../../../utils/widgets');
5
5
  const { buildOutputAppJson } = require('../../../core/buildAppJson');
6
- const { symLink } = require('../../../core/symbolicLink');
7
6
  const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG } = require('../../../config/constant');
8
7
  const { cloneModules } = require('../../../core/cloneModules');
9
8
  const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../../core/tmsMpconfig');
10
9
  const { fail, info } = require('../../../utils/log');
11
10
  const install = require('../install');
11
+ const { checkDependencies } = require('../../../core/checkDependencies');
12
12
 
13
13
  /**
14
14
  * 拷贝相关配置文件到编译输出目录
@@ -39,6 +39,25 @@ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
39
39
  });
40
40
  };
41
41
 
42
+ /**
43
+ * 校验相关配置项
44
+ * @param {*} targetModules
45
+ * @returns
46
+ */
47
+ function checkConfig(targetModules) {
48
+ for (const item of targetModules) {
49
+ if (!item.root) {
50
+ throw new Error(`检查${item.name} module.config.json的root字段`);
51
+ }
52
+
53
+ // 判断源码目录是否有该模块
54
+ if (item.path && !fs.existsSync(resolve(item.path))) {
55
+ throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
56
+ }
57
+ }
58
+ return true;
59
+ }
60
+
42
61
  async function task(tmsConfig, targetModules) {
43
62
  // 下载和移动代码
44
63
  await createTask(
@@ -52,6 +71,8 @@ async function task(tmsConfig, targetModules) {
52
71
  // A分包依赖了B分包的代码, merge B分包进行编译;
53
72
  newModules = subModulesMergeDepModules(tmsConfig, newModules);
54
73
 
74
+ checkConfig(newModules);
75
+
55
76
  // 拷贝相关配置文件到输出目录
56
77
  await createTask(
57
78
  cpFilesToOutput,
@@ -60,7 +81,9 @@ async function task(tmsConfig, targetModules) {
60
81
  )(tmsConfig, newModules, DEFAULT_COPY_CONFIG);
61
82
 
62
83
  // install
63
- await install(tmsConfig, newModules, false);
84
+ if (checkDependencies(newModules, resolve('./'), tmsConfig.outputDir)) {
85
+ await install(tmsConfig, newModules);
86
+ }
64
87
 
65
88
  // 动态生成编译后的app.json;
66
89
  await createTask(
@@ -69,12 +92,6 @@ async function task(tmsConfig, targetModules) {
69
92
  '生成编译后的app.json完成',
70
93
  )(tmsConfig, newModules);
71
94
 
72
- await createTask(
73
- symLink,
74
- '开始创建软链接',
75
- '创建软链接完成',
76
- )(tmsConfig);
77
-
78
95
  return newModules;
79
96
  }
80
97
  async function init(tmsConfig, targetModules) {
@@ -86,7 +103,7 @@ async function init(tmsConfig, targetModules) {
86
103
  };
87
104
  } catch (error) {
88
105
  const errMsg = typeof error === 'object' ? error.message : error;
89
- fail(`init流程出现错误${errMsg}`);
106
+ fail(`初始化流程出现错误${errMsg}`);
90
107
  info('详细的错误信息', error);
91
108
  process.exit(1);
92
109
  }
@@ -1,10 +1,10 @@
1
1
  const { createTask, resolve } = require('../../../utils/widgets');
2
2
  const { buildMpNpm } = require('../../../core/mpCi');
3
3
  const { CACHE_DIR } = require('../../../config/constant');
4
- const { cloudNpmInstall, mpNpmInstallAll } = require('../../../core/npm');
4
+ const { mpNpmInstallAll } = require('../../../core/npm');
5
5
  const { global } = require('../../../utils/global');
6
6
 
7
- async function install(tmsConfig, modules, isCloud = false) {
7
+ async function install(tmsConfig, modules) {
8
8
  // 小程序npm install
9
9
  await createTask(
10
10
  mpNpmInstallAll,
@@ -19,13 +19,6 @@ async function install(tmsConfig, modules, isCloud = false) {
19
19
  '开始构建miniprogram_npm',
20
20
  '构建miniprogram_npm 完成',
21
21
  )({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsPrivateCf.privateKey });
22
-
23
- // 安装云函数的
24
- isCloud && createTask(
25
- cloudNpmInstall,
26
- '云函数npm install',
27
- '云函数npm install安装完毕',
28
- )(resolve(tmsConfig.cloudDir));
29
22
  }
30
23
 
31
24
  module.exports = install;
package/src/utils/log.js CHANGED
@@ -14,7 +14,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
14
14
  const fail = (message = '') => {
15
15
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
16
16
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
17
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
17
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
18
18
  };
19
19
 
20
20
  /**
@@ -25,7 +25,7 @@ const fail = (message = '') => {
25
25
  const succeed = (message = '') => {
26
26
  const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
27
27
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
28
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
28
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
29
29
  };
30
30
 
31
31
 
@@ -35,10 +35,10 @@ const succeed = (message = '') => {
35
35
  * @returns {undefined} 无
36
36
  */
37
37
  const warn = (message) => {
38
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk.yellow(message));
38
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk.yellow(message));
39
39
  };
40
40
 
41
- const info = (...args) => console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
41
+ const info = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
42
42
 
43
43
  module.exports = {
44
44
  fail,
@@ -144,13 +144,13 @@ function createTask(task, startText, endText) {
144
144
  return async (...args) => {
145
145
  const start = Date.now();
146
146
 
147
- const spinner = ora(startText);
148
-
147
+ const spinner = ora();
148
+ info(startText);
149
149
  spinner.start();
150
150
 
151
151
  const result = await task(...args);
152
152
 
153
- endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
153
+ endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
154
154
  spinner.stop();
155
155
 
156
156
  return result;