diff --git a/scripts/.exec b/scripts/.exec index 6396091..052eb1c 100755 --- a/scripts/.exec +++ b/scripts/.exec @@ -5,6 +5,19 @@ process.env.PATH = `${join(cwd, 'node_modules', '.bin')}:${process.env.PATH}` const {exec,exit} = require('shelljs'); +async function printWithInterval() { + for (let count = 1; ; count++) { + if(count<5){ + console.log('执行中'+'.'.repeat(count)); + }else { + break; + } + } +} + + + + /** * 监听进程 * - 退出进程 @@ -13,11 +26,32 @@ process.on('exit', () => { exit() }) +async function syncExec(command){ + let size=100 + let count = 0; + const intervalId = setInterval(async () => { + console.log('执行中'+'.'.repeat(count),size,count); + count++; + size = await new Promise((resolve,reject)=>{ + exec(command,(code)=>{ + console.log(code) + console.log('Exit code:', code); + resolve() + }) + }) + console.log(size) + if (count > size) { + clearInterval(intervalId); // 停止打印 + } + }, 1000); + +} + /** * 执行shell指令 * @param commands */ -exports.execShell = commands => { +exports.execShell = async commands => { let runCommands=[] if(typeof commands ==='string'){ runCommands.push(commands) @@ -29,8 +63,9 @@ exports.execShell = commands => { } for (const command of runCommands) { - console.log(`------- command: >>> ${command} <<< start -------`) - exec(command) - console.log(`------- command: >>> ${command} <<< ending -------`) + console.log(`=== command: >>> ${command} <<< start === `) + + await syncExec(command) + console.log(`=== command: >>> ${command} <<< ending === `) } } diff --git a/scripts/build b/scripts/build deleted file mode 100644 index 3a6fd24..0000000 --- a/scripts/build +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env node - -const {execShell} = require("./.exec"); -const inquirer = require('inquirer'); - -(async ()=>{ - await execShell(['pnpm build','pnpm build:proxy']) -})() \ No newline at end of file diff --git a/scripts/bundle b/scripts/bundle new file mode 100755 index 0000000..98e391f --- /dev/null +++ b/scripts/bundle @@ -0,0 +1,79 @@ +#!/usr/bin/env node +/** + * + * 将应用程序打包成可部署的包、文件、镜像 + * 例如: + * - ./scripts/bundle build 基础部署打包 + * - ./scripts/bundle build_proxy 用于三方平台部署打包 + * - ./scripts/bundle image 构建容器镜像 + * - ./scripts/bundle image_faster 本地build,快速构建容器镜像 + * - ./scripts/bundle xxx 其他参数,默认执行build命令 + * - ./scripts/bundle 交互式选择执行的命令 + */ + +const { execShell } = require("./.exec"); +const { Select } = require('enquirer'); + + +/** + * 支持的脚本命令 + */ +const SupportScripts={ + build:'vuepress build docs', + build_proxy:'PROXY_DOMAIN=true vuepress build docs', + image:'bash scripts/build_image.sh $npm_package_version', + image_faster:'bash scripts/build_image.sh $npm_package_version faster' +} + + +async function getScriptCommand(){ + let scriptName=process.argv[2]; + let scriptCommand=SupportScripts.build + + if(scriptName==null){ + const prompt = new Select({ + header: '======================== 408CSFamily Cli For Building ========================', + footer: '======================== 408CSFamily Cli For Building ========================', + name: 'color', + message: 'What script will you want to run ', + choices: [ + { + message: 'build', + name: SupportScripts.build, + value: '#00ffff' + }, + { + message: 'build for fixing proxy', + name: SupportScripts.build_proxy, + value: '#000000' + }, + { + message: 'build to docker image', + name: SupportScripts.image, + value: '#0000ff' + }, + { + message: 'build to docker image faster', + name: SupportScripts.image_faster, + value: '#0000ff' + }, + ] + }); + scriptCommand = await prompt.run() + }else{ + // 命中支持的脚本 + if(Object.keys(SupportScripts).includes(scriptName)) + scriptCommand=SupportScripts[scriptName] + } + return scriptCommand +} + + +;(async ()=>{ + const scriptCommand= await getScriptCommand() + console.log(`>>>> ${scriptCommand} `) + + // 执行 + await execShell(scriptCommand) +})() + diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 0000000..ebdf6dd --- /dev/null +++ b/scripts/lint @@ -0,0 +1,27 @@ +#!/usr/bin/env node +/** + * + * 将应用程序打包成可部署的包、文件、镜像 + * 例如: + * - ./scripts/bundle build 基础部署打包 + * - ./scripts/bundle build_proxy 用于三方平台部署打包 + * - ./scripts/bundle image 构建容器镜像 + * - ./scripts/bundle image_faster 本地build,快速构建容器镜像 + * - ./scripts/bundle xxx 其他参数,默认执行build命令 + * - ./scripts/bundle 交互式选择执行的命令 + */ + +const { execShell } = require("./.exec"); +const scriptName=process.argv[2]; + +let fixed='' + +if(scriptName!=null){ + fixed='--fix' +} + +;(async ()=>{ + const scriptCommand= `eslint ${fixed} --ext .js,.ts,.vue --ignore-path .gitignore .` + // 执行 + await execShell(scriptCommand) +})() \ No newline at end of file diff --git a/scripts/test b/scripts/test index 85a38b7..c31ce94 100755 --- a/scripts/test +++ b/scripts/test @@ -1,7 +1,40 @@ #!/usr/bin/env node -const {execShell} = require("./.exec"); +// const {execShell} = require("./.exec"); (async ()=>{ - await execShell(['pnpm build','pnpm build:proxy']) + const { AutoComplete } = require('enquirer'); + + const prompt = new AutoComplete({ + name: 'flavor', + message: 'Pick your favorite flavor', + limit: 10, + initial: 2, + choices: [ + 'Almond', + 'Apple', + 'Banana', + 'Blackberry', + 'Blueberry', + 'Cherry', + 'Chocolate', + 'Cinnamon', + 'Coconut', + 'Cranberry', + 'Grape', + 'Nougat', + 'Orange', + 'Pear', + 'Pineapple', + 'Raspberry', + 'Strawberry', + 'Vanilla', + 'Watermelon', + 'Wintergreen' + ] + }); + + prompt.run() + .then(answer => console.log('Answer:', answer)) + .catch(console.error); })() \ No newline at end of file