@tmsfe/tmskit 0.0.15 → 0.0.18

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,13 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.15",
3
+ "version": "0.0.18",
4
4
  "description": "tmskit",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {
7
7
  "tmskit": "main.js"
8
8
  },
9
9
  "files": [
10
+ "build",
10
11
  "src",
11
12
  "dist",
12
13
  "main.js",
@@ -38,8 +39,18 @@
38
39
  "rollup-plugin-typescript2": "0.27.0"
39
40
  },
40
41
  "dependencies": {
42
+ "ansi-colors": "1.1.0",
43
+ "anymatch": "^1.3.0",
44
+ "fancy-log": "1.3.2",
45
+ "glob-parent": "^3.0.1",
46
+ "path-is-absolute": "^1.0.1",
47
+ "readable-stream": "^2.2.2",
48
+ "slash": "^1.0.0",
49
+ "vinyl": "^2.1.0",
50
+ "vinyl-file": "^2.0.0",
41
51
  "async": "^3.2.2",
42
52
  "chalk": "^4.1.0",
53
+ "chokidar": "^3.5.3",
43
54
  "commander": "^8.3.0",
44
55
  "copy-webpack-plugin": "^9.1.0",
45
56
  "ejs": "^3.1.5",
@@ -53,7 +64,7 @@
53
64
  "lodash": "^4.17.21",
54
65
  "metalsmith": "^2.3.0",
55
66
  "miniprogram-ci": "1.4.13",
56
- "moment": "^2.29.1",
67
+ "moment": "^2.29.2",
57
68
  "object-assign": "^4.0.1",
58
69
  "ora": "^5.1.0",
59
70
  "plugin-error": "^1.0.0",
@@ -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
  );
@@ -1,15 +1,16 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
  const ora = require('ora');
4
+ const chalk = require('chalk');
4
5
  const { parallel, series } = require('gulp');
5
- const { resolve, mergeMap } = require('../utils/widgets');
6
+ const { resolve, mergeMap, filterField } = require('../utils/widgets');
6
7
  const { buildOutputAppJson } = require('../core/buildAppJson');
7
8
  const { DEFAULT_COPY_CONFIG } = require('../config/constant');
8
9
  const compile = require('./compile');
9
10
  const watch = require('./watch');
10
11
  const { info } = require('../utils/log');
11
12
 
12
- const watchEvents = ['add', 'change', 'unlink', 'unlinkDir'];
13
+ const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
13
14
  function excludeGlob(glob) {
14
15
  const otherArr = new Set();
15
16
  otherArr.add('!**/*.{ttf,otf,woff,eot}');
@@ -35,18 +36,8 @@ function adaptPath(pathDir) {
35
36
  newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
36
37
  return newPath;
37
38
  }
38
- module.exports = async (tmsConfig, newModules, isWatch = true) => {
39
+ module.exports = async (tmsConfig, newModules, isDev = true) => {
39
40
  const compileTasksMap = new Map();
40
- // 监听app.json
41
- if (isWatch) {
42
- watch(
43
- [resolve('app.json')],
44
- { ignoreInitial: false, events: watchEvents },
45
- () => buildOutputAppJson(tmsConfig, newModules, isWatch),
46
- );
47
- } else {
48
- buildOutputAppJson(tmsConfig, newModules, isWatch);
49
- }
50
41
 
51
42
  // 监听根目录的文件
52
43
  mergeMap(compileTasksMap, compile(tmsConfig, {
@@ -55,10 +46,10 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
55
46
  // wxss: ['app.less', 'app.wxss'].map(item => resolve(item)),
56
47
  // js: ['app.js', 'app.ts'].map(item => resolve(item)),
57
48
  },
58
- module: { from: '', to: '' },
49
+ module: { from: resolve(), to: resolve(tmsConfig.outputDir) },
59
50
  destPath: resolve(tmsConfig.outputDir),
60
51
  srcOption: { allowEmpty: true },
61
- isWatch,
52
+ isDev,
62
53
  }));
63
54
 
64
55
  // 监听模块的文件
@@ -68,18 +59,19 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
68
59
  ...{ exclude: [] },
69
60
  ...module,
70
61
  };
62
+ const modulePath = adaptPath(module.path);
71
63
 
72
- if (isWatch) {
64
+ if (isDev) {
73
65
  // 监听模块配置文件
74
66
  watch(
75
- [`${resolve(module.path)}/**/module.config.json`],
67
+ [`${modulePath}/**/module.config.json`],
76
68
  { events: watchEvents },
77
- () => buildOutputAppJson(tmsConfig, newModules, isWatch),
69
+ () => buildOutputAppJson(tmsConfig, newModules, isDev),
70
+ { from: modulePath, to: modulePath },
78
71
  );
79
72
  }
80
73
 
81
74
  const excludes = module.exclude.map(key => `!${resolve(key)}`);
82
- const modulePath = adaptPath(module.path);
83
75
  const glob = {
84
76
  js: [`${modulePath}/**/*.{js,ts,wxs}`, ...excludes],
85
77
  json: [`${modulePath}/**/*.json`, `!${modulePath}/**/module.config.json`, ...excludes],
@@ -96,7 +88,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
96
88
  destPath: resolve(tmsConfig.outputDir, module.root),
97
89
  module: { from: module.path, to: module.root },
98
90
  srcOption: { allowEmpty: true },
99
- isWatch,
91
+ isDev,
100
92
  }));
101
93
  }
102
94
 
@@ -130,7 +122,7 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
130
122
  to: item.to,
131
123
  },
132
124
  srcOption: { allowEmpty: true },
133
- isWatch,
125
+ isDev,
134
126
  }));
135
127
  }
136
128
  }
@@ -138,28 +130,45 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
138
130
  let sTime;
139
131
  let eTime;
140
132
  const spinner = ora();
141
- function end(cb) {
142
- if (isWatch) {
133
+ function start(cb) {
134
+ info('启动编译...');
135
+ spinner.start();
136
+ sTime = new Date().getTime();
137
+ cb();
138
+ }
139
+ async function end(cb) {
140
+ if (isDev) {
141
+ // 监听app.json
142
+ watch(
143
+ [resolve('app.json')],
144
+ { ignoreInitial: false, events: watchEvents },
145
+ () => buildOutputAppJson(tmsConfig, newModules, isDev),
146
+ { from: resolve(), to: resolve(tmsConfig.outputDir) },
147
+ );
148
+ // 监听其他文件
143
149
  compileTasksMap.forEach(({ taskFn, module }, globValue) => {
144
150
  watch(globValue, { ignoreInitial: true, events: watchEvents }, taskFn, module);
145
151
  });
152
+ } else {
153
+ buildOutputAppJson(tmsConfig, newModules, isDev);
146
154
  }
147
155
  eTime = new Date().getTime() - sTime;
148
- spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即刻预览。`);
156
+ if (typeof tmsConfig?.hooks?.afterCompile === 'function') {
157
+ await tmsConfig?.hooks?.afterCompile({
158
+ isDev,
159
+ tmsConfig: filterField(tmsConfig, ['gitAccount']),
160
+ modules: newModules,
161
+ });
162
+ }
163
+ spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
149
164
  spinner.stop();
150
165
  cb();
151
166
  }
152
167
 
153
- function start(cb) {
154
- info('启动编译...');
155
- spinner.start();
156
- sTime = new Date().getTime();
157
- cb();
158
- }
159
-
160
168
  const compileTasks = [];
161
169
  compileTasksMap.forEach(({ taskFn }) => {
162
170
  compileTasks.push(taskFn);
163
171
  });
172
+ // 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
164
173
  series(start, parallel(...compileTasks), end)();
165
174
  };
@@ -0,0 +1,172 @@
1
+
2
+ /* eslint-disable */
3
+ // 该文件源于npm包 gulp-watch 但内部有bug, 故源码进行单独修改
4
+ const assign = require('object-assign');
5
+ const path = require('path');
6
+ const PluginError = require('plugin-error');
7
+ const fancyLog = require('fancy-log');
8
+ const colors = require('ansi-colors');
9
+ const chokidar = require('chokidar');
10
+ const { Duplex } = require('readable-stream');
11
+ const vinyl = require('vinyl-file');
12
+ const File = require('vinyl');
13
+ const anymatch = require('anymatch');
14
+ const pathIsAbsolute = require('path-is-absolute');
15
+ const globParent = require('glob-parent');
16
+ const slash = require('slash');
17
+
18
+ function normalizeGlobs(globs) {
19
+ if (!globs) {
20
+ throw new PluginError('gulp-watch', 'glob argument required');
21
+ }
22
+
23
+ if (typeof globs === 'string') {
24
+ globs = [globs];
25
+ }
26
+
27
+ if (!Array.isArray(globs)) {
28
+ throw new PluginError('gulp-watch', `glob should be String or Array, not ${typeof globs}`);
29
+ }
30
+
31
+ return globs;
32
+ }
33
+
34
+ function watch(globs, opts, cb) {
35
+ const originalGlobs = globs;
36
+ globs = normalizeGlobs(globs);
37
+
38
+ if (typeof opts === 'function') {
39
+ cb = opts;
40
+ opts = {};
41
+ }
42
+
43
+ opts = assign({}, watch._defaultOptions, opts);
44
+ cb = cb || function () {};
45
+
46
+ function resolveFilepath(filepath) {
47
+ if (pathIsAbsolute(filepath)) {
48
+ return path.normalize(filepath);
49
+ }
50
+ return path.resolve(opts.cwd || process.cwd(), filepath);
51
+ }
52
+
53
+ function resolveGlob(glob) {
54
+ let mod = '';
55
+
56
+ if (glob[0] === '!') {
57
+ mod = glob[0];
58
+ glob = glob.slice(1);
59
+ }
60
+
61
+ return mod + slash(resolveFilepath(glob));
62
+ }
63
+ globs = globs.map(resolveGlob);
64
+
65
+ const baseForced = Boolean(opts.base);
66
+ const outputStream = new Duplex({ objectMode: true, allowHalfOpen: true });
67
+
68
+ outputStream._write = function _write(file, enc, done) {
69
+ cb(file);
70
+ this.push(file);
71
+ done();
72
+ };
73
+
74
+ outputStream._read = function _read() { };
75
+
76
+ const watcher = chokidar.watch(globs, opts);
77
+
78
+ opts.events.forEach((ev) => {
79
+ watcher.on(ev, processEvent.bind(undefined, ev));
80
+ });
81
+
82
+ ['add', 'change', 'unlink', 'addDir', 'unlinkDir', 'error', 'ready', 'raw']
83
+ .forEach((ev) => {
84
+ watcher.on(ev, outputStream.emit.bind(outputStream, ev));
85
+ });
86
+
87
+ outputStream.add = function add(newGlobs) {
88
+ newGlobs = normalizeGlobs(newGlobs)
89
+ .map(resolveGlob);
90
+ watcher.add(newGlobs);
91
+ globs.push.apply(globs, newGlobs);
92
+ };
93
+ outputStream.unwatch = watcher.unwatch.bind(watcher);
94
+ outputStream.close = function () {
95
+ watcher.close();
96
+ this.emit('end');
97
+ };
98
+
99
+ function processEvent(event, filepath) {
100
+ filepath = resolveFilepath(filepath);
101
+ const fileOpts = assign({}, opts);
102
+
103
+ let glob;
104
+ let currentFilepath = filepath;
105
+ while (!(glob = globs[anymatch(globs, currentFilepath, true)]) && currentFilepath !== (currentFilepath = path.dirname(currentFilepath))) {} // eslint-disable-line no-empty-blocks/no-empty-blocks
106
+
107
+ if (!glob) {
108
+ console.error('[gulp-watch]没有匹配到glob')
109
+ return;
110
+ }
111
+
112
+ if (!baseForced) {
113
+ fileOpts.base = path.normalize(globParent(glob));
114
+ }
115
+
116
+ // Do not stat deleted files
117
+ if (event === 'unlink' || event === 'unlinkDir' || event === 'addDir') {
118
+ fileOpts.path = filepath;
119
+
120
+ write(event, null, new File(fileOpts));
121
+ return;
122
+ }
123
+
124
+ // Workaround for early read
125
+ setTimeout(() => {
126
+ vinyl.read(filepath, fileOpts).then((file) => {
127
+ write(event, null, file);
128
+ });
129
+ }, opts.readDelay);
130
+ }
131
+
132
+ function write(event, err, file) {
133
+ if (err) {
134
+ outputStream.emit('error', err);
135
+ return;
136
+ }
137
+
138
+ if (opts.verbose) {
139
+ log(event, file);
140
+ }
141
+
142
+ file.event = event;
143
+ outputStream.push(file);
144
+ cb(file);
145
+ }
146
+
147
+ function log(event, file) {
148
+ event = event[event.length - 1] === 'e' ? `${event}d` : `${event}ed`;
149
+
150
+ const msg = [colors.magenta(file.relative), 'was', event];
151
+
152
+ if (opts.name) {
153
+ msg.unshift(`${colors.cyan(opts.name)} saw`);
154
+ }
155
+
156
+ fancyLog.info.apply(null, msg);
157
+ }
158
+
159
+ return outputStream;
160
+ }
161
+
162
+ // This is not part of the public API as that would lead to global state (singleton) pollution,
163
+ // and allow unexpected interference between unrelated modules that make use of gulp-watch.
164
+ // This can be useful for unit tests and root application configuration, though.
165
+ // Avoid modifying gulp-watch's default options inside a library/reusable package, please.
166
+ watch._defaultOptions = {
167
+ events: ['add', 'change', 'unlink'],
168
+ ignoreInitial: true,
169
+ readDelay: 10,
170
+ };
171
+
172
+ module.exports = watch;
@@ -49,7 +49,7 @@ function mpJsonDep(
49
49
  }
50
50
 
51
51
  // eslint-disable-next-line
52
- const reg = new RegExp(`^(\./\.\.\/)+.*\/${includeName}\/(.*)`);
52
+ const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
53
53
  const regRes = componentPath.match(reg) || [];
54
54
  if (regRes[2]) {
55
55
  const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
@@ -1,29 +1,65 @@
1
- const watch = require('gulp-watch');
1
+ const watch = require('./plugins/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
+ const { findAllFilesOfDir } = require('../utils/io');
7
8
 
8
- module.exports = function (glob, watchOptions, callback, module) {
9
- watch(glob, {
10
- readDelay: 100,
9
+ const TIP_MAP = {
10
+ 'package.json': '若依赖有变动,请重新执行tmskit run dev',
11
+ 'module.config.json': '若dependencies字段有变动,需要重新执行tmskit run dev才会生效',
12
+ };
13
+
14
+ const logTip = (fileName, tipMap) => {
15
+ // eslint-disable-next-line
16
+ for (const item in tipMap) {
17
+ if (fileName.indexOf(item) > -1) {
18
+ warn(`${fileName}有更新, ${tipMap[item]}`);
19
+ return;
20
+ }
21
+ }
22
+ info(`${fileName}有更新`);
23
+ };
24
+
25
+ const getTargetFile = (sourceFile, module, outputDir) => {
26
+ const sourceFileRelativeModule = path.relative(resolve(module.from), sourceFile);
27
+ const targetFile = resolve(outputDir, module.to, sourceFileRelativeModule);
28
+ return targetFile;
29
+ };
30
+
31
+ module.exports = function (globValue, watchOptions, callback, module) {
32
+ watch(globValue, {
33
+ // readDelay: 100,
11
34
  ...watchOptions,
12
35
  }, (vinyl) => {
13
- const file = vinyl.history[0];
14
- const fileDirArr = file.replace(/\\/g, '/').split('/');
15
- const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
36
+ const sourceFile = vinyl.history[0];
37
+ const sourceFileDirArr = sourceFile.replace(/\\/g, '/').split('/');
38
+ const sourceFileName = sourceFileDirArr.slice(sourceFileDirArr.length - 2).join('/');
39
+
40
+ const tmsConfig = global.getData('tmsConfig');
41
+
42
+ if (vinyl.event === 'addDir') {
43
+ info(`更新${sourceFileName}目录`);
44
+ const files = findAllFilesOfDir(sourceFile);
45
+ for (const file of files) {
46
+ const fileDirArr = file.replace(/\\/g, '/').split('/');
47
+ const fileName = fileDirArr.slice(fileDirArr.length - 2).join('/');
48
+ const targetFile = getTargetFile(file, module, tmsConfig.outputDir);
49
+ logTip(fileName, TIP_MAP);
50
+ callback([file], path.dirname(targetFile));
51
+ }
52
+ return;
53
+ }
16
54
 
55
+ const targetFile = getTargetFile(sourceFile, module, tmsConfig.outputDir);
17
56
  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);
57
+ info(`删除${sourceFileName}`);
58
+ shellJs.rm('-rf', targetFile);
23
59
  return;
24
60
  }
25
61
 
26
- info(`更新${fileName}`);
27
- return callback(vinyl);
62
+ logTip(sourceFileName, TIP_MAP);
63
+ return callback([sourceFile], path.dirname(targetFile));
28
64
  });
29
65
  };
@@ -14,7 +14,7 @@ const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
14
14
  const MODULE_CODE_DIR = path.resolve(CACHE_DIR, 'modules_code');
15
15
 
16
16
  // 脚手架模板代码的具体路径
17
- const TEMPLATE_PATH = path.resolve(TEMPLATE_DIR, 'tools/tms-cli-template');
17
+ const TEMPLATE_PATH = path.resolve(TEMPLATE_DIR, 'tools/tmskit-template');
18
18
 
19
19
  // 脚手架的名称
20
20
  const TMS_NAME = 'tmskit';
@@ -47,7 +47,6 @@ const ENV = {
47
47
  };
48
48
 
49
49
  const TEMPLATE_TKIT_DIR = '_tmskit';
50
- const MODULE_CONFIG_INVALID_KEY = ['entranceDeclare', 'entryPagePath'];
51
50
 
52
51
  export {
53
52
  HOME_DIR,
@@ -64,6 +63,5 @@ export {
64
63
  MODULE_CODE_DIR,
65
64
  ENV,
66
65
  TEMPLATE_TKIT_DIR,
67
- MODULE_CONFIG_INVALID_KEY,
68
66
  DEFAULT_CLOUD_MODULE_DIR,
69
67
  };
@@ -3,7 +3,7 @@ module.exports = {
3
3
  // 全局的环境配置项
4
4
  envData: {},
5
5
  // 模块配置信息
6
- modules: [],
6
+ modules: {},
7
7
  cloudDir: 'cloud',
8
8
  // 第三方依赖代码需要拷贝到本项目的
9
9
  dependencies: {},