Commit dc153f11 authored by super-lin0's avatar super-lin0

upgrade

parent f2bef82f
Pipeline #152 canceled with stages
const fs = require("fs-extra"); const fs = require('fs-extra');
const path = require("path"); const path = require('path');
const chalk = require("chalk"); const chalk = require('chalk');
const glob = require("glob"); const glob = require('glob');
const exec = require("execa"); const exec = require('execa');
const BasicGenerator = require("../../BasicGenerator"); const BasicGenerator = require('../../BasicGenerator');
const filterPkg = require("./filterPkg"); const filterPkg = require('./filterPkg');
const prettier = require("prettier"); const prettier = require('prettier');
const sylvanas = require("sylvanas"); const sylvanas = require('sylvanas');
const sortPackage = require("sort-package-json"); const sortPackage = require('sort-package-json');
const { getFastGithub } = require("umi-utils"); // const { getFastGithub } = require('umi-utils');
function log(...args) { function log(...args) {
console.log(`${chalk.gray(">")}`, ...args); console.log(`${chalk.gray('>')}`, ...args);
} }
function globList(patternList, options) { function globList(patternList, options) {
...@@ -25,29 +25,28 @@ function globList(patternList, options) { ...@@ -25,29 +25,28 @@ function globList(patternList, options) {
const getGithubUrl = async () => { const getGithubUrl = async () => {
const fastGithub = await getFastGithub(); const fastGithub = await getFastGithub();
if (fastGithub === "github.com.cnpmjs.org") { // if (fastGithub === 'github.com.cnpmjs.org') {
return "https://github.com.cnpmjs.org/ant-design/ant-design-pro"; // return 'https://github.com.cnpmjs.org/ant-design/ant-design-pro';
} // }
return "https://github.com/ant-design/ant-design-pro"; return 'http://platform.kuopu.net:9999/gitlab/nemean-group/nemean-pro;
}; };
const PRO_PATH = const PRO_PATH = process.env.INIT_CWD || process.env.npm_rootpath || process.cwd();
process.env.INIT_CWD || process.env.npm_rootpath || process.cwd();
class AntDesignProGenerator extends BasicGenerator { class AntDesignProGenerator extends BasicGenerator {
prompting() { prompting() {
if (this.opts.args.language) { if (this.opts.args.language) {
this.prompts = { this.prompts = {
language: this.opts.args.language language: this.opts.args.language,
}; };
} else { } else {
const prompts = [ const prompts = [
{ {
name: "language", name: 'language',
type: "list", type: 'list',
message: "Which language do you want to use?", message: 'Which language do you want to use?',
choices: ["TypeScript", "JavaScript"] choices: ['TypeScript', 'JavaScript'],
} },
]; ];
return this.prompt(prompts).then(props => { return this.prompt(prompts).then(props => {
this.prompts = props; this.prompts = props;
...@@ -57,7 +56,7 @@ class AntDesignProGenerator extends BasicGenerator { ...@@ -57,7 +56,7 @@ class AntDesignProGenerator extends BasicGenerator {
async writing() { async writing() {
const { language } = this.prompts; const { language } = this.prompts;
const isTypeScript = language === "TypeScript"; const isTypeScript = language === 'TypeScript';
const projectName = this.opts.name || this.opts.env.cwd; const projectName = this.opts.name || this.opts.env.cwd;
...@@ -66,7 +65,7 @@ class AntDesignProGenerator extends BasicGenerator { ...@@ -66,7 +65,7 @@ class AntDesignProGenerator extends BasicGenerator {
const projectPath = path.resolve(projectName); const projectPath = path.resolve(projectName);
const envOptions = { const envOptions = {
cwd: projectPath cwd: projectPath,
}; };
const githubUrl = await getGithubUrl(); const githubUrl = await getGithubUrl();
...@@ -74,35 +73,32 @@ class AntDesignProGenerator extends BasicGenerator { ...@@ -74,35 +73,32 @@ class AntDesignProGenerator extends BasicGenerator {
// Set branch if provided // Set branch if provided
if (this.opts.args.branch) { if (this.opts.args.branch) {
gitArgs.push("--branch", this.opts.args.branch); gitArgs.push('--branch', this.opts.args.branch);
} }
gitArgs.push(projectName); gitArgs.push(projectName);
// Clone remote branch // Clone remote branch
log(`git ${gitArgs.join(" ")}`); log(`git ${gitArgs.join(' ')}`);
await exec(`git`, gitArgs); await exec(`git`, gitArgs);
const packageJsonPath = path.resolve(projectPath, "package.json"); const packageJsonPath = path.resolve(projectPath, 'package.json');
const pkg = require(packageJsonPath); const pkg = require(packageJsonPath);
// Handle js version // Handle js version
if (!isTypeScript) { if (!isTypeScript) {
log("[Sylvanas] Prepare js environment..."); log('[Sylvanas] Prepare js environment...');
const tsFiles = globList(["**/*.tsx", "**/*.ts"], { const tsFiles = globList(['**/*.tsx', '**/*.ts'], {
...envOptions, ...envOptions,
ignore: ["**/*.d.ts"] ignore: ['**/*.d.ts'],
}); });
sylvanas(tsFiles, { sylvanas(tsFiles, {
...envOptions, ...envOptions,
action: "overwrite" action: 'overwrite',
}); });
log("[JS] Clean up..."); log('[JS] Clean up...');
const removeTsFiles = globList( const removeTsFiles = globList(['tsconfig.json', '**/*.d.ts'], envOptions);
["tsconfig.json", "**/*.d.ts"],
envOptions
);
removeTsFiles.forEach(filePath => { removeTsFiles.forEach(filePath => {
const targetPath = path.resolve(projectPath, filePath); const targetPath = path.resolve(projectPath, filePath);
fs.removeSync(targetPath); fs.removeSync(targetPath);
...@@ -110,37 +106,35 @@ class AntDesignProGenerator extends BasicGenerator { ...@@ -110,37 +106,35 @@ class AntDesignProGenerator extends BasicGenerator {
} }
// copy readme // copy readme
const babelConfig = path.resolve(__dirname, "README.md"); const babelConfig = path.resolve(__dirname, 'README.md');
fs.copySync(babelConfig, path.resolve(projectPath, "README.md")); fs.copySync(babelConfig, path.resolve(projectPath, 'README.md'));
// gen package.json // gen package.json
if (pkg["create-nemean"]) { if (pkg['create-nemean']) {
const { ignoreScript = [], ignoreDependencies = [] } = pkg[ const { ignoreScript = [], ignoreDependencies = [] } = pkg['create-nemean'];
"create-nemean"
];
// filter scripts and devDependencies // filter scripts and devDependencies
const projectPkg = { const projectPkg = {
...pkg, ...pkg,
version: "1.0.0", version: '1.0.0',
scripts: filterPkg(pkg.scripts, ignoreScript), scripts: filterPkg(pkg.scripts, ignoreScript),
devDependencies: filterPkg(pkg.devDependencies, ignoreDependencies) devDependencies: filterPkg(pkg.devDependencies, ignoreDependencies),
}; };
// remove create-nemean config // remove create-nemean config
delete projectPkg["create-nemean"]; delete projectPkg['create-nemean'];
fs.writeFileSync( fs.writeFileSync(
path.resolve(projectPath, "package.json"), path.resolve(projectPath, 'package.json'),
// 删除一个包之后 json会多了一些空行。sortPackage 可以删除掉并且排序 // 删除一个包之后 json会多了一些空行。sortPackage 可以删除掉并且排序
// prettier 会容忍一个空行 // prettier 会容忍一个空行
prettier.format(JSON.stringify(sortPackage(projectPkg)), { prettier.format(JSON.stringify(sortPackage(projectPkg)), {
parser: "json" parser: 'json',
}) }),
); );
} }
// Clean up useless files // Clean up useless files
if (pkg["create-nemean"] && pkg["create-nemean"].ignore) { if (pkg['create-nemean'] && pkg['create-nemean'].ignore) {
log("Clean up..."); log('Clean up...');
const ignoreFiles = pkg["create-nemean"].ignore; const ignoreFiles = pkg['create-nemean'].ignore;
const fileList = globList(ignoreFiles, envOptions); const fileList = globList(ignoreFiles, envOptions);
fileList.forEach(filePath => { fileList.forEach(filePath => {
......
{ {
"name": "create-nemean", "name": "create-nemean",
"version": "0.0.19", "version": "0.0.20",
"description": "Creates a UmiJS application using the command line.", "description": "Creates a UmiJS application using the command line.",
"homepage": "https://github.com/umijs/create-umi", "homepage": "https://github.com/umijs/create-umi",
"bugs": { "bugs": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment