-
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
4785b5d
commit e267a66
Showing
14 changed files
with
1,668 additions
and
319 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,38 @@ | ||
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' | ||
import { handler } from './inquirer.utils.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 | ||
}, | ||
return inquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'name', | ||
message: '项目名称', | ||
default: name, | ||
validate(val) { | ||
if (!val) { | ||
return '请输入项目名称:' | ||
} | ||
return true | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'build_type', | ||
message: '构建工具', | ||
choices: ['rsbuild', 'vite'], | ||
filter(value) { | ||
return { | ||
rsbuild: 'rsbuild', | ||
vite: 'vite', | ||
}[value] | ||
}, | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'build_type', | ||
message: '构建工具', | ||
choices: ['rsbuild', 'vite'], | ||
filter(value) { | ||
return { | ||
rsbuild: 'rsbuild', | ||
vite: 'vite', | ||
}[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 = ['h5', build_type] | ||
|
||
// 下载文件 | ||
await download(name, _path) | ||
spinner.succeed(`created successfully`) | ||
} | ||
handler(answers, 'h5') | ||
}) | ||
} |
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,63 +1,37 @@ | ||
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' | ||
import { handler } from './inquirer.utils.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 | ||
}, | ||
return 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', | ||
}[value] | ||
}, | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'build_type', | ||
message: '框架', | ||
choices: ['vue'], | ||
filter(value) { | ||
return { | ||
vue: 'vue', | ||
}[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 = ['html', build_type] | ||
|
||
// 下载文件 | ||
await download(name, _path) | ||
|
||
spinner.succeed(`created successfully`) | ||
} | ||
handler(answers, 'html') | ||
}) | ||
} |
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,63 +1,37 @@ | ||
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' | ||
import { handler } from './inquirer.utils.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 | ||
}, | ||
return 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] | ||
}, | ||
}, | ||
{ | ||
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`) | ||
} | ||
handler(answers, 'lib') | ||
}) | ||
} |
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,23 @@ | ||
import { existsSync } from 'node:fs' | ||
import path from 'node:path' | ||
import process from 'node:process' | ||
import ora from 'ora' | ||
import download from '../utils/download.js' | ||
|
||
export async function handler(answers, type) { | ||
const { name, build_type } = answers | ||
const isMkdirExists = existsSync(path.resolve(process.cwd(), `./${name}`)) | ||
|
||
const spinner = ora().start() | ||
|
||
if (isMkdirExists) { | ||
spinner.warning(`${name}文件夹已经存在`) | ||
} else { | ||
const _path = [type, build_type] | ||
|
||
// 下载文件 | ||
await download(name, _path) | ||
|
||
spinner.succeed(`created successfully`) | ||
} | ||
} |
Oops, something went wrong.