From dbca87f94dda6d15b9f7c3e3d17675247bf21c09 Mon Sep 17 00:00:00 2001 From: super-lin0 <3924578651@qq.com> Date: Mon, 28 Oct 2019 16:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=B3=BB=E7=BB=9F=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/generators/nemean-pro/index.js | 2 +- lib/generators/nemean-simple/index.js | 2 +- lib/generators/system-manage/.babelrc | 10 ++ lib/generators/system-manage/README.md | 57 ++++++++++ lib/generators/system-manage/filterPkg.js | 15 +++ lib/generators/system-manage/index.js | 121 ++++++++++++++++++++++ lib/generators/system-manage/meta.json | 3 + package.json | 2 +- 8 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 lib/generators/system-manage/.babelrc create mode 100644 lib/generators/system-manage/README.md create mode 100644 lib/generators/system-manage/filterPkg.js create mode 100644 lib/generators/system-manage/index.js create mode 100644 lib/generators/system-manage/meta.json diff --git a/lib/generators/nemean-pro/index.js b/lib/generators/nemean-pro/index.js index af7310d..f68c222 100644 --- a/lib/generators/nemean-pro/index.js +++ b/lib/generators/nemean-pro/index.js @@ -28,7 +28,7 @@ const getGithubUrl = async () => { // if (fastGithub === 'github.com.cnpmjs.org') { // return 'https://github.com.cnpmjs.org/ant-design/ant-design-pro'; // } - return 'http://platform.kuopu.net:9999/gitlab/nemean-group/nemean-pro'; + return 'http://platform.kuopu.net:9999/gitlab/nemean-group/projects/nemean-pro'; }; const PRO_PATH = process.env.INIT_CWD || process.env.npm_rootpath || process.cwd(); diff --git a/lib/generators/nemean-simple/index.js b/lib/generators/nemean-simple/index.js index 191d489..c289fb3 100644 --- a/lib/generators/nemean-simple/index.js +++ b/lib/generators/nemean-simple/index.js @@ -24,7 +24,7 @@ function globList(patternList, options) { } const getGithubUrl = async () => { - return 'http://platform.kuopu.net:9999/gitlab/nemean-group/nemean-simple.git'; + return 'http://platform.kuopu.net:9999/gitlab/nemean-group/projects/nemean-simple.git'; }; const PRO_PATH = process.env.INIT_CWD || process.env.npm_rootpath || process.cwd(); diff --git a/lib/generators/system-manage/.babelrc b/lib/generators/system-manage/.babelrc new file mode 100644 index 0000000..18b3627 --- /dev/null +++ b/lib/generators/system-manage/.babelrc @@ -0,0 +1,10 @@ +{ + "plugins": [ + [ + "@babel/plugin-transform-typescript", + { + "isTSX": true + } + ] + ] +} diff --git a/lib/generators/system-manage/README.md b/lib/generators/system-manage/README.md new file mode 100644 index 0000000..4c89a72 --- /dev/null +++ b/lib/generators/system-manage/README.md @@ -0,0 +1,57 @@ +# 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). diff --git a/lib/generators/system-manage/filterPkg.js b/lib/generators/system-manage/filterPkg.js new file mode 100644 index 0000000..7e36cb2 --- /dev/null +++ b/lib/generators/system-manage/filterPkg.js @@ -0,0 +1,15 @@ +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; diff --git a/lib/generators/system-manage/index.js b/lib/generators/system-manage/index.js new file mode 100644 index 0000000..3afac22 --- /dev/null +++ b/lib/generators/system-manage/index.js @@ -0,0 +1,121 @@ +const fs = require('fs-extra'); +const path = require('path'); +const chalk = require('chalk'); +const glob = require('glob'); +const exec = require('execa'); +const BasicGenerator = require('../../BasicGenerator'); +const filterPkg = require('./filterPkg'); +const prettier = require('prettier'); +const sylvanas = require('sylvanas'); +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 () => { + return 'http://platform.kuopu.net:9999/gitlab/nemean-group/projects/kim-system-web.git'; +}; + +const PRO_PATH = process.env.INIT_CWD || process.env.npm_rootpath || process.cwd(); + +class AntDesignProGenerator extends BasicGenerator { + async writing() { + const isTypeScript = false; + + const projectName = this.opts.name || this.opts.env.cwd; + + const projectPath = path.resolve(projectName); + + const envOptions = { + cwd: projectPath, + }; + + const githubUrl = await getGithubUrl(); + const gitArgs = [`clone`, githubUrl, `--depth=1`]; + + // Set branch if provided + if (this.opts.args.branch) { + gitArgs.push('--branch', this.opts.args.branch); + } + + gitArgs.push(projectName); + + // Clone remote branch + log(`git ${gitArgs.join(' ')}`); + await exec(`git`, gitArgs); + + const packageJsonPath = path.resolve(projectPath, 'package.json'); + const pkg = require(packageJsonPath); + // Handle js version + if (!isTypeScript) { + log('[Sylvanas] Prepare js environment...'); + const tsFiles = globList(['**/*.tsx', '**/*.ts'], { + ...envOptions, + ignore: ['**/*.d.ts'], + }); + + sylvanas(tsFiles, { + ...envOptions, + action: 'overwrite', + }); + + log('[JS] Clean up...'); + const removeTsFiles = globList(['tsconfig.json', '**/*.d.ts'], envOptions); + removeTsFiles.forEach(filePath => { + const targetPath = path.resolve(projectPath, filePath); + fs.removeSync(targetPath); + }); + } + + // copy readme + const babelConfig = path.resolve(__dirname, 'README.md'); + fs.copySync(babelConfig, path.resolve(projectPath, 'README.md')); + + // gen package.json + if (pkg['create-nemean']) { + const { ignoreScript = [], ignoreDependencies = [] } = pkg['create-nemean']; + // filter scripts and devDependencies + const projectPkg = { + ...pkg, + version: '1.0.0', + scripts: filterPkg(pkg.scripts, ignoreScript), + devDependencies: filterPkg(pkg.devDependencies, ignoreDependencies), + }; + // remove create-nemean config + delete projectPkg['create-nemean']; + fs.writeFileSync( + path.resolve(projectPath, 'package.json'), + // 删除一个包之后 json会多了一些空行。sortPackage 可以删除掉并且排序 + // prettier 会容忍一个空行 + prettier.format(JSON.stringify(sortPackage(projectPkg)), { + parser: 'json', + }), + ); + } + + // Clean up useless files + if (pkg['create-nemean'] && pkg['create-nemean'].ignore) { + log('Clean up...'); + const ignoreFiles = pkg['create-nemean'].ignore; + const fileList = globList(ignoreFiles, envOptions); + + fileList.forEach(filePath => { + const targetPath = path.resolve(projectPath, filePath); + fs.removeSync(targetPath); + }); + } + } +} + +module.exports = AntDesignProGenerator; diff --git a/lib/generators/system-manage/meta.json b/lib/generators/system-manage/meta.json new file mode 100644 index 0000000..f9a7e0e --- /dev/null +++ b/lib/generators/system-manage/meta.json @@ -0,0 +1,3 @@ +{ + "description": "系统管理" +} diff --git a/package.json b/package.json index bf17bc0..ca18d5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-nemean", - "version": "0.0.28", + "version": "0.0.29", "description": "Creates a Nemean application using the command line.", "homepage": "http://platform.kuopu.net:9999/gitlab/nemean-group/create-nemean", "bugs": { -- GitLab