hsh19900502 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/hsh.mjs +34 -7
- package/package.json +2 -2
- package/src/commands/git.mjs +38 -0
- package/src/commands/story.mjs +37 -0
- package/src/constants.mjs +1 -0
- package/src/utils.mjs +7 -0
- package/src/commands/commit.mjs +0 -6
package/bin/hsh.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
import { require } from '../src/utils.mjs';
|
|
3
|
-
import { gcm } from '../src/commands/
|
|
3
|
+
import { gcm, push } from '../src/commands/git.mjs';
|
|
4
|
+
import { storyInit, openAllStoryDocs } from '../src/commands/story.mjs';
|
|
4
5
|
|
|
5
6
|
const { Command } = require('commander');
|
|
6
7
|
|
|
@@ -11,11 +12,37 @@ program.version(require('../package').version)
|
|
|
11
12
|
|
|
12
13
|
program.command('gcm')
|
|
13
14
|
.description('commit changes')
|
|
14
|
-
|
|
15
|
+
.option('--push', 'push to remote after commit')
|
|
15
16
|
.argument('<words...>')
|
|
16
|
-
.action((words) => {
|
|
17
|
-
console.log(words)
|
|
18
|
-
gcm(words.join(' '))
|
|
17
|
+
.action((words, options) => {
|
|
18
|
+
console.log(words, options)
|
|
19
|
+
gcm(words.join(' '), options.push)
|
|
19
20
|
})
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
program.command('push')
|
|
23
|
+
.description('push branch to remote')
|
|
24
|
+
.action(() => {
|
|
25
|
+
push()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
program.command('story')
|
|
29
|
+
.description('shortcut to open links of all related docs')
|
|
30
|
+
.argument('<words...>')
|
|
31
|
+
.action((words, options) => {
|
|
32
|
+
console.log(words, options)
|
|
33
|
+
if (words.length === 1) {
|
|
34
|
+
const subCommand = words[0]
|
|
35
|
+
switch (subCommand) {
|
|
36
|
+
case 'init':
|
|
37
|
+
storyInit();
|
|
38
|
+
break;
|
|
39
|
+
case 'open':
|
|
40
|
+
openAllStoryDocs();
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
console.log('===1')
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
program.parse();
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hsh19900502",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
-
"hsh": "bin/hsh.mjs"
|
|
10
|
+
"hsh": "./bin/hsh.mjs"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [],
|
|
13
13
|
"author": "",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import inquirer from 'inquirer'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import 'zx/globals'
|
|
4
|
+
import { getCurrentBranch } from '../utils.mjs'
|
|
5
|
+
|
|
6
|
+
export const gcm = async function (message, isPush) {
|
|
7
|
+
await $`git add -A`
|
|
8
|
+
await $`git commit -m ${message}`
|
|
9
|
+
console.log(chalk.green('Committed changes successfully!\n'))
|
|
10
|
+
|
|
11
|
+
if(isPush){
|
|
12
|
+
await push()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const question = [
|
|
18
|
+
{
|
|
19
|
+
type: 'input',
|
|
20
|
+
name: 'branch',
|
|
21
|
+
message: '请输入要推送到remote的分支名',
|
|
22
|
+
default: (await getCurrentBranch()),
|
|
23
|
+
validate(val) {
|
|
24
|
+
if (!val) {
|
|
25
|
+
return 'Branch is required!'
|
|
26
|
+
}
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export const push = async function () {
|
|
33
|
+
inquirer.prompt(question).then(async (answers) => {
|
|
34
|
+
const branch = answers.branch
|
|
35
|
+
await $`git push origin ${branch}`
|
|
36
|
+
console.log(chalk.green(`Pushed to remote ${branch} successfully!\n`))
|
|
37
|
+
})
|
|
38
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getCurrentBranch, getTicketId } from '../utils.mjs';
|
|
2
|
+
import { STORY_CONFIG_PATH } from '../constants.mjs';
|
|
3
|
+
|
|
4
|
+
import util from "util"
|
|
5
|
+
import childProcess from "child_process"
|
|
6
|
+
const exec = util.promisify(childProcess.exec);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const storyInit = async() => {
|
|
10
|
+
if(!fs.existsSync(STORY_CONFIG_PATH)){
|
|
11
|
+
fs.writeFileSync(STORY_CONFIG_PATH, '{}', 'utf-8');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const storyConfig = JSON.parse(fs.readFileSync(STORY_CONFIG_PATH, 'utf-8'));
|
|
15
|
+
const branch = await getCurrentBranch();
|
|
16
|
+
const ticketId = getTicketId(branch);
|
|
17
|
+
|
|
18
|
+
storyConfig[ticketId] = {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fs.writeFileSync(STORY_CONFIG_PATH, JSON.stringify(storyConfig, null, 2), 'utf-8')
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const openAllStoryDocs = async() => {
|
|
25
|
+
if(!fs.existsSync(STORY_CONFIG_PATH)){
|
|
26
|
+
console.error('Not inited yet')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const branch = await getCurrentBranch();
|
|
30
|
+
const ticketId = getTicketId(branch);
|
|
31
|
+
|
|
32
|
+
const storyConfig = JSON.parse(fs.readFileSync(STORY_CONFIG_PATH, 'utf-8'));
|
|
33
|
+
|
|
34
|
+
Object.values(storyConfig[ticketId]).forEach(async (url) => {
|
|
35
|
+
await exec(`open ${url}`);
|
|
36
|
+
})
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STORY_CONFIG_PATH = `${os.homedir()}/story.json`
|
package/src/utils.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
export const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
export const getCurrentBranch = async () => {
|
|
6
|
+
const branch = (await $`git branch --show-current`).stdout.trim();
|
|
7
|
+
return branch
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getTicketId = (branch) => branch.split('/')[1]
|