@modern-js/base-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.
package/dist/index.js CHANGED
@@ -35762,7 +35762,7 @@ var require_nodeEnv = __commonJS({
35762
35762
  });
35763
35763
  }
35764
35764
  exports.canUseNpm = canUseNpm;
35765
- function canUseYarn() {
35765
+ function canUseYarn2() {
35766
35766
  return __async(this, null, function* () {
35767
35767
  try {
35768
35768
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -35772,7 +35772,7 @@ var require_nodeEnv = __commonJS({
35772
35772
  }
35773
35773
  });
35774
35774
  }
35775
- exports.canUseYarn = canUseYarn;
35775
+ exports.canUseYarn = canUseYarn2;
35776
35776
  function canUsePnpm() {
35777
35777
  return __async(this, null, function* () {
35778
35778
  try {
@@ -44410,7 +44410,7 @@ var require_env = __commonJS({
44410
44410
  exports.canUseNpm = canUseNpm;
44411
44411
  exports.canUseNvm = canUseNvm;
44412
44412
  exports.canUsePnpm = canUsePnpm;
44413
- exports.canUseYarn = canUseYarn;
44413
+ exports.canUseYarn = canUseYarn2;
44414
44414
  var _utils = require_dist();
44415
44415
  function canUseNvm() {
44416
44416
  return __async(this, null, function* () {
@@ -44437,7 +44437,7 @@ var require_env = __commonJS({
44437
44437
  }
44438
44438
  });
44439
44439
  }
44440
- function canUseYarn() {
44440
+ function canUseYarn2() {
44441
44441
  return __async(this, null, function* () {
44442
44442
  try {
44443
44443
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45473,14 +45473,14 @@ var require_packageManager = __commonJS({
45473
45473
  value: true
45474
45474
  });
45475
45475
  exports.canUsePnpm = canUsePnpm;
45476
- exports.canUseYarn = canUseYarn;
45476
+ exports.canUseYarn = canUseYarn2;
45477
45477
  exports.runInstall = runInstall;
45478
45478
  var _path = _interopRequireDefault(require("path"));
45479
45479
  var _utils = require_dist();
45480
45480
  function _interopRequireDefault(obj) {
45481
45481
  return obj && obj.__esModule ? obj : { default: obj };
45482
45482
  }
45483
- function canUseYarn() {
45483
+ function canUseYarn2() {
45484
45484
  return __async(this, null, function* () {
45485
45485
  try {
45486
45486
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45527,7 +45527,7 @@ var require_packageManager = __commonJS({
45527
45527
  params.push(`--registry=${registryUrl}`);
45528
45528
  }
45529
45529
  yield (0, _utils.execa)("pnpm", params, options);
45530
- } else if (yield canUseYarn()) {
45530
+ } else if (yield canUseYarn2()) {
45531
45531
  const params = ["install", "--production", "--silent", "--ignore-scripts"];
45532
45532
  if (registryUrl) {
45533
45533
  params.push(`--registry=${registryUrl}`);
@@ -133829,6 +133829,26 @@ var require_compiled2 = __commonJS({
133829
133829
  }
133830
133830
  });
133831
133831
 
133832
+ // ../../../toolkit/utils/dist/commands.js
133833
+ var require_commands = __commonJS({
133834
+ "../../../toolkit/utils/dist/commands.js"(exports) {
133835
+ "use strict";
133836
+ Object.defineProperty(exports, "__esModule", { value: true });
133837
+ exports.isDevCommand = exports.getCommand = void 0;
133838
+ var getCommand = () => {
133839
+ const args = process.argv.slice(2);
133840
+ const command = args[0];
133841
+ return command;
133842
+ };
133843
+ exports.getCommand = getCommand;
133844
+ var isDevCommand = () => {
133845
+ const command = (0, exports.getCommand)();
133846
+ return command === "dev" || command === "start";
133847
+ };
133848
+ exports.isDevCommand = isDevCommand;
133849
+ }
133850
+ });
133851
+
133832
133852
  // ../../../toolkit/utils/dist/format.js
133833
133853
  var require_format2 = __commonJS({
133834
133854
  "../../../toolkit/utils/dist/format.js"(exports) {
@@ -134403,7 +134423,7 @@ var require_constants6 = __commonJS({
134403
134423
  exports.SERVER_DIR = "server";
134404
134424
  exports.SHARED_DIR = "shared";
134405
134425
  exports.CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
134406
- exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".ejs", ".mjs"];
134426
+ exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".mjs"];
134407
134427
  exports.OUTPUT_CONFIG_FILE = "modern.config.json";
134408
134428
  exports.DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
134409
134429
  exports.ROUTE_MINIFEST_FILE = "routes-manifest.json";
@@ -134894,7 +134914,7 @@ var require_nodeEnv2 = __commonJS({
134894
134914
  });
134895
134915
  }
134896
134916
  exports.canUseNpm = canUseNpm;
134897
- function canUseYarn() {
134917
+ function canUseYarn2() {
134898
134918
  return __async(this, null, function* () {
134899
134919
  try {
134900
134920
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -134904,7 +134924,7 @@ var require_nodeEnv2 = __commonJS({
134904
134924
  }
134905
134925
  });
134906
134926
  }
134907
- exports.canUseYarn = canUseYarn;
134927
+ exports.canUseYarn = canUseYarn2;
134908
134928
  function canUsePnpm() {
134909
134929
  return __async(this, null, function* () {
134910
134930
  try {
@@ -135983,6 +136003,7 @@ var require_dist2 = __commonJS({
135983
136003
  };
135984
136004
  Object.defineProperty(exports, "__esModule", { value: true });
135985
136005
  __exportStar(require_compiled2(), exports);
136006
+ __exportStar(require_commands(), exports);
135986
136007
  __exportStar(require_format2(), exports);
135987
136008
  __exportStar(require_FileSizeReporter2(), exports);
135988
136009
  __exportStar(require_printBuildError2(), exports);
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
  "types": "./src/index.ts",
17
17
  "main": "./dist/index.js",
@@ -27,10 +27,10 @@
27
27
  "@types/node": "^14",
28
28
  "jest": "^27",
29
29
  "typescript": "^4",
30
- "@scripts/jest-config": "2.2.0",
31
- "@scripts/build": "2.2.0",
32
- "@modern-js/generator-common": "3.0.4",
33
- "@modern-js/generator-utils": "3.0.4"
30
+ "@modern-js/generator-utils": "3.0.5",
31
+ "@modern-js/generator-common": "3.0.5",
32
+ "@scripts/jest-config": "2.3.0",
33
+ "@scripts/build": "2.3.0"
34
34
  },
35
35
  "sideEffects": false,
36
36
  "publishConfig": {
package/src/index.ts ADDED
@@ -0,0 +1,82 @@
1
+ import path from 'path';
2
+ import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
3
+ import { AppAPI } from '@modern-js/codesmith-api-app';
4
+ import { getBaseSchema, PackageManager } from '@modern-js/generator-common';
5
+ import { fs } from '@modern-js/generator-utils';
6
+
7
+ const handleTemplateFile = async (
8
+ context: GeneratorContext,
9
+ generator: GeneratorCore,
10
+ appApi: AppAPI,
11
+ ) => {
12
+ const { hasPlugin, generatorPlugin, ...extra } = context.config;
13
+
14
+ let ans: Record<string, unknown> = {};
15
+ if (hasPlugin) {
16
+ await generatorPlugin.installPlugins('custom', extra);
17
+ const schema = generatorPlugin.getInputSchema();
18
+ const inputValue = generatorPlugin.getInputValue();
19
+ ans = await appApi.getInputBySchema(
20
+ schema,
21
+ 'formily',
22
+ {
23
+ ...context.config,
24
+ ...inputValue,
25
+ },
26
+ {},
27
+ {},
28
+ );
29
+ } else {
30
+ ans = await appApi.getInputBySchemaFunc(getBaseSchema, context.config);
31
+ }
32
+
33
+ const { packageManager } = ans;
34
+
35
+ await appApi.forgeTemplate(
36
+ 'templates/base-templates/**/*',
37
+ undefined,
38
+ resourceKey =>
39
+ resourceKey
40
+ .replace('templates/base-templates/', '')
41
+ .replace('.handlebars', ''),
42
+ );
43
+ await appApi.forgeTemplate('templates/idea/**/*', undefined, resourceKey =>
44
+ resourceKey.replace('templates/idea/', '.idea/'),
45
+ );
46
+
47
+ if (packageManager === PackageManager.Pnpm) {
48
+ await appApi.forgeTemplate(
49
+ 'templates/pnpm-templates/**/*',
50
+ undefined,
51
+ resourceKey =>
52
+ resourceKey
53
+ .replace('templates/pnpm-templates/npmrc', '.npmrc')
54
+ .replace('.handlebars', ''),
55
+ );
56
+ }
57
+
58
+ fs.chmodSync(path.join(generator.outputPath, '.husky', 'pre-commit'), '755');
59
+ };
60
+
61
+ export default async (context: GeneratorContext, generator: GeneratorCore) => {
62
+ const appApi = new AppAPI(context, generator);
63
+ const { locale } = context.config;
64
+ appApi.i18n.changeLanguage({ locale });
65
+
66
+ if (!(await appApi.checkEnvironment())) {
67
+ // eslint-disable-next-line no-process-exit
68
+ process.exit(1);
69
+ }
70
+
71
+ generator.logger.debug(`start run @modern-js/base-generator`);
72
+ generator.logger.debug(`context=${JSON.stringify(context)}`);
73
+ generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
74
+
75
+ await handleTemplateFile(context, generator, appApi);
76
+
77
+ if (context.handleForged) {
78
+ await context.handleForged('custom', context, context.config.hasPlugin);
79
+ }
80
+
81
+ generator.logger.debug(`forge @modern-js/base-generator succeed `);
82
+ };
@@ -40,3 +40,7 @@ log/
40
40
  .changeset/pre.json
41
41
 
42
42
  .pnpm-store/
43
+
44
+ modern.config.local.ts
45
+ modern.config.local.js
46
+ modern.config.local.mjs