@tmsfe/tmskit 0.0.42 → 0.0.44

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
@@ -505,6 +505,8 @@ var defaultTmsConfig = {
505
505
  dependencies: {},
506
506
  /** 编译输出文件夹位置 */
507
507
  outputDir: 'dist',
508
+ /** 是否在编译前清空输出目录 */
509
+ cleanOutputDirBeforeCompile: true,
508
510
  /** 源码监听路径 */
509
511
  sourceDir: './',
510
512
  /** 静态资源目录 */
@@ -540,6 +542,28 @@ var defaultTmsConfig = {
540
542
  }
541
543
  };
542
544
 
545
+ const global$c = {
546
+ data: {},
547
+ setData(...args) {
548
+ if (args.length === 1) {
549
+ Object.keys(args[0]).forEach(k => {
550
+ if (args[0][k]) {
551
+ this.data[k] = args[0][k];
552
+ }
553
+ });
554
+ } else {
555
+ const [name, value] = args;
556
+ this.data[name] = value;
557
+ }
558
+ },
559
+ getData(name) {
560
+ return this.data[name];
561
+ }
562
+ };
563
+ var global_1 = {
564
+ global: global$c
565
+ };
566
+
543
567
  /**
544
568
  * 用来读取处理tms.config.js与module.config.json字段
545
569
  */
@@ -562,6 +586,9 @@ var defaultTmsConfig = {
562
586
  getAbsolutePath
563
587
  } = widgets;
564
588
  const defaultTmsConfig$1 = defaultTmsConfig;
589
+ const {
590
+ global
591
+ } = global_1;
565
592
  const {
566
593
  fail
567
594
  } = log$1;
@@ -576,8 +603,11 @@ var defaultTmsConfig = {
576
603
  fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
577
604
  process.exit(1);
578
605
  }
606
+ const isDev = global.getData('isDev');
579
607
  const tmsConfigFn = require(tmsConfigPath);
580
- const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn;
608
+ const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn({
609
+ isDev
610
+ }) : tmsConfigFn;
581
611
 
582
612
  // 合并默认值
583
613
  return loadash.mergeWith({}, defaultTmsConfig$1, tmsConfig);
@@ -591,8 +621,12 @@ var defaultTmsConfig = {
591
621
  let tmsPrivateCf = {};
592
622
  const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
593
623
  if (fs.existsSync(tmsPrivatePath)) {
624
+ const isDev = global.getData('isDev');
625
+ console.log(isDev, 'isDev');
594
626
  const tmsPrivateFn = require(tmsPrivatePath);
595
- tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn() : tmsPrivateFn;
627
+ tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn({
628
+ isDev
629
+ }) : tmsPrivateFn;
596
630
  }
597
631
  return tmsPrivateCf;
598
632
  };
@@ -1308,28 +1342,6 @@ var extendCmd = {
1308
1342
  loadExtendCmd: loadExtendCmd$1
1309
1343
  };
1310
1344
 
1311
- const global$c = {
1312
- data: {},
1313
- setData(...args) {
1314
- if (args.length === 1) {
1315
- Object.keys(args[0]).forEach(k => {
1316
- if (args[0][k]) {
1317
- this.data[k] = args[0][k];
1318
- }
1319
- });
1320
- } else {
1321
- const [name, value] = args;
1322
- this.data[name] = value;
1323
- }
1324
- },
1325
- getData(name) {
1326
- return this.data[name];
1327
- }
1328
- };
1329
- var global_1 = {
1330
- global: global$c
1331
- };
1332
-
1333
1345
  const {
1334
1346
  fail: fail$7
1335
1347
  } = log$1;
@@ -3289,7 +3301,9 @@ async function dev$3(tmsConfig, targetModules) {
3289
3301
  noCache
3290
3302
  } = global$4.getData('cmdOptions');
3291
3303
  if (noCache) {
3292
- shelljs$1.rm('-rf', resolve$9(tmsConfig.outputDir));
3304
+ if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
3305
+ shelljs$1.rm('-rf', resolve$9(tmsConfig.outputDir));
3306
+ }
3293
3307
  shelljs$1.rm('-rf', MODULE_CODE_DIR);
3294
3308
  shelljs$1.rm('-rf', NODE_MODULES_DIR);
3295
3309
  }
@@ -3342,7 +3356,9 @@ const {
3342
3356
  async function build$1(tmsConfig, targetModules) {
3343
3357
  var _tmsConfig$hooks;
3344
3358
  // 开始构建前,清理输出目录
3345
- await shelljs.rm('-rf', resolve$8(tmsConfig.outputDir));
3359
+ if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
3360
+ await shelljs.rm('-rf', resolve$8(tmsConfig.outputDir));
3361
+ }
3346
3362
  const {
3347
3363
  modules: newModules
3348
3364
  } = await init$1(tmsConfig, targetModules);
@@ -3999,6 +4015,10 @@ const getSpecificModuleNames = (moduleArg, modules) => {
3999
4015
  return all.map(item => item.moduleName);
4000
4016
  };
4001
4017
  async function run(commandName, cmdOptions) {
4018
+ if (['dev', 'build'].includes(commandName)) {
4019
+ // 先缓存环境,因为tmsConfig可能会用到
4020
+ global.setData('isDev', commandName === 'dev');
4021
+ }
4002
4022
  // 用户本地的配置
4003
4023
  const tmsConfig = getTmsConfig$1();
4004
4024
  try {
@@ -4053,7 +4073,6 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
4053
4073
  });
4054
4074
  return;
4055
4075
  case 'dev':
4056
- global.setData('isDev', true);
4057
4076
  dev(tmsConfig, newModules);
4058
4077
  report$1('run:dev', {
4059
4078
  appName: tmsConfig.appName
@@ -4066,7 +4085,6 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
4066
4085
  });
4067
4086
  return;
4068
4087
  case 'build':
4069
- global.setData('isDev', false);
4070
4088
  build(tmsConfig, newModules);
4071
4089
  report$1('run:build', {
4072
4090
  appName: tmsConfig.appName
@@ -4179,7 +4197,7 @@ var entry = [{
4179
4197
 
4180
4198
  var require$$12 = {
4181
4199
  name: "@tmsfe/tmskit",
4182
- version: "0.0.42",
4200
+ version: "0.0.44",
4183
4201
  description: "tmskit",
4184
4202
  main: "dist/index.cjs",
4185
4203
  bin: {
@@ -4238,7 +4256,7 @@ var require$$12 = {
4238
4256
  lodash: "^4.17.21",
4239
4257
  metalsmith: "^2.3.0",
4240
4258
  minimatch: "^5.1.0",
4241
- "miniprogram-ci": "1.8.25",
4259
+ "miniprogram-ci": "2.1.14",
4242
4260
  moment: "^2.29.2",
4243
4261
  "object-assign": "^4.0.1",
4244
4262
  ora: "^5.4.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
4
4
  "description": "tmskit",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {
@@ -59,7 +59,7 @@
59
59
  "lodash": "^4.17.21",
60
60
  "metalsmith": "^2.3.0",
61
61
  "minimatch": "^5.1.0",
62
- "miniprogram-ci": "1.8.25",
62
+ "miniprogram-ci": "2.1.14",
63
63
  "moment": "^2.29.2",
64
64
  "object-assign": "^4.0.1",
65
65
  "ora": "^5.4.1",
@@ -9,6 +9,8 @@ module.exports = {
9
9
  dependencies: {},
10
10
  /** 编译输出文件夹位置 */
11
11
  outputDir: 'dist',
12
+ /** 是否在编译前清空输出目录 */
13
+ cleanOutputDirBeforeCompile: true,
12
14
  /** 源码监听路径 */
13
15
  sourceDir: './',
14
16
  /** 静态资源目录 */
@@ -10,6 +10,7 @@ const JSON5 = require('json5');
10
10
  const { TMS_CONFIG_FILENAME, MODULE_CONFIG_FILENAME, TMS_PRIVATE_FILENAME } = require('../config/constant');
11
11
  const { resolve, isObject, isArray, getAbsolutePath } = require('../utils/widgets');
12
12
  const defaultTmsConfig = require('../config/defaultTmsConfig');
13
+ const { global } = require('../utils/global');
13
14
  const { fail } = require('../utils/log');
14
15
 
15
16
  /**
@@ -22,8 +23,9 @@ const readTmsConfig = function (configPath) {
22
23
  fail(`${path.dirname(tmsConfigPath)}没有找到tms.config.js,请进行配置`);
23
24
  process.exit(1);
24
25
  }
26
+ const isDev = global.getData('isDev');
25
27
  const tmsConfigFn = require(tmsConfigPath);
26
- const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn() : tmsConfigFn;
28
+ const tmsConfig = typeof tmsConfigFn === 'function' ? tmsConfigFn({ isDev }) : tmsConfigFn;
27
29
 
28
30
  // 合并默认值
29
31
  return loadash.mergeWith({}, defaultTmsConfig, tmsConfig);
@@ -38,8 +40,10 @@ const readTmsPrivateCf = function (configPath) {
38
40
  let tmsPrivateCf = {};
39
41
  const tmsPrivatePath = configPath ? `${configPath}/${TMS_PRIVATE_FILENAME}` : resolve(TMS_PRIVATE_FILENAME);
40
42
  if (fs.existsSync(tmsPrivatePath)) {
43
+ const isDev = global.getData('isDev');
44
+ console.log(isDev, 'isDev');
41
45
  const tmsPrivateFn = require(tmsPrivatePath);
42
- tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn() : tmsPrivateFn;
46
+ tmsPrivateCf = typeof tmsPrivateFn === 'function' ? tmsPrivateFn({ isDev }) : tmsPrivateFn;
43
47
  }
44
48
 
45
49
  return tmsPrivateCf;
@@ -8,7 +8,9 @@ const { global } = require('../../../utils/global');
8
8
 
9
9
  async function build(tmsConfig, targetModules) {
10
10
  // 开始构建前,清理输出目录
11
- await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
11
+ if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
12
+ await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
13
+ }
12
14
 
13
15
  const { modules: newModules } = await init(tmsConfig, targetModules);
14
16
  info('当前build有效模块', newModules.map(item => item.moduleName).sort());
@@ -31,7 +31,9 @@ function delOtherPackages(tmsConfig, targetSubPackages) {
31
31
  async function dev(tmsConfig, targetModules) {
32
32
  const { noCache } = global.getData('cmdOptions');
33
33
  if (noCache) {
34
- shelljs.rm('-rf', resolve(tmsConfig.outputDir));
34
+ if (tmsConfig.cleanOutputDirBeforeCompile !== false) {
35
+ shelljs.rm('-rf', resolve(tmsConfig.outputDir));
36
+ }
35
37
  shelljs.rm('-rf', MODULE_CODE_DIR);
36
38
  shelljs.rm('-rf', NODE_MODULES_DIR);
37
39
  }
@@ -50,6 +50,10 @@ const getSpecificModuleNames = (moduleArg, modules) => {
50
50
  };
51
51
 
52
52
  async function run(commandName, cmdOptions) {
53
+ if (['dev', 'build'].includes(commandName)) {
54
+ // 先缓存环境,因为tmsConfig可能会用到
55
+ global.setData('isDev', commandName === 'dev');
56
+ }
53
57
  // 用户本地的配置
54
58
  const tmsConfig = getTmsConfig();
55
59
  try {
@@ -101,7 +105,6 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
101
105
  report('run:init', { appName: tmsConfig.appName });
102
106
  return;
103
107
  case 'dev':
104
- global.setData('isDev', true);
105
108
  dev(tmsConfig, newModules);
106
109
  report('run:dev', { appName: tmsConfig.appName });
107
110
  return;
@@ -110,7 +113,6 @@ function otherCommands(tmsConfig, commandName, cmdOptions) {
110
113
  report('run:install', { appName: tmsConfig.appName });
111
114
  return;
112
115
  case 'build':
113
- global.setData('isDev', false);
114
116
  build(tmsConfig, newModules);
115
117
  report('run:build', { appName: tmsConfig.appName });
116
118
  return;