Showing
31 changed files
with
295 additions
and
58 deletions
Too many changes to show.
To preserve performance only 31 of 13595 files are displayed.
.gitignore
deleted
100644 → 0
@@ -5,17 +5,19 @@ qx-cli | @@ -5,17 +5,19 @@ qx-cli | ||
5 | ### 快速开始 | 5 | ### 快速开始 |
6 | 6 | ||
7 | #### 通过 npx 使用 (推荐) | 7 | #### 通过 npx 使用 (推荐) |
8 | -1. 安装NPX:`npm install -g npx` | 8 | + |
9 | +1. 安装 NPX:`npm install -g npx` | ||
9 | 2. 生成项目:`npx qx-cli init` | 10 | 2. 生成项目:`npx qx-cli init` |
10 | 3. 查看模板: `npx qx-cli list` | 11 | 3. 查看模板: `npx qx-cli list` |
11 | 12 | ||
12 | ### 通过 NPM 使用 | 13 | ### 通过 NPM 使用 |
14 | + | ||
13 | 1. `npm install -g qx-cli` | 15 | 1. `npm install -g qx-cli` |
14 | 2. 在终端输入 `qx-cli` | 16 | 2. 在终端输入 `qx-cli` |
15 | 17 | ||
16 | - Usage: qx <commands> | 18 | +Usage: qx <commands> |
17 | 19 | ||
18 | - Commands: | 20 | +Commands: |
19 | 21 | ||
20 | - list 查看所有的模板 | ||
21 | - init 通过模板生成项目(需按步骤选择) | 22 | + list 查看所有的模板 |
23 | + init 通过模板生成项目(需按步骤选择) |
bin/build.js
0 → 100755
1 | +#!/usr/bin/env node | ||
2 | + | ||
3 | +const path = require('path'); | ||
4 | +const fs = require('fs'); | ||
5 | +const execSync = require('child_process').execSync; | ||
6 | +const chalk = require('chalk'); | ||
7 | +const getConfigContent = require('../config/defaultConfig.js'); | ||
8 | + | ||
9 | +const umircCwdFilePath = path.resolve(process.cwd(), '.umirc.js'); | ||
10 | + | ||
11 | +async function writeFile() { | ||
12 | + const content = await getConfigContent(); | ||
13 | + fs.writeFile(umircCwdFilePath, content, (err) => { | ||
14 | + if (err) { | ||
15 | + console.log(chalk.red(`文件写入失败, ${err}`)); | ||
16 | + process.exit(1); | ||
17 | + } else { | ||
18 | + execSync(`npx cross-env ${process.argv.slice(2).join(' ')} umi build`, { stdio: 'inherit' }); | ||
19 | + fs.unlinkSync(umircCwdFilePath); | ||
20 | + } | ||
21 | + }); | ||
22 | +} | ||
23 | + | ||
24 | +writeFile(); |
1 | #!/usr/bin/env node | 1 | #!/usr/bin/env node |
2 | 2 | ||
3 | -const program = require('commander') | 3 | +const program = require('commander'); |
4 | 4 | ||
5 | // 定义CLI命令 | 5 | // 定义CLI命令 |
6 | program | 6 | program |
@@ -8,5 +8,7 @@ program | @@ -8,5 +8,7 @@ program | ||
8 | .usage('<command> [options]') | 8 | .usage('<command> [options]') |
9 | .command('list', '列出所有的模板') | 9 | .command('list', '列出所有的模板') |
10 | .command('init', '通过模板初始化新项目') | 10 | .command('init', '通过模板初始化新项目') |
11 | - | ||
12 | -program.parse(process.argv) | ||
11 | + .command('build', '打包项目') | ||
12 | + .command('start', '启动本地服务'); | ||
13 | + | ||
14 | +program.parse(process.argv); |
1 | #!/usr/bin/env node | 1 | #!/usr/bin/env node |
2 | 2 | ||
3 | -const inquirer = require('inquirer') | ||
4 | -const chalk = require('chalk') | 3 | +const inquirer = require('inquirer'); |
4 | +const chalk = require('chalk'); | ||
5 | const exec = require('child_process').exec; | 5 | const exec = require('child_process').exec; |
6 | 6 | ||
7 | -const templateMap = require(`${__dirname}/../template`) | 7 | +const templateMap = require(`${__dirname}/../template`); |
8 | 8 | ||
9 | const templateOptions = Object.keys(templateMap).reduce((list, key) => { | 9 | const templateOptions = Object.keys(templateMap).reduce((list, key) => { |
10 | list.push({ | 10 | list.push({ |
11 | name: `${templateMap[key].name} (${key})`, | 11 | name: `${templateMap[key].name} (${key})`, |
12 | value: key, | 12 | value: key, |
13 | short: templateMap[key].name, | 13 | short: templateMap[key].name, |
14 | - }) | ||
15 | - return list | ||
16 | -}, []) | 14 | + }); |
15 | + return list; | ||
16 | +}, []); | ||
17 | 17 | ||
18 | const questions = [ | 18 | const questions = [ |
19 | { | 19 | { |
@@ -23,65 +23,67 @@ const questions = [ | @@ -23,65 +23,67 @@ const questions = [ | ||
23 | choices: templateOptions, | 23 | choices: templateOptions, |
24 | }, | 24 | }, |
25 | { | 25 | { |
26 | - name: "projectName", | 26 | + name: 'projectName', |
27 | type: 'input', | 27 | type: 'input', |
28 | - message: "请输入系统名称", | 28 | + message: '请输入系统名称', |
29 | validate(val) { | 29 | validate(val) { |
30 | - if (val === '') return '请输入系统名称' | ||
31 | - return true | ||
32 | - } | 30 | + if (val === '') return '请输入系统名称'; |
31 | + return true; | ||
32 | + }, | ||
33 | }, | 33 | }, |
34 | -] | 34 | +]; |
35 | 35 | ||
36 | function initAsk() { | 36 | function initAsk() { |
37 | - inquirer.prompt(questions).then(answers => { | 37 | + inquirer.prompt(questions).then((answers) => { |
38 | const result = { | 38 | const result = { |
39 | template: answers.template, | 39 | template: answers.template, |
40 | projectName: answers.projectName, | 40 | projectName: answers.projectName, |
41 | - } | ||
42 | - const template = templateMap[result.template] | 41 | + }; |
42 | + const template = templateMap[result.template]; | ||
43 | 43 | ||
44 | - initProject(result.projectName, template) | ||
45 | - }) | 44 | + initProject(result.projectName, template); |
45 | + }); | ||
46 | } | 46 | } |
47 | 47 | ||
48 | function initProject(projectName, template) { | 48 | function initProject(projectName, template) { |
49 | - console.log(chalk.white('\n 开始下载模板... \n')) | 49 | + console.log(chalk.white('\n 开始下载模板... \n')); |
50 | 50 | ||
51 | - exec(`git clone -b ${template.branch} --depth=1 ${template.repo} ${projectName}`, err => { | 51 | + exec(`git clone -b ${template.branch} --depth=1 ${template.repo} ${projectName}`, (err) => { |
52 | if (err) { | 52 | if (err) { |
53 | - console.log(chalk.red(`模板下载失败. ${err}`)) | 53 | + console.log(chalk.red(`模板下载失败. ${err}`)); |
54 | process.exit(1); | 54 | process.exit(1); |
55 | } else { | 55 | } else { |
56 | try { | 56 | try { |
57 | - commitWork(projectName, err => { | 57 | + commitWork(projectName, (err) => { |
58 | if (err) { | 58 | if (err) { |
59 | - console.log(chalk.red(err)) | 59 | + console.log(chalk.red(err)); |
60 | } else { | 60 | } else { |
61 | - console.log(chalk.green('\n ✅下载完成!')) | ||
62 | - console.log('\n 快速开始') | ||
63 | - console.log(`\n cd ${projectName}`) | ||
64 | - console.log('\n npm install') | ||
65 | - console.log('\n npm start\n') | 61 | + console.log(chalk.green('\n ✅下载完成!')); |
62 | + console.log('\n 快速开始'); | ||
63 | + console.log(`\n cd ${projectName}`); | ||
64 | + console.log('\n npm install'); | ||
65 | + console.log('\n npm start\n'); | ||
66 | process.exit(1); | 66 | process.exit(1); |
67 | } | 67 | } |
68 | - }) | 68 | + }); |
69 | } catch (err) { | 69 | } catch (err) { |
70 | - console.log('项目配置生成失败', chalk.red(err)) | 70 | + console.log('项目配置生成失败', chalk.red(err)); |
71 | } | 71 | } |
72 | } | 72 | } |
73 | }); | 73 | }); |
74 | } | 74 | } |
75 | 75 | ||
76 | - | ||
77 | function commitWork(projectName, callback) { | 76 | function commitWork(projectName, callback) { |
78 | - exec(` | 77 | + exec( |
78 | + ` | ||
79 | cd ${projectName} | 79 | cd ${projectName} |
80 | rm -rf .git | 80 | rm -rf .git |
81 | git init | 81 | git init |
82 | git add . | 82 | git add . |
83 | git commit -m 'init ${projectName}' | 83 | git commit -m 'init ${projectName}' |
84 | - `, callback) | 84 | + `, |
85 | + callback, | ||
86 | + ); | ||
85 | } | 87 | } |
86 | 88 | ||
87 | -initAsk() | 89 | +initAsk(); |
bin/start.js
0 → 100755
1 | +#!/usr/bin/env node | ||
2 | + | ||
3 | +const path = require('path'); | ||
4 | +const fs = require('fs'); | ||
5 | +const execSync = require('child_process').execSync; | ||
6 | +const chalk = require('chalk'); | ||
7 | +const getConfigContent = require('../config/defaultConfig.js'); | ||
8 | +const { findUsablePort } = require('../utils'); | ||
9 | + | ||
10 | +const umircCwdFilePath = path.resolve(process.cwd(), '.umirc.js'); | ||
11 | + | ||
12 | +async function writeFile() { | ||
13 | + const port = await findUsablePort(process.env.PORT || 8000); | ||
14 | + const content = getConfigContent(port); | ||
15 | + | ||
16 | + fs.writeFile(umircCwdFilePath, content, (err) => { | ||
17 | + if (err) { | ||
18 | + console.log(chalk.red(`文件写入失败, ${err}`)); | ||
19 | + process.exit(1); | ||
20 | + } else { | ||
21 | + execSync( | ||
22 | + `npx cross-env ${process.argv | ||
23 | + .slice(2) | ||
24 | + .join(' ')} SOCKET_SERVER=http://localhost:${port} umi dev`, | ||
25 | + { stdio: 'inherit' }, | ||
26 | + ); | ||
27 | + fs.unlinkSync(umircCwdFilePath); | ||
28 | + } | ||
29 | + }); | ||
30 | +} | ||
31 | + | ||
32 | +writeFile(); |
config/defaultConfig.js
0 → 100644
1 | +const getConfigContent = (port) => { | ||
2 | + return ` | ||
3 | + import { defineConfig } from 'umi'; | ||
4 | + import path from 'path'; | ||
5 | + import fs from 'fs'; | ||
6 | + import MiniCssExtractPlugin from 'mini-css-extract-plugin' | ||
7 | + import routes from './src/routes' | ||
8 | + import pkg from './package.json' | ||
9 | + let userConfig = {}; | ||
10 | + let terserOptions = {}; | ||
11 | + let publicPath = '/' + pkg.name + '/' | ||
12 | + | ||
13 | + if (fs.existsSync(path.resolve(process.cwd(), '.qx.config.js'))) { | ||
14 | + userConfig = require(path.resolve(process.cwd(), '.qx.config.js')) | ||
15 | + } | ||
16 | + | ||
17 | + if (process.env.NODE_ENV === 'development') { | ||
18 | + publicPath = '//localhost:' + ${port} + '/' | ||
19 | + } | ||
20 | + | ||
21 | + if (process.env.UMI_APP_ENV === 'prod') { | ||
22 | + terserOptions = { | ||
23 | + compress: { | ||
24 | + pure_funcs: ['console.log', 'debugger'], | ||
25 | + }, | ||
26 | + }; | ||
27 | + } else { | ||
28 | + terserOptions = { | ||
29 | + compress: { | ||
30 | + drop_debugger: true, | ||
31 | + }, | ||
32 | + }; | ||
33 | + } | ||
34 | + | ||
35 | + export default defineConfig({ | ||
36 | + esbuild: {}, | ||
37 | + devServer: { | ||
38 | + port: ${port}, | ||
39 | + 'Access-Control-Allow-Origin': true | ||
40 | + }, | ||
41 | + runtimePublicPath: true, | ||
42 | + publicPath, | ||
43 | + mountElementId: pkg.name, | ||
44 | + webpack5: { | ||
45 | + lazyCompilation: {}, | ||
46 | + }, | ||
47 | + nodeModulesTransform: { | ||
48 | + type: 'none', | ||
49 | + }, | ||
50 | + history: { | ||
51 | + type: 'hash', | ||
52 | + }, | ||
53 | + alias: { | ||
54 | + '@/src': 'src', | ||
55 | + }, | ||
56 | + hash: true, | ||
57 | + title: false, | ||
58 | + lessLoader: { | ||
59 | + globalVars: { | ||
60 | + theme: 'true;@import "~@/variable.less"', | ||
61 | + }, | ||
62 | + }, | ||
63 | + antd: { | ||
64 | + config: {}, | ||
65 | + }, | ||
66 | + fastRefresh: {}, | ||
67 | + qiankun: { | ||
68 | + slave: {}, | ||
69 | + }, | ||
70 | + dynamicImport: { | ||
71 | + loading: '@/components/qx-page-loading', | ||
72 | + }, | ||
73 | + routes, | ||
74 | + terserOptions, | ||
75 | + chainWebpack: function (memo, { env, webpack, createCSSRule }) { | ||
76 | + memo.resolve.alias.set('@', path.resolve(__dirname, './src')); | ||
77 | + memo.resolve.alias.set('@@', path.resolve(__dirname, './src/.umi')); | ||
78 | + memo.optimization.delete('noEmitOnErrors'); | ||
79 | + memo.plugins.delete('optimize-css'); | ||
80 | + // if (env === 'production') { | ||
81 | + memo.merge({ | ||
82 | + plugins: env === 'production'? [new MiniCssExtractPlugin()] : [], | ||
83 | + optimization: { | ||
84 | + emitOnErrors: true, | ||
85 | + splitChunks: { | ||
86 | + chunks: 'async', | ||
87 | + minSize: 30000, | ||
88 | + minChunks: 3, | ||
89 | + automaticNameDelimiter: '.', | ||
90 | + cacheGroups: { | ||
91 | + antdesigns: { | ||
92 | + name: 'antdesigns', | ||
93 | + chunks: 'all', | ||
94 | + test: /(@antd|antd|@ant-design)/, | ||
95 | + priority: 10 | ||
96 | + }, | ||
97 | + x6: { | ||
98 | + name: 'x6', | ||
99 | + chunks: 'all', | ||
100 | + test: /(@antv\\/x6|@antv\\/x6-react-components|@antv\\/x6-react-shape)/, | ||
101 | + priority: 20, | ||
102 | + }, | ||
103 | + qxwidgets: { | ||
104 | + name: 'qxwidgets', | ||
105 | + chunks: 'all', | ||
106 | + test: /\\/src\\/packages\\/qx-form-generator/, | ||
107 | + priority: 10, | ||
108 | + }, | ||
109 | + formrender: { | ||
110 | + name: 'formrender', | ||
111 | + chunks: 'all', | ||
112 | + test: /@qx\\/form-render/, | ||
113 | + priority: 10, | ||
114 | + }, | ||
115 | + qx: { | ||
116 | + name: 'qx', | ||
117 | + chunks: 'all', | ||
118 | + test: /(@qx\\/view-render|@qx\\/form-design|@qx\\/hooks|@qx\\/utils|@qx\\/icon-btn)/, | ||
119 | + priority: 20, | ||
120 | + }, | ||
121 | + echarts: { | ||
122 | + name: 'echarts', | ||
123 | + chunks: 'all', | ||
124 | + test: /(echarts|echarts-for-react)/, | ||
125 | + priority: 20, | ||
126 | + }, | ||
127 | + // styles: { | ||
128 | + // name: "styles", | ||
129 | + // type: "css/mini-extract", | ||
130 | + // chunks: "all", | ||
131 | + // enforce: true, | ||
132 | + // }, | ||
133 | + vendors: { | ||
134 | + name: 'vendors', | ||
135 | + chunks: 'all', | ||
136 | + test: /[\\/]node_modules[\\/]/, | ||
137 | + priority: 10, | ||
138 | + }, | ||
139 | + }, | ||
140 | + }, | ||
141 | + }, | ||
142 | + externals: function ({ context, request }, callback) { | ||
143 | + if (env === 'production') { | ||
144 | + if (/^react$/.test(request)) { | ||
145 | + return callback(null, 'React', 'react'); | ||
146 | + } | ||
147 | + | ||
148 | + if (/^react-dom$/.test(request)) { | ||
149 | + return callback(null, 'ReactDOM', 'react-dom'); | ||
150 | + } | ||
151 | + } | ||
152 | + | ||
153 | + if (/antd.*.(css|less)$/.test(path.resolve(context, request))) { | ||
154 | + return callback(null, 'antd-style'); | ||
155 | + } | ||
156 | + | ||
157 | + callback(); | ||
158 | + }, | ||
159 | + }); | ||
160 | + // } | ||
161 | + }, | ||
162 | + ...userConfig, | ||
163 | + }); | ||
164 | + `; | ||
165 | +}; | ||
166 | + | ||
167 | +module.exports = getConfigContent; |
node_modules/.bin/acorn
0 → 120000
1 | +../acorn/bin/acorn |
node_modules/.bin/autoprefixer
0 → 120000
1 | +../autoprefixer/bin/autoprefixer |
node_modules/.bin/browserslist
0 → 120000
1 | +../browserslist/cli.js |
node_modules/.bin/bundler-webpack
0 → 120000
1 | +../@umijs/bundler-webpack/bin/bundler-webpack.js |
node_modules/.bin/css-blank-pseudo
0 → 120000
1 | +../css-blank-pseudo/cli.js |
node_modules/.bin/css-has-pseudo
0 → 120000
1 | +../css-has-pseudo/cli.js |
node_modules/.bin/css-prefers-color-scheme
0 → 120000
1 | +../css-prefers-color-scheme/cli.js |
node_modules/.bin/cssesc
0 → 120000
1 | +../cssesc/bin/cssesc |
node_modules/.bin/esparse
0 → 120000
1 | +../esprima/bin/esparse.js |
node_modules/.bin/esvalidate
0 → 120000
1 | +../esprima/bin/esvalidate.js |
node_modules/.bin/is-docker
0 → 120000
1 | +../is-docker/cli.js |
node_modules/.bin/js-yaml
0 → 120000
1 | +../js-yaml/bin/js-yaml.js |
node_modules/.bin/json5
0 → 120000
1 | +../json5/lib/cli.js |
node_modules/.bin/loose-envify
0 → 120000
1 | +../loose-envify/cli.js |
node_modules/.bin/miller-rabin
0 → 120000
1 | +../miller-rabin/bin/miller-rabin |
node_modules/.bin/prettier
0 → 120000
1 | +../prettier/bin-prettier.js |
node_modules/.bin/semver
0 → 120000
1 | +../semver/bin/semver |
node_modules/.bin/sha.js
0 → 120000
1 | +../sha.js/bin.js |
node_modules/.bin/terser
0 → 120000
1 | +../terser/bin/terser |
node_modules/.bin/umi
0 → 120000
1 | +../umi/bin/umi.js |
node_modules/.bin/update-browserslist-db
0 → 120000
1 | +../update-browserslist-db/cli.js |
node_modules/.bin/webpack
0 → 120000
1 | +../webpack/bin/webpack.js |
node_modules/.bin/which
0 → 120000
1 | +../which/bin/which |