1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-02-02 18:20:26 +08:00

style: 格式化脚本

This commit is contained in:
chu fan
2023-09-07 11:16:20 +08:00
parent 8673a64409
commit eeed9d8cd7
8 changed files with 188 additions and 192 deletions

View File

@@ -2,18 +2,18 @@
"name": "408CSFamily",
"description": "专业代号408计算机基础知识点合集",
"version": "0.0.1-alpha.0",
"packageManager": "pnpm@7.2.1",
"engines": {
"node": "14.x || 16.x || 18.x",
"pnpm": ">=7.2.1"
},
"packageManager": "pnpm@7.2.1",
"author": {
"name": "Chu Fan",
"email": "fairy_408@2925.com",
"url": "https://github.com/142vip"
},
"scripts": {
"prepare": "husky install && npx husky add .husky/pre-commit \"./scripts/lint --fix\" && chmod +x .husky/pre-commit",
"prepare": "rm -f .husky/pre-commit && husky install && npx husky add .husky/pre-commit \"./scripts/lint --fix\" && chmod +x .husky/pre-commit",
"dev": "vuepress dev docs",
"build": "./scripts/bundle build",
"build:proxy": "./scripts/bundle build_proxy",

View File

@@ -11,27 +11,32 @@
* - ./scripts/bundle 交互式选择执行的命令
*/
const { execShell } = require("./.exec");
const { Select } = require('enquirer');
const { execShell } = require('./.exec')
const { Select } = require('enquirer')
const packageVersion=require('../package.json').version
const projectName="408CSFamily"
const packageVersion = require('../package.json').version
const projectName = '408CSFamily'
// 仓库地址
const repoAddress="registry.cn-hangzhou.aliyuncs.com/142vip/doc_book"
const repoAddress = 'registry.cn-hangzhou.aliyuncs.com/142vip/doc_book'
// 镜像地址
const imageName=`${repoAddress}:${projectName}-${packageVersion}`
const imageName = `${repoAddress}:${projectName}-${packageVersion}`
/**
* 获取构建镜像的脚本
* @param containerBuild
* @param preBuild
* @param needProxy
* @returns {string[]}
*/
function getBuildImageScript({containerBuild,needProxy=false}){
// 基础构建脚本
const baseBuildScript=containerBuild?"":(
needProxy?"./scripts/bundle build_proxy":"./scripts/bundle build"
)
return [
function getBuildImageScript({ containerBuild, preBuild, needProxy = false }) {
// 基础构建脚本
let baseBuildScript = ''
if (preBuild) {
baseBuildScript = needProxy ? './scripts/bundle build_proxy' : './scripts/bundle build'
}
return [
// 构建镜像
`
${baseBuildScript}
@@ -53,82 +58,81 @@ function getBuildImageScript({containerBuild,needProxy=false}){
exit 1;
fi
`
]
]
}
/**
* 支持的脚本命令
*/
const SupportScripts={
build:'vuepress build docs',
build_proxy:'PROXY_DOMAIN=true vuepress build docs',
image:getBuildImageScript({
containerBuild:true,
needProxy:false
}),
image_proxy:getBuildImageScript({
containerBuild:true,
needProxy:true
}),
// 直接从本地拿dist文件生成镜像
image_faster:getBuildImageScript({
containerBuild:false,
needProxy:false
const SupportScripts = {
build: 'vuepress build docs',
build_proxy: 'PROXY_DOMAIN=true vuepress build docs',
image: getBuildImageScript({
containerBuild: true,
needProxy: false
}),
image_proxy: getBuildImageScript({
containerBuild: true,
needProxy: true
}),
// 直接从本地拿dist文件生成镜像
image_faster: getBuildImageScript({
containerBuild: false,
needProxy: false
})
}
async function getScriptCommand() {
const 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 with proxy',
name: SupportScripts.image_proxy,
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 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 with proxy',
name: SupportScripts.image_proxy,
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()
await execShell(scriptCommand)
;(async() => {
const scriptCommand = await getScriptCommand()
await execShell(scriptCommand)
})()

View File

@@ -5,19 +5,19 @@
* - ./scripts/deploy ali
* - ./scripts/deploy github
*/
const { execShell } = require("./.exec");
const packageVersion=require('../package.json').version
const { execShell } = require('./.exec')
const packageVersion = require('../package.json').version
const dockerDeployInfo={
repoAddress:"registry.cn-hangzhou.aliyuncs.com/142vip/doc_book",
containerName:'408CSFamily',
networkName:'service_env_net',
const dockerDeployInfo = {
repoAddress: 'registry.cn-hangzhou.aliyuncs.com/142vip/doc_book',
containerName: '408CSFamily',
networkName: 'service_env_net'
}
const imageName=`${dockerDeployInfo.repoAddress}:${dockerDeployInfo.containerName}-${packageVersion}`
const imageName = `${dockerDeployInfo.repoAddress}:${dockerDeployInfo.containerName}-${packageVersion}`
// 支持的命令
const SupportScripts={
Github:`
const SupportScripts = {
Github: `
set -e
./scripts/build proxy && cd docs/.vuepress/dist
git init && git add -A
@@ -30,7 +30,7 @@ const SupportScripts={
git push -f https://github.com/mmdapl/408CSFamily.git master:pages/github
cd -
`,
Ali:[
Ali: [
// 容器存在即删除
`
if docker inspect --format='{{.State.Running}}' ${dockerDeployInfo.containerName} >/dev/null 2>&1;then
@@ -59,31 +59,31 @@ const SupportScripts={
--restart=unless-stopped \
--ip=172.30.0.100 \
${imageName}
`,
]
`
]
}
const deployName=process.argv[2];
const deployName = process.argv[2]
function getDeployCommand(){
let deployCommand=SupportScripts.Ali
function getDeployCommand() {
let deployCommand = SupportScripts.Ali
// 部署到阿里云服务器
if(deployName==='ali'){
deployCommand=SupportScripts.Ali
if (deployName === 'ali') {
deployCommand = SupportScripts.Ali
}
// 部署到Github
if(deployName==='github'){
deployCommand=SupportScripts.Github
if (deployName === 'github') {
deployCommand = SupportScripts.Github
}
return deployCommand
}
// 执行
;(async ()=>{
const deployCommand=getDeployCommand()
// console.log(deployCommand)
await execShell(deployCommand)
})()
;(async() => {
const deployCommand = getDeployCommand()
// console.log(deployCommand)
await execShell(deployCommand)
})()

View File

@@ -6,5 +6,5 @@
* - ./scripts/dev
*/
const { execShell } = require("./.exec");
(async ()=>await execShell('vuepress dev docs'))()
const { execShell } = require('./.exec');
(async() => await execShell('vuepress dev docs'))()

View File

@@ -7,8 +7,8 @@
* - ./scripts/network image xxx 镜像相关
* - ./scripts/docker network xxx 网络相关
*/
const { execShell, BaseSetting} = require("./.exec");
const scriptName=process.argv[2];
const { execShell, BaseSetting } = require('./.exec')
const scriptName = process.argv[2]
/**
@@ -17,19 +17,19 @@ const scriptName=process.argv[2];
* - 子网掩码
* - 网关地址
*/
const dockerNetworkInfo={
defaultName:'service_env_net',
subnet:'172.30.0.0/24',
gateway:'172.30.0.1',
const dockerNetworkInfo = {
defaultName: 'service_env_net',
subnet: '172.30.0.0/24',
gateway: '172.30.0.1'
}
/**
* docker containers 容器相关指令
*/
const SupportScriptsInContainer={
run:'',
rm:'',
ps:'docker ps'
const SupportScriptsInContainer = {
run: '',
rm: '',
ps: 'docker ps'
}
/**
@@ -43,9 +43,9 @@ const SupportScriptsInImage = {
/**
* docker network 相关脚本指令
*/
const SupportScriptsInNetWork={
ls:'docker network ls',
create:[
const SupportScriptsInNetWork = {
ls: 'docker network ls',
create: [
// 创建网关
`
docker network create \
@@ -58,7 +58,7 @@ const SupportScriptsInNetWork={
docker network inspect ${dockerNetworkInfo.defaultName}
`
],
rm:[
rm: [
// 参数校验
`
if test -z "${dockerNetworkInfo.defaultName}";then
@@ -86,44 +86,39 @@ const SupportScriptsInNetWork={
}
function getContainerCommand() {
const name = process.argv[3]
function getContainerCommand(){
const name=process.argv[3];
if(SupportScriptsInContainer.hasOwnProperty(name)){
if (name in SupportScriptsInContainer) {
return SupportScriptsInContainer[name]
}
// 默认查看所有容器
return SupportScriptsInContainer.ps
}
function getImageCommand(){
const name=process.argv[3];
function getImageCommand() {
const name = process.argv[3]
if(SupportScriptsInImage.hasOwnProperty(name)){
if (name in SupportScriptsInImage) {
return SupportScriptsInImage[name]
}
return SupportScriptsInImage.ps
}
function getNetworkCommand(){
const name=process.argv[3];
if(SupportScriptsInNetWork.hasOwnProperty(name)){
function getNetworkCommand() {
const name = process.argv[3]
if (name in SupportScriptsInNetWork) {
return SupportScriptsInNetWork[scriptName]
}
return SupportScriptsInNetWork.ls
}
// 支持的命令
const SupportScripts={
ls:'docker network ls',
create:[
const SupportScripts = {
ls: 'docker network ls',
create: [
// 创建网关
`
docker network create \
@@ -136,7 +131,7 @@ const SupportScripts={
docker network inspect ${dockerNetworkInfo.defaultName}
`
],
rm:[
rm: [
// 参数校验
`
if test -z "${dockerNetworkInfo.defaultName}";then
@@ -163,9 +158,9 @@ const SupportScripts={
`
}
function getCommand(){
const scriptName=process.argv[3];
switch (scriptName){
function getCommand() {
const scriptName = process.argv[3]
switch (scriptName) {
case 'network':
return getNetworkCommand()
case 'container':
@@ -173,12 +168,11 @@ function getCommand(){
case 'image':
return getImageCommand()
}
}
// 执行
;(async ()=>{
const command=getCommand(scriptName)
;(async() => {
const command = getCommand(scriptName)
await execShell(command)
})()
})()

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env node
/**
*
* 格式化代码
@@ -7,13 +8,9 @@
* - ./scripts/lint --fix
*/
const { execShell } = require("./.exec");
const scriptName=process.argv[2];
const { execShell } = require('./.exec')
const scriptName = process.argv[2]
const fixed = scriptName != null ? '--fix' : '';
let fixed=''
if(scriptName!=null){
fixed='--fix'
}
;(async ()=>await execShell(`eslint ${fixed} --ext .js,.ts,.vue --ignore-path .gitignore .`))()
// 可以在--fix后指定目录
(async() => await execShell(`eslint ${fixed} --ext .js,.ts,.vue --ignore-path .gitignore .`))()

View File

@@ -1,16 +1,17 @@
#!/usr/bin/env node
/**
* 版本发布脚本
* 链接https://jstools.dev/version-bump-prompt/
* 使用: ./scripts/release
*/
#!/bin/bash
const {execShell} = require("./.exec");
##
## 版本发布脚本
## 链接https://jstools.dev/version-bump-prompt/
## 使用: ./scripts/release
##
// 利用commit-and-tag-version生成changelog文档并跳过commit、tag操作
const generateChangeLog='pnpm commit-and-tag-version && git add CHANGELOG.md'
// git提交信息
const commitInfo='chore(release): publish v%s'
;(async ()=>await execShell(`bumpp --preid alpha --execute="${generateChangeLog}" --commit "${commitInfo}" --all --tag --push`))()
## 利用commit-and-tag-version生成changelog文档并跳过commit、tag操作
readonly generateChangeLog='pnpm commit-and-tag-version && git add CHANGELOG.md'
## git提交信息
readonly commitInfo='chore(release): publish v%s'
bumpp --preid alpha --execute="$generateChangeLog" --commit "$commitInfo" --all --tag --push

View File

@@ -6,30 +6,30 @@
*/
// const {execShell} = require("./.exec");
(async ()=>{
const { AutoComplete } = require('enquirer');
(async() => {
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',
]
});
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'
]
})
prompt.run()
.then(answer => console.log('Answer:', answer))
.catch(console.error);
})()
prompt.run()
.then(answer => console.log('Answer:', answer))
.catch(console.error)
})()