@tmsfe/tmskit 0.0.5-beta.4 → 0.0.5-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -83,7 +83,7 @@ const fs$e = require$$0__default$1;
83
83
  const shelljs$6 = require$$5__default;
84
84
  const download = require$$6__default;
85
85
  const chalk$3 = require$$0__default$2;
86
- const shelljsOptons = {
86
+ const shelljsOptions = {
87
87
  slient: true
88
88
  }; // 获取当前目录
89
89
 
@@ -189,7 +189,7 @@ function downloadRepo(dest, downloadOptions = {
189
189
 
190
190
  function downloadRepoForGit$2(url, dest, branch) {
191
191
  const cwd = process.cwd();
192
- return new Promise(resolve => {
192
+ return new Promise((resolve, reject) => {
193
193
  // 如果目标目录不存在
194
194
  if (fs$e.existsSync(dest)) {
195
195
  shelljs$6.rm('-rf', path$a.join(dest));
@@ -197,7 +197,12 @@ function downloadRepoForGit$2(url, dest, branch) {
197
197
 
198
198
  shelljs$6.mkdir('-p', dest);
199
199
  shelljs$6.cd(dest);
200
- shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
200
+ const gitCloneRes = shelljs$6.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptions);
201
+
202
+ if (gitCloneRes.code !== 0) {
203
+ reject(gitCloneRes.stderr);
204
+ }
205
+
201
206
  shelljs$6.cd(cwd);
202
207
  resolve();
203
208
  });
@@ -911,7 +916,7 @@ function buildOutputAppJson$1(tmsConfig, modules) {
911
916
  processAppJson(appJson); // 更新主包,需在subpackages处理完成后执行, pages/
912
917
 
913
918
  updateMainPackages(appJson, tmsConfig.mainPackages);
914
- fs$a.writeFileSync(resolve$a(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
919
+ fs$a.writeFileSync(resolve$a(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
915
920
  return appJson;
916
921
  }
917
922
 
@@ -1063,19 +1068,17 @@ var defaultTmsConfig$1 = {
1063
1068
  // 模块配置信息
1064
1069
  modules: [],
1065
1070
  cloudDir: 'cloud',
1066
- gulp: {
1067
- // 第三方依赖代码需要拷贝到本项目的
1068
- dependencies: {},
1071
+ // 第三方依赖代码需要拷贝到本项目的
1072
+ dependencies: {},
1069
1073
 
1070
- /** 编译输出文件夹位置 */
1071
- outputDir: 'dist',
1074
+ /** 编译输出文件夹位置 */
1075
+ outputDir: 'dist',
1072
1076
 
1073
- /** 源码监听路径 */
1074
- sourceDir: './',
1077
+ /** 源码监听路径 */
1078
+ sourceDir: './',
1075
1079
 
1076
- /** 静态资源目录 */
1077
- static: []
1078
- }
1080
+ /** 静态资源目录 */
1081
+ static: []
1079
1082
  };
1080
1083
 
1081
1084
  const loadash = require$$0__default$5;
@@ -1455,7 +1458,7 @@ const {
1455
1458
  async function install$2(tmsConfig, modules, isCloud = true) {
1456
1459
  const newModules = tmsModulesMergeLocalModuleCfg$2(modules, tmsConfig.appName, DEFAULT_MODULE_DIR$2); // 小程序npm install
1457
1460
 
1458
- await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$7(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1461
+ await createTask$2(mpNpmInstallAll, '小程序 开始npm install', '小程序npm install 完成')(newModules, resolve$7(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`); // 构建miniprograme_npm
1459
1462
 
1460
1463
  await createTask$2(buildMpNpm, '开始构建miniprograme_npm', '构建miniprograme_npm 完成')({
1461
1464
  appId: tmsConfig.appId,
@@ -1502,16 +1505,16 @@ const install$1 = install_1;
1502
1505
  */
1503
1506
 
1504
1507
  const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
1505
- const outputDir = resolve$6(tmsConfig.gulp.outputDir);
1508
+ const outputDir = resolve$6(tmsConfig.outputDir);
1506
1509
  io.ensureDirExist(outputDir);
1507
1510
  defaultFiles.forEach(item => {
1508
1511
  if (fs$6.existsSync(resolve$6(item))) {
1509
- shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.gulp.outputDir, item));
1512
+ shelljs$3.cp('-rf', resolve$6(item), resolve$6(tmsConfig.outputDir, item));
1510
1513
  }
1511
1514
  }); // 拷贝模块的package.json到编译输出目录
1512
1515
 
1513
1516
  targetModules.forEach(item => {
1514
- const outputModuleDir = resolve$6(`${tmsConfig.gulp.outputDir}/${item.root}`);
1517
+ const outputModuleDir = resolve$6(`${tmsConfig.outputDir}/${item.root}`);
1515
1518
 
1516
1519
  if (!fs$6.existsSync(resolve$6(item.path))) {
1517
1520
  fail$5(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
@@ -1539,14 +1542,14 @@ async function task(tmsConfig, targetModules) {
1539
1542
  return newModules;
1540
1543
  }
1541
1544
 
1542
- async function bootstrap(tmsConfig, targetModules) {
1545
+ async function init$5(tmsConfig, targetModules) {
1543
1546
  const newModules = await task(tmsConfig, targetModules);
1544
1547
  return {
1545
1548
  targetModules: newModules
1546
1549
  };
1547
1550
  }
1548
1551
 
1549
- var init$5 = bootstrap;
1552
+ var init_1 = init$5;
1550
1553
 
1551
1554
  var dev$3 = {exports: {}};
1552
1555
 
@@ -1710,14 +1713,14 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
1710
1713
  // 依赖分析的文件
1711
1714
  const anaFileOriginFile = file.history[0];
1712
1715
  const anaFileRelativeModule = path$4.relative(resolve$5(module.from), anaFileOriginFile);
1713
- const anaFileDestFile = resolve$5(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
1716
+ const anaFileDestFile = resolve$5(tmsConfig.outputDir, module.to, anaFileRelativeModule);
1714
1717
 
1715
1718
  if (file.isBuffer()) {
1716
1719
  let contents = String(file.contents);
1717
1720
  const deps = cssFilter.indexOf(path$4.extname(file.path)) > -1 ? findCssImports(contents) : precinct(contents);
1718
1721
  const copyModules = new Map();
1719
- Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
1720
- const includePath = tmsConfig.gulp.dependencies[includeName];
1722
+ Object.keys(tmsConfig.dependencies).forEach(includeName => {
1723
+ const includePath = tmsConfig.dependencies[includeName];
1721
1724
  deps.forEach(depItem => {
1722
1725
  if (depItem.indexOf(includeName) > -1) {
1723
1726
  // 被依赖文件的存在的绝对路径 (eg: /User/thirdparty/loadsh)
@@ -1739,7 +1742,7 @@ function mpCommonDep$1(tmsConfig, module, extensions = [], isWatch = true) {
1739
1742
  const regRes = depItem.match(reg) || [];
1740
1743
 
1741
1744
  if (regRes[2]) {
1742
- const depDestPath = resolve$5(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1745
+ const depDestPath = resolve$5(tmsConfig.outputDir, module.to, includeName, regRes[2]);
1743
1746
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
1744
1747
 
1745
1748
  if (!copyModules.has(depDestFile)) {
@@ -1807,7 +1810,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
1807
1810
  // 当前分析的文件的路径
1808
1811
  const anaFileOriginFile = file.history[0];
1809
1812
  const anaFileRelativeModule = path$3.relative(resolve$4(module.from), anaFileOriginFile);
1810
- const anaFileDestFile = resolve$4(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
1813
+ const anaFileDestFile = resolve$4(tmsConfig.outputDir, module.to, anaFileRelativeModule);
1811
1814
 
1812
1815
  if (file.isBuffer()) {
1813
1816
  const copyModules = new Map();
@@ -1817,8 +1820,8 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
1817
1820
  contents = JSON.parse(contents);
1818
1821
 
1819
1822
  if (contents.usingComponents) {
1820
- Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
1821
- const includePath = tmsConfig.gulp.dependencies[includeName];
1823
+ Object.keys(tmsConfig.dependencies).forEach(includeName => {
1824
+ const includePath = tmsConfig.dependencies[includeName];
1822
1825
  Object.keys(contents.usingComponents).forEach(componentKey => {
1823
1826
  const componentPath = contents.usingComponents[componentKey];
1824
1827
 
@@ -1842,7 +1845,7 @@ function mpJsonDep$1(tmsConfig, module, extensions = ['.json'], filesExt = ['.wx
1842
1845
  const regRes = componentPath.match(reg) || [];
1843
1846
 
1844
1847
  if (regRes[2]) {
1845
- const depDestPath = resolve$4(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
1848
+ const depDestPath = resolve$4(tmsConfig.outputDir, module.to, includeName, regRes[2]);
1846
1849
  const depDestFile = depDestPath.endsWith(extAlias) ? depDestPath : depDestPath + extPath;
1847
1850
 
1848
1851
  if (!copyModules.has(depDestFile)) {
@@ -2033,7 +2036,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2033
2036
  // 依赖分析的文件
2034
2037
  const anaFileOriginFile = file.history[0];
2035
2038
  const anaFileRelativeModule = path$2.relative(resolve$3(module.from), anaFileOriginFile);
2036
- const anaFileDestFile = resolve$3(tmsConfig.gulp.outputDir, module.to, anaFileRelativeModule);
2039
+ const anaFileDestFile = resolve$3(tmsConfig.outputDir, module.to, anaFileRelativeModule);
2037
2040
 
2038
2041
  if (file.isBuffer()) {
2039
2042
  let contents = String(file.contents);
@@ -2050,9 +2053,9 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2050
2053
  file: depOriginFile,
2051
2054
  extPath
2052
2055
  } = extFile(name, depOriginPath);
2053
- Object.keys(tmsConfig.gulp.dependencies).forEach(includeName => {
2056
+ Object.keys(tmsConfig.dependencies).forEach(includeName => {
2054
2057
  if (attributes.src.indexOf(includeName) > -1) {
2055
- const includePath = tmsConfig.gulp.dependencies[includeName];
2058
+ const includePath = tmsConfig.dependencies[includeName];
2056
2059
 
2057
2060
  if (!fileInDir(includePath, depOriginFile)) {
2058
2061
  pluginError(new Error(`${anaFileOriginFile}引用路径${depOriginFile}不在${includePath}不在文件夹内, 请检查应用路径`), isWatch);
@@ -2064,7 +2067,7 @@ function mpWxmlDep$1(tmsConfig, module, isWatch) {
2064
2067
  const regRes = attributes.src.match(reg) || [];
2065
2068
 
2066
2069
  if (regRes[2]) {
2067
- const depDestPath = resolve$3(tmsConfig.gulp.outputDir, module.to, includeName, regRes[2]);
2070
+ const depDestPath = resolve$3(tmsConfig.outputDir, module.to, includeName, regRes[2]);
2068
2071
  const depDestFile = depDestPath.endsWith(ext) ? depDestPath : depDestPath + extPath;
2069
2072
 
2070
2073
  if (!copyModules.has(depDestFile)) {
@@ -2320,8 +2323,6 @@ var compile = function (tmsConfig, {
2320
2323
  }
2321
2324
 
2322
2325
  module.exports = async (tmsConfig, newModules, isWatch = true) => {
2323
- var _tmsConfig$gulp, _tmsConfig$gulp2;
2324
-
2325
2326
  // 监听app.json
2326
2327
  if (isWatch) {
2327
2328
  watch(resolve('app.json'), {
@@ -2345,7 +2346,7 @@ var compile = function (tmsConfig, {
2345
2346
  from: '',
2346
2347
  to: ''
2347
2348
  },
2348
- destPath: resolve(tmsConfig.gulp.outputDir),
2349
+ destPath: resolve(tmsConfig.outputDir),
2349
2350
  srcOption: {
2350
2351
  allowEmpty: true
2351
2352
  },
@@ -2381,7 +2382,7 @@ var compile = function (tmsConfig, {
2381
2382
  glob: { ...glob,
2382
2383
  other: [`${resolve(module.path)}/**/*`, ...excludeGlob(glob)]
2383
2384
  },
2384
- destPath: resolve(tmsConfig.gulp.outputDir, module.root),
2385
+ destPath: resolve(tmsConfig.outputDir, module.root),
2385
2386
  module: {
2386
2387
  from: module.path,
2387
2388
  to: module.root
@@ -2394,10 +2395,8 @@ var compile = function (tmsConfig, {
2394
2395
  } // 监听copy模块
2395
2396
 
2396
2397
 
2397
- if (tmsConfig !== null && tmsConfig !== void 0 && (_tmsConfig$gulp = tmsConfig.gulp) !== null && _tmsConfig$gulp !== void 0 && _tmsConfig$gulp.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : (_tmsConfig$gulp2 = tmsConfig.gulp) === null || _tmsConfig$gulp2 === void 0 ? void 0 : _tmsConfig$gulp2.static.length) > 0) {
2398
- for (const item of (_tmsConfig$gulp3 = tmsConfig.gulp) === null || _tmsConfig$gulp3 === void 0 ? void 0 : _tmsConfig$gulp3.static) {
2399
- var _tmsConfig$gulp3;
2400
-
2398
+ if (tmsConfig !== null && tmsConfig !== void 0 && tmsConfig.static && (tmsConfig === null || tmsConfig === void 0 ? void 0 : tmsConfig.static.length) > 0) {
2399
+ for (const item of tmsConfig.static) {
2401
2400
  const glob = {
2402
2401
  js: `${item.from}/**/*.{js,ts,wxs}`,
2403
2402
  json: `${item.from}/**/*.json`,
@@ -2518,7 +2517,7 @@ const fs = require$$0__default$1;
2518
2517
  const {
2519
2518
  resolve: resolve$1
2520
2519
  } = widgets;
2521
- const init$4 = init$5;
2520
+ const init$4 = init_1;
2522
2521
  const {
2523
2522
  DEFAULT_MODULE_DIR
2524
2523
  } = require$$3;
@@ -2573,7 +2572,7 @@ function isInit(tmsConfig, targetModules, contextDir) {
2573
2572
  } // 判断package.json的版本是否有新的版本
2574
2573
 
2575
2574
 
2576
- return checkDependencies(targetModules, resolve$1('./'), tmsConfig.gulp.outputDir);
2575
+ return checkDependencies(targetModules, resolve$1('./'), tmsConfig.outputDir);
2577
2576
  }
2578
2577
 
2579
2578
  async function dev$2(tmsConfig, targetModules, env) {
@@ -2596,7 +2595,7 @@ const shelljs$1 = require$$5__default;
2596
2595
  const dev$1 = dev$3.exports;
2597
2596
 
2598
2597
  var build$2 = async (tmsConfig, newModules) => {
2599
- shelljs$1.rm('-rf', tmsConfig.gulp.outputDir);
2598
+ shelljs$1.rm('-rf', tmsConfig.outputDir);
2600
2599
  dev$1(tmsConfig, newModules, false);
2601
2600
  };
2602
2601
 
@@ -2604,12 +2603,12 @@ const shelljs = require$$5__default;
2604
2603
  const {
2605
2604
  resolve
2606
2605
  } = widgets;
2607
- const init$3 = init$5;
2606
+ const init$3 = init_1;
2608
2607
  const gulpBuild = build$2;
2609
2608
 
2610
2609
  async function build$1(tmsConfig, targetModules, env) {
2611
2610
  // 开始构建前,清理输出目录
2612
- await shelljs.rm('-rf', resolve(tmsConfig.gulp.outputDir));
2611
+ await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
2613
2612
  const {
2614
2613
  targetModules: newModules
2615
2614
  } = await init$3(tmsConfig, targetModules);
@@ -2618,7 +2617,7 @@ async function build$1(tmsConfig, targetModules, env) {
2618
2617
 
2619
2618
  var build_1 = build$1;
2620
2619
 
2621
- const init$2 = init$5;
2620
+ const init$2 = init_1;
2622
2621
  const dev = dev_1;
2623
2622
  const build = build_1;
2624
2623
  const install = install_1;
@@ -2738,7 +2737,7 @@ var entry = [{
2738
2737
 
2739
2738
  var require$$6 = {
2740
2739
  name: "@tmsfe/tmskit",
2741
- version: "0.0.5-beta.4",
2740
+ version: "0.0.5-beta.5",
2742
2741
  description: "tmskit",
2743
2742
  main: "main.js",
2744
2743
  bin: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.5-beta.4",
3
+ "version": "0.0.5-beta.5",
4
4
  "description": "tmskit",
5
5
  "main": "main.js",
6
6
  "bin": {
@@ -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
@@ -2,7 +2,7 @@ const shelljs = require('shelljs');
2
2
  const dev = require('./dev');
3
3
 
4
4
  module.exports = async (tmsConfig, newModules) => {
5
- shelljs.rm('-rf', tmsConfig.gulp.outputDir);
5
+ shelljs.rm('-rf', tmsConfig.outputDir);
6
6
 
7
7
  dev(tmsConfig, newModules, false);
8
8
  };
package/src/gulp/dev.js CHANGED
@@ -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
  });
@@ -75,7 +75,7 @@ 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,
@@ -83,8 +83,8 @@ module.exports = async (tmsConfig, newModules, isWatch = true) => {
83
83
  }
84
84
 
85
85
  // 监听copy模块
86
- if (tmsConfig?.gulp?.static && tmsConfig?.gulp?.static.length > 0) {
87
- for (const item of tmsConfig.gulp?.static) {
86
+ if (tmsConfig?.static && tmsConfig?.static.length > 0) {
87
+ for (const item of tmsConfig.static) {
88
88
  const glob = {
89
89
  js: `${item.from}/**/*.{js,ts,wxs}`,
90
90
  json: `${item.from}/**/*.json`,
@@ -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,7 +88,7 @@ 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, {
@@ -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)) {
@@ -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,7 +136,7 @@ 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, {
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,7 +5,7 @@ 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
10
  const { targetModules: newModules } = await init(tmsConfig, targetModules);
11
11
 
@@ -45,7 +45,7 @@ function isInit(tmsConfig, targetModules, contextDir) {
45
45
  }
46
46
 
47
47
  // 判断package.json的版本是否有新的版本
48
- return checkDependencies(targetModules, resolve('./'), tmsConfig.gulp.outputDir);
48
+ return checkDependencies(targetModules, resolve('./'), tmsConfig.outputDir);
49
49
  }
50
50
 
51
51
  async function dev(tmsConfig, targetModules, env) {
@@ -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);
@@ -69,7 +69,7 @@ async function task(tmsConfig, targetModules) {
69
69
 
70
70
  return newModules;
71
71
  }
72
- async function bootstrap(tmsConfig, targetModules) {
72
+ async function init(tmsConfig, targetModules) {
73
73
  const newModules = await task(tmsConfig, targetModules);
74
74
 
75
75
  return {
@@ -77,4 +77,4 @@ async function bootstrap(tmsConfig, targetModules) {
77
77
  };
78
78
  }
79
79
 
80
- module.exports = bootstrap;
80
+ module.exports = init;
@@ -11,7 +11,7 @@ async function install(tmsConfig, modules, isCloud = true) {
11
11
  mpNpmInstallAll,
12
12
  '小程序 开始npm install',
13
13
  '小程序npm install 完成',
14
- )(newModules, resolve(tmsConfig.gulp.outputDir), `${CACHE_DIR}/node_modules`);
14
+ )(newModules, resolve(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
15
15
 
16
16
  // 构建miniprograme_npm
17
17
  await createTask(
@@ -189,7 +189,7 @@ function buildOutputAppJson(tmsConfig, modules) {
189
189
  // 更新主包,需在subpackages处理完成后执行, pages/
190
190
  updateMainPackages(appJson, tmsConfig.mainPackages, DEFAULT_MODULE_DIR);
191
191
 
192
- fs.writeFileSync(resolve(`${tmsConfig.gulp.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
192
+ fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
193
193
 
194
194
  return appJson;
195
195
  }
@@ -64,6 +64,7 @@ async function downLoadAndMoveModule(sourceDir, targetDir, moduleInfo) {
64
64
  const globalInstance = getGlobalInstance();
65
65
  const moduleInCache = globalInstance.getModuleCache(httpRepoUrl, cloneBranch);
66
66
 
67
+
67
68
  try {
68
69
  if (!moduleInCache) {
69
70
  await downloadRepoForGit(httpRepoUrl, sourcePath, cloneBranch);
@@ -7,7 +7,7 @@ const fs = require('fs');
7
7
  const shelljs = require('shelljs');
8
8
  const download = require('download-git-repo');
9
9
  const chalk = require('chalk');
10
- const shelljsOptons = { slient: true };
10
+ const shelljsOptions = { slient: true };
11
11
 
12
12
  // 获取当前目录
13
13
  const cwd = process.cwd();
@@ -96,7 +96,7 @@ function downloadRepo(dest, downloadOptions = { repoUrl: '', gitUrl: '', branch:
96
96
  function downloadRepoForGit(url, dest, branch) {
97
97
  const cwd = process.cwd();
98
98
 
99
- return new Promise((resolve) => {
99
+ return new Promise((resolve, reject) => {
100
100
  // 如果目标目录不存在
101
101
  if (fs.existsSync(dest)) {
102
102
  shelljs.rm('-rf', path.join(dest));
@@ -105,7 +105,10 @@ function downloadRepoForGit(url, dest, branch) {
105
105
  shelljs.mkdir('-p', dest);
106
106
  shelljs.cd(dest);
107
107
 
108
- shelljs.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptons);
108
+ const gitCloneRes = shelljs.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptions);
109
+ if (gitCloneRes.code !== 0) {
110
+ reject(gitCloneRes.stderr);
111
+ }
109
112
 
110
113
  shelljs.cd(cwd);
111
114
  resolve();
@@ -1,65 +0,0 @@
1
- const WebpackChain = require('webpack-chain');
2
- const webpack = require('webpack');
3
- const { getEntry, stringified, getAlias } = require('./utils');
4
- const { resolve } = require('../utils/widgets');
5
- const { DEFAULT_WEBPACK_ENTRY, DEFAULT_MODULE_DIR } = require('../config/constant');
6
-
7
- module.exports = (tmsConfig, modules) => {
8
- const { envData = {}, webpack: tmsWebpack } = tmsConfig;
9
- let webpackConfig = new WebpackChain();
10
-
11
- const alias = getAlias(modules);
12
- const entry = getEntry(DEFAULT_WEBPACK_ENTRY, modules, tmsConfig, DEFAULT_MODULE_DIR);
13
- webpackConfig.merge({
14
- entry,
15
- output: {
16
- path: resolve(`./${tmsWebpack.outputDir}`),
17
- libraryTarget: 'commonjs2',
18
- filename: '[name]',
19
- },
20
- // TODO 有报错,先注释掉
21
- // cache: {
22
- // type: 'filesystem',
23
- // cacheDirectory: resolve(`./${tmsConfig.webpack.outputDir}/node_modules/.cache`),
24
- // },
25
- resolve: {
26
- extensions: ['.tsx', '.ts', '.js'],
27
- alias: Object.assign(tmsWebpack.alias, alias),
28
- },
29
- devtool: tmsWebpack.sourceMap ? 'source-map' : false,
30
- });
31
-
32
- webpackConfig.module
33
- .rule('ts-loader')
34
- .test(/\.ts$/)
35
- .use('ts-loader')
36
- .loader(require.resolve('ts-loader'))
37
- .options({
38
- configFile: resolve('./tsconfig.json'),
39
- // 只进行语法转换,不进行类型校验,提高构建速度
40
- transpileOnly: true,
41
- })
42
- .end();
43
-
44
- // webpackConfig.module
45
- // .rule('babel')
46
- // .test(/\.(js|mjs|jsx|ts|tsx)$/)
47
- // .pre()
48
- // .exclude.add(/(node_modules|miniprogram_npm)/).end()
49
- // .use(require.resolve('babel-loader'))
50
- // .loader(require.resolve('babel-loader'));
51
-
52
- webpackConfig
53
- .plugin('definePlugin')
54
- .use(webpack.DefinePlugin, [stringified(envData)])
55
- .end();
56
-
57
- // 执行tms.config.js自定义的webpackChain
58
- if (tmsWebpack.webpackChain) {
59
- webpackConfig = tmsWebpack.webpackChain(webpackConfig, {
60
- modules,
61
- });
62
- }
63
-
64
- return webpackConfig;
65
- };
@@ -1,21 +0,0 @@
1
- const webpackConfig = require('./base');
2
- const { DEFAULT_COPY_CONFIG } = require('../config/constant');
3
- const { getCopyPlugin } = require('./utils');
4
-
5
- module.exports = (...args) => {
6
- const [tmsConfig, modules] = args;
7
- const webpackBuildConfig = webpackConfig(...args);
8
-
9
- webpackBuildConfig.mode('production');
10
-
11
- const copyPluginParams = getCopyPlugin(DEFAULT_COPY_CONFIG, modules, tmsConfig, 'build');
12
- // console.log('copyPluginParams', copyPluginParams);
13
- webpackBuildConfig
14
- .plugin('copy-webpack-plugin')
15
- .use(require('copy-webpack-plugin'), [{
16
- patterns: copyPluginParams,
17
- }])
18
- .end();
19
-
20
- return webpackBuildConfig;
21
- };
@@ -1,34 +0,0 @@
1
- const webpack = require('webpack');
2
- const webBuildConfig = require('./build');
3
- const { createTask } = require('../utils/widgets');
4
- const { fail } = require('../utils/log');
5
-
6
- function compilerRun(compiler) {
7
- return new Promise((resolve) => {
8
- compiler.run((err, stats) => {
9
- resolve({ err, stats });
10
- });
11
- });
12
- }
13
-
14
- module.exports = async (...args) => {
15
- const config = webBuildConfig(...args);
16
- const compiler = webpack(config.toConfig());
17
-
18
- const { err, stats } = await createTask(compilerRun, '开始webpack打包编译', 'webpack打包编译完成')(compiler);;
19
-
20
- if (err) {
21
- fail(err);
22
- console.log('详细的错误信息:', err);
23
- }
24
-
25
- if (stats.hasErrors() || stats.hasWarnings()) {
26
- console.log(stats.toString({
27
- // 增加控制台颜色开关
28
- colors: true,
29
- errorDetails: true,
30
- }));
31
- };
32
-
33
- return compiler;
34
- };
@@ -1,31 +0,0 @@
1
- const webpackConfig = require('./base');
2
- const { DEFAULT_COPY_CONFIG } = require('../config/constant');
3
- const { getCopyPlugin } = require('./utils');
4
-
5
- module.exports = (...args) => {
6
- const [tmsConfig, modules] = args;
7
- const webpackDevConfig = webpackConfig(...args);
8
-
9
- webpackDevConfig.devtool('source-map');
10
-
11
- webpackDevConfig.mode('development');
12
-
13
- const copyPluginParams = getCopyPlugin(DEFAULT_COPY_CONFIG, modules, tmsConfig, 'dev');
14
- // console.log('copyPluginParams', copyPluginParams);
15
- webpackDevConfig
16
- .plugin('copy-webpack-plugin')
17
- .use(require('copy-webpack-plugin'), [{
18
- patterns: copyPluginParams,
19
- }])
20
- .end();
21
-
22
- webpackDevConfig
23
- .plugin('ExtractPlugin')
24
- .use(require('./plugins/entryExtractPlugin'), [{
25
- tmsConfig,
26
- modules,
27
- }])
28
- .end();
29
-
30
- return webpackDevConfig;
31
- };
@@ -1,37 +0,0 @@
1
- const webpack = require('webpack');
2
- const webDevConfig = require('./dev');
3
- const { setupDevWebPackHooks } = require('./utils');
4
- const { fail } = require('../utils/log');
5
-
6
- module.exports = (...args) => {
7
- const config = webDevConfig(...args);
8
- const compiler = webpack(config.toConfig());
9
-
10
- setupDevWebPackHooks({
11
- compiler,
12
- }, () => {
13
- // TODO 判断open参数,打开微信开发者工具
14
- // openDevtool(api.resolve(config.outputDir || 'dist'))
15
- });
16
-
17
- compiler.watch(
18
- {
19
- aggregateTimeout: 1000,
20
- poll: undefined,
21
- },
22
- (err, stats) => {
23
- if (err) {
24
- fail(err);
25
- console.log('详细的错误信息:', err);
26
- }
27
- if (stats.hasErrors() || stats.hasWarnings()) {
28
- console.log(stats.toString({
29
- // 增加控制台颜色开关
30
- colors: true,
31
- }));
32
- };
33
- },
34
- );
35
-
36
- return compiler;
37
- };
@@ -1,28 +0,0 @@
1
- const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
2
- const { DEFAULT_WEBPACK_ENTRY, DEFAULT_MODULE_DIR } = require('../../../config/constant');
3
- const { getEntry } = require('../../utils');
4
-
5
- class EntryExtraPlugin {
6
- constructor(options = {}) {
7
- this.options = options;
8
- }
9
-
10
- applyEntry(compiler, entry) {
11
- const { context } = compiler.options;
12
-
13
- Object.keys(entry).forEach((key) => {
14
- new SingleEntryPlugin(context, entry[key], key).apply(compiler);
15
- });
16
- }
17
-
18
- apply(compiler) {
19
- const { tmsConfig = {}, modules = [] } = this.options;
20
-
21
- compiler.hooks.watchRun.tap('EntryExtraPlugin', () => {
22
- const entry = getEntry(DEFAULT_WEBPACK_ENTRY, modules, tmsConfig, DEFAULT_MODULE_DIR);
23
- this.applyEntry(compiler, entry);
24
- });
25
- }
26
- }
27
-
28
- module.exports = EntryExtraPlugin;
@@ -1,244 +0,0 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const { resolve } = require('../utils/widgets');
4
- const { buildOutputAppJson } = require('../utils/buildAppJson');
5
- const { tmsModulesMergeLocalModuleCfg } = require('../utils/tkitUtils');
6
- const { findAllPackageJson } = require('../utils/npmUtils');
7
- const { fail } = require('../utils/log');
8
- const replaceExt = require('replace-ext');
9
-
10
- const extensions = ['.ts', '.js'];
11
- function ext(entry, extensions) {
12
- let newEntry = entry;
13
- try {
14
- const stat = fs.lstatSync(newEntry);
15
- if (stat.isDirectory()) {
16
- newEntry += (newEntry[newEntry.length - 1] === '/') ? 'index' : '/index';
17
- }
18
- } catch (e) {}
19
-
20
- for (const ext of extensions) {
21
- const file = replaceExt(newEntry, ext);
22
- if (fs.existsSync(file)) {
23
- return {
24
- file,
25
- ext,
26
- };
27
- }
28
- }
29
- return null;
30
- }
31
-
32
- // 获取所有的package.json里的依赖包Dir
33
- function getAlias(modules) {
34
- const alias = {};
35
- const allPackages = findAllPackageJson(modules, resolve('./dist'));
36
- allPackages.forEach((packageFilePath) => {
37
- const { dependencies } = require(packageFilePath);
38
- Object.keys(dependencies).forEach((dependence) => {
39
- alias[dependence] = path.join(path.dirname(packageFilePath), `./miniprogram_npm/${dependence}`);
40
- });
41
- });
42
- return alias;
43
- }
44
-
45
-
46
- // 根据用户选择的modules,找到module.config.json的配置信息,找到所有的page
47
- function getPageEntry(modules, tmsConfig, moduleDir) {
48
- const entry = {};
49
- // tms.config.js的modules 合并 module.config.json的配置项
50
- const newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName, moduleDir);
51
- newModules.forEach(({ path: relativePath, pages, root }) => {
52
- pages.forEach((page) => {
53
- const pageJsonPath = `${resolve(relativePath, page)}.json`;
54
- if (fs.existsSync(pageJsonPath)) {
55
- const pageJsonContent = JSON.parse(fs.readFileSync(pageJsonPath, 'utf-8'));
56
- const pageDir = path.dirname(pageJsonPath); // 该页面所在的目录
57
- const extValue = ext(resolve(relativePath, page), extensions);
58
- if (!extValue) {
59
- fail(`当前${page}找不到入口.js或.ts文件`);
60
- process.exit(1);
61
- }
62
- const entryKey = `${root}/${page}${extValue.ext}`;
63
-
64
- Object.assign(
65
- entry,
66
- { [entryKey]: extValue.file },
67
- getComponentEntry(pageJsonContent, pageDir, path.dirname(entryKey)),
68
- );
69
- }
70
- });
71
- });
72
- return entry;
73
- }
74
-
75
- // 根据appJson,获取所有的page
76
- function getEntry(defaultWebpackEntry, modules, tmsConfig, moduleDir) {
77
- const defaultEntry = {};
78
- Object.keys(defaultWebpackEntry).forEach((key) => {
79
- const extValue = ext(defaultWebpackEntry[key], extensions);
80
- defaultEntry[key + extValue.ext] = extValue.file;
81
- });
82
- return {
83
- ...defaultEntry,
84
- ...getPageEntry(modules, tmsConfig, moduleDir),
85
- };
86
- }
87
-
88
- // 根据pageJson,filePath,获取页面引入的所有component
89
- function getComponentEntry(pageJson, pagePath, pageKey) {
90
- const componentEntry = {};
91
- function task(json, dir, rootKey) {
92
- if (!json.usingComponents) {
93
- return;
94
- }
95
-
96
- const componentKeys = Object.keys(json.usingComponents);
97
-
98
- // 如果存在依赖的组件
99
- componentKeys.forEach((key) => {
100
- if (json.usingComponents[key].startsWith('.')) {
101
- // 拼出组件所在位置的绝对路径
102
- const comValue = path.join(dir, json.usingComponents[key]);
103
- const extValue = ext(comValue, extensions);
104
- const comKey = path.resolve('/', rootKey, json.usingComponents[key]);
105
- if (!extValue) {
106
- fail(`当前page: ${pagePath} component: ${comValue}找不到入口.js或.ts文件`);
107
- process.exit(1);
108
- }
109
-
110
- componentEntry[`${comKey.slice(1)}${extValue.ext}`] = extValue.file;
111
- const comJsonPath = `${comValue}.json`;
112
- if (fs.existsSync(comJsonPath)) {
113
- const comJsonContent = JSON.parse(fs.readFileSync(comJsonPath, 'utf-8'));
114
-
115
- const comDir = path.dirname(comJsonPath); // 该页面所在的目录
116
- task(comJsonContent, comDir, path.dirname(comKey));
117
- }
118
- }
119
- });
120
- }
121
-
122
- task(pageJson, pagePath, pageKey);
123
-
124
- return componentEntry;
125
- }
126
-
127
- // 根据modules处理需要拷贝的模块,copy-webpack-plugin需要的参数
128
- function getCopyPlugin(defaultCopyConfig, modules, tmsConfig, env) {
129
- const toPath = tmsConfig.webpack.outputDir;
130
- function generatorAppJson(tmsConfig, modules) {
131
- try {
132
- return buildOutputAppJson(tmsConfig, modules);
133
- } catch (e) {
134
- fail(`动态生成app.json出现错误${e} 请检查你的配置项`);
135
- return {};
136
- }
137
- }
138
-
139
- const patterns = [];
140
- // 默认的一些配置拷贝文件 package.json、sitemap.json等
141
- defaultCopyConfig.forEach((item) => {
142
- if (fs.existsSync(resolve(item))) {
143
- patterns.push({
144
- from: resolve(item),
145
- to: resolve(`./${toPath}/${item}`),
146
- transform: {
147
- cache: true,
148
- },
149
- });
150
- }
151
- });
152
-
153
- // 拷贝模块的代码
154
- modules.forEach((item) => {
155
- patterns.push({
156
- from: resolve(item.path),
157
- to: resolve(`./${toPath}/${item.root}`),
158
- globOptions: {
159
- ignore: ['**/*.js', '*.js', '**/*.ts', '*.ts'],
160
- },
161
- transform: {
162
- cache: true,
163
- transformer: env === 'dev'
164
- ? (content, absoluteFrom) => {
165
- // 监听module.config.json的修改, 自动生成编译后的app.json
166
- if (absoluteFrom.indexOf('module.config.json') > -1) {
167
- generatorAppJson(tmsConfig, modules);
168
- }
169
- return content;
170
- }
171
- : content => content,
172
- },
173
- });
174
- });
175
-
176
- if (env === 'dev') {
177
- // 拷贝app.json时,自动生成编译后的app.json
178
- const appJsonConfig = ['app.json'];
179
- appJsonConfig.forEach((item) => {
180
- patterns.push({
181
- from: resolve(item),
182
- to: resolve(`./${toPath}/${item}`),
183
- transform: {
184
- cache: true,
185
- transformer: () => {
186
- const appJson = generatorAppJson(tmsConfig, modules);
187
- return JSON.stringify(appJson, null, 2);
188
- },
189
- },
190
- });
191
- });
192
- }
193
-
194
- return patterns;
195
- }
196
-
197
- // dev时,给webpack注入相应的事件
198
- const setupDevWebPackHooks = (context, firstDone) => {
199
- let tempFirstDone = true;
200
-
201
- const invalid = () => {
202
- // eslint-disable-next-line
203
- context.stats = undefined;
204
- };
205
-
206
- const done = (stats) => {
207
- // eslint-disable-next-line
208
- context.stats = stats;
209
-
210
- process.nextTick(() => {
211
- const { stats } = context;
212
- if (!stats) return;
213
-
214
- if (tempFirstDone) {
215
- tempFirstDone = false;
216
- firstDone();
217
- }
218
- });
219
- };
220
- const { compiler } = context;
221
-
222
- compiler.hooks.watchRun.tap('miniprogram-dev', invalid);
223
- compiler.hooks.invalid.tap('miniprogram-dev', invalid);
224
- compiler.hooks.done.tap('miniprogram-dev', done);
225
- };
226
-
227
- const stringified = raw => ({
228
- 'process.env': Object.keys(raw).reduce(
229
- (env, key) => {
230
- // eslint-disable-next-line
231
- env[key] = JSON.stringify(raw[key]);
232
- return env;
233
- },
234
- {},
235
- ),
236
- });
237
-
238
- module.exports = {
239
- getCopyPlugin,
240
- setupDevWebPackHooks,
241
- getEntry,
242
- stringified,
243
- getAlias,
244
- };