@tmsfe/tmskit 0.0.53 → 0.0.55

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
@@ -132,7 +132,7 @@ var log$1 = {
132
132
 
133
133
  const ora$2 = require$$0__default;
134
134
  const path$h = require$$1__default$1;
135
- const fs$k = require$$0__default$1;
135
+ const fs$j = require$$0__default$1;
136
136
  const shelljs$7 = require$$0__default$2;
137
137
  const glob = require$$4__default;
138
138
  const {
@@ -178,7 +178,7 @@ function downloadRepoForGit$1(url, dest, branch) {
178
178
  const cwd = process.cwd();
179
179
  return new Promise((resolve, reject) => {
180
180
  // 如果目标目录不存在
181
- if (fs$k.existsSync(dest)) {
181
+ if (fs$j.existsSync(dest)) {
182
182
  shelljs$7.rm('-rf', path$h.join(dest));
183
183
  }
184
184
  shelljs$7.mkdir('-p', dest);
@@ -872,7 +872,7 @@ var global_1 = {
872
872
  };
873
873
  })(tmsMpconfig);
874
874
 
875
- const fs$j = require$$0__default$1;
875
+ const fs$i = require$$0__default$1;
876
876
  const path$f = require$$1__default$1;
877
877
  const {
878
878
  info: info$j
@@ -885,12 +885,12 @@ const {
885
885
  * @param {string} dirname 目录名
886
886
  * @returns
887
887
  */
888
- const isDirEmpty = dirname => fs$j.promises.readdir(dirname).then(files => files.length === 0);
888
+ const isDirEmpty = dirname => fs$i.promises.readdir(dirname).then(files => files.length === 0);
889
889
 
890
890
  // 判断是否是文件
891
891
  const isFile = pathName => {
892
892
  try {
893
- const stat = fs$j.lstatSync(pathName);
893
+ const stat = fs$i.lstatSync(pathName);
894
894
  return stat.isFile();
895
895
  } catch {
896
896
  return false;
@@ -902,8 +902,8 @@ const isFile = pathName => {
902
902
  * @param {*} dirname 目录名
903
903
  */
904
904
  const ensureDirExist$6 = dirname => {
905
- if (!fs$j.existsSync(dirname)) {
906
- fs$j.mkdirSync(dirname, {
905
+ if (!fs$i.existsSync(dirname)) {
906
+ fs$i.mkdirSync(dirname, {
907
907
  recursive: true
908
908
  });
909
909
  }
@@ -911,19 +911,19 @@ const ensureDirExist$6 = dirname => {
911
911
 
912
912
  // 复制文件
913
913
  const copyFile = function (src, dest) {
914
- if (fs$j.existsSync(dest)) {
915
- fs$j.unlinkSync(dest);
914
+ if (fs$i.existsSync(dest)) {
915
+ fs$i.unlinkSync(dest);
916
916
  }
917
917
  const dir = path$f.dirname(dest);
918
918
  ensureDirExist$6(dir);
919
- fs$j.copyFileSync(src, dest);
919
+ fs$i.copyFileSync(src, dest);
920
920
  };
921
921
 
922
922
  // 判断文件内容是否一致,不一致再进行拷贝
923
923
  function diffContentCopyFile(originFile, destFile) {
924
- if (fs$j.existsSync(destFile)) {
925
- const depDestContent = fs$j.readFileSync(destFile, 'utf8');
926
- const depOriginContent = fs$j.readFileSync(originFile, 'utf8');
924
+ if (fs$i.existsSync(destFile)) {
925
+ const depDestContent = fs$i.readFileSync(destFile, 'utf8');
926
+ const depOriginContent = fs$i.readFileSync(originFile, 'utf8');
927
927
  if (depDestContent !== depOriginContent) {
928
928
  info$j(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
929
929
  copyFile(originFile, destFile);
@@ -940,7 +940,7 @@ function ext(filePath, extensions) {
940
940
  let extPath = '';
941
941
  // try catch需要包裹:用来处理'./lib/timer'没有后缀的情况
942
942
  try {
943
- const stat = fs$j.lstatSync(newFilePath);
943
+ const stat = fs$i.lstatSync(newFilePath);
944
944
  if (stat.isDirectory()) {
945
945
  extPath = newFilePath[newFilePath.length - 1] === '/' ? 'index' : '/index';
946
946
  newFilePath += extPath;
@@ -948,7 +948,7 @@ function ext(filePath, extensions) {
948
948
  } catch (e) {}
949
949
  for (const ext of extensions) {
950
950
  const file = newFilePath.endsWith(ext) ? newFilePath : newFilePath + ext;
951
- if (fs$j.existsSync(file)) {
951
+ if (fs$i.existsSync(file)) {
952
952
  return {
953
953
  ext,
954
954
  extPath: extPath + ext,
@@ -965,7 +965,7 @@ function ext(filePath, extensions) {
965
965
 
966
966
  // 判断文件是否在某个目录
967
967
  const fileInDir = (dir, file) => {
968
- if (!fs$j.existsSync(dir) || !fs$j.existsSync(file)) {
968
+ if (!fs$i.existsSync(dir) || !fs$i.existsSync(file)) {
969
969
  return false;
970
970
  }
971
971
  const relativePath = path$f.relative(dir, file);
@@ -977,10 +977,10 @@ const fileInDir = (dir, file) => {
977
977
  function findAllFilesOfDir(dir) {
978
978
  const list = [];
979
979
  function listFile(dir) {
980
- const arr = fs$j.readdirSync(dir);
980
+ const arr = fs$i.readdirSync(dir);
981
981
  arr.forEach(item => {
982
982
  const fullPath = path$f.join(dir, item);
983
- const stats = fs$j.statSync(fullPath);
983
+ const stats = fs$i.statSync(fullPath);
984
984
  if (stats.isDirectory()) {
985
985
  listFile(fullPath);
986
986
  } else {
@@ -1019,7 +1019,7 @@ const render$1 = (files, metalsmith, next) => {
1019
1019
  };
1020
1020
  var render_1 = render$1;
1021
1021
 
1022
- const fs$i = require$$0__default$1;
1022
+ const fs$h = require$$0__default$1;
1023
1023
  const inquirer$1 = require$$1__default$5;
1024
1024
  const {
1025
1025
  resolve: resolve$k
@@ -1034,11 +1034,11 @@ const {
1034
1034
  */
1035
1035
  const parseTemplateQuestions = dir => {
1036
1036
  let prompts = [];
1037
- if (!fs$i.existsSync(`${dir}/questions.json`)) {
1037
+ if (!fs$h.existsSync(`${dir}/questions.json`)) {
1038
1038
  return prompts;
1039
1039
  }
1040
1040
  try {
1041
- const json = JSON.parse(fs$i.readFileSync(`${dir}/questions.json`));
1041
+ const json = JSON.parse(fs$h.readFileSync(`${dir}/questions.json`));
1042
1042
  if (Array.isArray(json) && json.length > 0) {
1043
1043
  json.forEach((item, index) => {
1044
1044
  if (!isQuestionType(item)) {
@@ -1132,7 +1132,7 @@ const report$b = (name, attrs = {}) => {
1132
1132
  var report_1 = report$b;
1133
1133
 
1134
1134
  const path$e = require$$1__default$1;
1135
- const fs$h = require$$0__default$1;
1135
+ const fs$g = require$$0__default$1;
1136
1136
  const shelljs$6 = require$$0__default$2;
1137
1137
  const inquirer = require$$1__default$5;
1138
1138
  const {
@@ -1163,7 +1163,7 @@ const report$a = report_1;
1163
1163
  */
1164
1164
  async function createProjectDir(targetDir) {
1165
1165
  // 如果目录非空或者已经存在,提示用户,做选择
1166
- if (fs$h.existsSync(targetDir)) {
1166
+ if (fs$g.existsSync(targetDir)) {
1167
1167
  if (!(await io$2.isDirEmpty(targetDir))) {
1168
1168
  fail$9('该目录名已经存在,换个项目名字吧~');
1169
1169
  process.exit(1);
@@ -1183,13 +1183,13 @@ async function createProjectDir(targetDir) {
1183
1183
  function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
1184
1184
  return new Promise((resolve, reject) => {
1185
1185
  const localZipPath = `${templateDir}/${templateName}.zip`;
1186
- const stream = fs$h.createWriteStream(localZipPath);
1186
+ const stream = fs$g.createWriteStream(localZipPath);
1187
1187
  request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream).on('close', err => {
1188
1188
  if (err) {
1189
1189
  reject(err);
1190
1190
  return;
1191
1191
  }
1192
- fs$h.createReadStream(localZipPath).pipe(unzip.Extract({
1192
+ fs$g.createReadStream(localZipPath).pipe(unzip.Extract({
1193
1193
  path: templateDir
1194
1194
  })).on('close', err => {
1195
1195
  if (err) {
@@ -1221,10 +1221,10 @@ async function create(projectName) {
1221
1221
  await createProjectDir(targetDir);
1222
1222
 
1223
1223
  // 新创建缓存目录
1224
- if (fs$h.existsSync(TEMPLATE_DIR)) {
1224
+ if (fs$g.existsSync(TEMPLATE_DIR)) {
1225
1225
  shelljs$6.rm('-rf', TEMPLATE_DIR);
1226
1226
  }
1227
- fs$h.mkdirSync(TEMPLATE_DIR, {
1227
+ fs$g.mkdirSync(TEMPLATE_DIR, {
1228
1228
  recursive: true
1229
1229
  });
1230
1230
 
@@ -1235,7 +1235,7 @@ async function create(projectName) {
1235
1235
  generator(path$e.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
1236
1236
  shelljs$6.cd(projectName);
1237
1237
  const hookFilePath = resolve$j(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
1238
- if (fs$h.existsSync(hookFilePath)) {
1238
+ if (fs$g.existsSync(hookFilePath)) {
1239
1239
  const hooks = require(hookFilePath);
1240
1240
  if (hooks.afterCreate) {
1241
1241
  hooks.afterCreate.forEach(item => {
@@ -1261,7 +1261,7 @@ async function create(projectName) {
1261
1261
  }
1262
1262
  var create_1 = create;
1263
1263
 
1264
- const fs$g = require$$0__default$1;
1264
+ const fs$f = require$$0__default$1;
1265
1265
  const path$d = require$$1__default$1;
1266
1266
  const shellJs$3 = require$$0__default$2;
1267
1267
  const {
@@ -1286,9 +1286,9 @@ const {
1286
1286
  async function installCmd(npmName, cmd) {
1287
1287
  try {
1288
1288
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1289
- if (!fs$g.existsSync(cmdPackageJson)) {
1289
+ if (!fs$f.existsSync(cmdPackageJson)) {
1290
1290
  ensureDirExist$5(EXTEND_CMD);
1291
- fs$g.writeFileSync(cmdPackageJson, JSON.stringify({
1291
+ fs$f.writeFileSync(cmdPackageJson, JSON.stringify({
1292
1292
  dependencies: {}
1293
1293
  }, null, 2));
1294
1294
  }
@@ -1319,8 +1319,8 @@ async function installCmd(npmName, cmd) {
1319
1319
  function loadExtendCmd$1() {
1320
1320
  const cmdPackageJson = `${EXTEND_CMD}/package.json`;
1321
1321
  const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
1322
- if (fs$g.existsSync(cmdPackageJson)) {
1323
- const content = fs$g.readFileSync(cmdPackageJson, 'utf8');
1322
+ if (fs$f.existsSync(cmdPackageJson)) {
1323
+ const content = fs$f.readFileSync(cmdPackageJson, 'utf8');
1324
1324
  const json = JSON.parse(content);
1325
1325
  const deps = json.dependencies || {};
1326
1326
  const cmdConfigs = [];
@@ -1328,7 +1328,7 @@ function loadExtendCmd$1() {
1328
1328
  // 检索cmd的npm包
1329
1329
  if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
1330
1330
  const cmdConfig = path$d.join(cmdNpmDir, name, 'tms.config.js');
1331
- if (fs$g.existsSync(cmdConfig)) {
1331
+ if (fs$f.existsSync(cmdConfig)) {
1332
1332
  cmdConfigs.push(cmdConfig);
1333
1333
  }
1334
1334
  });
@@ -1371,7 +1371,6 @@ const {
1371
1371
  const {
1372
1372
  info: info$g
1373
1373
  } = log$1;
1374
- const fs$f = require$$0__default$1;
1375
1374
 
1376
1375
  /* eslint-disable no-param-reassign */
1377
1376
  /**
@@ -1405,35 +1404,8 @@ function handleAgentConfig$1(appJson) {
1405
1404
  info$g('已移除 agent 配置');
1406
1405
  }
1407
1406
  }
1408
-
1409
- /**
1410
- * 处理 project.config.json 中的 packOptions.include 配置
1411
- * @param {Object} appJson app.json配置对象
1412
- * @param {string} outputDir 输出目录
1413
- */
1414
- function handleProjectConfigInclude$1(appJson, outputDir) {
1415
- const projectConfigPath = resolve$i(outputDir, 'project.config.json');
1416
- if (!fs$f.existsSync(projectConfigPath)) return;
1417
- const projectConfig = require(projectConfigPath);
1418
- const hasMetaServices = hasMetaServicesSubpackage(appJson);
1419
- if (!projectConfig.packOptions) projectConfig.packOptions = {};
1420
- if (!projectConfig.packOptions.include) projectConfig.packOptions.include = [];
1421
- const existingIndex = projectConfig.packOptions.include.findIndex(item => item.type === 'folder' && item.value === 'modules/meta-services');
1422
- if (hasMetaServices && existingIndex === -1) {
1423
- projectConfig.packOptions.include.push({
1424
- type: 'folder',
1425
- value: 'modules/meta-services'
1426
- });
1427
- info$g('已添加 meta-services 到 project.config.json');
1428
- } else if (!hasMetaServices && existingIndex !== -1) {
1429
- projectConfig.packOptions.include.splice(existingIndex, 1);
1430
- info$g('已从 project.config.json 移除 meta-services');
1431
- }
1432
- fs$f.writeFileSync(projectConfigPath, JSON.stringify(projectConfig, null, 2));
1433
- }
1434
1407
  var handleAgentConfig_1 = {
1435
- handleAgentConfig: handleAgentConfig$1,
1436
- handleProjectConfigInclude: handleProjectConfigInclude$1
1408
+ handleAgentConfig: handleAgentConfig$1
1437
1409
  };
1438
1410
 
1439
1411
  /**
@@ -1463,8 +1435,7 @@ const {
1463
1435
  } = global_1;
1464
1436
  const report$9 = report_1;
1465
1437
  const {
1466
- handleAgentConfig,
1467
- handleProjectConfigInclude
1438
+ handleAgentConfig
1468
1439
  } = handleAgentConfig_1;
1469
1440
 
1470
1441
  /**
@@ -1643,8 +1614,6 @@ async function buildOutputAppJson$3(tmsConfig, modules) {
1643
1614
  fixAppJson(appJson);
1644
1615
  // 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除
1645
1616
  handleAgentConfig(appJson);
1646
- // 处理 project.config.json 中的 packOptions.include 配置
1647
- handleProjectConfigInclude(appJson, tmsConfig.outputDir);
1648
1617
  // 更新主包,需在subpackages处理完成后执行, pages/
1649
1618
  updateMainPackages(appJson, tmsConfig.mainPackages);
1650
1619
 
@@ -3227,6 +3196,10 @@ var dev$4 = async (tmsConfig, modules, isDev = true) => {
3227
3196
  }
3228
3197
  return `!${resolve$a(srcModulePath, newPath)}/**/*`;
3229
3198
  });
3199
+
3200
+ // 构建时排除 README 文件,减小包体积(仅本地 dev 保留)
3201
+ excludes.push(`!${srcModulePath}/**/README.md`);
3202
+ excludes.push(`!${srcModulePath}/**/readme.md`);
3230
3203
  const moduleConfigPath = `${srcModulePath}/**/module.config.json`;
3231
3204
  const moduleConfigGlob = tmsConfig.isKeepModuleConfig ? `${moduleConfigPath}` : `!${moduleConfigPath}`;
3232
3205
  mergeMap(compileTasksMap, compile(tmsConfig, {
@@ -4274,7 +4247,7 @@ var entry = [{
4274
4247
 
4275
4248
  var require$$12 = {
4276
4249
  name: "@tmsfe/tmskit",
4277
- version: "0.0.53",
4250
+ version: "0.0.55",
4278
4251
  description: "tmskit",
4279
4252
  main: "dist/index.cjs",
4280
4253
  bin: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tmskit",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "tmskit",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {
@@ -72,6 +72,10 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
72
72
  return `!${resolve(srcModulePath, newPath)}/**/*`;
73
73
  });
74
74
 
75
+ // 构建时排除 README 文件,减小包体积(仅本地 dev 保留)
76
+ excludes.push(`!${srcModulePath}/**/README.md`);
77
+ excludes.push(`!${srcModulePath}/**/readme.md`);
78
+
75
79
  const moduleConfigPath = `${srcModulePath}/**/module.config.json`;
76
80
 
77
81
  const moduleConfigGlob = tmsConfig.isKeepModuleConfig ? `${moduleConfigPath}` : `!${moduleConfigPath}`;
@@ -10,7 +10,7 @@ const { resolve, filterField } = require('../utils/widgets');
10
10
  const { handleError } = require('./handleError');
11
11
  const { global } = require('../utils/global');
12
12
  const report = require('../core/report');
13
- const { handleAgentConfig, handleProjectConfigInclude } = require('./handleAgentConfig');
13
+ const { handleAgentConfig } = require('./handleAgentConfig');
14
14
 
15
15
 
16
16
  /**
@@ -194,8 +194,6 @@ async function buildOutputAppJson(tmsConfig, modules) {
194
194
  fixAppJson(appJson);
195
195
  // 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除
196
196
  handleAgentConfig(appJson);
197
- // 处理 project.config.json 中的 packOptions.include 配置
198
- handleProjectConfigInclude(appJson, tmsConfig.outputDir);
199
197
  // 更新主包,需在subpackages处理完成后执行, pages/
200
198
  updateMainPackages(appJson, tmsConfig.mainPackages);
201
199
 
@@ -1,6 +1,5 @@
1
1
  const { resolve } = require('../utils/widgets');
2
2
  const { info } = require('../utils/log');
3
- const fs = require('fs');
4
3
 
5
4
  /* eslint-disable no-param-reassign */
6
5
  /**
@@ -35,36 +34,6 @@ function handleAgentConfig(appJson) {
35
34
  }
36
35
  }
37
36
 
38
- /**
39
- * 处理 project.config.json 中的 packOptions.include 配置
40
- * @param {Object} appJson app.json配置对象
41
- * @param {string} outputDir 输出目录
42
- */
43
- function handleProjectConfigInclude(appJson, outputDir) {
44
- const projectConfigPath = resolve(outputDir, 'project.config.json');
45
- if (!fs.existsSync(projectConfigPath)) return;
46
-
47
- const projectConfig = require(projectConfigPath);
48
- const hasMetaServices = hasMetaServicesSubpackage(appJson);
49
-
50
- if (!projectConfig.packOptions) projectConfig.packOptions = {};
51
- if (!projectConfig.packOptions.include) projectConfig.packOptions.include = [];
52
-
53
- const existingIndex = projectConfig.packOptions.include.findIndex(item => item.type === 'folder' && item.value === 'modules/meta-services');
54
-
55
- if (hasMetaServices && existingIndex === -1) {
56
- projectConfig.packOptions.include.push({ type: 'folder', value: 'modules/meta-services' });
57
- info('已添加 meta-services 到 project.config.json');
58
- } else if (!hasMetaServices && existingIndex !== -1) {
59
- projectConfig.packOptions.include.splice(existingIndex, 1);
60
- info('已从 project.config.json 移除 meta-services');
61
- }
62
-
63
- fs.writeFileSync(projectConfigPath, JSON.stringify(projectConfig, null, 2));
64
- }
65
-
66
-
67
37
  module.exports = {
68
38
  handleAgentConfig,
69
- handleProjectConfigInclude,
70
39
  };