@modern-js/repo-generator 3.0.4 → 3.0.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.
Files changed (3) hide show
  1. package/dist/index.js +31 -19
  2. package/package.json +11 -11
  3. package/src/index.ts +156 -0
package/dist/index.js CHANGED
@@ -35757,7 +35757,7 @@ var require_nodeEnv = __commonJS({
35757
35757
  });
35758
35758
  }
35759
35759
  exports.canUseNpm = canUseNpm3;
35760
- function canUseYarn3() {
35760
+ function canUseYarn2() {
35761
35761
  return __async(this, null, function* () {
35762
35762
  try {
35763
35763
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -35767,7 +35767,7 @@ var require_nodeEnv = __commonJS({
35767
35767
  }
35768
35768
  });
35769
35769
  }
35770
- exports.canUseYarn = canUseYarn3;
35770
+ exports.canUseYarn = canUseYarn2;
35771
35771
  function canUsePnpm3() {
35772
35772
  return __async(this, null, function* () {
35773
35773
  try {
@@ -44405,7 +44405,7 @@ var require_env = __commonJS({
44405
44405
  exports.canUseNpm = canUseNpm3;
44406
44406
  exports.canUseNvm = canUseNvm;
44407
44407
  exports.canUsePnpm = canUsePnpm3;
44408
- exports.canUseYarn = canUseYarn3;
44408
+ exports.canUseYarn = canUseYarn2;
44409
44409
  var _utils = require_dist();
44410
44410
  function canUseNvm() {
44411
44411
  return __async(this, null, function* () {
@@ -44432,7 +44432,7 @@ var require_env = __commonJS({
44432
44432
  }
44433
44433
  });
44434
44434
  }
44435
- function canUseYarn3() {
44435
+ function canUseYarn2() {
44436
44436
  return __async(this, null, function* () {
44437
44437
  try {
44438
44438
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45468,14 +45468,14 @@ var require_packageManager = __commonJS({
45468
45468
  value: true
45469
45469
  });
45470
45470
  exports.canUsePnpm = canUsePnpm3;
45471
- exports.canUseYarn = canUseYarn3;
45471
+ exports.canUseYarn = canUseYarn2;
45472
45472
  exports.runInstall = runInstall;
45473
45473
  var _path = _interopRequireDefault(require("path"));
45474
45474
  var _utils = require_dist();
45475
45475
  function _interopRequireDefault(obj) {
45476
45476
  return obj && obj.__esModule ? obj : { default: obj };
45477
45477
  }
45478
- function canUseYarn3() {
45478
+ function canUseYarn2() {
45479
45479
  return __async(this, null, function* () {
45480
45480
  try {
45481
45481
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45522,7 +45522,7 @@ var require_packageManager = __commonJS({
45522
45522
  params.push(`--registry=${registryUrl}`);
45523
45523
  }
45524
45524
  yield (0, _utils.execa)("pnpm", params, options);
45525
- } else if (yield canUseYarn3()) {
45525
+ } else if (yield canUseYarn2()) {
45526
45526
  const params = ["install", "--production", "--silent", "--ignore-scripts"];
45527
45527
  if (registryUrl) {
45528
45528
  params.push(`--registry=${registryUrl}`);
@@ -133817,6 +133817,26 @@ var require_compiled2 = __commonJS({
133817
133817
  }
133818
133818
  });
133819
133819
 
133820
+ // ../../../toolkit/utils/dist/commands.js
133821
+ var require_commands = __commonJS({
133822
+ "../../../toolkit/utils/dist/commands.js"(exports) {
133823
+ "use strict";
133824
+ Object.defineProperty(exports, "__esModule", { value: true });
133825
+ exports.isDevCommand = exports.getCommand = void 0;
133826
+ var getCommand = () => {
133827
+ const args = process.argv.slice(2);
133828
+ const command = args[0];
133829
+ return command;
133830
+ };
133831
+ exports.getCommand = getCommand;
133832
+ var isDevCommand = () => {
133833
+ const command = (0, exports.getCommand)();
133834
+ return command === "dev" || command === "start";
133835
+ };
133836
+ exports.isDevCommand = isDevCommand;
133837
+ }
133838
+ });
133839
+
133820
133840
  // ../../../toolkit/utils/dist/format.js
133821
133841
  var require_format2 = __commonJS({
133822
133842
  "../../../toolkit/utils/dist/format.js"(exports) {
@@ -134391,7 +134411,7 @@ var require_constants6 = __commonJS({
134391
134411
  exports.SERVER_DIR = "server";
134392
134412
  exports.SHARED_DIR = "shared";
134393
134413
  exports.CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
134394
- exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".ejs", ".mjs"];
134414
+ exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".mjs"];
134395
134415
  exports.OUTPUT_CONFIG_FILE = "modern.config.json";
134396
134416
  exports.DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
134397
134417
  exports.ROUTE_MINIFEST_FILE = "routes-manifest.json";
@@ -134882,7 +134902,7 @@ var require_nodeEnv2 = __commonJS({
134882
134902
  });
134883
134903
  }
134884
134904
  exports.canUseNpm = canUseNpm3;
134885
- function canUseYarn3() {
134905
+ function canUseYarn2() {
134886
134906
  return __async(this, null, function* () {
134887
134907
  try {
134888
134908
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -134892,7 +134912,7 @@ var require_nodeEnv2 = __commonJS({
134892
134912
  }
134893
134913
  });
134894
134914
  }
134895
- exports.canUseYarn = canUseYarn3;
134915
+ exports.canUseYarn = canUseYarn2;
134896
134916
  function canUsePnpm3() {
134897
134917
  return __async(this, null, function* () {
134898
134918
  try {
@@ -135971,6 +135991,7 @@ var require_dist2 = __commonJS({
135971
135991
  };
135972
135992
  Object.defineProperty(exports, "__esModule", { value: true });
135973
135993
  __exportStar(require_compiled2(), exports);
135994
+ __exportStar(require_commands(), exports);
135974
135995
  __exportStar(require_format2(), exports);
135975
135996
  __exportStar(require_FileSizeReporter2(), exports);
135976
135997
  __exportStar(require_printBuildError2(), exports);
@@ -138100,15 +138121,6 @@ function getPackageVersion(packageName, registry2) {
138100
138121
  spinner.stop();
138101
138122
  return stripAnsi2(result.stdout);
138102
138123
  }
138103
- if (yield (0, import_utils3.canUseYarn)()) {
138104
- const args = ["info", packageName, "version", "--silent"];
138105
- if (registry2) {
138106
- args.push(`--registry=${registry2}`);
138107
- }
138108
- const result = yield (0, import_utils3.execa)("yarn", args);
138109
- spinner.stop();
138110
- return stripAnsi2(result.stdout);
138111
- }
138112
138124
  if (yield (0, import_utils3.canUseNpm)()) {
138113
138125
  const args = ["view", packageName, "version"];
138114
138126
  if (registry2) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "3.0.4",
14
+ "version": "3.0.5",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "main": "./dist/index.js",
17
17
  "files": [
@@ -26,16 +26,16 @@
26
26
  "@types/node": "^14",
27
27
  "jest": "^27",
28
28
  "typescript": "^4",
29
- "@modern-js/generator-common": "3.0.4",
30
- "@modern-js/base-generator": "3.0.4",
31
- "@modern-js/monorepo-generator": "3.0.4",
32
- "@modern-js/module-generator": "3.0.4",
33
- "@modern-js/mwa-generator": "3.0.4",
34
- "@modern-js/utils": "2.2.0",
35
- "@modern-js/generator-utils": "3.0.4",
36
- "@modern-js/generator-plugin": "3.0.4",
37
- "@scripts/jest-config": "2.2.0",
38
- "@scripts/build": "2.2.0"
29
+ "@modern-js/generator-utils": "3.0.5",
30
+ "@modern-js/module-generator": "3.0.5",
31
+ "@modern-js/monorepo-generator": "3.0.5",
32
+ "@modern-js/generator-plugin": "3.0.5",
33
+ "@modern-js/generator-common": "3.0.5",
34
+ "@modern-js/base-generator": "3.0.5",
35
+ "@modern-js/mwa-generator": "3.0.5",
36
+ "@modern-js/utils": "2.3.0",
37
+ "@scripts/jest-config": "2.3.0",
38
+ "@scripts/build": "2.3.0"
39
39
  },
40
40
  "sideEffects": false,
41
41
  "publishConfig": {
package/src/index.ts ADDED
@@ -0,0 +1,156 @@
1
+ import path from 'path';
2
+ import { merge } from '@modern-js/utils/lodash';
3
+ import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
4
+ import { AppAPI } from '@modern-js/codesmith-api-app';
5
+ import {
6
+ i18n,
7
+ getSolutionSchema,
8
+ SolutionGenerator,
9
+ Solution,
10
+ SolutionDefaultConfig,
11
+ BaseGenerator,
12
+ getMonorepoNewActionSchema,
13
+ SubSolution,
14
+ SubSolutionGenerator,
15
+ MonorepoNewActionConfig,
16
+ getSolutionNameFromSubSolution,
17
+ getScenesSchema,
18
+ } from '@modern-js/generator-common';
19
+ import { GeneratorPlugin } from '@modern-js/generator-plugin';
20
+
21
+ const getGeneratorPath = (generator: string, distTag: string) => {
22
+ if (process.env.CODESMITH_ENV === 'development') {
23
+ return path.dirname(require.resolve(generator));
24
+ } else if (distTag) {
25
+ return `${generator}@${distTag}`;
26
+ }
27
+ return generator;
28
+ };
29
+
30
+ const mergeDefaultConfig = (context: GeneratorContext) => {
31
+ const { defaultSolution } = context.config;
32
+
33
+ if (defaultSolution) {
34
+ merge(
35
+ context.config,
36
+ { solution: defaultSolution },
37
+ SolutionDefaultConfig[defaultSolution as Solution],
38
+ );
39
+ }
40
+ };
41
+
42
+ const getNeedRunPlugin = (
43
+ context: GeneratorContext,
44
+ generatorPlugin?: GeneratorPlugin,
45
+ ): boolean => {
46
+ if (!generatorPlugin) {
47
+ return false;
48
+ }
49
+ const { extendPlugin, customPlugin } = generatorPlugin;
50
+ const { isMonorepo, solution, scenes } = context.config;
51
+ const pluginSolution = isMonorepo
52
+ ? getSolutionNameFromSubSolution(solution)
53
+ : solution;
54
+ if (!scenes || scenes === pluginSolution) {
55
+ return (
56
+ extendPlugin?.[pluginSolution] && extendPlugin[pluginSolution].length > 0
57
+ );
58
+ }
59
+ return Boolean(
60
+ customPlugin[pluginSolution]?.find(plugin => plugin.key === scenes),
61
+ );
62
+ };
63
+
64
+ const handleTemplateFile = async (
65
+ context: GeneratorContext,
66
+ generator: GeneratorCore,
67
+ appApi: AppAPI,
68
+ generatorPlugin?: GeneratorPlugin,
69
+ ) => {
70
+ const { isMonorepo } = context.config;
71
+
72
+ const { solution } = await appApi.getInputBySchemaFunc(
73
+ isMonorepo ? getMonorepoNewActionSchema : getSolutionSchema,
74
+ {
75
+ ...context.config,
76
+ customPlugin: generatorPlugin?.customPlugin,
77
+ },
78
+ );
79
+
80
+ await appApi.getInputBySchemaFunc(getScenesSchema, context.config);
81
+
82
+ const solutionGenerator =
83
+ // eslint-disable-next-line no-nested-ternary
84
+ solution === 'custom'
85
+ ? BaseGenerator
86
+ : isMonorepo
87
+ ? SubSolutionGenerator[solution as SubSolution]
88
+ : SolutionGenerator[solution as Solution];
89
+
90
+ if (!solution || !solutionGenerator) {
91
+ generator.logger.error('solution is not valid ');
92
+ }
93
+
94
+ await appApi.runSubGenerator(
95
+ getGeneratorPath(solutionGenerator, context.config.distTag),
96
+ undefined,
97
+ {
98
+ ...(isMonorepo
99
+ ? MonorepoNewActionConfig[solution as SubSolution] || {}
100
+ : {}),
101
+ ...context.config,
102
+ hasPlugin: getNeedRunPlugin(context, generatorPlugin),
103
+ generatorPlugin,
104
+ },
105
+ );
106
+ };
107
+
108
+ const handlePlugin = async (
109
+ context: GeneratorContext,
110
+ generator: GeneratorCore,
111
+ ) => {
112
+ const { plugins, registry, locale } = context.config;
113
+ const generatorPlugin = new GeneratorPlugin(
114
+ generator.logger,
115
+ generator.event,
116
+ locale,
117
+ );
118
+ await generatorPlugin.setupPlugin(plugins, registry);
119
+ return generatorPlugin;
120
+ };
121
+
122
+ export default async (context: GeneratorContext, generator: GeneratorCore) => {
123
+ process.setMaxListeners(20);
124
+
125
+ const appApi = new AppAPI(context, generator);
126
+
127
+ const { locale } = context.config;
128
+ i18n.changeLanguage({ locale });
129
+ appApi.i18n.changeLanguage({ locale });
130
+
131
+ if (!(await appApi.checkEnvironment())) {
132
+ // eslint-disable-next-line no-process-exit
133
+ process.exit(1);
134
+ }
135
+
136
+ generator.logger.debug(`start run @modern-js/repo-generator`);
137
+ generator.logger.debug(`context=${JSON.stringify(context)}`);
138
+ generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
139
+
140
+ mergeDefaultConfig(context);
141
+
142
+ let generatorPlugin;
143
+ if (context.config.plugins?.length > 0) {
144
+ generatorPlugin = await handlePlugin(context, generator);
145
+ }
146
+
147
+ try {
148
+ await handleTemplateFile(context, generator, appApi, generatorPlugin);
149
+ } catch (e) {
150
+ generator.logger.error(e);
151
+ // eslint-disable-next-line no-process-exit
152
+ process.exit(1);
153
+ }
154
+
155
+ generator.logger.debug(`forge @modern-js/repo-generator succeed `);
156
+ };