create-umi 4.0.8 → 4.0.11

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/cli.d.ts CHANGED
File without changes
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- // cli.ts
1
+ // src/cli.ts
2
2
  var import_utils = require("@umijs/utils");
3
3
  var args = (0, import_utils.yParser)(process.argv.slice(2), {
4
4
  alias: {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { yParser } from '@umijs/utils';
2
- declare const _default: ({ cwd, args, }: {
2
+ interface IArgs extends yParser.Arguments {
3
+ default?: boolean;
4
+ plugin?: boolean;
5
+ git?: boolean;
6
+ install?: boolean;
7
+ }
8
+ declare const _default: ({ cwd, args }: {
3
9
  cwd: string;
4
- args: yParser.Arguments;
10
+ args: IArgs;
5
11
  }) => Promise<void>;
6
12
  export default _default;
package/dist/index.js CHANGED
@@ -16,13 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // index.ts
19
+ // src/index.ts
20
20
  var src_exports = {};
21
21
  __export(src_exports, {
22
22
  default: () => src_default
23
23
  });
24
24
  module.exports = __toCommonJS(src_exports);
25
25
  var import_utils = require("@umijs/utils");
26
+ var import_fs = require("fs");
26
27
  var import_path = require("path");
27
28
  var testData = {
28
29
  name: "umi-plugin-demo",
@@ -34,10 +35,7 @@ var testData = {
34
35
  npmClient: "pnpm",
35
36
  registry: "https://registry.npmjs.org/"
36
37
  };
37
- var src_default = async ({
38
- cwd,
39
- args
40
- }) => {
38
+ var src_default = async ({ cwd, args }) => {
41
39
  const [name] = args._;
42
40
  let npmClient = "pnpm";
43
41
  let registry = "https://registry.npmjs.org/";
@@ -123,6 +121,11 @@ var src_default = async ({
123
121
  const target = name ? (0, import_path.join)(cwd, name) : cwd;
124
122
  const templateName = args.plugin ? "plugin" : appTemplate;
125
123
  const version = require("../package").version;
124
+ const monorepoRoot = await detectMonorepoRoot({ target });
125
+ const inMonorepo = !!monorepoRoot;
126
+ const projectRoot = inMonorepo ? monorepoRoot : target;
127
+ const shouldInitGit = args.git !== false;
128
+ const withHusky = shouldInitGit && !inMonorepo;
126
129
  const generator = new import_utils.BaseGenerator({
127
130
  path: (0, import_path.join)(__dirname, "..", "templates", templateName),
128
131
  target,
@@ -130,14 +133,76 @@ var src_default = async ({
130
133
  version: version.includes("-canary.") ? version : `^${version}`,
131
134
  npmClient,
132
135
  registry,
133
- author
136
+ author,
137
+ withHusky,
138
+ extraNpmrc: npmClient === "pnpm" ? `strict-peer-dependencies=false` : ""
134
139
  },
135
140
  questions: args.default ? [] : args.plugin ? pluginPrompts : []
136
141
  });
137
142
  await generator.run();
138
- if (!args.default) {
143
+ const context = {
144
+ inMonorepo,
145
+ target,
146
+ projectRoot
147
+ };
148
+ if (!withHusky) {
149
+ await removeHusky(context);
150
+ }
151
+ if (inMonorepo) {
152
+ await moveNpmrc(context);
153
+ }
154
+ if (shouldInitGit) {
155
+ await initGit(context);
156
+ } else {
157
+ import_utils.logger.info(`Skip Git init`);
158
+ }
159
+ if (!args.default && args.install !== false) {
139
160
  (0, import_utils.installWithNpmClient)({ npmClient, cwd: target });
161
+ } else {
162
+ import_utils.logger.info(`Skip install deps`);
140
163
  }
141
164
  };
165
+ async function detectMonorepoRoot(opts) {
166
+ const { target } = opts;
167
+ const rootPkg = await import_utils.pkgUp.pkgUp({ cwd: (0, import_path.dirname)(target) });
168
+ if (!rootPkg) {
169
+ return null;
170
+ }
171
+ const rootDir = (0, import_path.dirname)(rootPkg);
172
+ if ((0, import_utils.tryPaths)([
173
+ (0, import_path.join)(rootDir, "lerna.json"),
174
+ (0, import_path.join)(rootDir, "pnpm-workspace.yaml")
175
+ ])) {
176
+ return rootDir;
177
+ }
178
+ return null;
179
+ }
180
+ async function moveNpmrc(opts) {
181
+ const { target, projectRoot } = opts;
182
+ const sourceNpmrc = (0, import_path.join)(target, "./.npmrc");
183
+ const targetNpmrc = (0, import_path.join)(projectRoot, "./.npmrc");
184
+ if (!(0, import_fs.existsSync)(targetNpmrc)) {
185
+ await import_utils.fsExtra.copyFile(sourceNpmrc, targetNpmrc);
186
+ }
187
+ await import_utils.fsExtra.remove(sourceNpmrc);
188
+ }
189
+ async function initGit(opts) {
190
+ const { projectRoot } = opts;
191
+ const isGit = (0, import_fs.existsSync)((0, import_path.join)(projectRoot, ".git"));
192
+ if (isGit)
193
+ return;
194
+ try {
195
+ await import_utils.execa.execa("git", ["init"], { cwd: projectRoot });
196
+ import_utils.logger.ready(`Git initialized successfully`);
197
+ } catch {
198
+ import_utils.logger.error(`Initial the git repo failed`);
199
+ }
200
+ }
201
+ async function removeHusky(opts) {
202
+ const dir = (0, import_path.join)(opts.target, "./.husky");
203
+ if ((0, import_fs.existsSync)(dir)) {
204
+ await import_utils.fsExtra.remove(dir);
205
+ }
206
+ }
142
207
  // Annotate the CommonJS export names for ESM import in node:
143
208
  0 && (module.exports = {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-umi",
3
- "version": "4.0.8",
3
+ "version": "4.0.11",
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,13 +19,13 @@
19
19
  "templates"
20
20
  ],
21
21
  "scripts": {
22
- "build": "pnpm father build",
22
+ "build": "umi-scripts father build",
23
23
  "build:deps": "umi-scripts bundleDeps",
24
- "dev": "pnpm father dev",
24
+ "dev": "umi-scripts father dev",
25
25
  "test": "umi-scripts jest-turbo"
26
26
  },
27
27
  "dependencies": {
28
- "@umijs/utils": "4.0.8"
28
+ "@umijs/utils": "4.0.11"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
@@ -4,4 +4,5 @@
4
4
  /config/config.local.ts
5
5
  /src/.umi
6
6
  /src/.umi-production
7
+ /src/.umi-test
7
8
  /dist
@@ -1 +1,2 @@
1
1
  registry={{{ registry }}}
2
+ {{{ extraNpmrc }}}
@@ -4,6 +4,7 @@
4
4
  /config/config.local.ts
5
5
  /src/.umi
6
6
  /src/.umi-production
7
+ /src/.umi-test
7
8
  /.umi
8
9
  /.umi-production
9
10
  /.umi-test
@@ -1 +1,2 @@
1
1
  registry={{{ registry }}}
2
+ {{{ extraNpmrc }}}
@@ -4,8 +4,8 @@
4
4
  "scripts": {
5
5
  "dev": "max dev",
6
6
  "build": "max build",
7
- "format": "prettier --cache --write .",
8
- "prepare": "husky install",
7
+ "format": "prettier --cache --write .",{{#withHusky}}
8
+ "prepare": "husky install",{{/withHusky}}
9
9
  "postinstall": "max setup",
10
10
  "setup": "max setup",
11
11
  "start": "npm run dev"
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/react": "^18.0.0",
21
- "@types/react-dom": "^18.0.0",
22
- "husky": "^8.0.1",
21
+ "@types/react-dom": "^18.0.0",{{#withHusky}}
22
+ "husky": "^8.0.1",{{/withHusky}}
23
23
  "lint-staged": "^13.0.3",
24
24
  "prettier": "^2.7.1",
25
25
  "prettier-plugin-organize-imports": "^2",
@@ -1 +1,2 @@
1
1
  registry={{{ registry }}}
2
+ {{{ extraNpmrc }}}
@@ -4,6 +4,7 @@
4
4
  /config/config.local.ts
5
5
  /src/.umi
6
6
  /src/.umi-production
7
+ /src/.umi-test
7
8
  /.umi
8
9
  /.umi-production
9
10
  /.umi-test
@@ -1 +1,2 @@
1
1
  registry={{{ registry }}}
2
+ {{{ extraNpmrc }}}