@modern-js/dependence-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 -10
  2. package/package.json +6 -6
  3. package/src/index.ts +113 -0
package/dist/index.js CHANGED
@@ -35750,7 +35750,7 @@ var require_nodeEnv = __commonJS({
35750
35750
  });
35751
35751
  }
35752
35752
  exports.canUseNpm = canUseNpm3;
35753
- function canUseYarn3() {
35753
+ function canUseYarn2() {
35754
35754
  return __async(this, null, function* () {
35755
35755
  try {
35756
35756
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -35760,7 +35760,7 @@ var require_nodeEnv = __commonJS({
35760
35760
  }
35761
35761
  });
35762
35762
  }
35763
- exports.canUseYarn = canUseYarn3;
35763
+ exports.canUseYarn = canUseYarn2;
35764
35764
  function canUsePnpm3() {
35765
35765
  return __async(this, null, function* () {
35766
35766
  try {
@@ -44398,7 +44398,7 @@ var require_env = __commonJS({
44398
44398
  exports.canUseNpm = canUseNpm3;
44399
44399
  exports.canUseNvm = canUseNvm;
44400
44400
  exports.canUsePnpm = canUsePnpm3;
44401
- exports.canUseYarn = canUseYarn3;
44401
+ exports.canUseYarn = canUseYarn2;
44402
44402
  var _utils = require_dist();
44403
44403
  function canUseNvm() {
44404
44404
  return __async(this, null, function* () {
@@ -44425,7 +44425,7 @@ var require_env = __commonJS({
44425
44425
  }
44426
44426
  });
44427
44427
  }
44428
- function canUseYarn3() {
44428
+ function canUseYarn2() {
44429
44429
  return __async(this, null, function* () {
44430
44430
  try {
44431
44431
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45461,14 +45461,14 @@ var require_packageManager = __commonJS({
45461
45461
  value: true
45462
45462
  });
45463
45463
  exports.canUsePnpm = canUsePnpm3;
45464
- exports.canUseYarn = canUseYarn3;
45464
+ exports.canUseYarn = canUseYarn2;
45465
45465
  exports.runInstall = runInstall;
45466
45466
  var _path = _interopRequireDefault(require("path"));
45467
45467
  var _utils = require_dist();
45468
45468
  function _interopRequireDefault(obj) {
45469
45469
  return obj && obj.__esModule ? obj : { default: obj };
45470
45470
  }
45471
- function canUseYarn3() {
45471
+ function canUseYarn2() {
45472
45472
  return __async(this, null, function* () {
45473
45473
  try {
45474
45474
  yield (0, _utils.execa)("yarn", ["--version"], {
@@ -45515,7 +45515,7 @@ var require_packageManager = __commonJS({
45515
45515
  params.push(`--registry=${registryUrl}`);
45516
45516
  }
45517
45517
  yield (0, _utils.execa)("pnpm", params, options);
45518
- } else if (yield canUseYarn3()) {
45518
+ } else if (yield canUseYarn2()) {
45519
45519
  const params = ["install", "--production", "--silent", "--ignore-scripts"];
45520
45520
  if (registryUrl) {
45521
45521
  params.push(`--registry=${registryUrl}`);
@@ -134808,6 +134808,26 @@ var require_compiled2 = __commonJS({
134808
134808
  }
134809
134809
  });
134810
134810
 
134811
+ // ../../../toolkit/utils/dist/commands.js
134812
+ var require_commands = __commonJS({
134813
+ "../../../toolkit/utils/dist/commands.js"(exports) {
134814
+ "use strict";
134815
+ Object.defineProperty(exports, "__esModule", { value: true });
134816
+ exports.isDevCommand = exports.getCommand = void 0;
134817
+ var getCommand = () => {
134818
+ const args = process.argv.slice(2);
134819
+ const command = args[0];
134820
+ return command;
134821
+ };
134822
+ exports.getCommand = getCommand;
134823
+ var isDevCommand = () => {
134824
+ const command = (0, exports.getCommand)();
134825
+ return command === "dev" || command === "start";
134826
+ };
134827
+ exports.isDevCommand = isDevCommand;
134828
+ }
134829
+ });
134830
+
134811
134831
  // ../../../toolkit/utils/dist/format.js
134812
134832
  var require_format2 = __commonJS({
134813
134833
  "../../../toolkit/utils/dist/format.js"(exports) {
@@ -135382,7 +135402,7 @@ var require_constants6 = __commonJS({
135382
135402
  exports.SERVER_DIR = "server";
135383
135403
  exports.SHARED_DIR = "shared";
135384
135404
  exports.CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
135385
- exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".ejs", ".mjs"];
135405
+ exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".mjs"];
135386
135406
  exports.OUTPUT_CONFIG_FILE = "modern.config.json";
135387
135407
  exports.DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
135388
135408
  exports.ROUTE_MINIFEST_FILE = "routes-manifest.json";
@@ -135873,7 +135893,7 @@ var require_nodeEnv2 = __commonJS({
135873
135893
  });
135874
135894
  }
135875
135895
  exports.canUseNpm = canUseNpm3;
135876
- function canUseYarn3() {
135896
+ function canUseYarn2() {
135877
135897
  return __async(this, null, function* () {
135878
135898
  try {
135879
135899
  yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
@@ -135883,7 +135903,7 @@ var require_nodeEnv2 = __commonJS({
135883
135903
  }
135884
135904
  });
135885
135905
  }
135886
- exports.canUseYarn = canUseYarn3;
135906
+ exports.canUseYarn = canUseYarn2;
135887
135907
  function canUsePnpm3() {
135888
135908
  return __async(this, null, function* () {
135889
135909
  try {
@@ -136962,6 +136982,7 @@ var require_dist3 = __commonJS({
136962
136982
  };
136963
136983
  Object.defineProperty(exports, "__esModule", { value: true });
136964
136984
  __exportStar(require_compiled2(), exports);
136985
+ __exportStar(require_commands(), exports);
136965
136986
  __exportStar(require_format2(), exports);
136966
136987
  __exportStar(require_FileSizeReporter2(), exports);
136967
136988
  __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
  "main": "./dist/index.js",
17
17
  "files": [
@@ -27,11 +27,11 @@
27
27
  "@types/node": "^14",
28
28
  "jest": "^27",
29
29
  "typescript": "^4",
30
- "@modern-js/generator-common": "3.0.4",
31
- "@modern-js/plugin-i18n": "2.2.0",
32
- "@scripts/build": "2.2.0",
33
- "@scripts/jest-config": "2.2.0",
34
- "@modern-js/generator-utils": "3.0.4"
30
+ "@modern-js/plugin-i18n": "2.3.0",
31
+ "@modern-js/generator-common": "3.0.5",
32
+ "@modern-js/generator-utils": "3.0.5",
33
+ "@scripts/jest-config": "2.3.0",
34
+ "@scripts/build": "2.3.0"
35
35
  },
36
36
  "sideEffects": false,
37
37
  "publishConfig": {
package/src/index.ts ADDED
@@ -0,0 +1,113 @@
1
+ import path from 'path';
2
+ import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
3
+ import { AppAPI } from '@modern-js/codesmith-api-app';
4
+ import { JsonAPI } from '@modern-js/codesmith-api-json';
5
+ import { i18n as commonI18n } from '@modern-js/generator-common';
6
+ import { fs, getModernConfigFile } from '@modern-js/generator-utils';
7
+ import { i18n, localeKeys } from './locale';
8
+
9
+ export const handleTemplateFile = async (
10
+ context: GeneratorContext,
11
+ generator: GeneratorCore,
12
+ ) => {
13
+ const jsonAPI = new JsonAPI(generator);
14
+ const {
15
+ devDependencies,
16
+ dependencies,
17
+ peerDependencies,
18
+ appendTypeContent,
19
+ sourceTypeFile,
20
+ projectPath,
21
+ } = context.config;
22
+
23
+ const setJSON: Record<string, Record<string, string>> = {};
24
+ Object.keys(devDependencies || {}).forEach(key => {
25
+ setJSON[`devDependencies.${key}`] = devDependencies[key];
26
+ });
27
+ Object.keys(dependencies || {}).forEach(key => {
28
+ setJSON[`dependencies.${key}`] = dependencies[key];
29
+ });
30
+ Object.keys(peerDependencies || {}).forEach(key => {
31
+ setJSON[`peerDependencies.${key}`] = peerDependencies[key];
32
+ });
33
+ if (Object.keys(setJSON).length > 0) {
34
+ await jsonAPI.update(
35
+ context.materials.default.get(
36
+ path.join(projectPath || '', 'package.json'),
37
+ ),
38
+ {
39
+ query: {},
40
+ update: { $set: setJSON },
41
+ },
42
+ );
43
+ }
44
+
45
+ const appDir = context.materials.default.basePath;
46
+ const isTs = fs.existsSync(
47
+ path.join(appDir, projectPath || '', 'tsconfig.json'),
48
+ );
49
+ if (appendTypeContent && isTs) {
50
+ const typePath = path.join(
51
+ appDir,
52
+ projectPath || '',
53
+ 'src',
54
+ sourceTypeFile || 'modern-app-env.d.ts',
55
+ );
56
+ if (fs.existsSync(typePath)) {
57
+ const npmrc = fs.readFileSync(typePath, 'utf-8');
58
+ if (!npmrc.includes(appendTypeContent)) {
59
+ fs.writeFileSync(typePath, `${appendTypeContent}\n${npmrc}`, 'utf-8');
60
+ }
61
+ } else {
62
+ fs.ensureFileSync(typePath);
63
+ fs.writeFileSync(typePath, appendTypeContent, 'utf-8');
64
+ }
65
+ }
66
+ };
67
+
68
+ export default async (context: GeneratorContext, generator: GeneratorCore) => {
69
+ const appApi = new AppAPI(context, generator);
70
+
71
+ // when use new command, listeners will create more than 10
72
+ process.setMaxListeners(20);
73
+
74
+ const { locale } = context.config;
75
+ commonI18n.changeLanguage({ locale });
76
+ i18n.changeLanguage({ locale });
77
+ appApi.i18n.changeLanguage({ locale });
78
+
79
+ if (!(await appApi.checkEnvironment())) {
80
+ // eslint-disable-next-line no-process-exit
81
+ process.exit(1);
82
+ }
83
+
84
+ generator.logger.debug(`start run @modern-js/dependence-generator`);
85
+ generator.logger.debug(`context=${JSON.stringify(context)}`);
86
+ generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
87
+
88
+ await handleTemplateFile(context, generator);
89
+
90
+ if (!context.config.isSubGenerator) {
91
+ await appApi.runInstall(undefined, { ignoreScripts: true });
92
+ if (!context.config.pluginName) {
93
+ appApi.showSuccessInfo();
94
+ } else {
95
+ const appDir = context.materials.default.basePath;
96
+ const configFile = await getModernConfigFile(appDir);
97
+ appApi.showSuccessInfo(
98
+ i18n.t(
99
+ configFile.endsWith('ts')
100
+ ? localeKeys.successTs
101
+ : localeKeys.successJS,
102
+ {
103
+ configFile,
104
+ pluginName: context.config.pluginName,
105
+ pluginDependence: context.config.pluginDependence,
106
+ },
107
+ ),
108
+ );
109
+ }
110
+ }
111
+
112
+ generator.logger.debug(`forge @modern-js/dependence-generator succeed `);
113
+ };