@modern-js/upgrade-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 +31 -19
- package/package.json +6 -6
- package/src/index.ts +214 -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
|
|
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 =
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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", ".
|
|
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
|
|
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 =
|
|
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);
|
|
@@ -137441,15 +137462,6 @@ function getPackageVersion(packageName, registry2) {
|
|
|
137441
137462
|
spinner.stop();
|
|
137442
137463
|
return stripAnsi2(result.stdout);
|
|
137443
137464
|
}
|
|
137444
|
-
if (yield (0, import_utils3.canUseYarn)()) {
|
|
137445
|
-
const args = ["info", packageName, "version", "--silent"];
|
|
137446
|
-
if (registry2) {
|
|
137447
|
-
args.push(`--registry=${registry2}`);
|
|
137448
|
-
}
|
|
137449
|
-
const result = yield (0, import_utils3.execa)("yarn", args);
|
|
137450
|
-
spinner.stop();
|
|
137451
|
-
return stripAnsi2(result.stdout);
|
|
137452
|
-
}
|
|
137453
137465
|
if (yield (0, import_utils3.canUseNpm)()) {
|
|
137454
137466
|
const args = ["view", packageName, "version"];
|
|
137455
137467
|
if (registry2) {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "3.0.
|
|
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/
|
|
31
|
-
"@modern-js/generator-utils": "3.0.
|
|
32
|
-
"@modern-js/
|
|
33
|
-
"@scripts/jest-config": "2.
|
|
34
|
-
"@scripts/build": "2.
|
|
30
|
+
"@modern-js/generator-common": "3.0.5",
|
|
31
|
+
"@modern-js/generator-utils": "3.0.5",
|
|
32
|
+
"@modern-js/plugin-i18n": "2.3.0",
|
|
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,214 @@
|
|
|
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 {
|
|
6
|
+
ora,
|
|
7
|
+
getAvailableVersion,
|
|
8
|
+
getModernVersion,
|
|
9
|
+
getPackageManager,
|
|
10
|
+
getPackageObj,
|
|
11
|
+
execa,
|
|
12
|
+
semver,
|
|
13
|
+
fs,
|
|
14
|
+
} from '@modern-js/generator-utils';
|
|
15
|
+
import {
|
|
16
|
+
PackageManager,
|
|
17
|
+
Solution,
|
|
18
|
+
SolutionText,
|
|
19
|
+
SolutionToolsMap,
|
|
20
|
+
} from '@modern-js/generator-common';
|
|
21
|
+
import { i18n, localeKeys } from './locale';
|
|
22
|
+
|
|
23
|
+
export const handleTemplateFile = async (
|
|
24
|
+
context: GeneratorContext,
|
|
25
|
+
generator: GeneratorCore,
|
|
26
|
+
appApi: AppAPI,
|
|
27
|
+
) => {
|
|
28
|
+
const jsonAPI = new JsonAPI(generator);
|
|
29
|
+
// get project solution type
|
|
30
|
+
const pkgInfo = await getPackageObj(context);
|
|
31
|
+
const deps = {
|
|
32
|
+
...pkgInfo.devDependencies,
|
|
33
|
+
...pkgInfo.dependencies,
|
|
34
|
+
};
|
|
35
|
+
const solutions = Object.keys(SolutionToolsMap).filter(
|
|
36
|
+
solution => deps[SolutionToolsMap[solution as Solution]],
|
|
37
|
+
);
|
|
38
|
+
if (solutions.length === 0) {
|
|
39
|
+
throw Error(i18n.t(localeKeys.tooltip.no_solution));
|
|
40
|
+
}
|
|
41
|
+
if (solutions.length >= 2) {
|
|
42
|
+
throw Error(i18n.t(localeKeys.tooltip.more_solution));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
generator.logger.info(
|
|
46
|
+
`[${i18n.t(localeKeys.projectType)}]: ${SolutionText[
|
|
47
|
+
solutions[0] as Solution
|
|
48
|
+
]()}`,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// get modern latest version
|
|
52
|
+
const modernVersion = await getModernVersion(
|
|
53
|
+
solutions[0] as Solution,
|
|
54
|
+
context.config.registry,
|
|
55
|
+
context.config.distTag,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
generator.logger.info(
|
|
59
|
+
`[${i18n.t(localeKeys.modernVersion)}]: ${modernVersion}`,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// adjust Modern.js packages' version is latest?
|
|
63
|
+
if (
|
|
64
|
+
Object.keys(deps)
|
|
65
|
+
.filter(
|
|
66
|
+
dep => dep.startsWith('@modern-js') || dep.startsWith('@modern-js-app'),
|
|
67
|
+
)
|
|
68
|
+
.filter(dep => !dep.includes('electron'))
|
|
69
|
+
.filter(dep => !dep.includes('codesmith') && !dep.includes('easy-form'))
|
|
70
|
+
.filter(dep => !dep.startsWith('@modern-js-reduck'))
|
|
71
|
+
.every(dep => deps[dep] === modernVersion)
|
|
72
|
+
) {
|
|
73
|
+
generator.logger.info(
|
|
74
|
+
`[${i18n.t(localeKeys.alreadyLatest)}]: ${modernVersion}`,
|
|
75
|
+
);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const appDir = context.materials.default.basePath;
|
|
80
|
+
|
|
81
|
+
const packageManager = await getPackageManager(appDir);
|
|
82
|
+
context.config.packageManager = packageManager;
|
|
83
|
+
|
|
84
|
+
if (packageManager === PackageManager.Pnpm) {
|
|
85
|
+
const npmrcPath = path.join(generator.outputPath, '.npmrc');
|
|
86
|
+
if (fs.existsSync(npmrcPath)) {
|
|
87
|
+
const content = fs.readFileSync(npmrcPath, 'utf-8');
|
|
88
|
+
if (!content.includes('strict-peer-dependencies=false')) {
|
|
89
|
+
fs.appendFileSync(npmrcPath, '\nstrict-peer-dependencies=false\n');
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
fs.ensureFileSync(npmrcPath);
|
|
93
|
+
fs.writeFileSync(npmrcPath, 'strict-peer-dependencies=false');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (
|
|
98
|
+
solutions[0] === Solution.Monorepo &&
|
|
99
|
+
packageManager === PackageManager.Pnpm
|
|
100
|
+
) {
|
|
101
|
+
await execa(
|
|
102
|
+
'pnpm',
|
|
103
|
+
['update', '@modern-js/*', '@modern-js-app/*', '--recursive', '--latest'],
|
|
104
|
+
{
|
|
105
|
+
stdin: 'inherit',
|
|
106
|
+
stdout: 'inherit',
|
|
107
|
+
stderr: 'inherit',
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const modernDeps = Object.keys(pkgInfo.dependencies || {}).filter(
|
|
114
|
+
dep => dep.startsWith('@modern-js') || dep.startsWith('@modern-js-app'),
|
|
115
|
+
);
|
|
116
|
+
const modernDevDeps = Object.keys(pkgInfo.devDependencies || {}).filter(
|
|
117
|
+
dep => dep.startsWith('@modern-js') || dep.startsWith('@modern-js-app'),
|
|
118
|
+
);
|
|
119
|
+
const updateInfo: Record<string, string> = {};
|
|
120
|
+
|
|
121
|
+
const spinner = ora({
|
|
122
|
+
text: 'Load Generator...',
|
|
123
|
+
spinner: 'runner',
|
|
124
|
+
}).start();
|
|
125
|
+
|
|
126
|
+
await Promise.all(
|
|
127
|
+
modernDeps.map(
|
|
128
|
+
async dep =>
|
|
129
|
+
(updateInfo[`dependencies.${dep}`] = await getAvailableVersion(
|
|
130
|
+
dep,
|
|
131
|
+
modernVersion,
|
|
132
|
+
)),
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
await Promise.all(
|
|
137
|
+
modernDevDeps.map(
|
|
138
|
+
async dep =>
|
|
139
|
+
(updateInfo[`devDependencies.${dep}`] = await getAvailableVersion(
|
|
140
|
+
dep,
|
|
141
|
+
modernVersion,
|
|
142
|
+
)),
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
await jsonAPI.update(
|
|
146
|
+
context.materials.default.get(path.join(appDir, 'package.json')),
|
|
147
|
+
{
|
|
148
|
+
query: {},
|
|
149
|
+
update: {
|
|
150
|
+
$set: updateInfo,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
spinner.stop();
|
|
156
|
+
|
|
157
|
+
// update husky
|
|
158
|
+
const huskyVersion = deps.husky;
|
|
159
|
+
try {
|
|
160
|
+
if (huskyVersion && semver.lt(huskyVersion, '8.0.0')) {
|
|
161
|
+
generator.logger.info(`${i18n.t(localeKeys.updateHusky)}`);
|
|
162
|
+
await jsonAPI.update(
|
|
163
|
+
context.materials.default.get(path.join(appDir, 'package.json')),
|
|
164
|
+
{
|
|
165
|
+
query: {},
|
|
166
|
+
update: {
|
|
167
|
+
$set: {
|
|
168
|
+
'devDependencies.husky': '^8.0.0',
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const pkgPath = context.materials.default.get(
|
|
175
|
+
path.join(appDir, 'package.json'),
|
|
176
|
+
).filePath;
|
|
177
|
+
const pkgInfo = fs.readJSONSync(pkgPath, 'utf-8');
|
|
178
|
+
const { prepare } = pkgInfo.scripts;
|
|
179
|
+
if (!prepare) {
|
|
180
|
+
pkgInfo.scripts.prepare = 'husky install';
|
|
181
|
+
} else if (!prepare.includes('husky install')) {
|
|
182
|
+
pkgInfo.scripts.prepare = `${prepare} && husky install`;
|
|
183
|
+
}
|
|
184
|
+
pkgInfo.husky = undefined;
|
|
185
|
+
|
|
186
|
+
fs.writeJSONSync(pkgPath, pkgInfo, { spaces: 2 });
|
|
187
|
+
|
|
188
|
+
await appApi.forgeTemplate('templates/**/*');
|
|
189
|
+
fs.chmodSync(
|
|
190
|
+
path.join(generator.outputPath, '.husky', 'pre-commit'),
|
|
191
|
+
'755',
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
} catch (e) {}
|
|
195
|
+
|
|
196
|
+
await appApi.runInstall();
|
|
197
|
+
|
|
198
|
+
appApi.showSuccessInfo(i18n.t(localeKeys.success));
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
|
202
|
+
const appApi = new AppAPI(context, generator);
|
|
203
|
+
|
|
204
|
+
const { locale } = context.config;
|
|
205
|
+
appApi.i18n.changeLanguage({ locale });
|
|
206
|
+
|
|
207
|
+
generator.logger.debug(`start run @modern-js/upgrade-generator`);
|
|
208
|
+
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
|
209
|
+
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
|
210
|
+
|
|
211
|
+
await handleTemplateFile(context, generator, appApi);
|
|
212
|
+
|
|
213
|
+
generator.logger.debug(`forge @modern-js/upgrade-generator succeed `);
|
|
214
|
+
};
|