@modern-js/generator-utils 3.1.9 → 3.1.10
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/CHANGELOG.md +16 -0
- package/dist/cjs/index.js +103 -121
- package/dist/cjs/locale/en.js +13 -27
- package/dist/cjs/locale/index.js +18 -28
- package/dist/cjs/locale/zh.js +13 -27
- package/dist/cjs/utils/fsExist.js +9 -27
- package/dist/cjs/utils/index.js +19 -18
- package/dist/cjs/utils/package.js +37 -42
- package/dist/cjs/utils/stripAnsi.js +7 -25
- package/dist/esm/index.js +44 -77
- package/dist/esm/locale/en.js +7 -6
- package/dist/esm/locale/index.js +5 -5
- package/dist/esm/locale/zh.js +7 -6
- package/dist/esm/utils/fsExist.js +1 -4
- package/dist/esm/utils/package.js +17 -13
- package/dist/esm/utils/stripAnsi.js +1 -4
- package/package.json +11 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @modern-js/generator-utils
|
|
2
2
|
|
|
3
|
+
## 3.1.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
|
8
|
+
|
|
9
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5954330]
|
|
12
|
+
- Updated dependencies [84a8008]
|
|
13
|
+
- Updated dependencies [7596520]
|
|
14
|
+
- Updated dependencies [4e876ab]
|
|
15
|
+
- @modern-js/utils@2.16.0
|
|
16
|
+
- @modern-js/generator-common@3.1.10
|
|
17
|
+
- @modern-js/plugin-i18n@2.16.0
|
|
18
|
+
|
|
3
19
|
## 3.1.9
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,98 +1,103 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var src_exports = {};
|
|
30
|
-
__export(src_exports, {
|
|
31
|
-
canUseNpm: () => import_utils2.canUseNpm,
|
|
32
|
-
canUsePnpm: () => import_utils2.canUsePnpm,
|
|
33
|
-
canUseYarn: () => import_utils2.canUseYarn,
|
|
34
|
-
chalk: () => import_utils2.chalk,
|
|
35
|
-
execa: () => import_utils2.execa,
|
|
36
|
-
fs: () => import_utils2.fs,
|
|
37
|
-
getAllPackages: () => getAllPackages,
|
|
38
|
-
getDocProjectPath: () => getDocProjectPath,
|
|
39
|
-
getMWAProjectPath: () => getMWAProjectPath,
|
|
40
|
-
getModernConfigFile: () => getModernConfigFile,
|
|
41
|
-
getModernPluginVersion: () => getModernPluginVersion,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
ora: () => _utils.ora,
|
|
14
|
+
fs: () => _utils.fs,
|
|
15
|
+
semver: () => _utils.semver,
|
|
16
|
+
execa: () => _utils.execa,
|
|
17
|
+
chalk: () => _utils.chalk,
|
|
18
|
+
readTsConfigByFile: () => _utils.readTsConfigByFile,
|
|
19
|
+
getPackageManager: () => _utils.getPackageManager,
|
|
20
|
+
canUseNpm: () => _utils.canUseNpm,
|
|
21
|
+
canUsePnpm: () => _utils.canUsePnpm,
|
|
22
|
+
canUseYarn: () => _utils.canUseYarn,
|
|
23
|
+
isReact18: () => _utils.isReact18,
|
|
24
|
+
i18n: () => _locale.i18n,
|
|
25
|
+
getPackageVersion: () => getPackageVersion,
|
|
42
26
|
getModernVersion: () => getModernVersion,
|
|
43
|
-
|
|
44
|
-
getPackageManager: () => import_utils2.getPackageManager,
|
|
27
|
+
getModernPluginVersion: () => getModernPluginVersion,
|
|
45
28
|
getPackageManagerText: () => getPackageManagerText,
|
|
46
|
-
getPackageObj: () => getPackageObj,
|
|
47
|
-
getPackageVersion: () => getPackageVersion,
|
|
48
|
-
i18n: () => import_locale2.i18n,
|
|
49
|
-
isReact18: () => import_utils2.isReact18,
|
|
50
29
|
isTsProject: () => isTsProject,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
semver: () => import_utils2.semver,
|
|
30
|
+
getPackageObj: () => getPackageObj,
|
|
31
|
+
getAllPackages: () => getAllPackages,
|
|
54
32
|
validatePackageName: () => validatePackageName,
|
|
55
|
-
validatePackagePath: () => validatePackagePath
|
|
33
|
+
validatePackagePath: () => validatePackagePath,
|
|
34
|
+
getModuleProjectPath: () => getModuleProjectPath,
|
|
35
|
+
getMWAProjectPath: () => getMWAProjectPath,
|
|
36
|
+
getDocProjectPath: () => getDocProjectPath,
|
|
37
|
+
getModernConfigFile: () => getModernConfigFile
|
|
56
38
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
39
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
|
40
|
+
const _utils = require("@modern-js/utils");
|
|
41
|
+
const _generatorcommon = require("@modern-js/generator-common");
|
|
42
|
+
const _stripAnsi = require("./utils/stripAnsi");
|
|
43
|
+
const _locale = require("./locale");
|
|
44
|
+
const _package = require("./utils/package");
|
|
45
|
+
const _fsExist = require("./utils/fsExist");
|
|
46
|
+
_export_star(require("./utils"), exports);
|
|
47
|
+
function _export_star(from, to) {
|
|
48
|
+
Object.keys(from).forEach(function(k) {
|
|
49
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
50
|
+
Object.defineProperty(to, k, {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function() {
|
|
53
|
+
return from[k];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return from;
|
|
59
|
+
}
|
|
60
|
+
function _interop_require_default(obj) {
|
|
61
|
+
return obj && obj.__esModule ? obj : {
|
|
62
|
+
default: obj
|
|
63
|
+
};
|
|
64
|
+
}
|
|
68
65
|
async function getPackageVersion(packageName, registry) {
|
|
69
|
-
const spinner = (0,
|
|
66
|
+
const spinner = (0, _utils.ora)({
|
|
70
67
|
text: "Load Generator...",
|
|
71
68
|
spinner: "runner"
|
|
72
69
|
}).start();
|
|
73
|
-
if (await (0,
|
|
74
|
-
const args = [
|
|
70
|
+
if (await (0, _utils.canUsePnpm)()) {
|
|
71
|
+
const args = [
|
|
72
|
+
"info",
|
|
73
|
+
packageName,
|
|
74
|
+
"version"
|
|
75
|
+
];
|
|
75
76
|
if (registry) {
|
|
76
77
|
args.push(`--registry=${registry}`);
|
|
77
78
|
}
|
|
78
|
-
const result = await (0,
|
|
79
|
+
const result = await (0, _utils.execa)("pnpm", args);
|
|
79
80
|
spinner.stop();
|
|
80
|
-
return (0,
|
|
81
|
+
return (0, _stripAnsi.stripAnsi)(result.stdout);
|
|
81
82
|
}
|
|
82
|
-
if (await (0,
|
|
83
|
-
const args = [
|
|
83
|
+
if (await (0, _utils.canUseNpm)()) {
|
|
84
|
+
const args = [
|
|
85
|
+
"view",
|
|
86
|
+
packageName,
|
|
87
|
+
"version"
|
|
88
|
+
];
|
|
84
89
|
if (registry) {
|
|
85
90
|
args.push(`--registry=${registry}`);
|
|
86
91
|
}
|
|
87
|
-
const result = await (0,
|
|
92
|
+
const result = await (0, _utils.execa)("npm", args);
|
|
88
93
|
spinner.stop();
|
|
89
|
-
return (0,
|
|
94
|
+
return (0, _stripAnsi.stripAnsi)(result.stdout);
|
|
90
95
|
}
|
|
91
96
|
spinner.stop();
|
|
92
97
|
throw new Error("not found npm, please install npm before");
|
|
93
98
|
}
|
|
94
99
|
async function getModernVersion(solution, registry, distTag = "latest") {
|
|
95
|
-
const dep =
|
|
100
|
+
const dep = _generatorcommon.SolutionToolsMap[solution];
|
|
96
101
|
const modernVersion = await getPackageVersion(`${dep}@${distTag}`, registry);
|
|
97
102
|
return modernVersion;
|
|
98
103
|
}
|
|
@@ -101,27 +106,24 @@ async function getModernPluginVersion(solution, packageName, options = {
|
|
|
101
106
|
}) {
|
|
102
107
|
const { cwd = process.cwd(), registry, distTag } = options;
|
|
103
108
|
const getLatetPluginVersion = async (tag) => {
|
|
104
|
-
const version = await getPackageVersion(
|
|
105
|
-
`${packageName}@${tag || distTag || "latest"}`,
|
|
106
|
-
registry
|
|
107
|
-
);
|
|
109
|
+
const version = await getPackageVersion(`${packageName}@${tag || distTag || "latest"}`, registry);
|
|
108
110
|
return version;
|
|
109
111
|
};
|
|
110
112
|
if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
|
|
111
113
|
return getLatetPluginVersion("latest");
|
|
112
114
|
}
|
|
113
|
-
const pkgPath =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
if (
|
|
119
|
-
const pkgInfo =
|
|
115
|
+
const pkgPath = _path.default.join(require.resolve(_generatorcommon.SolutionToolsMap[solution], {
|
|
116
|
+
paths: [
|
|
117
|
+
cwd
|
|
118
|
+
]
|
|
119
|
+
}), "../../../../", "package.json");
|
|
120
|
+
if (_utils.fs.existsSync(pkgPath)) {
|
|
121
|
+
const pkgInfo = _utils.fs.readJSONSync(pkgPath);
|
|
120
122
|
const modernVersion = pkgInfo.version;
|
|
121
123
|
if (typeof modernVersion !== "string") {
|
|
122
124
|
return getLatetPluginVersion();
|
|
123
125
|
}
|
|
124
|
-
return (0,
|
|
126
|
+
return (0, _package.getAvailableVersion)(packageName, modernVersion, registry);
|
|
125
127
|
}
|
|
126
128
|
return getLatetPluginVersion();
|
|
127
129
|
}
|
|
@@ -129,14 +131,14 @@ function getPackageManagerText(packageManager) {
|
|
|
129
131
|
return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
130
132
|
}
|
|
131
133
|
function isTsProject(appDir) {
|
|
132
|
-
return
|
|
134
|
+
return _utils.fs.existsSync(_path.default.join(appDir, "tsconfig.json"));
|
|
133
135
|
}
|
|
134
136
|
async function getPackageObj(context) {
|
|
135
137
|
const pkgStr = (await context.materials.default.get(`package.json`).value()).content;
|
|
136
138
|
return JSON.parse(pkgStr);
|
|
137
139
|
}
|
|
138
140
|
function getAllPackages(appDir) {
|
|
139
|
-
const packages = (0,
|
|
141
|
+
const packages = (0, _utils.getMonorepoPackages)(appDir);
|
|
140
142
|
return packages.map((pkg) => pkg.name);
|
|
141
143
|
}
|
|
142
144
|
function validatePackageName(value, packages, options) {
|
|
@@ -144,10 +146,14 @@ function validatePackageName(value, packages, options) {
|
|
|
144
146
|
if (isMonorepoSubProject && packages.includes(value)) {
|
|
145
147
|
return {
|
|
146
148
|
success: false,
|
|
147
|
-
error:
|
|
149
|
+
error: _locale.i18n.t(_locale.localeKeys.packageName.exit, {
|
|
150
|
+
value
|
|
151
|
+
})
|
|
148
152
|
};
|
|
149
153
|
}
|
|
150
|
-
return {
|
|
154
|
+
return {
|
|
155
|
+
success: true
|
|
156
|
+
};
|
|
151
157
|
}
|
|
152
158
|
function validatePackagePath(value, projectDir, options) {
|
|
153
159
|
const { isMwa, isPublic, isTest, isDoc } = options || {};
|
|
@@ -159,14 +165,18 @@ function validatePackagePath(value, projectDir, options) {
|
|
|
159
165
|
} else {
|
|
160
166
|
dir = isPublic ? "packages" : "features";
|
|
161
167
|
}
|
|
162
|
-
const packageDir =
|
|
163
|
-
if (
|
|
168
|
+
const packageDir = _path.default.resolve(projectDir || "", dir, value);
|
|
169
|
+
if (_utils.fs.existsSync(packageDir)) {
|
|
164
170
|
return {
|
|
165
171
|
success: false,
|
|
166
|
-
error:
|
|
172
|
+
error: _locale.i18n.t(_locale.localeKeys.packagePath.exit, {
|
|
173
|
+
value
|
|
174
|
+
})
|
|
167
175
|
};
|
|
168
176
|
}
|
|
169
|
-
return {
|
|
177
|
+
return {
|
|
178
|
+
success: true
|
|
179
|
+
};
|
|
170
180
|
}
|
|
171
181
|
function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
|
|
172
182
|
if (isLocalPackages && packagePath) {
|
|
@@ -190,41 +200,13 @@ function getDocProjectPath(packagePath, isMonorepoSubProject) {
|
|
|
190
200
|
return "";
|
|
191
201
|
}
|
|
192
202
|
async function getModernConfigFile(appDir) {
|
|
193
|
-
let exist = await (0,
|
|
203
|
+
let exist = await (0, _fsExist.fileExist)(_path.default.join(appDir, "modern.config.ts"));
|
|
194
204
|
if (exist) {
|
|
195
205
|
return "modern.config.ts";
|
|
196
206
|
}
|
|
197
|
-
exist = await (0,
|
|
207
|
+
exist = await (0, _fsExist.fileExist)(_path.default.join(appDir, "modern.config.js"));
|
|
198
208
|
if (exist) {
|
|
199
209
|
return "modern.config.js";
|
|
200
210
|
}
|
|
201
211
|
return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
|
|
202
212
|
}
|
|
203
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
-
0 && (module.exports = {
|
|
205
|
-
canUseNpm,
|
|
206
|
-
canUsePnpm,
|
|
207
|
-
canUseYarn,
|
|
208
|
-
chalk,
|
|
209
|
-
execa,
|
|
210
|
-
fs,
|
|
211
|
-
getAllPackages,
|
|
212
|
-
getDocProjectPath,
|
|
213
|
-
getMWAProjectPath,
|
|
214
|
-
getModernConfigFile,
|
|
215
|
-
getModernPluginVersion,
|
|
216
|
-
getModernVersion,
|
|
217
|
-
getModuleProjectPath,
|
|
218
|
-
getPackageManager,
|
|
219
|
-
getPackageManagerText,
|
|
220
|
-
getPackageObj,
|
|
221
|
-
getPackageVersion,
|
|
222
|
-
i18n,
|
|
223
|
-
isReact18,
|
|
224
|
-
isTsProject,
|
|
225
|
-
ora,
|
|
226
|
-
readTsConfigByFile,
|
|
227
|
-
semver,
|
|
228
|
-
validatePackageName,
|
|
229
|
-
validatePackagePath
|
|
230
|
-
});
|
package/dist/cjs/locale/en.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var en_exports = {};
|
|
19
|
-
__export(en_exports, {
|
|
20
|
-
EN_LOCALE: () => EN_LOCALE
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "EN_LOCALE", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => EN_LOCALE
|
|
21
8
|
});
|
|
22
|
-
module.exports = __toCommonJS(en_exports);
|
|
23
9
|
const EN_LOCALE = {
|
|
24
|
-
packageName: {
|
|
25
|
-
|
|
10
|
+
packageName: {
|
|
11
|
+
exit: "package name `{value}` is already exists"
|
|
12
|
+
},
|
|
13
|
+
packagePath: {
|
|
14
|
+
exit: "package path {value} is already exists"
|
|
15
|
+
}
|
|
26
16
|
};
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
EN_LOCALE
|
|
30
|
-
});
|
package/dist/cjs/locale/index.js
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var locale_exports = {};
|
|
19
|
-
__export(locale_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
20
13
|
i18n: () => i18n,
|
|
21
14
|
localeKeys: () => localeKeys
|
|
22
15
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
i18n,
|
|
32
|
-
localeKeys
|
|
16
|
+
const _plugini18n = require("@modern-js/plugin-i18n");
|
|
17
|
+
const _zh = require("./zh");
|
|
18
|
+
const _en = require("./en");
|
|
19
|
+
const i18n = new _plugini18n.I18n();
|
|
20
|
+
const localeKeys = i18n.init("en", {
|
|
21
|
+
zh: _zh.ZH_LOCALE,
|
|
22
|
+
en: _en.EN_LOCALE
|
|
33
23
|
});
|
package/dist/cjs/locale/zh.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var zh_exports = {};
|
|
19
|
-
__export(zh_exports, {
|
|
20
|
-
ZH_LOCALE: () => ZH_LOCALE
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ZH_LOCALE", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => ZH_LOCALE
|
|
21
8
|
});
|
|
22
|
-
module.exports = __toCommonJS(zh_exports);
|
|
23
9
|
const ZH_LOCALE = {
|
|
24
|
-
packageName: {
|
|
25
|
-
|
|
10
|
+
packageName: {
|
|
11
|
+
exit: "项目名称 {value} 已存在"
|
|
12
|
+
},
|
|
13
|
+
packagePath: {
|
|
14
|
+
exit: "目录 {value} 已存在"
|
|
15
|
+
}
|
|
26
16
|
};
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
ZH_LOCALE
|
|
30
|
-
});
|
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var fsExist_exports = {};
|
|
19
|
-
__export(fsExist_exports, {
|
|
20
|
-
fileExist: () => fileExist
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "fileExist", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => fileExist
|
|
21
8
|
});
|
|
22
|
-
|
|
23
|
-
var import_utils = require("@modern-js/utils");
|
|
9
|
+
const _utils = require("@modern-js/utils");
|
|
24
10
|
async function fileExist(filePath) {
|
|
25
11
|
try {
|
|
26
|
-
const stat = await
|
|
12
|
+
const stat = await _utils.fs.stat(filePath);
|
|
27
13
|
if (stat.isFile()) {
|
|
28
14
|
return true;
|
|
29
15
|
}
|
|
@@ -32,7 +18,3 @@ async function fileExist(filePath) {
|
|
|
32
18
|
return false;
|
|
33
19
|
}
|
|
34
20
|
}
|
|
35
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
-
0 && (module.exports = {
|
|
37
|
-
fileExist
|
|
38
|
-
});
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./stripAnsi"), exports);
|
|
6
|
+
_export_star(require("./package"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var package_exports = {};
|
|
19
|
-
__export(package_exports, {
|
|
20
|
-
getAvailableVersion: () => getAvailableVersion,
|
|
21
|
-
isPackageDeprecated: () => isPackageDeprecated,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
22
13
|
isPackageExist: () => isPackageExist,
|
|
23
|
-
|
|
14
|
+
isPackageDeprecated: () => isPackageDeprecated,
|
|
15
|
+
semverDecrease: () => semverDecrease,
|
|
16
|
+
getAvailableVersion: () => getAvailableVersion
|
|
24
17
|
});
|
|
25
|
-
|
|
26
|
-
var import_utils = require("@modern-js/utils");
|
|
18
|
+
const _utils = require("@modern-js/utils");
|
|
27
19
|
async function isPackageExist(packageName, registry) {
|
|
28
|
-
if (await (0,
|
|
29
|
-
const args = [
|
|
20
|
+
if (await (0, _utils.canUseNpm)()) {
|
|
21
|
+
const args = [
|
|
22
|
+
"view",
|
|
23
|
+
packageName,
|
|
24
|
+
"version"
|
|
25
|
+
];
|
|
30
26
|
if (registry) {
|
|
31
27
|
args.push(`--registry=${registry}`);
|
|
32
28
|
}
|
|
33
|
-
const result = await (0,
|
|
34
|
-
return (0,
|
|
29
|
+
const result = await (0, _utils.execa)("npm", args);
|
|
30
|
+
return (0, _utils.stripAnsi)(result.stdout);
|
|
35
31
|
}
|
|
36
32
|
throw new Error("not found npm, please install npm before");
|
|
37
33
|
}
|
|
38
34
|
async function isPackageDeprecated(packageName, registry) {
|
|
39
|
-
if (await (0,
|
|
40
|
-
const args = [
|
|
35
|
+
if (await (0, _utils.canUseNpm)()) {
|
|
36
|
+
const args = [
|
|
37
|
+
"view",
|
|
38
|
+
packageName,
|
|
39
|
+
"deprecated"
|
|
40
|
+
];
|
|
41
41
|
if (registry) {
|
|
42
42
|
args.push(`--registry=${registry}`);
|
|
43
43
|
}
|
|
44
|
-
const result = await (0,
|
|
45
|
-
return (0,
|
|
44
|
+
const result = await (0, _utils.execa)("npm", args);
|
|
45
|
+
return (0, _utils.stripAnsi)(result.stdout);
|
|
46
46
|
}
|
|
47
47
|
throw new Error("not found npm, please install npm before");
|
|
48
48
|
}
|
|
49
49
|
function semverDecrease(version) {
|
|
50
|
-
const versionObj =
|
|
50
|
+
const versionObj = _utils.semver.parse(version, {
|
|
51
|
+
loose: true
|
|
52
|
+
});
|
|
51
53
|
if (!versionObj) {
|
|
52
54
|
throw new Error(`Version ${version} is not valid semver`);
|
|
53
55
|
}
|
|
@@ -55,8 +57,8 @@ function semverDecrease(version) {
|
|
|
55
57
|
versionObj.prerelease = [];
|
|
56
58
|
versionObj.patch--;
|
|
57
59
|
const result = versionObj.format();
|
|
58
|
-
if (!
|
|
59
|
-
|
|
60
|
+
if (!_utils.semver.valid(result)) {
|
|
61
|
+
_utils.logger.debug(`Version ${result} is not valid semver`);
|
|
60
62
|
return version;
|
|
61
63
|
}
|
|
62
64
|
return result;
|
|
@@ -66,7 +68,7 @@ async function getAvailableVersion(packageName, currentVersion, registry) {
|
|
|
66
68
|
let version = currentVersion;
|
|
67
69
|
while (times) {
|
|
68
70
|
if (!await isPackageExist(`${packageName}@${version}`, registry) || await isPackageDeprecated(`${packageName}@${version}`, registry)) {
|
|
69
|
-
version =
|
|
71
|
+
version = _utils.semver.inc(version, "patch");
|
|
70
72
|
times--;
|
|
71
73
|
continue;
|
|
72
74
|
}
|
|
@@ -83,10 +85,3 @@ async function getAvailableVersion(packageName, currentVersion, registry) {
|
|
|
83
85
|
}
|
|
84
86
|
return currentVersion;
|
|
85
87
|
}
|
|
86
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
-
0 && (module.exports = {
|
|
88
|
-
getAvailableVersion,
|
|
89
|
-
isPackageDeprecated,
|
|
90
|
-
isPackageExist,
|
|
91
|
-
semverDecrease
|
|
92
|
-
});
|
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var stripAnsi_exports = {};
|
|
19
|
-
__export(stripAnsi_exports, {
|
|
20
|
-
stripAnsi: () => stripAnsi
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "stripAnsi", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => stripAnsi
|
|
21
8
|
});
|
|
22
|
-
module.exports = __toCommonJS(stripAnsi_exports);
|
|
23
9
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
24
10
|
const pattern = [
|
|
25
11
|
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
@@ -33,7 +19,3 @@ function stripAnsi(string) {
|
|
|
33
19
|
}
|
|
34
20
|
return string.replace(ansiRegex(), "");
|
|
35
21
|
}
|
|
36
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
-
0 && (module.exports = {
|
|
38
|
-
stripAnsi
|
|
39
|
-
});
|
package/dist/esm/index.js
CHANGED
|
@@ -1,39 +1,24 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
fs,
|
|
4
|
-
ora,
|
|
5
|
-
execa,
|
|
6
|
-
getMonorepoPackages,
|
|
7
|
-
canUseNpm,
|
|
8
|
-
canUsePnpm
|
|
9
|
-
} from "@modern-js/utils";
|
|
2
|
+
import { fs, ora, execa, getMonorepoPackages, canUseNpm, canUsePnpm } from "@modern-js/utils";
|
|
10
3
|
import { SolutionToolsMap } from "@modern-js/generator-common";
|
|
11
4
|
import { stripAnsi } from "./utils/stripAnsi";
|
|
12
5
|
import { i18n, localeKeys } from "./locale";
|
|
13
6
|
import { getAvailableVersion } from "./utils/package";
|
|
14
7
|
import { fileExist } from "./utils/fsExist";
|
|
15
8
|
export * from "./utils";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
semver,
|
|
20
|
-
execa as execa2,
|
|
21
|
-
chalk,
|
|
22
|
-
readTsConfigByFile,
|
|
23
|
-
getPackageManager,
|
|
24
|
-
canUseNpm as canUseNpm2,
|
|
25
|
-
canUsePnpm as canUsePnpm2,
|
|
26
|
-
canUseYarn,
|
|
27
|
-
isReact18
|
|
28
|
-
} from "@modern-js/utils";
|
|
29
|
-
import { i18n as i18n2 } from "./locale";
|
|
30
|
-
async function getPackageVersion(packageName, registry) {
|
|
9
|
+
export { ora, fs, semver, execa, chalk, readTsConfigByFile, getPackageManager, canUseNpm, canUsePnpm, canUseYarn, isReact18 } from "@modern-js/utils";
|
|
10
|
+
export { i18n } from "./locale";
|
|
11
|
+
export async function getPackageVersion(packageName, registry) {
|
|
31
12
|
const spinner = ora({
|
|
32
13
|
text: "Load Generator...",
|
|
33
14
|
spinner: "runner"
|
|
34
15
|
}).start();
|
|
35
16
|
if (await canUsePnpm()) {
|
|
36
|
-
const args = [
|
|
17
|
+
const args = [
|
|
18
|
+
"info",
|
|
19
|
+
packageName,
|
|
20
|
+
"version"
|
|
21
|
+
];
|
|
37
22
|
if (registry) {
|
|
38
23
|
args.push(`--registry=${registry}`);
|
|
39
24
|
}
|
|
@@ -42,7 +27,11 @@ async function getPackageVersion(packageName, registry) {
|
|
|
42
27
|
return stripAnsi(result.stdout);
|
|
43
28
|
}
|
|
44
29
|
if (await canUseNpm()) {
|
|
45
|
-
const args = [
|
|
30
|
+
const args = [
|
|
31
|
+
"view",
|
|
32
|
+
packageName,
|
|
33
|
+
"version"
|
|
34
|
+
];
|
|
46
35
|
if (registry) {
|
|
47
36
|
args.push(`--registry=${registry}`);
|
|
48
37
|
}
|
|
@@ -53,30 +42,27 @@ async function getPackageVersion(packageName, registry) {
|
|
|
53
42
|
spinner.stop();
|
|
54
43
|
throw new Error("not found npm, please install npm before");
|
|
55
44
|
}
|
|
56
|
-
async function getModernVersion(solution, registry, distTag = "latest") {
|
|
45
|
+
export async function getModernVersion(solution, registry, distTag = "latest") {
|
|
57
46
|
const dep = SolutionToolsMap[solution];
|
|
58
47
|
const modernVersion = await getPackageVersion(`${dep}@${distTag}`, registry);
|
|
59
48
|
return modernVersion;
|
|
60
49
|
}
|
|
61
|
-
async function getModernPluginVersion(solution, packageName, options = {
|
|
50
|
+
export async function getModernPluginVersion(solution, packageName, options = {
|
|
62
51
|
distTag: "latest"
|
|
63
52
|
}) {
|
|
64
53
|
const { cwd = process.cwd(), registry, distTag } = options;
|
|
65
54
|
const getLatetPluginVersion = async (tag) => {
|
|
66
|
-
const version = await getPackageVersion(
|
|
67
|
-
`${packageName}@${tag || distTag || "latest"}`,
|
|
68
|
-
registry
|
|
69
|
-
);
|
|
55
|
+
const version = await getPackageVersion(`${packageName}@${tag || distTag || "latest"}`, registry);
|
|
70
56
|
return version;
|
|
71
57
|
};
|
|
72
58
|
if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
|
|
73
59
|
return getLatetPluginVersion("latest");
|
|
74
60
|
}
|
|
75
|
-
const pkgPath = path.join(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
);
|
|
61
|
+
const pkgPath = path.join(require.resolve(SolutionToolsMap[solution], {
|
|
62
|
+
paths: [
|
|
63
|
+
cwd
|
|
64
|
+
]
|
|
65
|
+
}), "../../../../", "package.json");
|
|
80
66
|
if (fs.existsSync(pkgPath)) {
|
|
81
67
|
const pkgInfo = fs.readJSONSync(pkgPath);
|
|
82
68
|
const modernVersion = pkgInfo.version;
|
|
@@ -87,31 +73,35 @@ async function getModernPluginVersion(solution, packageName, options = {
|
|
|
87
73
|
}
|
|
88
74
|
return getLatetPluginVersion();
|
|
89
75
|
}
|
|
90
|
-
function getPackageManagerText(packageManager) {
|
|
76
|
+
export function getPackageManagerText(packageManager) {
|
|
91
77
|
return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
92
78
|
}
|
|
93
|
-
function isTsProject(appDir) {
|
|
79
|
+
export function isTsProject(appDir) {
|
|
94
80
|
return fs.existsSync(path.join(appDir, "tsconfig.json"));
|
|
95
81
|
}
|
|
96
|
-
async function getPackageObj(context) {
|
|
82
|
+
export async function getPackageObj(context) {
|
|
97
83
|
const pkgStr = (await context.materials.default.get(`package.json`).value()).content;
|
|
98
84
|
return JSON.parse(pkgStr);
|
|
99
85
|
}
|
|
100
|
-
function getAllPackages(appDir) {
|
|
86
|
+
export function getAllPackages(appDir) {
|
|
101
87
|
const packages = getMonorepoPackages(appDir);
|
|
102
88
|
return packages.map((pkg) => pkg.name);
|
|
103
89
|
}
|
|
104
|
-
function validatePackageName(value, packages, options) {
|
|
90
|
+
export function validatePackageName(value, packages, options) {
|
|
105
91
|
const { isMonorepoSubProject } = options;
|
|
106
92
|
if (isMonorepoSubProject && packages.includes(value)) {
|
|
107
93
|
return {
|
|
108
94
|
success: false,
|
|
109
|
-
error: i18n.t(localeKeys.packageName.exit, {
|
|
95
|
+
error: i18n.t(localeKeys.packageName.exit, {
|
|
96
|
+
value
|
|
97
|
+
})
|
|
110
98
|
};
|
|
111
99
|
}
|
|
112
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
success: true
|
|
102
|
+
};
|
|
113
103
|
}
|
|
114
|
-
function validatePackagePath(value, projectDir, options) {
|
|
104
|
+
export function validatePackagePath(value, projectDir, options) {
|
|
115
105
|
const { isMwa, isPublic, isTest, isDoc } = options || {};
|
|
116
106
|
let dir = "apps";
|
|
117
107
|
if (isMwa && isTest) {
|
|
@@ -125,12 +115,16 @@ function validatePackagePath(value, projectDir, options) {
|
|
|
125
115
|
if (fs.existsSync(packageDir)) {
|
|
126
116
|
return {
|
|
127
117
|
success: false,
|
|
128
|
-
error: i18n.t(localeKeys.packagePath.exit, {
|
|
118
|
+
error: i18n.t(localeKeys.packagePath.exit, {
|
|
119
|
+
value
|
|
120
|
+
})
|
|
129
121
|
};
|
|
130
122
|
}
|
|
131
|
-
return {
|
|
123
|
+
return {
|
|
124
|
+
success: true
|
|
125
|
+
};
|
|
132
126
|
}
|
|
133
|
-
function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
|
|
127
|
+
export function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
|
|
134
128
|
if (isLocalPackages && packagePath) {
|
|
135
129
|
return `${packagePath}/`;
|
|
136
130
|
}
|
|
@@ -139,19 +133,19 @@ function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLoc
|
|
|
139
133
|
}
|
|
140
134
|
return "";
|
|
141
135
|
}
|
|
142
|
-
function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
|
|
136
|
+
export function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
|
|
143
137
|
if (isMonorepoSubProject && packagePath) {
|
|
144
138
|
return `${isTest ? "examples" : "apps"}/${packagePath}/`;
|
|
145
139
|
}
|
|
146
140
|
return "";
|
|
147
141
|
}
|
|
148
|
-
function getDocProjectPath(packagePath, isMonorepoSubProject) {
|
|
142
|
+
export function getDocProjectPath(packagePath, isMonorepoSubProject) {
|
|
149
143
|
if (isMonorepoSubProject && packagePath) {
|
|
150
144
|
return `website/${packagePath}/`;
|
|
151
145
|
}
|
|
152
146
|
return "";
|
|
153
147
|
}
|
|
154
|
-
async function getModernConfigFile(appDir) {
|
|
148
|
+
export async function getModernConfigFile(appDir) {
|
|
155
149
|
let exist = await fileExist(path.join(appDir, "modern.config.ts"));
|
|
156
150
|
if (exist) {
|
|
157
151
|
return "modern.config.ts";
|
|
@@ -162,30 +156,3 @@ async function getModernConfigFile(appDir) {
|
|
|
162
156
|
}
|
|
163
157
|
return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
|
|
164
158
|
}
|
|
165
|
-
export {
|
|
166
|
-
canUseNpm2 as canUseNpm,
|
|
167
|
-
canUsePnpm2 as canUsePnpm,
|
|
168
|
-
canUseYarn,
|
|
169
|
-
chalk,
|
|
170
|
-
execa2 as execa,
|
|
171
|
-
fs2 as fs,
|
|
172
|
-
getAllPackages,
|
|
173
|
-
getDocProjectPath,
|
|
174
|
-
getMWAProjectPath,
|
|
175
|
-
getModernConfigFile,
|
|
176
|
-
getModernPluginVersion,
|
|
177
|
-
getModernVersion,
|
|
178
|
-
getModuleProjectPath,
|
|
179
|
-
getPackageManager,
|
|
180
|
-
getPackageManagerText,
|
|
181
|
-
getPackageObj,
|
|
182
|
-
getPackageVersion,
|
|
183
|
-
i18n2 as i18n,
|
|
184
|
-
isReact18,
|
|
185
|
-
isTsProject,
|
|
186
|
-
ora2 as ora,
|
|
187
|
-
readTsConfigByFile,
|
|
188
|
-
semver,
|
|
189
|
-
validatePackageName,
|
|
190
|
-
validatePackagePath
|
|
191
|
-
};
|
package/dist/esm/locale/en.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const EN_LOCALE = {
|
|
2
|
-
packageName: {
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export const EN_LOCALE = {
|
|
2
|
+
packageName: {
|
|
3
|
+
exit: "package name `{value}` is already exists"
|
|
4
|
+
},
|
|
5
|
+
packagePath: {
|
|
6
|
+
exit: "package path {value} is already exists"
|
|
7
|
+
}
|
|
7
8
|
};
|
package/dist/esm/locale/index.js
CHANGED
|
@@ -2,8 +2,8 @@ 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("en", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
5
|
+
const localeKeys = i18n.init("en", {
|
|
6
|
+
zh: ZH_LOCALE,
|
|
7
|
+
en: EN_LOCALE
|
|
8
|
+
});
|
|
9
|
+
export { i18n, localeKeys };
|
package/dist/esm/locale/zh.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const ZH_LOCALE = {
|
|
2
|
-
packageName: {
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export const ZH_LOCALE = {
|
|
2
|
+
packageName: {
|
|
3
|
+
exit: "项目名称 {value} 已存在"
|
|
4
|
+
},
|
|
5
|
+
packagePath: {
|
|
6
|
+
exit: "目录 {value} 已存在"
|
|
7
|
+
}
|
|
7
8
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fs } from "@modern-js/utils";
|
|
2
|
-
async function fileExist(filePath) {
|
|
2
|
+
export async function fileExist(filePath) {
|
|
3
3
|
try {
|
|
4
4
|
const stat = await fs.stat(filePath);
|
|
5
5
|
if (stat.isFile()) {
|
|
@@ -10,6 +10,3 @@ async function fileExist(filePath) {
|
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export {
|
|
14
|
-
fileExist
|
|
15
|
-
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { canUseNpm, execa, logger, semver, stripAnsi } from "@modern-js/utils";
|
|
2
|
-
async function isPackageExist(packageName, registry) {
|
|
2
|
+
export async function isPackageExist(packageName, registry) {
|
|
3
3
|
if (await canUseNpm()) {
|
|
4
|
-
const args = [
|
|
4
|
+
const args = [
|
|
5
|
+
"view",
|
|
6
|
+
packageName,
|
|
7
|
+
"version"
|
|
8
|
+
];
|
|
5
9
|
if (registry) {
|
|
6
10
|
args.push(`--registry=${registry}`);
|
|
7
11
|
}
|
|
@@ -10,9 +14,13 @@ async function isPackageExist(packageName, registry) {
|
|
|
10
14
|
}
|
|
11
15
|
throw new Error("not found npm, please install npm before");
|
|
12
16
|
}
|
|
13
|
-
async function isPackageDeprecated(packageName, registry) {
|
|
17
|
+
export async function isPackageDeprecated(packageName, registry) {
|
|
14
18
|
if (await canUseNpm()) {
|
|
15
|
-
const args = [
|
|
19
|
+
const args = [
|
|
20
|
+
"view",
|
|
21
|
+
packageName,
|
|
22
|
+
"deprecated"
|
|
23
|
+
];
|
|
16
24
|
if (registry) {
|
|
17
25
|
args.push(`--registry=${registry}`);
|
|
18
26
|
}
|
|
@@ -21,8 +29,10 @@ async function isPackageDeprecated(packageName, registry) {
|
|
|
21
29
|
}
|
|
22
30
|
throw new Error("not found npm, please install npm before");
|
|
23
31
|
}
|
|
24
|
-
function semverDecrease(version) {
|
|
25
|
-
const versionObj = semver.parse(version, {
|
|
32
|
+
export function semverDecrease(version) {
|
|
33
|
+
const versionObj = semver.parse(version, {
|
|
34
|
+
loose: true
|
|
35
|
+
});
|
|
26
36
|
if (!versionObj) {
|
|
27
37
|
throw new Error(`Version ${version} is not valid semver`);
|
|
28
38
|
}
|
|
@@ -36,7 +46,7 @@ function semverDecrease(version) {
|
|
|
36
46
|
}
|
|
37
47
|
return result;
|
|
38
48
|
}
|
|
39
|
-
async function getAvailableVersion(packageName, currentVersion, registry) {
|
|
49
|
+
export async function getAvailableVersion(packageName, currentVersion, registry) {
|
|
40
50
|
let times = 5;
|
|
41
51
|
let version = currentVersion;
|
|
42
52
|
while (times) {
|
|
@@ -58,9 +68,3 @@ async function getAvailableVersion(packageName, currentVersion, registry) {
|
|
|
58
68
|
}
|
|
59
69
|
return currentVersion;
|
|
60
70
|
}
|
|
61
|
-
export {
|
|
62
|
-
getAvailableVersion,
|
|
63
|
-
isPackageDeprecated,
|
|
64
|
-
isPackageExist,
|
|
65
|
-
semverDecrease
|
|
66
|
-
};
|
|
@@ -5,12 +5,9 @@ function ansiRegex({ onlyFirst = false } = {}) {
|
|
|
5
5
|
].join("|");
|
|
6
6
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
7
7
|
}
|
|
8
|
-
function stripAnsi(string) {
|
|
8
|
+
export function stripAnsi(string) {
|
|
9
9
|
if (typeof string !== "string") {
|
|
10
10
|
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
11
11
|
}
|
|
12
12
|
return string.replace(ansiRegex(), "");
|
|
13
13
|
}
|
|
14
|
-
export {
|
|
15
|
-
stripAnsi
|
|
16
|
-
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/modern.js/issues",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/web-infra-dev/modern.js",
|
|
9
|
+
"directory": "packages/generator/generator-utils"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"keywords": [
|
|
9
13
|
"react",
|
|
@@ -11,7 +15,7 @@
|
|
|
11
15
|
"modern",
|
|
12
16
|
"modern.js"
|
|
13
17
|
],
|
|
14
|
-
"version": "3.1.
|
|
18
|
+
"version": "3.1.10",
|
|
15
19
|
"jsnext:source": "./src/index.ts",
|
|
16
20
|
"types": "./dist/types/index.d.ts",
|
|
17
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -27,9 +31,9 @@
|
|
|
27
31
|
},
|
|
28
32
|
"dependencies": {
|
|
29
33
|
"@babel/runtime": "^7.18.0",
|
|
30
|
-
"@modern-js/plugin-i18n": "2.
|
|
31
|
-
"@modern-js/generator-common": "3.1.
|
|
32
|
-
"@modern-js/utils": "2.
|
|
34
|
+
"@modern-js/plugin-i18n": "2.16.0",
|
|
35
|
+
"@modern-js/generator-common": "3.1.10",
|
|
36
|
+
"@modern-js/utils": "2.16.0"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
|
35
39
|
"@modern-js/codesmith": "2.1.0",
|
|
@@ -37,8 +41,8 @@
|
|
|
37
41
|
"@types/node": "^14",
|
|
38
42
|
"jest": "^29",
|
|
39
43
|
"typescript": "^4",
|
|
40
|
-
"@scripts/build": "2.
|
|
41
|
-
"@scripts/jest-config": "2.
|
|
44
|
+
"@scripts/build": "2.16.0",
|
|
45
|
+
"@scripts/jest-config": "2.16.0"
|
|
42
46
|
},
|
|
43
47
|
"sideEffects": false,
|
|
44
48
|
"modernConfig": {
|