create-umi 4.0.0-beta.17 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/bin/create-umi.js +1 -0
- package/dist/cli.js +20 -28
- package/dist/index.d.ts +42 -3
- package/dist/index.js +286 -96
- package/dist/template.d.ts +12 -0
- package/dist/template.js +113 -0
- package/package.json +13 -12
- package/templates/app/.gitignore.tpl +2 -3
- package/templates/app/.npmrc.tpl +1 -0
- package/templates/app/.umirc.ts.tpl +9 -3
- package/templates/app/package.json.tpl +6 -4
- package/templates/app/{layouts → src/layouts}/index.tsx.tpl +0 -1
- package/templates/app/{pages → src/pages}/docs.tsx +3 -3
- package/templates/app/{pages → src/pages}/index.tsx +2 -2
- package/templates/app/tsconfig.json.tpl +3 -0
- package/templates/app/typings.d.ts +1 -3
- package/templates/max/.eslintrc.js.tpl +3 -0
- package/templates/max/.gitignore.tpl +13 -0
- package/templates/max/.husky/commit-msg +1 -0
- package/templates/max/.husky/pre-commit +1 -0
- package/templates/max/.lintstagedrc.tpl +17 -0
- package/templates/max/.npmrc.tpl +2 -0
- package/templates/max/.prettierignore.tpl +3 -0
- package/templates/max/.prettierrc.tpl +8 -0
- package/templates/max/.stylelintrc.js.tpl +3 -0
- package/templates/max/.umirc.ts.tpl +35 -0
- package/templates/max/README.md +3 -0
- package/templates/max/mock/userAPI.ts +20 -0
- package/templates/max/package.json.tpl +29 -0
- package/templates/max/src/access.ts +10 -0
- package/templates/max/src/app.ts +16 -0
- package/templates/max/src/assets/.gitkeep +0 -0
- package/templates/max/src/components/Guide/Guide.less +4 -0
- package/templates/max/src/components/Guide/Guide.tsx +23 -0
- package/templates/max/src/components/Guide/index.ts +2 -0
- package/templates/max/src/constants/index.ts +1 -0
- package/templates/max/src/models/global.ts +13 -0
- package/templates/max/src/pages/Access/index.tsx +21 -0
- package/templates/max/src/pages/Home/index.less +3 -0
- package/templates/max/src/pages/Home/index.tsx +18 -0
- package/templates/max/src/pages/Table/components/CreateForm.tsx +26 -0
- package/templates/max/src/pages/Table/components/UpdateForm.tsx +138 -0
- package/templates/max/src/pages/Table/index.tsx +270 -0
- package/templates/max/src/services/demo/UserController.ts +96 -0
- package/templates/max/src/services/demo/index.ts +7 -0
- package/templates/max/src/services/demo/typings.d.ts +68 -0
- package/templates/max/src/utils/format.ts +4 -0
- package/templates/max/tsconfig.json +3 -0
- package/templates/max/typings.d.ts +1 -0
- package/templates/plugin/.fatherrc.ts +5 -5
- package/templates/plugin/.gitignore.tpl +1 -1
- package/templates/plugin/.npmrc.tpl +1 -0
- package/templates/plugin/README.md.tpl +5 -14
- package/templates/plugin/package.json.tpl +12 -10
- package/templates/plugin/src/index.ts.tpl +2 -2
- package/templates/plugin/tsconfig.json +20 -0
- package/templates/vue-app/.gitignore.tpl +13 -0
- package/templates/vue-app/.npmrc.tpl +2 -0
- package/templates/vue-app/.umirc.ts.tpl +6 -0
- package/templates/vue-app/package.json.tpl +18 -0
- package/templates/vue-app/src/assets/yay.jpg +0 -0
- package/templates/vue-app/src/layouts/index.vue +28 -0
- package/templates/vue-app/src/pages/docs.vue +5 -0
- package/templates/vue-app/src/pages/index.vue +9 -0
- package/templates/vue-app/tsconfig.json.tpl +3 -0
- package/templates/vue-app/typings.d.ts +1 -0
- package/templates/app/tsconfig.json +0 -18
- /package/templates/app/{assets → src/assets}/yay.jpg +0 -0
- /package/templates/app/{layouts → src/layouts}/index.less +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present ChenCheng (sorrycc@gmail.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/bin/create-umi.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
help: ['h'],
|
|
10
|
-
},
|
|
11
|
-
boolean: ['version'],
|
|
1
|
+
// src/cli.ts
|
|
2
|
+
var import_utils = require("@umijs/utils");
|
|
3
|
+
var args = (0, import_utils.yParser)(process.argv.slice(2), {
|
|
4
|
+
alias: {
|
|
5
|
+
version: ["v"],
|
|
6
|
+
help: ["h"]
|
|
7
|
+
},
|
|
8
|
+
boolean: ["version"]
|
|
12
9
|
});
|
|
13
10
|
if (args.version && !args._[0]) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
.catch((err) => {
|
|
28
|
-
console.error(`Create failed, ${err.message}`);
|
|
29
|
-
console.error(err);
|
|
30
|
-
});
|
|
11
|
+
args._[0] = "version";
|
|
12
|
+
const local = (0, import_utils.isLocalDev)() ? import_utils.chalk.cyan("@local") : "";
|
|
13
|
+
const { name, version } = require("../package.json");
|
|
14
|
+
console.log(`${name}@${version}${local}`);
|
|
15
|
+
} else {
|
|
16
|
+
require("./").default({
|
|
17
|
+
cwd: process.cwd(),
|
|
18
|
+
args
|
|
19
|
+
}).catch((err) => {
|
|
20
|
+
console.error(`Create failed, ${err.message}`);
|
|
21
|
+
console.error(err);
|
|
22
|
+
});
|
|
31
23
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
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 {
|
|
7
|
+
default?: boolean;
|
|
8
|
+
git?: boolean;
|
|
9
|
+
install?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface ITemplatePluginParams {
|
|
12
|
+
pluginName?: string;
|
|
13
|
+
}
|
|
14
|
+
interface ITemplateParams extends ITemplatePluginParams {
|
|
15
|
+
version: string;
|
|
16
|
+
npmClient: ENpmClient;
|
|
17
|
+
registry: string;
|
|
18
|
+
author: string;
|
|
19
|
+
email: string;
|
|
20
|
+
withHusky: boolean;
|
|
21
|
+
extraNpmrc: string;
|
|
22
|
+
}
|
|
23
|
+
declare enum ENpmClient {
|
|
24
|
+
npm = "npm",
|
|
25
|
+
cnpm = "cnpm",
|
|
26
|
+
tnpm = "tnpm",
|
|
27
|
+
yarn = "yarn",
|
|
28
|
+
pnpm = "pnpm"
|
|
29
|
+
}
|
|
30
|
+
declare enum ETemplate {
|
|
31
|
+
app = "app",
|
|
32
|
+
max = "max",
|
|
33
|
+
vueApp = "vue-app",
|
|
34
|
+
plugin = "plugin"
|
|
35
|
+
}
|
|
36
|
+
export interface IDefaultData extends ITemplateParams {
|
|
37
|
+
appTemplate?: ETemplate;
|
|
38
|
+
}
|
|
39
|
+
interface IGeneratorOpts {
|
|
3
40
|
cwd: string;
|
|
4
|
-
args:
|
|
5
|
-
|
|
41
|
+
args: IArgs;
|
|
42
|
+
defaultData?: IDefaultData;
|
|
43
|
+
}
|
|
44
|
+
declare const _default: ({ cwd, args, defaultData, }: IGeneratorOpts) => Promise<void>;
|
|
6
45
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,106 +1,296 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
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 });
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
author: 'xiaohuoni',
|
|
19
|
-
org: 'umijs',
|
|
20
|
-
version: require('../package').version,
|
|
21
|
-
npmClient: 'pnpm',
|
|
22
|
-
registry: 'https://registry.npmjs.org/',
|
|
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;
|
|
23
16
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
default: () => src_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
var import_template = require("./template");
|
|
29
|
+
var pkg = require("../package");
|
|
30
|
+
var DEFAULT_DATA = {
|
|
31
|
+
pluginName: "umi-plugin-demo",
|
|
32
|
+
email: "i@domain.com",
|
|
33
|
+
author: "umijs",
|
|
34
|
+
version: pkg.version,
|
|
35
|
+
npmClient: "pnpm" /* pnpm */,
|
|
36
|
+
registry: import_template.ERegistry.npm,
|
|
37
|
+
withHusky: false,
|
|
38
|
+
extraNpmrc: "",
|
|
39
|
+
appTemplate: "app" /* app */
|
|
40
|
+
};
|
|
41
|
+
var src_default = async ({
|
|
42
|
+
cwd,
|
|
43
|
+
args,
|
|
44
|
+
defaultData = DEFAULT_DATA
|
|
45
|
+
}) => {
|
|
46
|
+
let [name] = args._;
|
|
47
|
+
let npmClient = "pnpm" /* pnpm */;
|
|
48
|
+
let registry = import_template.ERegistry.npm;
|
|
49
|
+
let appTemplate = (defaultData == null ? void 0 : defaultData.appTemplate) || "app" /* app */;
|
|
50
|
+
const { username, email } = await (0, import_utils.getGitInfo)();
|
|
51
|
+
const author = email && username ? `${username} <${email}>` : "";
|
|
52
|
+
let pluginName = `umi-plugin-${name || "demo"}`;
|
|
53
|
+
const target = name ? (0, import_path.join)(cwd, name) : cwd;
|
|
54
|
+
const { isCancel, text, select, intro, outro } = import_utils.clackPrompts;
|
|
55
|
+
const exitPrompt = () => {
|
|
56
|
+
outro(import_utils.chalk.red("Exit create-umi"));
|
|
57
|
+
process.exit(1);
|
|
58
|
+
};
|
|
59
|
+
const selectAppTemplate = async () => {
|
|
60
|
+
appTemplate = await select({
|
|
61
|
+
message: "Pick Umi App Template",
|
|
62
|
+
options: [
|
|
63
|
+
{ label: "Simple App", value: "app" /* app */ },
|
|
68
64
|
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
label: "Ant Design Pro",
|
|
66
|
+
value: "max" /* max */,
|
|
67
|
+
hint: "more plugins and ready to use features"
|
|
72
68
|
},
|
|
69
|
+
{ label: "Vue Simple App", value: "vue-app" /* vueApp */ },
|
|
73
70
|
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
71
|
+
label: "Umi Plugin",
|
|
72
|
+
value: "plugin" /* plugin */,
|
|
73
|
+
hint: "for plugin development"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
initialValue: "app" /* app */
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const selectNpmClient = async () => {
|
|
80
|
+
npmClient = await select({
|
|
81
|
+
message: "Pick Npm Client",
|
|
82
|
+
options: [
|
|
83
|
+
{ label: "npm" /* npm */, value: "npm" /* npm */ },
|
|
84
|
+
{ label: "cnpm" /* cnpm */, value: "cnpm" /* cnpm */ },
|
|
85
|
+
{ label: "tnpm" /* tnpm */, value: "tnpm" /* tnpm */ },
|
|
86
|
+
{ label: "yarn" /* yarn */, value: "yarn" /* yarn */ },
|
|
87
|
+
{ label: "pnpm" /* pnpm */, value: "pnpm" /* pnpm */, hint: "recommended" }
|
|
88
|
+
],
|
|
89
|
+
initialValue: "pnpm" /* pnpm */
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const selectRegistry = async () => {
|
|
93
|
+
registry = await select({
|
|
94
|
+
message: "Pick Npm Registry",
|
|
95
|
+
options: [
|
|
78
96
|
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
message: `What's your name?`,
|
|
97
|
+
label: "npm",
|
|
98
|
+
value: import_template.ERegistry.npm
|
|
82
99
|
},
|
|
83
100
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
path: (0, path_1.join)(__dirname, '..', 'templates', args.plugin ? 'plugin' : 'app'),
|
|
91
|
-
target: name ? (0, path_1.join)(cwd, name) : cwd,
|
|
92
|
-
data: args.default
|
|
93
|
-
? testData
|
|
94
|
-
: {
|
|
95
|
-
version: require('../package').version,
|
|
96
|
-
npmClient,
|
|
97
|
-
registry,
|
|
98
|
-
},
|
|
99
|
-
questions: args.default ? [] : args.plugin ? pluginPrompts : [],
|
|
101
|
+
label: "taobao",
|
|
102
|
+
value: import_template.ERegistry.taobao,
|
|
103
|
+
hint: "recommended for China"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
initialValue: import_template.ERegistry.npm
|
|
100
107
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
};
|
|
109
|
+
const internalTemplatePrompts = async () => {
|
|
110
|
+
intro(import_utils.chalk.bgHex("#19BDD2")(" create-umi "));
|
|
111
|
+
await selectAppTemplate();
|
|
112
|
+
if (isCancel(appTemplate)) {
|
|
113
|
+
exitPrompt();
|
|
105
114
|
}
|
|
106
|
-
|
|
115
|
+
await selectNpmClient();
|
|
116
|
+
if (isCancel(npmClient)) {
|
|
117
|
+
exitPrompt();
|
|
118
|
+
}
|
|
119
|
+
await selectRegistry();
|
|
120
|
+
if (isCancel(registry)) {
|
|
121
|
+
exitPrompt();
|
|
122
|
+
}
|
|
123
|
+
const isPlugin = appTemplate === "plugin" /* plugin */;
|
|
124
|
+
if (isPlugin) {
|
|
125
|
+
pluginName = await text({
|
|
126
|
+
message: `What's the plugin name?`,
|
|
127
|
+
placeholder: pluginName,
|
|
128
|
+
validate: (value) => {
|
|
129
|
+
if (!(value == null ? void 0 : value.length)) {
|
|
130
|
+
return "Please input plugin name";
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
if (isCancel(pluginName)) {
|
|
135
|
+
exitPrompt();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
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
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const version = pkg.version;
|
|
164
|
+
const monorepoRoot = await detectMonorepoRoot({ target });
|
|
165
|
+
const inMonorepo = !!monorepoRoot;
|
|
166
|
+
const projectRoot = inMonorepo ? monorepoRoot : target;
|
|
167
|
+
const shouldInitGit = args.git !== false;
|
|
168
|
+
const withHusky = shouldInitGit && !inMonorepo;
|
|
169
|
+
let pnpmExtraNpmrc = "";
|
|
170
|
+
const isPnpm = npmClient === "pnpm" /* pnpm */;
|
|
171
|
+
let pnpmMajorVersion;
|
|
172
|
+
let pnpmVersion;
|
|
173
|
+
if (isPnpm) {
|
|
174
|
+
pnpmVersion = await getPnpmVersion();
|
|
175
|
+
pnpmMajorVersion = parseInt(pnpmVersion.split(".")[0], 10);
|
|
176
|
+
import_utils.logger.debug(`pnpm version: ${pnpmVersion}`);
|
|
177
|
+
if (pnpmMajorVersion === 7) {
|
|
178
|
+
pnpmExtraNpmrc = `strict-peer-dependencies=false`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const injectInternalTemplateFiles = async () => {
|
|
182
|
+
const generator = new import_utils.BaseGenerator({
|
|
183
|
+
path: (0, import_path.join)(__dirname, "..", "templates", appTemplate),
|
|
184
|
+
target,
|
|
185
|
+
slient: true,
|
|
186
|
+
data: useDefaultData ? defaultData : {
|
|
187
|
+
version: version.includes("-canary.") ? version : `^${version}`,
|
|
188
|
+
npmClient,
|
|
189
|
+
registry,
|
|
190
|
+
author,
|
|
191
|
+
email,
|
|
192
|
+
withHusky,
|
|
193
|
+
extraNpmrc: isPnpm ? pnpmExtraNpmrc : "",
|
|
194
|
+
pluginName
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
await generator.run();
|
|
198
|
+
};
|
|
199
|
+
if (!useExternalTemplate) {
|
|
200
|
+
await injectInternalTemplateFiles();
|
|
201
|
+
}
|
|
202
|
+
const context = {
|
|
203
|
+
inMonorepo,
|
|
204
|
+
target,
|
|
205
|
+
projectRoot
|
|
206
|
+
};
|
|
207
|
+
if (!withHusky) {
|
|
208
|
+
await removeHusky(context);
|
|
209
|
+
}
|
|
210
|
+
if (inMonorepo) {
|
|
211
|
+
await moveNpmrc(context);
|
|
212
|
+
}
|
|
213
|
+
if (shouldInitGit) {
|
|
214
|
+
await initGit(context);
|
|
215
|
+
} else {
|
|
216
|
+
import_utils.logger.info(`Skip Git init`);
|
|
217
|
+
}
|
|
218
|
+
const isPnpm8 = pnpmMajorVersion === 8;
|
|
219
|
+
const pnpmHighestResolutionMinVersion = "8.7.0";
|
|
220
|
+
const isPnpmHighestResolution = isPnpm8 && import_utils.semver.gte(pnpmVersion, pnpmHighestResolutionMinVersion);
|
|
221
|
+
if (!useDefaultData && args.install !== false) {
|
|
222
|
+
if (isPnpm8 && !isPnpmHighestResolution) {
|
|
223
|
+
await installAndUpdateWithPnpm(target);
|
|
224
|
+
} else {
|
|
225
|
+
(0, import_utils.installWithNpmClient)({ npmClient, cwd: target });
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
import_utils.logger.info(`Skip install deps`);
|
|
229
|
+
if (isPnpm8) {
|
|
230
|
+
import_utils.logger.warn(
|
|
231
|
+
import_utils.chalk.yellow(
|
|
232
|
+
`You current using pnpm v8, it will install minimal version of dependencies`
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
import_utils.logger.warn(
|
|
236
|
+
import_utils.chalk.green(
|
|
237
|
+
`Recommended that you run ${import_utils.chalk.bold.cyan(
|
|
238
|
+
"pnpm up -L"
|
|
239
|
+
)} to install latest version of dependencies`
|
|
240
|
+
)
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
async function detectMonorepoRoot(opts) {
|
|
246
|
+
const { target } = opts;
|
|
247
|
+
const rootPkg = await import_utils.pkgUp.pkgUp({ cwd: (0, import_path.dirname)(target) });
|
|
248
|
+
if (!rootPkg) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
const rootDir = (0, import_path.dirname)(rootPkg);
|
|
252
|
+
if ((0, import_utils.tryPaths)([
|
|
253
|
+
(0, import_path.join)(rootDir, "lerna.json"),
|
|
254
|
+
(0, import_path.join)(rootDir, "pnpm-workspace.yaml")
|
|
255
|
+
])) {
|
|
256
|
+
return rootDir;
|
|
257
|
+
}
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
async function moveNpmrc(opts) {
|
|
261
|
+
const { target, projectRoot } = opts;
|
|
262
|
+
const sourceNpmrc = (0, import_path.join)(target, "./.npmrc");
|
|
263
|
+
const targetNpmrc = (0, import_path.join)(projectRoot, "./.npmrc");
|
|
264
|
+
if (!(0, import_fs.existsSync)(targetNpmrc)) {
|
|
265
|
+
await import_utils.fsExtra.copyFile(sourceNpmrc, targetNpmrc);
|
|
266
|
+
}
|
|
267
|
+
await import_utils.fsExtra.remove(sourceNpmrc);
|
|
268
|
+
}
|
|
269
|
+
async function initGit(opts) {
|
|
270
|
+
const { projectRoot } = opts;
|
|
271
|
+
const isGit = (0, import_fs.existsSync)((0, import_path.join)(projectRoot, ".git"));
|
|
272
|
+
if (isGit)
|
|
273
|
+
return;
|
|
274
|
+
try {
|
|
275
|
+
await import_utils.execa.execa("git", ["init"], { cwd: projectRoot });
|
|
276
|
+
} catch {
|
|
277
|
+
import_utils.logger.error(`Initial the git repo failed`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async function removeHusky(opts) {
|
|
281
|
+
const dir = (0, import_path.join)(opts.target, "./.husky");
|
|
282
|
+
if ((0, import_fs.existsSync)(dir)) {
|
|
283
|
+
await import_utils.fsExtra.remove(dir);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function installAndUpdateWithPnpm(cwd) {
|
|
287
|
+
await import_utils.execa.execa("pnpm", ["up", "-L"], { cwd, stdio: "inherit" });
|
|
288
|
+
}
|
|
289
|
+
async function getPnpmVersion() {
|
|
290
|
+
try {
|
|
291
|
+
const { stdout } = await import_utils.execa.execa("pnpm", ["--version"]);
|
|
292
|
+
return stdout.trim();
|
|
293
|
+
} catch (e) {
|
|
294
|
+
throw new Error("Please install pnpm first", { cause: e });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -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`;
|
|
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
|
+
});
|