create-umi 4.0.63 → 4.0.64
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.d.ts +5 -1
- package/dist/index.js +71 -34
- package/dist/template.d.ts +12 -0
- package/dist/template.js +113 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { yParser } from '@umijs/utils';
|
|
2
|
-
|
|
2
|
+
import { type UmiTemplate } from './template';
|
|
3
|
+
interface ITemplateArgs {
|
|
4
|
+
template?: UmiTemplate;
|
|
5
|
+
}
|
|
6
|
+
interface IArgs extends yParser.Arguments, ITemplateArgs {
|
|
3
7
|
default?: boolean;
|
|
4
8
|
git?: boolean;
|
|
5
9
|
install?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
25
25
|
var import_utils = require("@umijs/utils");
|
|
26
26
|
var import_fs = require("fs");
|
|
27
27
|
var import_path = require("path");
|
|
28
|
+
var import_template = require("./template");
|
|
28
29
|
var pkg = require("../package");
|
|
29
30
|
var DEFAULT_DATA = {
|
|
30
31
|
pluginName: "umi-plugin-demo",
|
|
@@ -32,7 +33,7 @@ var DEFAULT_DATA = {
|
|
|
32
33
|
author: "umijs",
|
|
33
34
|
version: pkg.version,
|
|
34
35
|
npmClient: "pnpm" /* pnpm */,
|
|
35
|
-
registry:
|
|
36
|
+
registry: import_template.ERegistry.npm,
|
|
36
37
|
withHusky: false,
|
|
37
38
|
extraNpmrc: "",
|
|
38
39
|
appTemplate: "app" /* app */
|
|
@@ -44,19 +45,18 @@ var src_default = async ({
|
|
|
44
45
|
}) => {
|
|
45
46
|
let [name] = args._;
|
|
46
47
|
let npmClient = "pnpm" /* pnpm */;
|
|
47
|
-
let registry =
|
|
48
|
+
let registry = import_template.ERegistry.npm;
|
|
48
49
|
let appTemplate = (defaultData == null ? void 0 : defaultData.appTemplate) || "app" /* app */;
|
|
49
50
|
const { username, email } = await (0, import_utils.getGitInfo)();
|
|
50
51
|
const author = email && username ? `${username} <${email}>` : "";
|
|
51
52
|
let pluginName = `umi-plugin-${name || "demo"}`;
|
|
53
|
+
const target = name ? (0, import_path.join)(cwd, name) : cwd;
|
|
52
54
|
const { isCancel, text, select, intro, outro } = import_utils.clackPrompts;
|
|
53
55
|
const exitPrompt = () => {
|
|
54
56
|
outro(import_utils.chalk.red("Exit create-umi"));
|
|
55
57
|
process.exit(1);
|
|
56
58
|
};
|
|
57
|
-
const
|
|
58
|
-
if (!useDefaultData) {
|
|
59
|
-
intro(import_utils.chalk.bgHex("#19BDD2")(" create-umi "));
|
|
59
|
+
const selectAppTemplate = async () => {
|
|
60
60
|
appTemplate = await select({
|
|
61
61
|
message: "Pick Umi App Template",
|
|
62
62
|
options: [
|
|
@@ -75,9 +75,8 @@ var src_default = async ({
|
|
|
75
75
|
],
|
|
76
76
|
initialValue: "app" /* app */
|
|
77
77
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
78
|
+
};
|
|
79
|
+
const selectNpmClient = async () => {
|
|
81
80
|
npmClient = await select({
|
|
82
81
|
message: "Pick Npm Client",
|
|
83
82
|
options: [
|
|
@@ -89,24 +88,35 @@ var src_default = async ({
|
|
|
89
88
|
],
|
|
90
89
|
initialValue: "pnpm" /* pnpm */
|
|
91
90
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
91
|
+
};
|
|
92
|
+
const selectRegistry = async () => {
|
|
95
93
|
registry = await select({
|
|
96
94
|
message: "Pick Npm Registry",
|
|
97
95
|
options: [
|
|
98
96
|
{
|
|
99
97
|
label: "npm",
|
|
100
|
-
value:
|
|
98
|
+
value: import_template.ERegistry.npm
|
|
101
99
|
},
|
|
102
100
|
{
|
|
103
101
|
label: "taobao",
|
|
104
|
-
value:
|
|
102
|
+
value: import_template.ERegistry.taobao,
|
|
105
103
|
hint: "recommended for China"
|
|
106
104
|
}
|
|
107
105
|
],
|
|
108
|
-
initialValue:
|
|
106
|
+
initialValue: import_template.ERegistry.npm
|
|
109
107
|
});
|
|
108
|
+
};
|
|
109
|
+
const internalTemplatePrompts = async () => {
|
|
110
|
+
intro(import_utils.chalk.bgHex("#19BDD2")(" create-umi "));
|
|
111
|
+
await selectAppTemplate();
|
|
112
|
+
if (isCancel(appTemplate)) {
|
|
113
|
+
exitPrompt();
|
|
114
|
+
}
|
|
115
|
+
await selectNpmClient();
|
|
116
|
+
if (isCancel(npmClient)) {
|
|
117
|
+
exitPrompt();
|
|
118
|
+
}
|
|
119
|
+
await selectRegistry();
|
|
110
120
|
if (isCancel(registry)) {
|
|
111
121
|
exitPrompt();
|
|
112
122
|
}
|
|
@@ -126,8 +136,30 @@ var src_default = async ({
|
|
|
126
136
|
}
|
|
127
137
|
}
|
|
128
138
|
outro(import_utils.chalk.green(`You're all set!`));
|
|
139
|
+
};
|
|
140
|
+
const useDefaultData = !!args.default;
|
|
141
|
+
const useExternalTemplate = !!args.template;
|
|
142
|
+
switch (true) {
|
|
143
|
+
case useExternalTemplate:
|
|
144
|
+
await selectNpmClient();
|
|
145
|
+
if (isCancel(npmClient)) {
|
|
146
|
+
exitPrompt();
|
|
147
|
+
}
|
|
148
|
+
await selectRegistry();
|
|
149
|
+
if (isCancel(registry)) {
|
|
150
|
+
exitPrompt();
|
|
151
|
+
}
|
|
152
|
+
await (0, import_template.unpackTemplate)({
|
|
153
|
+
template: args.template,
|
|
154
|
+
dest: target,
|
|
155
|
+
registry
|
|
156
|
+
});
|
|
157
|
+
break;
|
|
158
|
+
default:
|
|
159
|
+
if (!useDefaultData) {
|
|
160
|
+
await internalTemplatePrompts();
|
|
161
|
+
}
|
|
129
162
|
}
|
|
130
|
-
const target = name ? (0, import_path.join)(cwd, name) : cwd;
|
|
131
163
|
const version = pkg.version;
|
|
132
164
|
const monorepoRoot = await detectMonorepoRoot({ target });
|
|
133
165
|
const inMonorepo = !!monorepoRoot;
|
|
@@ -135,25 +167,30 @@ var src_default = async ({
|
|
|
135
167
|
const shouldInitGit = args.git !== false;
|
|
136
168
|
const withHusky = shouldInitGit && !inMonorepo;
|
|
137
169
|
const isPnpm = npmClient === "pnpm" /* pnpm */;
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
const injectInternalTemplateFiles = async () => {
|
|
171
|
+
const generator = new import_utils.BaseGenerator({
|
|
172
|
+
path: (0, import_path.join)(__dirname, "..", "templates", appTemplate),
|
|
173
|
+
target,
|
|
174
|
+
slient: true,
|
|
175
|
+
data: useDefaultData ? defaultData : {
|
|
176
|
+
version: version.includes("-canary.") ? version : `^${version}`,
|
|
177
|
+
npmClient,
|
|
178
|
+
registry,
|
|
179
|
+
author,
|
|
180
|
+
email,
|
|
181
|
+
withHusky,
|
|
182
|
+
// suppress pnpm v7 warning
|
|
183
|
+
// No need when `pnpm` > v7.13.5 , but we are forward compatible
|
|
184
|
+
// https://pnpm.io/npmrc#strict-peer-dependencies
|
|
185
|
+
extraNpmrc: isPnpm ? `strict-peer-dependencies=false` : "",
|
|
186
|
+
pluginName
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
await generator.run();
|
|
190
|
+
};
|
|
191
|
+
if (!useExternalTemplate) {
|
|
192
|
+
await injectInternalTemplateFiles();
|
|
193
|
+
}
|
|
157
194
|
const context = {
|
|
158
195
|
inMonorepo,
|
|
159
196
|
target,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum ERegistry {
|
|
2
|
+
npm = "https://registry.npmjs.com/",
|
|
3
|
+
taobao = "https://registry.npmmirror.com/"
|
|
4
|
+
}
|
|
5
|
+
export declare type UmiTemplate = `@umijs/${string}-template`;
|
|
6
|
+
interface IUnpackTemplateOpts {
|
|
7
|
+
template: UmiTemplate;
|
|
8
|
+
dest: string;
|
|
9
|
+
registry: ERegistry;
|
|
10
|
+
}
|
|
11
|
+
export declare const unpackTemplate: (opts: IUnpackTemplateOpts) => Promise<string>;
|
|
12
|
+
export {};
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
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
|
+
|
|
19
|
+
// src/template.ts
|
|
20
|
+
var template_exports = {};
|
|
21
|
+
__export(template_exports, {
|
|
22
|
+
ERegistry: () => ERegistry,
|
|
23
|
+
unpackTemplate: () => unpackTemplate
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(template_exports);
|
|
26
|
+
var import_utils = require("@umijs/utils");
|
|
27
|
+
var import_tar = require("@umijs/utils/compiled/tar");
|
|
28
|
+
var ERegistry = /* @__PURE__ */ ((ERegistry2) => {
|
|
29
|
+
ERegistry2["npm"] = "https://registry.npmjs.com/";
|
|
30
|
+
ERegistry2["taobao"] = "https://registry.npmmirror.com/";
|
|
31
|
+
return ERegistry2;
|
|
32
|
+
})(ERegistry || {});
|
|
33
|
+
var unpackTemplate = async (opts) => {
|
|
34
|
+
const { template, dest, registry } = opts;
|
|
35
|
+
import_utils.logger.info(
|
|
36
|
+
`Init a new project with template ${import_utils.chalk.blue(template)} from npm ...`
|
|
37
|
+
);
|
|
38
|
+
const tryDownload = async (name) => {
|
|
39
|
+
const url = await getNpmPkgTarUrl({ registry, name });
|
|
40
|
+
if (!url) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
return await downloadTar({ dest, url });
|
|
45
|
+
} catch (e) {
|
|
46
|
+
throw new Error(`Download ${name} failed from ${registry}`, { cause: e });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const nameList = [];
|
|
50
|
+
const isStartWithUmi = template.startsWith("@umijs/");
|
|
51
|
+
if (template.endsWith("-template")) {
|
|
52
|
+
if (isStartWithUmi) {
|
|
53
|
+
nameList.push(template);
|
|
54
|
+
} else {
|
|
55
|
+
nameList.push(`@umijs/${template}`);
|
|
56
|
+
}
|
|
57
|
+
} else if (isStartWithUmi) {
|
|
58
|
+
nameList.push(`${template}-template`);
|
|
59
|
+
} else {
|
|
60
|
+
nameList.push(`@umijs/${template}-template`);
|
|
61
|
+
}
|
|
62
|
+
for await (const name of nameList) {
|
|
63
|
+
const success = await tryDownload(name);
|
|
64
|
+
if (success) {
|
|
65
|
+
import_utils.logger.ready(`Init ${import_utils.chalk.green(name)} success`);
|
|
66
|
+
return success;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Template ${nameList.map((i) => import_utils.chalk.yellow(i)).join(", ")} not found from ${registry}`
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
async function getNpmPkgTarUrl(opts) {
|
|
74
|
+
var _a;
|
|
75
|
+
const { registry, name } = opts;
|
|
76
|
+
const nameWithoutScope = name.startsWith("@") ? name.split("/")[1] : name;
|
|
77
|
+
const latestPkgInfoUrl = `${registry}${name}/latest?date=${Date.now()}`;
|
|
78
|
+
const res = await import_utils.axios.get(latestPkgInfoUrl, { validateStatus: () => true });
|
|
79
|
+
const latestVersion = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.version;
|
|
80
|
+
if (!latestVersion) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const latestTarUrl = `${registry}${name}/-/${nameWithoutScope}-${latestVersion}.tgz`;
|
|
84
|
+
return latestTarUrl;
|
|
85
|
+
}
|
|
86
|
+
async function downloadTar(opts) {
|
|
87
|
+
const { dest, url } = opts;
|
|
88
|
+
return new Promise(async (resolve, reject) => {
|
|
89
|
+
try {
|
|
90
|
+
const res = await import_utils.axios.get(url, {
|
|
91
|
+
responseType: "stream"
|
|
92
|
+
});
|
|
93
|
+
import_utils.fsExtra.mkdirpSync(dest);
|
|
94
|
+
res.data.pipe(
|
|
95
|
+
(0, import_tar.x)({
|
|
96
|
+
C: dest,
|
|
97
|
+
strip: 1
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
resolve(dest);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
if (import_utils.fsExtra.existsSync(dest)) {
|
|
103
|
+
import_utils.fsExtra.removeSync(dest);
|
|
104
|
+
}
|
|
105
|
+
reject(e);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
ERegistry,
|
|
112
|
+
unpackTemplate
|
|
113
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.64",
|
|
4
4
|
"description": "create-umi",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/create-umi#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"templates"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@umijs/utils": "4.0.
|
|
22
|
+
"@umijs/utils": "4.0.64"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|