@modern-js/monorepo-tools 2.0.0-beta.3 → 2.0.0-beta.4

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/bin/modern.js +3 -1
  3. package/dist/js/modern/cli/build-watch.js +30 -5
  4. package/dist/js/modern/cli/build.js +31 -5
  5. package/dist/js/modern/cli/clear.js +30 -5
  6. package/dist/js/modern/cli/deploy.js +35 -7
  7. package/dist/js/modern/cli/index.js +1 -1
  8. package/dist/js/modern/cli/install.js +30 -5
  9. package/dist/js/modern/cli/new.js +56 -14
  10. package/dist/js/modern/commands/build-watch.js +32 -18
  11. package/dist/js/modern/commands/build.js +49 -23
  12. package/dist/js/modern/commands/clear.js +31 -15
  13. package/dist/js/modern/commands/deploy.js +38 -24
  14. package/dist/js/modern/commands/index.js +1 -1
  15. package/dist/js/modern/commands/install.js +32 -17
  16. package/dist/js/modern/constants.js +13 -9
  17. package/dist/js/modern/dag/create.js +27 -23
  18. package/dist/js/modern/dag/edge-manager.js +5 -4
  19. package/dist/js/modern/dag/index.js +6 -5
  20. package/dist/js/modern/dag/operator.js +174 -156
  21. package/dist/js/modern/dag/task.js +64 -39
  22. package/dist/js/modern/dag/utils.js +32 -38
  23. package/dist/js/modern/features/build/index.js +47 -28
  24. package/dist/js/modern/features/clear/index.js +16 -15
  25. package/dist/js/modern/features/deploy/index.js +107 -82
  26. package/dist/js/modern/features/dev/cmds.js +4 -3
  27. package/dist/js/modern/features/dev/create-task.js +43 -34
  28. package/dist/js/modern/features/dev/index.js +60 -41
  29. package/dist/js/modern/features/dev/watch-projects-state.js +47 -24
  30. package/dist/js/modern/features/install/index.js +43 -22
  31. package/dist/js/modern/hooks/index.js +6 -3
  32. package/dist/js/modern/index.js +18 -16
  33. package/dist/js/modern/locale/en.js +10 -7
  34. package/dist/js/modern/locale/index.js +6 -6
  35. package/dist/js/modern/locale/zh.js +11 -8
  36. package/dist/js/modern/log/error.js +6 -3
  37. package/dist/js/modern/log/multi-tasks-log.js +25 -34
  38. package/dist/js/modern/log/time.js +26 -11
  39. package/dist/js/modern/log/utils.js +9 -5
  40. package/dist/js/modern/package/index.js +5 -6
  41. package/dist/js/modern/parse-config/index.js +49 -22
  42. package/dist/js/modern/parse-config/monorepo.js +41 -26
  43. package/dist/js/modern/projects/check-project-change.js +59 -30
  44. package/dist/js/modern/projects/clear-memory-files.js +17 -7
  45. package/dist/js/modern/projects/get-projects-by-packages-config.js +89 -52
  46. package/dist/js/modern/projects/get-projects-by-workspace-file.js +68 -32
  47. package/dist/js/modern/projects/get-projects.js +96 -53
  48. package/dist/js/modern/type.js +0 -1
  49. package/dist/js/modern/utils/install.js +36 -19
  50. package/dist/js/modern/utils/language.js +6 -3
  51. package/dist/js/node/cli/build-watch.js +47 -10
  52. package/dist/js/node/cli/build.js +48 -10
  53. package/dist/js/node/cli/clear.js +47 -10
  54. package/dist/js/node/cli/deploy.js +52 -12
  55. package/dist/js/node/cli/index.js +22 -71
  56. package/dist/js/node/cli/install.js +47 -10
  57. package/dist/js/node/cli/new.js +73 -19
  58. package/dist/js/node/commands/build-watch.js +55 -29
  59. package/dist/js/node/commands/build.js +72 -32
  60. package/dist/js/node/commands/clear.js +53 -25
  61. package/dist/js/node/commands/deploy.js +61 -35
  62. package/dist/js/node/commands/index.js +21 -60
  63. package/dist/js/node/commands/install.js +55 -28
  64. package/dist/js/node/constants.js +28 -13
  65. package/dist/js/node/dag/create.js +44 -28
  66. package/dist/js/node/dag/edge-manager.js +21 -8
  67. package/dist/js/node/dag/index.js +26 -13
  68. package/dist/js/node/dag/operator.js +209 -174
  69. package/dist/js/node/dag/task.js +88 -46
  70. package/dist/js/node/dag/utils.js +51 -47
  71. package/dist/js/node/features/build/index.js +79 -47
  72. package/dist/js/node/features/clear/index.js +44 -28
  73. package/dist/js/node/features/deploy/index.js +135 -104
  74. package/dist/js/node/features/dev/cmds.js +22 -9
  75. package/dist/js/node/features/dev/create-task.js +75 -51
  76. package/dist/js/node/features/dev/index.js +94 -58
  77. package/dist/js/node/features/dev/watch-projects-state.js +69 -30
  78. package/dist/js/node/features/install/index.js +78 -41
  79. package/dist/js/node/hooks/index.js +23 -8
  80. package/dist/js/node/index.js +51 -32
  81. package/dist/js/node/locale/en.js +26 -11
  82. package/dist/js/node/locale/index.js +27 -15
  83. package/dist/js/node/locale/zh.js +27 -12
  84. package/dist/js/node/log/error.js +22 -7
  85. package/dist/js/node/log/multi-tasks-log.js +44 -41
  86. package/dist/js/node/log/time.js +43 -18
  87. package/dist/js/node/log/utils.js +26 -10
  88. package/dist/js/node/package/index.js +21 -10
  89. package/dist/js/node/parse-config/index.js +73 -30
  90. package/dist/js/node/parse-config/monorepo.js +71 -44
  91. package/dist/js/node/projects/check-project-change.js +96 -56
  92. package/dist/js/node/projects/clear-memory-files.js +38 -15
  93. package/dist/js/node/projects/get-projects-by-packages-config.js +116 -65
  94. package/dist/js/node/projects/get-projects-by-workspace-file.js +103 -55
  95. package/dist/js/node/projects/get-projects.js +109 -61
  96. package/dist/js/node/type.js +0 -5
  97. package/dist/js/node/utils/install.js +63 -31
  98. package/dist/js/node/utils/language.js +24 -8
  99. package/dist/types/dag/operator.d.ts +3 -0
  100. package/dist/types/dag/utils.d.ts +1 -0
  101. package/dist/types/features/dev/index.d.ts +1 -0
  102. package/dist/types/index.d.ts +2 -0
  103. package/dist/types/projects/get-projects.d.ts +1 -0
  104. package/package.json +12 -19
@@ -1,29 +1,49 @@
1
- import * as path from 'path';
2
- import { fs, yaml } from '@modern-js/utils';
3
- import { JsonFile } from '@rushstack/node-core-library';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import * as path from "path";
22
+ import { fs, yaml } from "@modern-js/utils";
23
+ import { JsonFile } from "@rushstack/node-core-library";
4
24
  import { WORKSPACE_FILE } from "../../constants";
5
25
  import { installByPackageManager } from "../../utils/install";
6
26
  const replaceWorkspaces = ({
7
27
  rootPath,
8
28
  projectsInWorkspaces
9
29
  }) => {
10
- // pnpm
30
+ var _a;
11
31
  const pnpmWsFilePath = path.join(rootPath, WORKSPACE_FILE.PNPM);
12
32
  if (fs.existsSync(pnpmWsFilePath)) {
13
- const pnpmWorkspace = fs.readFileSync(pnpmWsFilePath, 'utf-8');
33
+ const pnpmWorkspace = fs.readFileSync(pnpmWsFilePath, "utf-8");
14
34
  const originalPnpmWorkspaces = yaml.load(pnpmWorkspace);
15
- fs.writeFileSync(pnpmWsFilePath, yaml.dump({
16
- packages: projectsInWorkspaces
17
- }));
35
+ fs.writeFileSync(
36
+ pnpmWsFilePath,
37
+ yaml.dump({ packages: projectsInWorkspaces })
38
+ );
18
39
  return () => {
19
40
  yaml.dump(originalPnpmWorkspaces);
20
41
  };
21
42
  }
22
43
  const pkgFilePath = path.join(rootPath, WORKSPACE_FILE.YARN);
23
44
  if (fs.existsSync(pkgFilePath)) {
24
- var _pkg$workspaces;
25
45
  const pkg = JsonFile.load(pkgFilePath);
26
- if (pkg !== null && pkg !== void 0 && (_pkg$workspaces = pkg.workspaces) !== null && _pkg$workspaces !== void 0 && _pkg$workspaces.packages) {
46
+ if ((_a = pkg == null ? void 0 : pkg.workspaces) == null ? void 0 : _a.packages) {
27
47
  const originalPkg = pkg;
28
48
  pkg.workspaces.packages = projectsInWorkspaces;
29
49
  JsonFile.save(pkg, pkgFilePath);
@@ -34,30 +54,31 @@ const replaceWorkspaces = ({
34
54
  }
35
55
  return false;
36
56
  };
37
- export const runInstallTask = async (projectNames, operator, config) => {
38
- const {
39
- rootPath,
40
- packageManager
41
- } = config;
57
+ const runInstallTask = (projectNames, operator, config) => __async(void 0, null, function* () {
58
+ const { rootPath, packageManager } = config;
42
59
  let projectsInWorkspaces = [];
43
60
  if (projectNames.length === 0) {
44
- console.info('install all projects');
61
+ console.info("install all projects");
45
62
  return;
46
63
  }
47
64
  for (const projectName of projectNames) {
48
65
  const allDeps = operator.getNodeAllDependencyData(projectName);
49
- projectsInWorkspaces = [...projectsInWorkspaces, path.relative(rootPath, operator.getNodeData(projectName).extra.path), ...allDeps.map(p => path.relative(rootPath, p.extra.path))];
66
+ projectsInWorkspaces = [
67
+ ...projectsInWorkspaces,
68
+ path.relative(rootPath, operator.getNodeData(projectName).extra.path),
69
+ ...allDeps.map((p) => path.relative(rootPath, p.extra.path))
70
+ ];
50
71
  }
51
72
  const noDupProjectList = Array.from(new Set(projectsInWorkspaces));
52
73
  const restorWorkspace = replaceWorkspaces({
53
74
  rootPath,
54
75
  projectsInWorkspaces: noDupProjectList
55
76
  });
56
- await installByPackageManager(packageManager, {
57
- rootPath,
58
- removeLock: true
59
- });
77
+ yield installByPackageManager(packageManager, { rootPath, removeLock: true });
60
78
  if (restorWorkspace) {
61
79
  restorWorkspace();
62
80
  }
63
- };
81
+ });
82
+ export {
83
+ runInstallTask
84
+ };
@@ -1,5 +1,8 @@
1
- import { createAsyncWorkflow } from '@modern-js/plugin';
1
+ import { createAsyncWorkflow } from "@modern-js/plugin";
2
2
  const afterMonorepoDeploy = createAsyncWorkflow();
3
- export const hooks = {
3
+ const hooks = {
4
4
  afterMonorepoDeploy
5
- };
5
+ };
6
+ export {
7
+ hooks
8
+ };
@@ -1,30 +1,32 @@
1
- import ChangesetPlugin from '@modern-js/plugin-changeset';
2
- import LintPlugin from '@modern-js/plugin-lint';
3
- import { Import } from '@modern-js/utils';
1
+ import ChangesetPlugin from "@modern-js/plugin-changeset";
2
+ import LintPlugin from "@modern-js/plugin-lint";
3
+ import { Import } from "@modern-js/utils";
4
4
  import { i18n } from "./locale";
5
5
  import { newCli, deployCli, clearCli } from "./cli";
6
6
  import { getLocaleLanguage } from "./utils/language";
7
7
  import { hooks } from "./hooks";
8
- const upgradeModel = Import.lazy('@modern-js/upgrade', require);
9
- export default (() => ({
10
- name: '@modern-js/monorepo-tools',
8
+ const upgradeModel = Import.lazy(
9
+ "@modern-js/upgrade",
10
+ require
11
+ );
12
+ var src_default = () => ({
13
+ name: "@modern-js/monorepo-tools",
11
14
  usePlugins: [ChangesetPlugin(), LintPlugin()],
12
15
  registerHook: hooks,
13
- setup: api => {
16
+ setup: (api) => {
14
17
  const locale = getLocaleLanguage();
15
- i18n.changeLanguage({
16
- locale
17
- });
18
+ i18n.changeLanguage({ locale });
18
19
  return {
19
- commands({
20
- program
21
- }) {
20
+ commands({ program }) {
22
21
  clearCli(program, api);
23
22
  deployCli(program, api);
24
23
  newCli(program, locale);
25
- upgradeModel.defineCommand(program.command('upgrade'));
24
+ upgradeModel.defineCommand(program.command("upgrade"));
26
25
  }
27
26
  };
28
27
  },
29
- post: ['@modern-js/plugin-changeset']
30
- }));
28
+ post: ["@modern-js/plugin-changeset"]
29
+ });
30
+ export {
31
+ src_default as default
32
+ };
@@ -1,12 +1,15 @@
1
- export const EN_LOCALE = {
1
+ const EN_LOCALE = {
2
2
  command: {
3
3
  new: {
4
- describe: 'generator runner for monorepo project',
5
- debug: 'using debug mode to log something',
6
- config: 'set default generator config(json string)',
7
- plugin: 'use generator plugin to create new sub-solution project or customize Modern.js sub-solution project',
4
+ describe: "generator runner for monorepo project",
5
+ debug: "using debug mode to log something",
6
+ config: "set default generator config(json string)",
7
+ plugin: "use generator plugin to create new sub-solution project or customize Modern.js sub-solution project",
8
8
  distTag: `use specified tag version for it's generator`,
9
- registry: 'set npm registry url to run npm command'
9
+ registry: "set npm registry url to run npm command"
10
10
  }
11
11
  }
12
- };
12
+ };
13
+ export {
14
+ EN_LOCALE
15
+ };
@@ -1,9 +1,9 @@
1
- import { I18n } from '@modern-js/plugin-i18n';
1
+ import { I18n } from "@modern-js/plugin-i18n";
2
2
  import { ZH_LOCALE } from "./zh";
3
3
  import { EN_LOCALE } from "./en";
4
4
  const i18n = new I18n();
5
- const localeKeys = i18n.init('zh', {
6
- zh: ZH_LOCALE,
7
- en: EN_LOCALE
8
- });
9
- export { i18n, localeKeys };
5
+ const localeKeys = i18n.init("zh", { zh: ZH_LOCALE, en: EN_LOCALE });
6
+ export {
7
+ i18n,
8
+ localeKeys
9
+ };
@@ -1,12 +1,15 @@
1
- export const ZH_LOCALE = {
1
+ const ZH_LOCALE = {
2
2
  command: {
3
3
  new: {
4
- describe: 'Monorepo 创建子项目',
5
- debug: '开启 Debug 模式,打印调试日志信息',
6
- config: '生成器运行默认配置(JSON 字符串)',
7
- plugin: '使用生成器插件创建新的工程方案子项目或定制化 Modern.js 工程方案子项目',
8
- distTag: '生成器使用特殊的 npm Tag 版本',
9
- registry: '生成器运行过程中定制 npm Registry'
4
+ describe: "Monorepo 创建子项目",
5
+ debug: "开启 Debug 模式,打印调试日志信息",
6
+ config: "生成器运行默认配置(JSON 字符串)",
7
+ plugin: "使用生成器插件创建新的工程方案子项目或定制化 Modern.js 工程方案子项目",
8
+ distTag: "生成器使用特殊的 npm Tag 版本",
9
+ registry: "生成器运行过程中定制 npm Registry"
10
10
  }
11
11
  }
12
- };
12
+ };
13
+ export {
14
+ ZH_LOCALE
15
+ };
@@ -1,3 +1,6 @@
1
- export const errorLog = (...rest) => {
2
- throw new Error(rest.join('\n'));
3
- };
1
+ const errorLog = (...rest) => {
2
+ throw new Error(rest.join("\n"));
3
+ };
4
+ export {
5
+ errorLog
6
+ };
@@ -1,54 +1,40 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- import { Signale } from '@modern-js/utils';
1
+ import { Signale } from "@modern-js/utils";
3
2
  import { formatLog } from "./utils";
4
3
  const createLogger = (name, config) => {
5
4
  const options = {
6
5
  scope: config.label ? config.label + name : name,
7
6
  types: {
8
7
  info: {
9
- badge: '',
10
- color: 'blue',
11
- label: ''
8
+ badge: "",
9
+ color: "blue",
10
+ label: ""
12
11
  }
13
12
  }
14
13
  };
15
14
  return new Signale(options);
16
15
  };
17
16
  const createListenHandler = (name, config) => {
18
- // const sb = new StringBuilder();
19
17
  const logger = createLogger(name, config);
20
- // eslint-disable-next-line node/prefer-global/buffer
21
- const stdout = chunk => {
22
- // console.info(chunk.toString().split(/\r\n|\n\r|\r|\n/g).length);
18
+ const stdout = (chunk) => {
23
19
  logger.info(formatLog(chunk.toString()));
24
20
  };
25
- // eslint-disable-next-line node/prefer-global/buffer
26
- const stderr = chunk => {
21
+ const stderr = (chunk) => {
27
22
  logger.error(chunk.toString());
28
- // logger.log('#####################');
29
- };
30
-
31
- return {
32
- stdout,
33
- stderr
34
23
  };
24
+ return { stdout, stderr };
35
25
  };
36
- export class MultitasksLogger {
26
+ class MultitasksLogger {
37
27
  constructor() {
38
- _defineProperty(this, "_taskNameList", void 0);
39
- _defineProperty(this, "_taskStdoutListenerMap", void 0);
40
- _defineProperty(this, "_taskStderrListenerMap", void 0);
41
- _defineProperty(this, "_taskLogConfigMap", void 0);
42
28
  this._taskNameList = [];
43
- this._taskStdoutListenerMap = new Map();
44
- this._taskStderrListenerMap = new Map();
45
- this._taskLogConfigMap = new Map();
29
+ this._taskStdoutListenerMap = /* @__PURE__ */ new Map();
30
+ this._taskStderrListenerMap = /* @__PURE__ */ new Map();
31
+ this._taskLogConfigMap = /* @__PURE__ */ new Map();
46
32
  }
47
33
  addLogProvider(name, config) {
34
+ var _a, _b;
48
35
  if (this._taskNameList.includes(name)) {
49
- var _this$_taskStdoutList, _this$_taskStderrList;
50
- (_this$_taskStdoutList = this._taskStdoutListenerMap.get(name)) === null || _this$_taskStdoutList === void 0 ? void 0 : _this$_taskStdoutList.removeAllListeners();
51
- (_this$_taskStderrList = this._taskStderrListenerMap.get(name)) === null || _this$_taskStderrList === void 0 ? void 0 : _this$_taskStderrList.removeAllListeners();
36
+ (_a = this._taskStdoutListenerMap.get(name)) == null ? void 0 : _a.removeAllListeners();
37
+ (_b = this._taskStderrListenerMap.get(name)) == null ? void 0 : _b.removeAllListeners();
52
38
  this._taskStdoutListenerMap.delete(name);
53
39
  this._taskStderrListenerMap.delete(name);
54
40
  }
@@ -59,10 +45,13 @@ export class MultitasksLogger {
59
45
  this.startListen(name);
60
46
  }
61
47
  startListen(taskName) {
62
- const listenHandler = createListenHandler(taskName, this._taskLogConfigMap.get(taskName).logConfig);
63
- this._taskStdoutListenerMap.get(taskName).on('data', listenHandler.stdout);
64
- this._taskStdoutListenerMap.get(taskName).on('error', listenHandler.stderr);
65
- this._taskStderrListenerMap.get(taskName).on('data', listenHandler.stderr);
48
+ const listenHandler = createListenHandler(
49
+ taskName,
50
+ this._taskLogConfigMap.get(taskName).logConfig
51
+ );
52
+ this._taskStdoutListenerMap.get(taskName).on("data", listenHandler.stdout);
53
+ this._taskStdoutListenerMap.get(taskName).on("error", listenHandler.stderr);
54
+ this._taskStderrListenerMap.get(taskName).on("data", listenHandler.stderr);
66
55
  }
67
56
  startListenAll() {
68
57
  for (const taskName of this._taskNameList) {
@@ -70,6 +59,8 @@ export class MultitasksLogger {
70
59
  }
71
60
  }
72
61
  finishListen() {
73
- // 是否需要
74
62
  }
75
- }
63
+ }
64
+ export {
65
+ MultitasksLogger
66
+ };
@@ -1,14 +1,29 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import { Signale } from '@modern-js/utils';
5
- export const initTimeLog = (option = {}) => new Signale(_objectSpread({
6
- interactive: true,
7
- scope: 'time-log'
8
- }, option));
9
- export const startTime = (signaleInstance, prefix = '') => {
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import { Signale } from "@modern-js/utils";
18
+ const initTimeLog = (option = {}) => new Signale(__spreadValues({ interactive: true, scope: "time-log" }, option));
19
+ const startTime = (signaleInstance, prefix = "") => {
10
20
  signaleInstance.time(prefix);
11
21
  };
12
- export const endTime = (signaleInstance, prefix = '') => {
22
+ const endTime = (signaleInstance, prefix = "") => {
13
23
  signaleInstance.timeEnd(prefix);
14
- };
24
+ };
25
+ export {
26
+ endTime,
27
+ initTimeLog,
28
+ startTime
29
+ };
@@ -1,7 +1,11 @@
1
- export const formatLog = log => {
1
+ const formatLog = (log) => {
2
2
  const strs = log.split(/\r\n|\n\r|\r|\n/g);
3
- if (strs[0].trim() === '') {
4
- return `\n${strs.slice(1).filter(s => Boolean(s)).join('\n')}`;
3
+ if (strs[0].trim() === "") {
4
+ return `
5
+ ${strs.slice(1).filter((s) => Boolean(s)).join("\n")}`;
5
6
  }
6
- return strs.filter(s => Boolean(s)).join('\n');
7
- };
7
+ return strs.filter((s) => Boolean(s)).join("\n");
8
+ };
9
+ export {
10
+ formatLog
11
+ };
@@ -1,9 +1,5 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- export class Package {
1
+ class Package {
3
2
  constructor(packageJson, packageConfigPath, rootPath) {
4
- _defineProperty(this, "json", void 0);
5
- _defineProperty(this, "configPath", void 0);
6
- _defineProperty(this, "rootPath", void 0);
7
3
  this.configPath = packageConfigPath;
8
4
  this.rootPath = rootPath;
9
5
  this.json = packageJson;
@@ -17,4 +13,7 @@ export class Package {
17
13
  get(key) {
18
14
  return this.json[key];
19
15
  }
20
- }
16
+ }
17
+ export {
18
+ Package
19
+ };
@@ -1,24 +1,51 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import * as path from 'path';
5
- import { JsonFile } from '@rushstack/node-core-library';
6
- import { getMonorepoBaseData } from "./monorepo";
7
- const defaultConfig = {
8
- // packagesMatchs: {
9
- // workspaceFile: 'pnpm-lock.yaml',
10
- // },
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
11
36
  };
12
- export const getFinalConfig = async (currentPath = process.cwd()) => {
13
- // TODO:
14
- // 1. 初始化获取信息
15
- // 2. 配置文件是否存在校验
16
-
37
+ import * as path from "path";
38
+ import { JsonFile } from "@rushstack/node-core-library";
39
+ import { getMonorepoBaseData } from "./monorepo";
40
+ const defaultConfig = {};
41
+ const getFinalConfig = (..._0) => __async(void 0, [..._0], function* (currentPath = process.cwd()) {
17
42
  const monorepo = getMonorepoBaseData(currentPath);
18
- const userConfig = await JsonFile.loadAsync(path.resolve(monorepo.rootPath, 'mono-config.json'));
19
- const config = _objectSpread(_objectSpread({}, defaultConfig), userConfig);
20
- return {
21
- monorepo,
22
- config
23
- };
24
- };
43
+ const userConfig = yield JsonFile.loadAsync(
44
+ path.resolve(monorepo.rootPath, "mono-config.json")
45
+ );
46
+ const config = __spreadValues(__spreadValues({}, defaultConfig), userConfig);
47
+ return { monorepo, config };
48
+ });
49
+ export {
50
+ getFinalConfig
51
+ };
@@ -1,50 +1,52 @@
1
- import * as path from 'path';
2
- import { FileSystem, JsonFile } from '@rushstack/node-core-library';
1
+ import * as path from "path";
2
+ import { FileSystem, JsonFile } from "@rushstack/node-core-library";
3
3
  import { WORKSPACE_FILE } from "../constants";
4
- const useLerna = monorepoRootPath => {
4
+ const useLerna = (monorepoRootPath) => {
5
5
  if (FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.LERNA))) {
6
6
  return true;
7
7
  }
8
8
  return false;
9
9
  };
10
- const useYarnWorkspaces = monorepoRootPath => {
10
+ const useYarnWorkspaces = (monorepoRootPath) => {
11
11
  if (!FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.YARN))) {
12
12
  return false;
13
13
  }
14
14
  const json = JsonFile.load(path.join(monorepoRootPath, WORKSPACE_FILE.YARN));
15
- if ('workspaces' in json && json.workspaces.packages) {
15
+ if ("workspaces" in json && json.workspaces.packages) {
16
16
  return true;
17
17
  }
18
18
  return false;
19
19
  };
20
- const usePnpmWorkspaces = monorepoRootPath => {
20
+ const usePnpmWorkspaces = (monorepoRootPath) => {
21
21
  if (FileSystem.exists(path.join(monorepoRootPath, WORKSPACE_FILE.PNPM))) {
22
22
  return true;
23
23
  }
24
24
  return false;
25
25
  };
26
- const isMonorepo = monorepoRootPath => {
26
+ const isMonorepo = (monorepoRootPath) => {
27
27
  if (usePnpmWorkspaces(monorepoRootPath) || useLerna(monorepoRootPath) || useYarnWorkspaces(monorepoRootPath)) {
28
28
  return true;
29
29
  }
30
30
  return false;
31
31
  };
32
- export const findMonorepoRoot = starFindPath => {
32
+ const findMonorepoRoot = (starFindPath) => {
33
33
  let inMonorepo = false;
34
34
  let findPath = starFindPath;
35
- while (findPath !== '/') {
35
+ while (findPath !== "/") {
36
36
  if (isMonorepo(findPath)) {
37
37
  inMonorepo = true;
38
38
  break;
39
39
  }
40
40
  findPath = path.dirname(findPath);
41
41
  }
42
- return inMonorepo ? findPath : undefined;
42
+ return inMonorepo ? findPath : void 0;
43
43
  };
44
- export const getWorkspaceFile = startFindPath => {
44
+ const getWorkspaceFile = (startFindPath) => {
45
45
  const rootPath = findMonorepoRoot(startFindPath);
46
46
  if (!rootPath) {
47
- throw new Error('[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`');
47
+ throw new Error(
48
+ "[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`"
49
+ );
48
50
  }
49
51
  if (usePnpmWorkspaces(rootPath)) {
50
52
  return WORKSPACE_FILE.PNPM;
@@ -53,36 +55,49 @@ export const getWorkspaceFile = startFindPath => {
53
55
  } else if (useYarnWorkspaces(rootPath)) {
54
56
  return WORKSPACE_FILE.YARN;
55
57
  } else {
56
- throw new Error('[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`');
58
+ throw new Error(
59
+ "[Auto Find Mode]: not find any monorepo workspace file, you can set `packagesMatchs.workspaceFile`"
60
+ );
57
61
  }
58
62
  };
59
- export const packageManagerFlag = {
60
- pnpm: [WORKSPACE_FILE.PNPM, 'pnpm-lock.yaml'],
61
- yarn: ['yarn.lock', useYarnWorkspaces],
63
+ const packageManagerFlag = {
64
+ pnpm: [WORKSPACE_FILE.PNPM, "pnpm-lock.yaml"],
65
+ yarn: ["yarn.lock", useYarnWorkspaces],
62
66
  npm: [() => true]
63
67
  };
64
- const usePnpmPackageManager = monorepoRootPath => packageManagerFlag.pnpm.some(flag => FileSystem.exists(path.join(monorepoRootPath, flag)));
65
- const useYarnPackageManager = monorepoRootPath => packageManagerFlag.yarn.some(flag => {
66
- if (typeof flag === 'function') {
68
+ const usePnpmPackageManager = (monorepoRootPath) => packageManagerFlag.pnpm.some(
69
+ (flag) => FileSystem.exists(path.join(monorepoRootPath, flag))
70
+ );
71
+ const useYarnPackageManager = (monorepoRootPath) => packageManagerFlag.yarn.some((flag) => {
72
+ if (typeof flag === "function") {
67
73
  return flag(monorepoRootPath);
68
74
  }
69
75
  return FileSystem.exists(path.join(monorepoRootPath, flag));
70
76
  });
71
- export const getPackageManager = monorepoRootPath => {
77
+ const getPackageManager = (monorepoRootPath) => {
72
78
  if (usePnpmPackageManager(monorepoRootPath)) {
73
- return 'pnpm';
79
+ return "pnpm";
74
80
  } else if (useYarnPackageManager(monorepoRootPath)) {
75
- return 'yarn';
81
+ return "yarn";
76
82
  }
77
- return 'npm';
83
+ return "npm";
78
84
  };
79
- export const getMonorepoBaseData = (root = process.cwd()) => {
85
+ const getMonorepoBaseData = (root = process.cwd()) => {
80
86
  const rootPath = findMonorepoRoot(root);
81
87
  if (!rootPath) {
82
- throw new Error('not find any monorepo, you can add lerna、pnpm or yarn workspace file');
88
+ throw new Error(
89
+ "not find any monorepo, you can add lerna、pnpm or yarn workspace file"
90
+ );
83
91
  }
84
92
  return {
85
93
  rootPath,
86
94
  packageManager: getPackageManager(rootPath)
87
95
  };
88
- };
96
+ };
97
+ export {
98
+ findMonorepoRoot,
99
+ getMonorepoBaseData,
100
+ getPackageManager,
101
+ getWorkspaceFile,
102
+ packageManagerFlag
103
+ };