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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/bin/create-umi.js +1 -0
  3. package/dist/cli.js +20 -28
  4. package/dist/index.d.ts +42 -3
  5. package/dist/index.js +286 -96
  6. package/dist/template.d.ts +12 -0
  7. package/dist/template.js +113 -0
  8. package/package.json +13 -12
  9. package/templates/app/.gitignore.tpl +2 -3
  10. package/templates/app/.npmrc.tpl +1 -0
  11. package/templates/app/.umirc.ts.tpl +9 -3
  12. package/templates/app/package.json.tpl +6 -4
  13. package/templates/app/{layouts → src/layouts}/index.tsx.tpl +0 -1
  14. package/templates/app/{pages → src/pages}/docs.tsx +3 -3
  15. package/templates/app/{pages → src/pages}/index.tsx +2 -2
  16. package/templates/app/tsconfig.json.tpl +3 -0
  17. package/templates/app/typings.d.ts +1 -3
  18. package/templates/max/.eslintrc.js.tpl +3 -0
  19. package/templates/max/.gitignore.tpl +13 -0
  20. package/templates/max/.husky/commit-msg +1 -0
  21. package/templates/max/.husky/pre-commit +1 -0
  22. package/templates/max/.lintstagedrc.tpl +17 -0
  23. package/templates/max/.npmrc.tpl +2 -0
  24. package/templates/max/.prettierignore.tpl +3 -0
  25. package/templates/max/.prettierrc.tpl +8 -0
  26. package/templates/max/.stylelintrc.js.tpl +3 -0
  27. package/templates/max/.umirc.ts.tpl +35 -0
  28. package/templates/max/README.md +3 -0
  29. package/templates/max/mock/userAPI.ts +20 -0
  30. package/templates/max/package.json.tpl +29 -0
  31. package/templates/max/src/access.ts +10 -0
  32. package/templates/max/src/app.ts +16 -0
  33. package/templates/max/src/assets/.gitkeep +0 -0
  34. package/templates/max/src/components/Guide/Guide.less +4 -0
  35. package/templates/max/src/components/Guide/Guide.tsx +23 -0
  36. package/templates/max/src/components/Guide/index.ts +2 -0
  37. package/templates/max/src/constants/index.ts +1 -0
  38. package/templates/max/src/models/global.ts +13 -0
  39. package/templates/max/src/pages/Access/index.tsx +21 -0
  40. package/templates/max/src/pages/Home/index.less +3 -0
  41. package/templates/max/src/pages/Home/index.tsx +18 -0
  42. package/templates/max/src/pages/Table/components/CreateForm.tsx +26 -0
  43. package/templates/max/src/pages/Table/components/UpdateForm.tsx +138 -0
  44. package/templates/max/src/pages/Table/index.tsx +270 -0
  45. package/templates/max/src/services/demo/UserController.ts +96 -0
  46. package/templates/max/src/services/demo/index.ts +7 -0
  47. package/templates/max/src/services/demo/typings.d.ts +68 -0
  48. package/templates/max/src/utils/format.ts +4 -0
  49. package/templates/max/tsconfig.json +3 -0
  50. package/templates/max/typings.d.ts +1 -0
  51. package/templates/plugin/.fatherrc.ts +5 -5
  52. package/templates/plugin/.gitignore.tpl +1 -1
  53. package/templates/plugin/.npmrc.tpl +1 -0
  54. package/templates/plugin/README.md.tpl +5 -14
  55. package/templates/plugin/package.json.tpl +12 -10
  56. package/templates/plugin/src/index.ts.tpl +2 -2
  57. package/templates/plugin/tsconfig.json +20 -0
  58. package/templates/vue-app/.gitignore.tpl +13 -0
  59. package/templates/vue-app/.npmrc.tpl +2 -0
  60. package/templates/vue-app/.umirc.ts.tpl +6 -0
  61. package/templates/vue-app/package.json.tpl +18 -0
  62. package/templates/vue-app/src/assets/yay.jpg +0 -0
  63. package/templates/vue-app/src/layouts/index.vue +28 -0
  64. package/templates/vue-app/src/pages/docs.vue +5 -0
  65. package/templates/vue-app/src/pages/index.vue +9 -0
  66. package/templates/vue-app/tsconfig.json.tpl +3 -0
  67. package/templates/vue-app/typings.d.ts +1 -0
  68. package/templates/app/tsconfig.json +0 -18
  69. /package/templates/app/{assets → src/assets}/yay.jpg +0 -0
  70. /package/templates/app/{layouts → src/layouts}/index.less +0 -0
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "create-umi",
3
- "version": "4.0.0-beta.17",
3
+ "version": "4.0.0-canary-20240513.3",
4
4
  "description": "create-umi",
5
- "homepage": "https://github.com/umijs/umi-next/tree/master/packages/create-umi#readme",
6
- "bugs": "https://github.com/umijs/umi-next/issues",
5
+ "homepage": "https://github.com/umijs/umi/tree/master/packages/create-umi#readme",
6
+ "bugs": "https://github.com/umijs/umi/issues",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/umijs/umi-next"
9
+ "url": "https://github.com/umijs/umi"
10
10
  },
11
11
  "license": "MIT",
12
12
  "main": "dist/index.js",
@@ -18,18 +18,19 @@
18
18
  "dist",
19
19
  "templates"
20
20
  ],
21
- "scripts": {
22
- "build": "pnpm tsc",
23
- "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
24
- "dev": "pnpm build -- --watch"
25
- },
26
21
  "dependencies": {
27
- "@umijs/utils": "4.0.0-beta.17"
22
+ "@umijs/utils": "4.0.0-canary-20240513.3"
28
23
  },
29
24
  "publishConfig": {
30
25
  "access": "public"
31
26
  },
32
27
  "authors": [
33
28
  "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
34
- ]
35
- }
29
+ ],
30
+ "scripts": {
31
+ "build": "umi-scripts father build",
32
+ "build:deps": "umi-scripts bundleDeps",
33
+ "dev": "umi-scripts father dev",
34
+ "test": "umi-scripts jest-turbo"
35
+ }
36
+ }
@@ -4,7 +4,6 @@
4
4
  /config/config.local.ts
5
5
  /src/.umi
6
6
  /src/.umi-production
7
- /.umi
8
- /.umi-production
7
+ /src/.umi-test
9
8
  /dist
10
- /.mfsu
9
+ .swc
@@ -1 +1,2 @@
1
1
  registry={{{ registry }}}
2
+ {{{ extraNpmrc }}}
@@ -1,3 +1,9 @@
1
- export default {
2
- npmClient: '{{{ npmClient }}}'
3
- };
1
+ import { defineConfig } from "umi";
2
+
3
+ export default defineConfig({
4
+ routes: [
5
+ { path: "/", component: "index" },
6
+ { path: "/docs", component: "docs" },
7
+ ],
8
+ npmClient: '{{{ npmClient }}}',
9
+ });
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "private": true,
3
+ "author": "{{{ author }}}",
3
4
  "scripts": {
4
5
  "dev": "umi dev",
5
6
  "build": "umi build",
6
7
  "postinstall": "umi setup",
8
+ "setup": "umi setup",
7
9
  "start": "npm run dev"
8
10
  },
9
11
  "dependencies": {
10
- "umi": "^{{{ version }}}"
12
+ "umi": "{{{ version }}}"
11
13
  },
12
14
  "devDependencies": {
13
- "@types/react": "^17.0.0",
14
- "@types/react-dom": "^17.0.0",
15
- "typescript": "^4.1.2"
15
+ "@types/react": "^18.0.33",
16
+ "@types/react-dom": "^18.0.11",
17
+ "typescript": "^5.0.3"
16
18
  }
17
19
  }
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { Link, Outlet } from 'umi';
3
2
  import styles from './index.less';
4
3
 
@@ -1,9 +1,9 @@
1
- import React from 'react';
2
-
3
- export default () => {
1
+ const DocsPage = () => {
4
2
  return (
5
3
  <div>
6
4
  <p>This is umi docs.</p>
7
5
  </div>
8
6
  );
9
7
  };
8
+
9
+ export default DocsPage;
@@ -1,11 +1,11 @@
1
- import React from 'react';
1
+ import yayJpg from '../assets/yay.jpg';
2
2
 
3
3
  export default function HomePage() {
4
4
  return (
5
5
  <div>
6
6
  <h2>Yay! Welcome to umi!</h2>
7
7
  <p>
8
- <img src={require('../assets/yay.jpg')} width="388" />
8
+ <img src={yayJpg} width="388" />
9
9
  </p>
10
10
  <p>
11
11
  To get started, edit <code>pages/index.tsx</code> and save to reload.
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./src/.umi/tsconfig.json"
3
+ }
@@ -1,3 +1 @@
1
- declare module '*.less';
2
- declare module '*.css';
3
- declare module '*.png';
1
+ import 'umi/typings';
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: require.resolve('@umijs/max/eslint'),
3
+ };
@@ -0,0 +1,13 @@
1
+ /node_modules
2
+ /.env.local
3
+ /.umirc.local.ts
4
+ /config/config.local.ts
5
+ /src/.umi
6
+ /src/.umi-production
7
+ /src/.umi-test
8
+ /.umi
9
+ /.umi-production
10
+ /.umi-test
11
+ /dist
12
+ /.mfsu
13
+ .swc
@@ -0,0 +1 @@
1
+ npx --no-install max verify-commit $1
@@ -0,0 +1 @@
1
+ npx --no-install lint-staged --quiet
@@ -0,0 +1,17 @@
1
+ {
2
+ "*.{md,json}": [
3
+ "prettier --cache --write"
4
+ ],
5
+ "*.{js,jsx}": [
6
+ "max lint --fix --eslint-only",
7
+ "prettier --cache --write"
8
+ ],
9
+ "*.{css,less}": [
10
+ "max lint --fix --stylelint-only",
11
+ "prettier --cache --write"
12
+ ],
13
+ "*.ts?(x)": [
14
+ "max lint --fix --eslint-only",
15
+ "prettier --cache --parser=typescript --write"
16
+ ]
17
+ }
@@ -0,0 +1,2 @@
1
+ registry={{{ registry }}}
2
+ {{{ extraNpmrc }}}
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ .umi
3
+ .umi-production
@@ -0,0 +1,8 @@
1
+ {
2
+ "printWidth": 80,
3
+ "singleQuote": true,
4
+ "trailingComma": "all",
5
+ "proseWrap": "never",
6
+ "overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }],
7
+ "plugins": ["prettier-plugin-organize-imports", "prettier-plugin-packagejson"]
8
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: require.resolve('@umijs/max/stylelint'),
3
+ };
@@ -0,0 +1,35 @@
1
+ import { defineConfig } from '@umijs/max';
2
+
3
+ export default defineConfig({
4
+ antd: {},
5
+ access: {},
6
+ model: {},
7
+ initialState: {},
8
+ request: {},
9
+ layout: {
10
+ title: '@umijs/max',
11
+ },
12
+ routes: [
13
+ {
14
+ path: '/',
15
+ redirect: '/home',
16
+ },
17
+ {
18
+ name: '首页',
19
+ path: '/home',
20
+ component: './Home',
21
+ },
22
+ {
23
+ name: '权限演示',
24
+ path: '/access',
25
+ component: './Access',
26
+ },
27
+ {
28
+ name: ' CRUD 示例',
29
+ path: '/table',
30
+ component: './Table',
31
+ },
32
+ ],
33
+ npmClient: '{{{ npmClient }}}',
34
+ });
35
+
@@ -0,0 +1,3 @@
1
+ # README
2
+
3
+ `@umijs/max` 模板项目,更多功能参考 [Umi Max 简介](https://umijs.org/docs/max/introduce)
@@ -0,0 +1,20 @@
1
+ const users = [
2
+ { id: 0, name: 'Umi', nickName: 'U', gender: 'MALE' },
3
+ { id: 1, name: 'Fish', nickName: 'B', gender: 'FEMALE' },
4
+ ];
5
+
6
+ export default {
7
+ 'GET /api/v1/queryUserList': (req: any, res: any) => {
8
+ res.json({
9
+ success: true,
10
+ data: { list: users },
11
+ errorCode: 0,
12
+ });
13
+ },
14
+ 'PUT /api/v1/user/': (req: any, res: any) => {
15
+ res.json({
16
+ success: true,
17
+ errorCode: 0,
18
+ });
19
+ },
20
+ };
@@ -0,0 +1,29 @@
1
+ {
2
+ "private": true,
3
+ "author": "{{{ author }}}",
4
+ "scripts": {
5
+ "dev": "max dev",
6
+ "build": "max build",
7
+ "format": "prettier --cache --write .",{{#withHusky}}
8
+ "prepare": "husky",{{/withHusky}}
9
+ "postinstall": "max setup",
10
+ "setup": "max setup",
11
+ "start": "npm run dev"
12
+ },
13
+ "dependencies": {
14
+ "@ant-design/icons": "^5.0.1",
15
+ "@ant-design/pro-components": "^2.4.4",
16
+ "@umijs/max": "{{{ version }}}",
17
+ "antd": "^5.4.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/react": "^18.0.33",
21
+ "@types/react-dom": "^18.0.11",{{#withHusky}}
22
+ "husky": "^9",{{/withHusky}}
23
+ "lint-staged": "^13.2.0",
24
+ "prettier": "^2.8.7",
25
+ "prettier-plugin-organize-imports": "^3.2.2",
26
+ "prettier-plugin-packagejson": "^2.4.3",
27
+ "typescript": "^5.0.3"
28
+ }
29
+ }
@@ -0,0 +1,10 @@
1
+ export default (initialState: API.UserInfo) => {
2
+ // 在这里按照初始化数据定义项目中的权限,统一管理
3
+ // 参考文档 https://umijs.org/docs/max/access
4
+ const canSeeAdmin = !!(
5
+ initialState && initialState.name !== 'dontHaveAccess'
6
+ );
7
+ return {
8
+ canSeeAdmin,
9
+ };
10
+ };
@@ -0,0 +1,16 @@
1
+ // 运行时配置
2
+
3
+ // 全局初始化数据配置,用于 Layout 用户信息和权限初始化
4
+ // 更多信息见文档:https://umijs.org/docs/api/runtime-config#getinitialstate
5
+ export async function getInitialState(): Promise<{ name: string }> {
6
+ return { name: '@umijs/max' };
7
+ }
8
+
9
+ export const layout = () => {
10
+ return {
11
+ logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
12
+ menu: {
13
+ locale: false,
14
+ },
15
+ };
16
+ };
File without changes
@@ -0,0 +1,4 @@
1
+ .title {
2
+ margin: 0 auto;
3
+ font-weight: 200;
4
+ }
@@ -0,0 +1,23 @@
1
+ import { Layout, Row, Typography } from 'antd';
2
+ import React from 'react';
3
+ import styles from './Guide.less';
4
+
5
+ interface Props {
6
+ name: string;
7
+ }
8
+
9
+ // 脚手架示例组件
10
+ const Guide: React.FC<Props> = (props) => {
11
+ const { name } = props;
12
+ return (
13
+ <Layout>
14
+ <Row>
15
+ <Typography.Title level={3} className={styles.title}>
16
+ 欢迎使用 <strong>{name}</strong> !
17
+ </Typography.Title>
18
+ </Row>
19
+ </Layout>
20
+ );
21
+ };
22
+
23
+ export default Guide;
@@ -0,0 +1,2 @@
1
+ import Guide from './Guide';
2
+ export default Guide;
@@ -0,0 +1 @@
1
+ export const DEFAULT_NAME = 'Umi Max';
@@ -0,0 +1,13 @@
1
+ // 全局共享数据示例
2
+ import { DEFAULT_NAME } from '@/constants';
3
+ import { useState } from 'react';
4
+
5
+ const useUser = () => {
6
+ const [name, setName] = useState<string>(DEFAULT_NAME);
7
+ return {
8
+ name,
9
+ setName,
10
+ };
11
+ };
12
+
13
+ export default useUser;
@@ -0,0 +1,21 @@
1
+ import { PageContainer } from '@ant-design/pro-components';
2
+ import { Access, useAccess } from '@umijs/max';
3
+ import { Button } from 'antd';
4
+
5
+ const AccessPage: React.FC = () => {
6
+ const access = useAccess();
7
+ return (
8
+ <PageContainer
9
+ ghost
10
+ header={{
11
+ title: '权限示例',
12
+ }}
13
+ >
14
+ <Access accessible={access.canSeeAdmin}>
15
+ <Button>只有 Admin 可以看到这个按钮</Button>
16
+ </Access>
17
+ </PageContainer>
18
+ );
19
+ };
20
+
21
+ export default AccessPage;
@@ -0,0 +1,3 @@
1
+ .container {
2
+ padding-top: 80px;
3
+ }
@@ -0,0 +1,18 @@
1
+ import Guide from '@/components/Guide';
2
+ import { trim } from '@/utils/format';
3
+ import { PageContainer } from '@ant-design/pro-components';
4
+ import { useModel } from '@umijs/max';
5
+ import styles from './index.less';
6
+
7
+ const HomePage: React.FC = () => {
8
+ const { name } = useModel('global');
9
+ return (
10
+ <PageContainer ghost>
11
+ <div className={styles.container}>
12
+ <Guide name={trim(name)} />
13
+ </div>
14
+ </PageContainer>
15
+ );
16
+ };
17
+
18
+ export default HomePage;
@@ -0,0 +1,26 @@
1
+ import { Modal } from 'antd';
2
+ import React, { PropsWithChildren } from 'react';
3
+
4
+ interface CreateFormProps {
5
+ modalVisible: boolean;
6
+ onCancel: () => void;
7
+ }
8
+
9
+ const CreateForm: React.FC<PropsWithChildren<CreateFormProps>> = (props) => {
10
+ const { modalVisible, onCancel } = props;
11
+
12
+ return (
13
+ <Modal
14
+ destroyOnClose
15
+ title="新建"
16
+ width={420}
17
+ open={modalVisible}
18
+ onCancel={() => onCancel()}
19
+ footer={null}
20
+ >
21
+ {props.children}
22
+ </Modal>
23
+ );
24
+ };
25
+
26
+ export default CreateForm;
@@ -0,0 +1,138 @@
1
+ import {
2
+ ProFormDateTimePicker,
3
+ ProFormRadio,
4
+ ProFormSelect,
5
+ ProFormText,
6
+ ProFormTextArea,
7
+ StepsForm,
8
+ } from '@ant-design/pro-components';
9
+ import { Modal } from 'antd';
10
+ import React from 'react';
11
+
12
+ export interface FormValueType extends Partial<API.UserInfo> {
13
+ target?: string;
14
+ template?: string;
15
+ type?: string;
16
+ time?: string;
17
+ frequency?: string;
18
+ }
19
+
20
+ export interface UpdateFormProps {
21
+ onCancel: (flag?: boolean, formVals?: FormValueType) => void;
22
+ onSubmit: (values: FormValueType) => Promise<void>;
23
+ updateModalVisible: boolean;
24
+ values: Partial<API.UserInfo>;
25
+ }
26
+
27
+ const UpdateForm: React.FC<UpdateFormProps> = (props) => (
28
+ <StepsForm
29
+ stepsProps={{
30
+ size: 'small',
31
+ }}
32
+ stepsFormRender={(dom, submitter) => {
33
+ return (
34
+ <Modal
35
+ width={640}
36
+ bodyStyle={{ padding: '32px 40px 48px' }}
37
+ destroyOnClose
38
+ title="规则配置"
39
+ open={props.updateModalVisible}
40
+ footer={submitter}
41
+ onCancel={() => props.onCancel()}
42
+ >
43
+ {dom}
44
+ </Modal>
45
+ );
46
+ }}
47
+ onFinish={props.onSubmit}
48
+ >
49
+ <StepsForm.StepForm
50
+ initialValues={{
51
+ name: props.values.name,
52
+ nickName: props.values.nickName,
53
+ }}
54
+ title="基本信息"
55
+ >
56
+ <ProFormText
57
+ width="md"
58
+ name="name"
59
+ label="规则名称"
60
+ rules={[{ required: true, message: '请输入规则名称!' }]}
61
+ />
62
+ <ProFormTextArea
63
+ name="desc"
64
+ width="md"
65
+ label="规则描述"
66
+ placeholder="请输入至少五个字符"
67
+ rules={[
68
+ { required: true, message: '请输入至少五个字符的规则描述!', min: 5 },
69
+ ]}
70
+ />
71
+ </StepsForm.StepForm>
72
+ <StepsForm.StepForm
73
+ initialValues={{
74
+ target: '0',
75
+ template: '0',
76
+ }}
77
+ title="配置规则属性"
78
+ >
79
+ <ProFormSelect
80
+ width="md"
81
+ name="target"
82
+ label="监控对象"
83
+ valueEnum={{
84
+ 0: '表一',
85
+ 1: '表二',
86
+ }}
87
+ />
88
+ <ProFormSelect
89
+ width="md"
90
+ name="template"
91
+ label="规则模板"
92
+ valueEnum={{
93
+ 0: '规则模板一',
94
+ 1: '规则模板二',
95
+ }}
96
+ />
97
+ <ProFormRadio.Group
98
+ name="type"
99
+ width="md"
100
+ label="规则类型"
101
+ options={[
102
+ {
103
+ value: '0',
104
+ label: '强',
105
+ },
106
+ {
107
+ value: '1',
108
+ label: '弱',
109
+ },
110
+ ]}
111
+ />
112
+ </StepsForm.StepForm>
113
+ <StepsForm.StepForm
114
+ initialValues={{
115
+ type: '1',
116
+ frequency: 'month',
117
+ }}
118
+ title="设定调度周期"
119
+ >
120
+ <ProFormDateTimePicker
121
+ name="time"
122
+ label="开始时间"
123
+ rules={[{ required: true, message: '请选择开始时间!' }]}
124
+ />
125
+ <ProFormSelect
126
+ name="frequency"
127
+ label="监控对象"
128
+ width="xs"
129
+ valueEnum={{
130
+ month: '月',
131
+ week: '周',
132
+ }}
133
+ />
134
+ </StepsForm.StepForm>
135
+ </StepsForm>
136
+ );
137
+
138
+ export default UpdateForm;