Repository: ant-design/ant-design-pro-cli Branch: master Commit: c90c0a1f0f74 Files: 38 Total size: 89.5 KB Directory structure: gitextract_ywymsz60/ ├── .eslintrc.js ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── cli.js ├── package.json ├── src/ │ ├── create/ │ │ ├── BasicGenerator.js │ │ ├── generators/ │ │ │ └── ant-design-pro/ │ │ │ ├── .babelrc │ │ │ ├── README.md │ │ │ ├── filterPkg.js │ │ │ ├── index.js │ │ │ └── meta.json │ │ └── index.js │ ├── fetch-blocks/ │ │ ├── blocks.json │ │ ├── index.js │ │ ├── insertCode.js │ │ ├── replaceRouter.js │ │ └── router.config.js │ ├── i18n/ │ │ ├── formatRoute.js │ │ ├── getLocalFileList.js │ │ ├── index.js │ │ ├── removeLocale.js │ │ ├── transform.js │ │ └── utils.js │ ├── pro-components-codemod/ │ │ ├── PACKAGE_CONSTANT.js │ │ ├── index.js │ │ ├── pkgApi.js │ │ ├── transform.js │ │ ├── updateDependency.js │ │ └── updateImports.js │ ├── screenshot/ │ │ ├── diff.js │ │ ├── dumi.js │ │ ├── getBrowser.js │ │ ├── index.js │ │ └── portAvailable.js │ └── utils/ │ └── getNpmRegistry.js └── test.code.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc.js ================================================ module.exports = { extends: [require.resolve('@umijs/fabric/dist/eslint')], }; ================================================ FILE: .gitignore ================================================ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies **/node_modules # roadhog-api-doc ignore /src/utils/request-temp.js _roadhog-api-doc # production /dist /.vscode # misc .DS_Store npm-debug.log* yarn-error.log /coverage .idea yarn.lock package-lock.json *bak lib .vscode # visual studio code .history *.log functions/* .temp/** # umi .umi .umi-production # screenshot .firebase ================================================ FILE: .prettierrc ================================================ { "printWidth": 100, "singleQuote": true, "trailingComma": "all", "proseWrap": "never", "overrides": [ { "files": ".webpackrc", "options": { "parser": "json" } }, { "files": ".prettierrc", "options": { "parser": "json" } } ] } ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2017-2018 Alipay Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Cli for Ant Design Pro [![NPM version][npm-image]][npm-url] [![NPM downloads][download-image]][download-url] [npm-image]: https://img.shields.io/npm/v/@ant-design/pro-cli.svg?style=flat-square [npm-url]: https://npmjs.org/package/@ant-design/pro-cli [download-image]: https://img.shields.io/npm/dm/@ant-design/pro-cli.svg?style=flat-square [download-url]: https://npmjs.org/package/@ant-design/pro-cli ## Install ```shell npm i @ant-design/pro-cli # or yarn add @ant-design/pro-cli ``` ## Commands - screenshot 对区块进行截图 - i18n-remove 从项目中移除国际化 - fetch-blocks 下载 pro 所有的官方区块 - pro-components-codemod 自动更新 @ant-design/pro-components 的 import 方式 ## Options for the screenshot command - --path 区块的路径,可以用于只截图一个 - --mobile 使用手机大小的屏幕进行截图 ## Options for the i18n-remove command - --locale 设置语言 - --write 是否写入文件 ## Options for the pro-components-codemod command - --writePkg 是否自动更新 package.json 中的 dependencies 的添加/删除,默认开启 - --cleanup 是否开启 cleanup 模式,默认开启 - --path 需要更新文件的目录,默认 src 目录下的文件 ## debug ### bash ```bash DEBUG=pro-cli pro XXX ``` ### PowerShell ```powershell $env:DEBUG="pro-cli" pro xxx ``` ### CMD ```cmd set DEBUG=pro-cli pro xxx ``` ## Examples ### pro pro -h ### screenshot - pro screenshot 对所有区块进行截图 - pro screenshot --path DashboardWorkplace 对单个区块进行截图 - pro screenshot --mobile 对所有区块进行截图 - pro screenshot --dumi 使用 dumi 构建的资产,支持手机模式 ### i18n-remove - pro i18n-remove --write - pro i18n-remove --locale en-US --write ### fetch-blocks - pro fetch-blocks ### pro-components-codemod - pro pro-components-codemod 自动更新 package.json 中的 dependencies 的添加/删除,并将导入模块全部合并到一条 import 语句导入 - pro pro-components-codemod --writePkg 0 不处理 package.json 中的 dependencies 的添加/删除,只进行 import 导入方式的更新 - pro pro-components-codemod --path packages 处理 packages 目录下的文件 - pro pro-components-codemod --cleanup 0 只更新子包的名称为 @ant-design/pro-components,保留旧项目的 import 方式 ================================================ FILE: cli.js ================================================ #!/usr/bin/env node const yParser = require('yargs-parser'); const semver = require('semver'); const { existsSync } = require('fs'); const { join } = require('path'); const chalk = require('chalk'); // print version and @local const args = yParser(process.argv.slice(2)); if (args.v || args.version) { // eslint-disable-next-line global-require console.log(require('./package').version); if (existsSync(join(__dirname, '.local'))) { console.log(chalk.cyan('@local')); } process.exit(0); } if (!semver.satisfies(process.version, '>= 8.0.0')) { console.error(chalk.red('✘ The generator will only work with Node v8.0.0 and up!')); process.exit(1); } const cwd = process.cwd(); const option = args._[0]; const screenshot = async (props) => { // eslint-disable-next-line global-require await require('./src/screenshot/index')(props); process.exit(0); }; const screenshotDumi = async (props) => { // eslint-disable-next-line global-require await require('./src/screenshot/dumi')(props); process.exit(0); }; switch (option) { case 'screenshot': if (args.dumi) { screenshotDumi({ cwd, ...args }); } else { screenshot({ cwd, ...args }); } break; case 'i18n-remove': // eslint-disable-next-line global-require require('./src/i18n/index')({ cwd, ...args }); break; case 'fetch-blocks': // eslint-disable-next-line global-require require('./src/fetch-blocks/index')({ cwd, ...args }); break; case 'create': const name = args._[1] || ''; // eslint-disable-next-line global-require require('./src/create/index')({ cwd, name, ...args }); break; case 'pro-components-codemod': // eslint-disable-next-line global-require require('./src/pro-components-codemod/index')({ cwd, ...args }); break; default: if (args.h || args.help) { const details = ` Commands: ${chalk.cyan('create')} 创建新的 Ant Design Pro 项目 ${chalk.cyan('screenshot ')} 对区块进行截图 ${chalk.cyan('i18n-remove')} 从项目中移除国际化 ${chalk.cyan('fetch-blocks')} 下载 pro 所有的官方区块 ${chalk.cyan('pro-components-codemod')} 自动更新 pro-components 的 import 方式 Options for the ${chalk.cyan('create')} command: ${chalk.green('--list-templates ')} 列出可用的模板 ${chalk.green('--template ')} 模板类型(非交互式模式) ${chalk.green('--origin ')} 指定源: github 或 gitee Options for the ${chalk.cyan('screenshot')} command: ${chalk.green('--path ')} 区块的路径,可以用于只截图一个 ${chalk.green('--mobile ')} 使用手机大小的屏幕进行截图 Options for the ${chalk.cyan('i18n-remove')} command: ${chalk.green('--locale ')} 设置语言 ${chalk.green('--write ')} 是否写入文件 Options for the ${chalk.cyan('pro-components-codemod')} command: ${chalk.green('--writePkg ')} 是否更新 package.json 中的 dependencies ${chalk.green('--path ')} 更新 pro-components import 的路径 ${chalk.green('--cleanup ')} 是否开启 cleanup 模式,多个 import 合并为 单个 import ${chalk.green('--list-versions ')} 列出可用的 pro-components 版本 ${chalk.green('--version ')} 指定 pro-components 版本(非交互式模式,可用 latest) Examples: ${chalk.gray('pro')} pro -h ${chalk.gray('create (list available templates)')} pro create --list-templates ${chalk.gray('create (interactive)')} pro create myapp ${chalk.gray('create (non-interactive)')} pro create myapp --template simple pro create myapp --template complete ${chalk.gray('screenshot')} pro screenshot pro screenshot --path DashboardWorkplace ${chalk.gray('i18n-remove')} pro i18n-remove --write pro i18n-remove --locale en-US --write ${chalk.gray('fetch-blocks')} pro fetch-blocks ${chalk.gray('pro-components-codemod (interactive)')} pro pro-components-codemod --writePkg ${chalk.gray('pro-components-codemod (list available versions)')} pro pro-components-codemod --list-versions ${chalk.gray('pro-components-codemod (non-interactive)')} pro pro-components-codemod --version latest pro pro-components-codemod --version 2.6.0 --path src --cleanup `.trim(); console.log(details); } break; } ================================================ FILE: package.json ================================================ { "name": "@ant-design/pro-cli", "version": "3.4.0", "description": "The command tool for ant design pro", "repository": { "type": "git", "url": "https://github.com/ant-design/ant-design-pro-cli" }, "bin": { "pro": "./cli.js" }, "files": [ "src", "cli.js" ], "publishConfig": { "access": "public" }, "dependencies": { "@babel/core": "^7.23.7", "@babel/generator": "^7.23.6", "@babel/parser": "^7.23.6", "@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/plugin-proposal-decorators": "^7.23.7", "@babel/plugin-transform-typescript": "^7.23.6", "@babel/preset-env": "^7.23.8", "@babel/preset-react": "^7.23.3", "@babel/preset-typescript": "^7.23.3", "@babel/traverse": "^7.23.7", "@babel/types": "^7.23.6", "@umijs/fabric": "^2.14.1", "babel-types": "^6.26.0", "blink-diff": "^1.0.13", "carlo": "^0.9.46", "chalk": "^4.1.2", "cross-port-killer": "^1.4.0", "execa": "^5.1.1", "fs-extra": "^10.1.0", "glob": "^7.2.3", "import-fresh": "^3.3.0", "inquirer": "^8.2.6", "intl-messageformat": "^9.13.0", "lodash.groupby": "^4.6.0", "node-fetch": "^2.7.0", "node-import-ts": "^1.0.6", "ora": "^5.4.1", "pngjs-image": "^0.11.7", "prettier": "^2.8.8", "recast": "^0.21.5", "rimraf": "^3.0.2", "semver": "^7.5.4", "typescript": "^4.9.5", "umi-utils": "^1.7.3", "yargs-parser": "^20.2.9", "yeoman-environment": "^3.19.3", "yeoman-generator": "^5.10.0" }, "devDependencies": { "eslint": "^8.56.0" } } ================================================ FILE: src/create/BasicGenerator.js ================================================ const Generator = require('yeoman-generator'); const glob = require('glob'); const { statSync } = require('fs'); const { basename } = require('path'); const debug = require('debug')('create-umi:BasicGenerator'); function noop() { return true; } class BasicGenerator extends Generator { constructor(opts) { super(opts); this.opts = opts; this.name = basename(opts.env.cwd); } isTsFile(f) { return f.endsWith('.ts') || f.endsWith('.tsx') || !!/(tsconfig\.json)/g.test(f); } writeFiles({ context, filterFiles = noop }) { // We have multiple welcome file, random this const welcomeImages = glob .sync('**/assets/welcomeImgs/*', { cwd: this.templatePath(), dot: true, }) .filter(filterFiles); if (welcomeImages.length) { const welcomeImg = welcomeImages[Math.floor(Math.random() * welcomeImages.length)]; debug(`copy ${welcomeImg}`); this.fs.copyTpl( this.templatePath(welcomeImg), this.destinationPath(welcomeImg.replace(/welcomeImgs.*$/, 'yay.jpg')), context, ); } debug(`context: ${JSON.stringify(context)}`); glob .sync('**/*', { cwd: this.templatePath(), dot: true, }) .filter(filterFiles) .filter((file) => !file.includes('welcomeImgs')) .forEach((file) => { debug(`copy ${file}`); const filePath = this.templatePath(file); if (statSync(filePath).isFile()) { this.fs.copyTpl( this.templatePath(filePath), this.destinationPath(file.replace(/^_/, '.')), context, ); } }); } prompt(questions) { process.send && process.send({ type: 'prompt' }); process.emit('message', { type: 'prompt' }); return super.prompt(questions); } } module.exports = BasicGenerator; ================================================ FILE: src/create/generators/ant-design-pro/.babelrc ================================================ { "plugins": [ [ "@babel/plugin-transform-typescript", { "isTSX": true } ] ] } ================================================ FILE: src/create/generators/ant-design-pro/README.md ================================================ # Ant Design Pro This project is initialized with [Ant Design Pro](https://pro.ant.design). Follow is the quick guide for how to use. ## Environment Prepare Install `node_modules`: ```bash npm install ``` or ```bash yarn ``` ## Provided Scripts Ant Design Pro provides some useful script to help you quick start and build with web project, code style check and test. Scripts provided in `package.json`. It's safe to modify or add additional script: ### Start project ```bash npm start ``` ### Build project ```bash npm run build ``` ### Check code style ```bash npm run lint ``` You can also use script to auto fix some lint error: ```bash npm run lint:fix ``` ### Test code ```bash npm test ``` ## More You can view full document on our [official website](https://pro.ant.design). And welcome any feedback in our [github](https://github.com/ant-design/ant-design-pro). ================================================ FILE: src/create/generators/ant-design-pro/filterPkg.js ================================================ const filterPkg = (pkgObject, ignoreList) => { const devObj = {}; Object.keys(pkgObject).forEach(key => { const isIgnore = ignoreList.some(reg => { return new RegExp(reg).test(key); }); if (isIgnore) { return; } devObj[key] = pkgObject[key]; }); return devObj; }; module.exports = filterPkg; ================================================ FILE: src/create/generators/ant-design-pro/index.js ================================================ const fs = require('fs-extra'); const path = require('path'); const chalk = require('chalk'); const glob = require('glob'); const exec = require('execa'); const rimraf = require('rimraf'); const BasicGenerator = require('../../BasicGenerator'); const filterPkg = require('./filterPkg'); const prettier = require('prettier'); const sortPackage = require('sort-package-json'); const { getFastGithub } = require('umi-utils'); function log(...args) { console.log(`${chalk.gray('>')}`, ...args); } function globList(patternList, options) { let fileList = []; patternList.forEach((pattern) => { fileList = [...fileList, ...glob.sync(pattern, options)]; }); return fileList; } const getGithubUrl = async (origin = '') => { const githubUrl = 'https://github.com/ant-design/ant-design-pro'; const giteeUrl = 'https://gitee.com/ant-design/ant-design-pro'; // 通过 --origin=xxx指定源 if (origin === 'github') { return githubUrl; } if (origin === 'gitee') { return giteeUrl; } // 不指定源 const fastGithub = await getFastGithub(); if (fastGithub === 'gitee.com' || fastGithub === 'github.com.cnpmjs.org') { return giteeUrl; } return githubUrl; }; class AntDesignProGenerator extends BasicGenerator { prompting() { const TEMPLATES = [ { name: 'simple', description: '简单脚手架,只包含基础框架' }, { name: 'complete', description: '全量版本,包含所有区块和功能' }, ]; // 列出可用模板 if (this.opts.args.listTemplates) { console.log(`\nAvailable templates for ${chalk.green('create')} command:\n`); TEMPLATES.forEach((t) => { console.log(` ${chalk.cyan(t.name.padEnd(12))} ${chalk.gray(t.description)}`); }); console.log(`\nUsage: pro create --template