1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-04-05 11:38:27 +08:00

feat: update

This commit is contained in:
chufan
2023-09-05 19:42:45 +08:00
parent d94f30aa20
commit 0842ce3276
5 changed files with 180 additions and 14 deletions

View File

@@ -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 === `)
}
}

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env node
const {execShell} = require("./.exec");
const inquirer = require('inquirer');
(async ()=>{
await execShell(['pnpm build','pnpm build:proxy'])
})()

79
scripts/bundle Executable file
View File

@@ -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)
})()

27
scripts/lint Executable file
View File

@@ -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)
})()

View File

@@ -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);
})()