-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be4234c
commit 8db505c
Showing
6 changed files
with
127 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import path from 'node:path' | ||
import process from 'node:process' | ||
import inquirer from 'inquirer' | ||
import ora from 'ora' | ||
import { checkMkdirExists } from '../utils/copy.js' | ||
import download from '../utils/download.js' | ||
|
||
function inquirerPrompt(argv) { | ||
const { name } = argv | ||
return new Promise((resolve, reject) => { | ||
inquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'name', | ||
message: '项目名称', | ||
default: name, | ||
validate(val) { | ||
if (!val) { | ||
return '请输入项目名称:' | ||
} | ||
return true | ||
}, | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'build_type', | ||
message: '组件类型', | ||
choices: ['Vue组件'], | ||
filter(value) { | ||
return { | ||
Vue组件: 'vue-comp', | ||
}[value] | ||
}, | ||
}, | ||
]).then((answers) => { | ||
resolve(answers) | ||
}).catch((error) => { | ||
reject(error) | ||
}) | ||
}) | ||
} | ||
|
||
export default function (argv) { | ||
inquirerPrompt(argv).then(async (answers) => { | ||
const { name, build_type } = answers | ||
const isMkdirExists = checkMkdirExists( | ||
path.resolve(process.cwd(), `./${name}`), | ||
) | ||
|
||
const spinner = ora().start() | ||
|
||
if (isMkdirExists) { | ||
spinner.warning(`${name}文件夹已经存在`) | ||
} else { | ||
const _path = ['lib', build_type] | ||
|
||
// 下载文件 | ||
await download(name, _path) | ||
|
||
spinner.succeed(`created successfully`) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
{ | ||
"name": "@muyianking/cli", | ||
"type": "module", | ||
"version": "0.2.1", | ||
"description": "慕易安的脚手架", | ||
"author": "muyianking", | ||
"license": "ISC", | ||
"keywords": [ | ||
"cli", | ||
"vue", | ||
"rsbuild" | ||
], | ||
"bin": { | ||
"mu": "./bin/index.js" | ||
}, | ||
"dependencies": { | ||
"copy-dir": "^1.3.0", | ||
"fs-extra": "^11.2.0", | ||
"inquirer": "8.2.5", | ||
"mustache": "^4.2.0", | ||
"ora": "^8.1.1", | ||
"yargs": "^17.7.2" | ||
} | ||
} | ||
"name": "@muyianking/cli", | ||
"type": "module", | ||
"version": "0.2.1", | ||
"description": "慕易安的脚手架", | ||
"author": "muyianking", | ||
"license": "ISC", | ||
"keywords": [ | ||
"cli", | ||
"vue", | ||
"rsbuild" | ||
], | ||
"bin": { | ||
"mu": "./bin/index.js" | ||
}, | ||
"dependencies": { | ||
"copy-dir": "^1.3.0", | ||
"fs-extra": "^11.2.0", | ||
"inquirer": "8.2.5", | ||
"mustache": "^4.2.0", | ||
"ora": "^8.1.1", | ||
"yargs": "^17.7.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters