hsh19900502 1.0.6 → 1.0.7
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/dist/commands/git.d.ts +3 -0
- package/dist/commands/git.js +32 -0
- package/dist/commands/mono.d.ts +4 -0
- package/dist/commands/mono.js +57 -0
- package/dist/hsh.d.ts +2 -0
- package/dist/hsh.js +34 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/package.json +16 -3
- package/src/commands/git.ts +48 -0
- package/src/commands/mono.ts +71 -0
- package/src/hsh.ts +43 -0
- package/src/types/index.ts +1 -0
- package/tsconfig.json +21 -0
- package/bin/hsh.mjs +0 -55
- package/pnpm-lock.yaml +0 -892
- package/src/commands/git.mjs +0 -38
- package/src/commands/story.mjs +0 -39
- package/src/constants.mjs +0 -3
- package/src/utils.mjs +0 -30
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import 'zx/globals';
|
|
4
|
+
export const gcm = async function (message, isPush) {
|
|
5
|
+
await $ `git add -A`;
|
|
6
|
+
await $ `git commit -m ${message}`;
|
|
7
|
+
console.log(chalk.green('Committed changes successfully!\n'));
|
|
8
|
+
if (isPush) {
|
|
9
|
+
await push();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const push = async function () {
|
|
13
|
+
const question = [
|
|
14
|
+
{
|
|
15
|
+
type: 'input',
|
|
16
|
+
name: 'branch',
|
|
17
|
+
message: '请输入要推送到remote的分支名',
|
|
18
|
+
default: (await $ `git branch --show-current`).stdout.trim(),
|
|
19
|
+
validate(val) {
|
|
20
|
+
if (!val) {
|
|
21
|
+
return 'Branch is required!';
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
inquirer.prompt(question).then(async (answers) => {
|
|
28
|
+
const branch = answers.branch;
|
|
29
|
+
await $ `git push origin ${branch}`;
|
|
30
|
+
console.log(chalk.green(`Pushed to remote ${branch} successfully!\n`));
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import 'zx/globals';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
import inquirerAutocomplete from 'inquirer-autocomplete-prompt';
|
|
6
|
+
export const initMonoRepo = () => {
|
|
7
|
+
if (fs.existsSync('.hsh')) {
|
|
8
|
+
console.warn(chalk.yellow('Workspace Initialized Already'));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
fs.writeFileSync('.hsh', 'mono'); // write mono for time being
|
|
12
|
+
console.log(chalk.green('Workspace Initialized Successfully'));
|
|
13
|
+
};
|
|
14
|
+
const getMonoRoot = () => {
|
|
15
|
+
while (!fs.existsSync('.hsh')) {
|
|
16
|
+
process.chdir('..');
|
|
17
|
+
}
|
|
18
|
+
return process.cwd();
|
|
19
|
+
};
|
|
20
|
+
export const monoCd = async (repoDirLevel, repo) => {
|
|
21
|
+
const monoRoot = getMonoRoot();
|
|
22
|
+
if (repoDirLevel === 'root') {
|
|
23
|
+
console.log(`cd ${monoRoot}`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const repoName = repo || await chooseRepo();
|
|
27
|
+
if (repoDirLevel === 'client') {
|
|
28
|
+
console.log(`cd ${monoRoot}/${repoName}/client`);
|
|
29
|
+
}
|
|
30
|
+
if (repoDirLevel === 'server') {
|
|
31
|
+
console.log(`cd ${monoRoot}/${repoName}/server`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
async function searchDirectories(answers, input = '') {
|
|
35
|
+
const monoRoot = getMonoRoot();
|
|
36
|
+
const directories = fs.readdirSync(monoRoot, { withFileTypes: true })
|
|
37
|
+
.filter(dirent => dirent.isDirectory())
|
|
38
|
+
.map(dirent => dirent.name);
|
|
39
|
+
if (!input) {
|
|
40
|
+
return directories;
|
|
41
|
+
}
|
|
42
|
+
return directories.filter(dir => dir.toLowerCase().includes(input.toLowerCase()));
|
|
43
|
+
}
|
|
44
|
+
const chooseRepo = async () => {
|
|
45
|
+
// 注册自动补全提示插件
|
|
46
|
+
inquirer.registerPrompt('autocomplete', inquirerAutocomplete);
|
|
47
|
+
const answer = await inquirer.prompt([
|
|
48
|
+
{
|
|
49
|
+
type: 'autocomplete',
|
|
50
|
+
name: 'directory',
|
|
51
|
+
message: 'Select repo to navigate to:',
|
|
52
|
+
source: searchDirectories,
|
|
53
|
+
pageSize: 10,
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
return answer.directory;
|
|
57
|
+
};
|
package/dist/hsh.d.ts
ADDED
package/dist/hsh.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { gcm, push } from './commands/git.js';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import packageJson from '../package.json' assert { type: "json" };
|
|
5
|
+
import { initMonoRepo, monoCd } from './commands/mono.js';
|
|
6
|
+
const program = new Command();
|
|
7
|
+
program.usage('<command> [options]');
|
|
8
|
+
program.version(packageJson.version);
|
|
9
|
+
program
|
|
10
|
+
.command('gcm')
|
|
11
|
+
.description('commit changes')
|
|
12
|
+
.option('--push', 'push to remote after commit')
|
|
13
|
+
.argument('<words...>')
|
|
14
|
+
.action((words, options) => {
|
|
15
|
+
console.log(words, options);
|
|
16
|
+
gcm(words.join(' '), options.push);
|
|
17
|
+
});
|
|
18
|
+
program
|
|
19
|
+
.command('push')
|
|
20
|
+
.description('push branch to remote')
|
|
21
|
+
.action(() => {
|
|
22
|
+
push();
|
|
23
|
+
});
|
|
24
|
+
const mono = program.command('mono').description('multi repo management');
|
|
25
|
+
mono.command('init').description('init mono repo').action(() => {
|
|
26
|
+
initMonoRepo();
|
|
27
|
+
});
|
|
28
|
+
mono.command('cd').description('cd into repo')
|
|
29
|
+
.option('--repo <value>', 'specify repo name')
|
|
30
|
+
.argument('<repoDirLevel>') // currently only supports root, client, server
|
|
31
|
+
.action(async (repoDirLevel, options) => {
|
|
32
|
+
await monoCd(repoDirLevel, options.repo);
|
|
33
|
+
});
|
|
34
|
+
program.parse();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RepoDirLevel = 'root' | 'client' | 'server';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hsh19900502",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "rm -rf dist && tsc",
|
|
10
|
+
"build:install": "npm run build && npm uninstall -g && npm install -g",
|
|
11
|
+
"start": "node dist/bin/hsh.js",
|
|
12
|
+
"dev": "ts-node bin/hsh.ts"
|
|
8
13
|
},
|
|
9
14
|
"bin": {
|
|
10
|
-
"hsh": "./
|
|
15
|
+
"hsh": "./dist/hsh.js"
|
|
11
16
|
},
|
|
12
17
|
"keywords": [],
|
|
13
18
|
"author": "",
|
|
@@ -16,8 +21,16 @@
|
|
|
16
21
|
"chalk": "^5.3.0",
|
|
17
22
|
"commander": "^12.0.0",
|
|
18
23
|
"inquirer": "^9.2.15",
|
|
24
|
+
"inquirer-autocomplete-prompt": "^3.0.1",
|
|
19
25
|
"log-symbols": "^6.0.0",
|
|
20
26
|
"ora": "^8.0.1",
|
|
21
27
|
"zx": "^7.2.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/inquirer": "^9.0.7",
|
|
31
|
+
"@types/inquirer-autocomplete-prompt": "^3.0.3",
|
|
32
|
+
"@types/node": "^20.0.0",
|
|
33
|
+
"ts-node": "^10.9.0",
|
|
34
|
+
"typescript": "^5.0.0"
|
|
22
35
|
}
|
|
23
36
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import 'zx/globals';
|
|
4
|
+
|
|
5
|
+
export const gcm = async function (message: string, isPush?: boolean): Promise<void> {
|
|
6
|
+
await $`git add -A`;
|
|
7
|
+
await $`git commit -m ${message}`;
|
|
8
|
+
console.log(chalk.green('Committed changes successfully!\n'));
|
|
9
|
+
|
|
10
|
+
if (isPush) {
|
|
11
|
+
await push();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
interface BranchQuestion {
|
|
16
|
+
type: 'input';
|
|
17
|
+
name: 'branch';
|
|
18
|
+
message: string;
|
|
19
|
+
default: string;
|
|
20
|
+
validate(val: string): boolean | string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface AnswerType {
|
|
24
|
+
branch: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const push = async function (): Promise<void> {
|
|
28
|
+
const question: BranchQuestion[] = [
|
|
29
|
+
{
|
|
30
|
+
type: 'input',
|
|
31
|
+
name: 'branch',
|
|
32
|
+
message: '请输入要推送到remote的分支名',
|
|
33
|
+
default: (await $`git branch --show-current`).stdout.trim(),
|
|
34
|
+
validate(val) {
|
|
35
|
+
if (!val) {
|
|
36
|
+
return 'Branch is required!';
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
inquirer.prompt<AnswerType>(question).then(async (answers) => {
|
|
44
|
+
const branch = answers.branch;
|
|
45
|
+
await $`git push origin ${branch}`;
|
|
46
|
+
console.log(chalk.green(`Pushed to remote ${branch} successfully!\n`));
|
|
47
|
+
});
|
|
48
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import 'zx/globals';
|
|
4
|
+
import { RepoDirLevel } from '../types/index.js';
|
|
5
|
+
import inquirer from 'inquirer';
|
|
6
|
+
import inquirerAutocomplete from 'inquirer-autocomplete-prompt';
|
|
7
|
+
|
|
8
|
+
export const initMonoRepo = () => {
|
|
9
|
+
if(fs.existsSync('.hsh')) {
|
|
10
|
+
console.warn(chalk.yellow('Workspace Initialized Already'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
fs.writeFileSync('.hsh', 'mono'); // write mono for time being
|
|
14
|
+
console.log(chalk.green('Workspace Initialized Successfully'));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const getMonoRoot = () => {
|
|
18
|
+
while(!fs.existsSync('.hsh')){
|
|
19
|
+
process.chdir('..');
|
|
20
|
+
}
|
|
21
|
+
return process.cwd();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const monoCd = async (repoDirLevel: RepoDirLevel, repo?: string) => {
|
|
25
|
+
const monoRoot = getMonoRoot();
|
|
26
|
+
if(repoDirLevel === 'root') {
|
|
27
|
+
console.log(`cd ${monoRoot}`);
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const repoName = repo || await chooseRepo();
|
|
32
|
+
|
|
33
|
+
if(repoDirLevel === 'client') {
|
|
34
|
+
console.log(`cd ${monoRoot}/${repoName}/client`);
|
|
35
|
+
}
|
|
36
|
+
if(repoDirLevel === 'server') {
|
|
37
|
+
console.log(`cd ${monoRoot}/${repoName}/server`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function searchDirectories(answers: any, input = '') {
|
|
42
|
+
const monoRoot = getMonoRoot();
|
|
43
|
+
const directories = fs.readdirSync(monoRoot, { withFileTypes: true })
|
|
44
|
+
.filter(dirent => dirent.isDirectory())
|
|
45
|
+
.map(dirent => dirent.name);
|
|
46
|
+
|
|
47
|
+
if (!input) {
|
|
48
|
+
return directories;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return directories.filter(dir =>
|
|
52
|
+
dir.toLowerCase().includes(input.toLowerCase())
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const chooseRepo = async () => {
|
|
57
|
+
// 注册自动补全提示插件
|
|
58
|
+
inquirer.registerPrompt('autocomplete', inquirerAutocomplete);
|
|
59
|
+
|
|
60
|
+
const answer = await inquirer.prompt([
|
|
61
|
+
{
|
|
62
|
+
type: 'autocomplete',
|
|
63
|
+
name: 'directory',
|
|
64
|
+
message: 'Select repo to navigate to:',
|
|
65
|
+
source: searchDirectories,
|
|
66
|
+
pageSize: 10,
|
|
67
|
+
}
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
return answer.directory;
|
|
71
|
+
}
|
package/src/hsh.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { gcm, push } from './commands/git.js';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import packageJson from '../package.json' assert { type: "json" };
|
|
5
|
+
import { initMonoRepo, monoCd } from './commands/mono.js';
|
|
6
|
+
import { RepoDirLevel } from './types/index.js';
|
|
7
|
+
|
|
8
|
+
const program = new Command();
|
|
9
|
+
|
|
10
|
+
program.usage('<command> [options]');
|
|
11
|
+
program.version(packageJson.version);
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.command('gcm')
|
|
15
|
+
.description('commit changes')
|
|
16
|
+
.option('--push', 'push to remote after commit')
|
|
17
|
+
.argument('<words...>')
|
|
18
|
+
.action((words: string[], options: { push?: boolean }) => {
|
|
19
|
+
console.log(words, options);
|
|
20
|
+
gcm(words.join(' '), options.push);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
program
|
|
24
|
+
.command('push')
|
|
25
|
+
.description('push branch to remote')
|
|
26
|
+
.action(() => {
|
|
27
|
+
push();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const mono = program.command('mono').description('multi repo management')
|
|
31
|
+
mono.command('init').description('init mono repo').action(() => {
|
|
32
|
+
initMonoRepo();
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
mono.command('cd').description('cd into repo')
|
|
37
|
+
.option('--repo <value>', 'specify repo name')
|
|
38
|
+
.argument('<repoDirLevel>') // currently only supports root, client, server
|
|
39
|
+
.action(async (repoDirLevel: RepoDirLevel, options: { repo?: string }) => {
|
|
40
|
+
await monoCd(repoDirLevel, options.repo);
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
program.parse();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RepoDirLevel = 'root' | 'client' | 'server';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"rootDir": "src",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"types": ["node"],
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"baseUrl": "./",
|
|
15
|
+
"paths": {
|
|
16
|
+
"*": ["*", "*.js"]
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["node_modules", "dist"]
|
|
21
|
+
}
|
package/bin/hsh.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { require } from '../src/utils.mjs';
|
|
3
|
-
import { gcm, push } from '../src/commands/git.mjs';
|
|
4
|
-
import { storyInit, openAllStoryDocs, listAllStoryDocs, openOneDoc } from '../src/commands/story.mjs';
|
|
5
|
-
|
|
6
|
-
const { Command } = require('commander');
|
|
7
|
-
|
|
8
|
-
const program = new Command();
|
|
9
|
-
|
|
10
|
-
program.usage('<command> [options]')
|
|
11
|
-
program.version(require('../package').version)
|
|
12
|
-
|
|
13
|
-
program.command('gcm')
|
|
14
|
-
.description('commit changes')
|
|
15
|
-
.option('--push', 'push to remote after commit')
|
|
16
|
-
.argument('<words...>')
|
|
17
|
-
.action((words, options) => {
|
|
18
|
-
console.log(words, options)
|
|
19
|
-
gcm(words.join(' '), options.push)
|
|
20
|
-
})
|
|
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
|
-
case 'list':
|
|
43
|
-
listAllStoryDocs();
|
|
44
|
-
break;
|
|
45
|
-
default:
|
|
46
|
-
console.log('===1')
|
|
47
|
-
}
|
|
48
|
-
}else if(words.length === 2){
|
|
49
|
-
if(words[0] === 'open'){
|
|
50
|
-
openOneDoc(words[1])
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
program.parse();
|