chore(create-vant-cli-app): remove yeoman deps (#9827)

This commit is contained in:
neverland 2021-11-10 09:38:09 +08:00 committed by GitHub
parent 6fc929f317
commit 8d1d029f5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 1328 deletions

View File

@ -30,8 +30,7 @@
"license": "MIT",
"devDependencies": {
"@types/fs-extra": "^8.1.0",
"@types/yeoman-environment": "^2.3.3",
"@types/yeoman-generator": "^3.1.4",
"@types/inquirer": "^8.1.3",
"release-it": "^13.0.0",
"typescript": "4.x"
},
@ -40,9 +39,7 @@
"consola": "^2.11.3",
"fast-glob": "^3.2.4",
"fs-extra": "^8.1.0",
"inquirer": "^7.0.6",
"yeoman-environment": "^2.8.0",
"yeoman-generator": "^4.6.0"
"inquirer": "^7.0.6"
},
"release-it": {
"git": {

View File

@ -1,10 +1,10 @@
import fs from 'fs-extra';
import glob from 'fast-glob';
import chalk from 'chalk';
import consola from 'consola';
import { join } from 'path';
import { prompt } from 'inquirer';
import { sep, join } from 'path';
import { CWD, GENERATOR_DIR } from './constant';
import Yeoman from 'yeoman-environment';
import Generator from 'yeoman-generator';
const PROMPTS = [
{
@ -30,7 +30,9 @@ const PROMPTS = [
},
];
export class VanGenerator extends Generator {
export class VanGenerator {
outputDir = '';
inputs = {
name: '',
cssLang: '',
@ -39,18 +41,18 @@ export class VanGenerator extends Generator {
};
constructor(name: string) {
super([], {
env: Yeoman.createEnv([], {
cwd: join(CWD, name),
}),
resolved: GENERATOR_DIR,
});
this.inputs.name = name;
this.outputDir = join(CWD, name);
}
async run() {
await this.prompting();
this.writing();
this.end();
}
async prompting() {
return this.prompt<Record<string, string>>(PROMPTS).then((inputs) => {
return prompt<Record<string, string>>(PROMPTS).then((inputs) => {
const preprocessor = inputs.preprocessor.toLowerCase();
const cssLang = preprocessor === 'sass' ? 'scss' : preprocessor;
@ -61,42 +63,43 @@ export class VanGenerator extends Generator {
}
writing() {
consola.info(`Creating project in ${join(CWD, this.inputs.name)}\n`);
/**
@see {@link https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows}
*/
console.log();
consola.info(`Creating project in ${chalk.green(this.outputDir)}\n`);
// see https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows
const templatePath = join(GENERATOR_DIR, this.inputs.vueVersion).replace(
/\\/g,
'/'
);
const templateFiles = glob.sync(
join(templatePath, '**', '*').replace(/\\/g, '/'),
{
dot: true,
}
);
const destinationRoot = this.destinationRoot();
templateFiles.forEach((filePath) => {
const outputPath = filePath
.replace('.tpl', '')
.replace(templatePath, destinationRoot);
this.fs.copyTpl(filePath, outputPath, this.inputs);
.replace(templatePath, this.outputDir);
this.copyTpl(filePath, outputPath, this.inputs);
});
}
install() {
console.log();
consola.info('Install dependencies...\n');
copyTpl(from: string, to: string, args: Record<string, any>) {
fs.copySync(from, to);
let content = fs.readFileSync(to, 'utf-8');
process.chdir(this.inputs.name);
this.installDependencies({
npm: false,
bower: false,
yarn: true,
skipMessage: true,
Object.keys(args).forEach((key) => {
const regexp = new RegExp(`<%= ${key} %>`, 'g');
content = content.replace(regexp, args[key]);
});
fs.writeFileSync(to, content);
const name = to.replace(this.outputDir + sep, '');
consola.success(`${chalk.green('create')} ${name}`);
}
end() {
@ -105,7 +108,9 @@ export class VanGenerator extends Generator {
console.log();
consola.success(`Successfully created ${chalk.yellow(name)}.`);
consola.success(
`Run ${chalk.yellow(`cd ${name} && npm run dev`)} to start development!`
`Run ${chalk.yellow(
`cd ${name} && git init && yarn && yarn dev`
)} to start development!`
);
}
}

View File

@ -1,7 +1,7 @@
#!/usr/bin/env node
import inquirer from 'inquirer';
import consola from 'consola';
import { prompt } from 'inquirer';
import { ensureDir } from 'fs-extra';
import { VanGenerator } from './generator';
@ -13,14 +13,13 @@ const PROMPTS = [
},
];
export default async function run() {
const { name } = await inquirer.prompt(PROMPTS);
async function run() {
const { name } = await prompt(PROMPTS);
try {
await ensureDir(name);
const generator = new VanGenerator(name);
generator.run();
await generator.run();
} catch (e) {
consola.error(e);
}

1298
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff