Commit 229949be by felix

first commit

parent 72d27f2f
const { execFile,execFileSync } = require('child_process')
const readline = require('readline');
if(process.argv.length <= 2){
console.error('not find docker name')
return;
}
let dockerName = process.argv[2]
//创建readline接口实例
const rl = readline.createInterface({
input:process.stdin,
output:process.stdout
});
let json = {
'shPath':'/data/sh',
'basePath':'/data',
'product':{
'sample':{
git:'git@116.62.143.3:sample/server-app.git',
path:'/nserver/app/sample'
}
}
}
let defaultArgs = [];
defaultArgs.push('exec')
defaultArgs.push('-i')
defaultArgs.push(dockerName)
defaultArgs.push('/bin/bash')
start().then(() => {
rl.close()
}).catch((e) => {
console.log(e)
rl.close()
})
async function start(){
let productName = await makeQuestion('请输入项目名称')
checkProductExists(productName)
let actionList = ['clone','publish','rollback','makeTag'];
let action = await makeQuestion(`请问你要执行什么操作[${actionList.join(',')}]`)
switch(action){
case 'clone':
await cloneProcess(productName)
break
case 'publish':
await publishProcess(productName)
break
case 'rollback':
await rollbackProcess(productName)
break
case 'makeTag':
await makeTagProcess(productName)
break
default:
throw new Error(`not found action:${action}`)
}
}
async function rollbackProcess(productName){
let args = []
args.push(`${json.shPath}/getAllTag.sh`)
args.push(json.basePath)
args = formatArgs(productName, args)
exec(defaultArgs.concat(args))
args = []
args.push(`${json.shPath}/checkoutTag.sh`)
args.push(json.basePath)
args = formatArgs(productName, args)
let tagName = await makeQuestion('请选择要切换的tag(直接回车切换到最新的tag)')
args.push(tagName)
exec(defaultArgs.concat(args))
}
async function publishProcess(productName){
let args = []
args.push(`${json.shPath}/pull.sh`)
args.push(json.basePath)
args = formatArgs(productName, args)
exec(defaultArgs.concat(args))
}
async function makeTagProcess(productName){
let args = []
args.push(`${json.shPath}/tag.sh`)
args.push(json.basePath)
let tagName = await makeQuestion('请输入tag')
let message = await makeQuestion('请输入描述')
args = formatArgs(productName, args)
args.push(tagName)
args.push(message)
exec(defaultArgs.concat(args))
}
async function cloneProcess(productName){
let args = []
args.push(`${json.shPath}/clone.sh`)
args.push(json.basePath)
args = formatArgs(productName, args, true)
exec(defaultArgs.concat(args))
}
function formatArgs(productName,args,needGit = false){
let info = json.product[productName];
if(needGit)
args.push(info.git)
args.push(json.basePath+info.path)
return args;
}
function exec(args){
try{
let cl = execFileSync('docker',args)
console.log(cl.toString())
}catch(e){
console.log(e)
}
}
function checkProductExists(productName){
if(!(productName in json.product)){
throw new Error("not found productName")
}
}
async function makeQuestion(question){
return new Promise((r,j) => {
rl.question(question+":",function(answer){
r(answer)
});
})
}
{
"name": "gitPublish",
"version": "1.0.0",
"main": "cmd.js",
"repository": "git@116.62.143.3:felix/gitPublish.git",
"author": "felix <ffu@u-gen.net>",
"license": "MIT",
"scripts": {
"pr": "node cmd.js test",
"pd": "node cmd.js test"
}
}
#!/bin/bash
set -e
base_path="$1"
cd $base_path
cd $2
git checkout $3
pm2 reload $2
#!/bin/bash
set -e
base_path="$1"
cd $base_path
pwd
if [ -n "$2" ] && [ -n "$3" ]; then
git clone $2 $3
fi
#!/bin/bash
set -e
base_path="$1"
cd $base_path
cd $2
git tag
#!/bin/bash
set -e
base_path="$1"
cd $base_path
cd $2
git pull
pm2 reload $2
#!/bin/bash
set -e
base_path="$1"
cd $base_path
cd $2
git tag -a $3 -m $4
git push origin --tags
Arguments:
/usr/local/bin/node /usr/local/Cellar/yarn/1.5.1_1/libexec/bin/yarn.js run pr
PATH:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/felix/Library/Android/sdk/tools:/Users/felix/Library/Android/sdk/platform-tools:/Users/felix/Library/Android/sdk/tools:/Users/felix/Library/Android/sdk/platform-tools
Yarn version:
1.5.1
Node version:
8.11.2
Platform:
darwin x64
npm manifest:
{
"name": "gitPublish",
"version": "1.0.0",
"main": "cmd.js",
"repository": "git@116.62.143.3:felix/gitPublish.git",
"author": "felix <ffu@u-gen.net>",
"license": "MIT",
"scripts": {
"pr": "node cmd.js test",
"pd": "node cmd.js test"
},
}
yarn manifest:
No manifest
Lockfile:
No lockfile
Trace:
SyntaxError: /Users/felix/Desktop/ugengit/node/gitPublish/package.json: Unexpected token } in JSON at position 261
at JSON.parse (<anonymous>)
at /usr/local/Cellar/yarn/1.5.1_1/libexec/lib/cli.js:1036:59
at Generator.next (<anonymous>)
at step (/usr/local/Cellar/yarn/1.5.1_1/libexec/lib/cli.js:98:30)
at /usr/local/Cellar/yarn/1.5.1_1/libexec/lib/cli.js:109:13
at <anonymous>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment