bia
Version:
a tool for download git repository
111 lines (101 loc) • 2.74 kB
JavaScript
/*
* @Author: hzxulin@yeah.net
* @Date: 2018-11-21 17:44:34
* @Last Modified by: hzxulin@yeah.net
* @Last Modified time: 2018-11-21 21:14:27
*/
const path = require('path')
const inquirer = require('inquirer')
/**
* 选择goods的操作
*/
const askGoodsOperation = () => {
return new Promise((resolve, reject) => {
const question = [{
type: 'list',
name: 'type',
message: '请选择要进行的操作',
choices: [
{
name: '生成goods模板',
value: 'export',
},
{
name: '格式化生成skuList',
value: 'import',
},
],
filter: (val) => {
return val
},
}]
try {
inquirer.prompt(question).then((answer) => {
resolve(answer.type)
})
} catch (err) {
reject(err)
}
})
}
/**
* 选择导出的路径
*/
const askExportPath = () => {
return new Promise((resolve, reject) => {
const question = [
{
type: 'input',
name: 'dist',
message: '选择生成的excel模板的目录(默认当前目录)',
default: process.cwd(),
validate: function (_val) {
if (/\S+/.test(_val)) {
return true
}
return '请输入正确的路径'
},
},
]
try {
inquirer.prompt(question).then((answer) => {
resolve(answer.dist)
})
} catch (err) {
reject(err)
}
})
}
/**
* 选择导入的excel文件
*/
const askImportExcel = () => {
return new Promise((resolve, reject) => {
const question = [
{
type: 'input',
name: 'file',
message: '选择导入的excel模板的目录(默认当前目录的 goods-tpl.xlsx)',
default: 'goods-tpl.xlsx',
validate: function (_val) {
if (/\.xlsx$/.test(_val)) {
return true
}
return '请输入正确的 xlsx 文件'
},
},
]
try {
inquirer.prompt(question).then((answer) => {
resolve(path.resolve(process.cwd(), answer.file))
})
} catch (err) {
reject(err)
}
})
}
module.exports = {
askGoodsOperation,
askExportPath,
askImportExcel,
}