Skip to content

Commit

Permalink
feat: 当前用户查看
Browse files Browse the repository at this point in the history
  • Loading branch information
alqmc authored and alqmc committed Jun 22, 2022
1 parent e9f9ba6 commit 41adefa
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 324 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
6 changes: 0 additions & 6 deletions .huskyrc

This file was deleted.

1 change: 1 addition & 0 deletions build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { dependencies } from '../package.json';
const external = Object.keys(dependencies || '');
const globals = external.reduce((prev, current) => {
const newPrev = prev;
//@ts-ignore
newPrev[current] = current;
return newPrev;
}, {});
Expand Down
3 changes: 2 additions & 1 deletion build/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default series(
withTask('update:version', () => run('pnpm run update:version')),
withTask('clear', () => run('pnpm run clear')),
buildBundle,
copyFiles
copyFiles,
withTask('clear', () => run('pnpm run link'))
);
6 changes: 3 additions & 3 deletions build/utils/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile, writeFile } from 'fs/promises';
import readline from 'readline';
import { resolve } from 'path';
import chalk from 'chalk';
import { green, red } from 'kolorist';

import pkg from '../../package/package.json';
import { enterPath, rootPath } from './path';
Expand All @@ -24,7 +24,7 @@ const changeVersion = (version: string, source: string) => {
writeFile(source, JSON.stringify(pkg, null, 2))
.then(() => {
// eslint-disable-next-line no-console
console.log(chalk.green(`${source}文件,version更改为:${version}`));
console.log(green(`${source}文件,version更改为:${version}`));
})
.catch((err) => {
console.error(err);
Expand All @@ -50,7 +50,7 @@ const getVersion = (rl: readline.Interface): Promise<string> => {
resolve(version);
} else {
// eslint-disable-next-line no-console
console.log(chalk.red(`请输入正确的版本号!`));
console.log(red(`请输入正确的版本号!`));
resolve(await getVersion(rl));
}
});
Expand Down
44 changes: 24 additions & 20 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
'use strict';

var commander = require('commander');
var util = require('util');
var chalk = require('chalk');
var chalk = require('kolorist');
var path = require('path');
var fs = require('fs');
var child_process = require('child_process');
var process$1 = require('process');
var execa = require('execa');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);

var name = "gacm";
var version$1 = "0.0.4";
var version$1 = "0.0.5";
var description = "git account manage";
var keywords = [
"git",
Expand All @@ -30,12 +31,10 @@ var publishConfig = {
access: "public"
};
var dependencies = {
chalk: "4.1.2",
commander: "^9.1.0",
figlet: "^1.5.2",
inquirer: "^8.2.1",
ora: "^5.1.0",
shelljs: "^0.8.5"
kolorist: "^1.5.1",
minimist: "^1.2.6",
prompts: "^2.4.2",
execa: "5.0.1"
};
var pkg = {
name: name,
Expand All @@ -50,24 +49,20 @@ var pkg = {
dependencies: dependencies
};

/* eslint-disable no-console */
const { green, red, yellowBright, blueBright } = chalk__default["default"];
const { green, red, lightYellow, blue } = chalk__default["default"];
const success = (msg) => console.log(green(msg));
const error = (msg) => console.log(red(msg));
const warning = (msg) => console.log(yellowBright(msg));
const info = (msg) => console.log(blueBright(msg));
const warning = (msg) => console.log(lightYellow(msg));
const info = (msg) => console.log(blue(msg));
const log = {
success,
error,
warning,
info,
};

// eslint-disable-next-line @typescript-eslint/no-var-requires
const figlet = util.promisify(require('figlet'));
const version = async () => {
const info = await figlet(`${pkg.name}`);
log.success(`${info} ${pkg.version}`);
log.success(`${pkg.version}`);
};

const baseAction = async (cmd) => {
Expand Down Expand Up @@ -106,7 +101,6 @@ async function writeFileUser(dir, data) {
});
}

// run shell
const run = (command, dir = process$1.cwd()) => {
const [cmd, ...args] = command.split(' ');
return new Promise((resolve, reject) => {
Expand All @@ -125,12 +119,16 @@ const run = (command, dir = process$1.cwd()) => {
});
process.on('exit', processExit);
});
};
const execCommand = async (cmd, args) => {
const res = await execa__default["default"](cmd, args);
return res.stdout.trim();
};

/* eslint-disable no-console */
const geneDashLine = (message, length) => {
const finalMessage = new Array(Math.max(2, length - message.length + 2)).join('-');
return padding(chalk__default["default"].dim(finalMessage));
return padding(chalk.white(finalMessage));
};
const padding = (message = '', before = 1, after = 1) => {
return (new Array(before).fill(' ').join(' ') +
Expand Down Expand Up @@ -172,9 +170,15 @@ const lsAction = async () => {
const keys = Object.keys(userList);
const length = Math.max(...keys.map((key) => key.length)) + 3;
const prefix = ' ';
const currectUser = await execCommand('git', ['config', 'user.name']);
const messages = keys.map((key) => {
const registry = userList[key];
return prefix + registry.name + geneDashLine(key, length) + registry.email;
const currect = registry.name === currectUser ? `${chalk.green('*')}` : '';
return (prefix +
currect +
registry.name +
geneDashLine(key, length) +
registry.email);
});
printMessages(messages);
};
Expand Down
12 changes: 5 additions & 7 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gacm",
"version": "0.0.4",
"version": "0.0.5",
"private": false,
"description": "git account manage",
"keywords": [
Expand All @@ -17,11 +17,9 @@
"access": "public"
},
"dependencies": {
"chalk": "4.1.2",
"commander": "^9.1.0",
"figlet": "^1.5.2",
"inquirer": "^8.2.1",
"ora": "^5.1.0",
"shelljs": "^0.8.5"
"kolorist": "^1.5.1",
"minimist": "^1.2.6",
"prompts": "^2.4.2",
"execa": "5.0.1"
}
}
2 changes: 1 addition & 1 deletion dist/registries.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "gacm",
"version": "0.0.4",
"version": "0.0.5",
"description": "gacm",
"scripts": {
"build": "gulp --require sucrase/register/ts --gulpfile build/gulpfile.ts",
"clear": "rimraf dist",
"link": "npm link",
"push": "git push gitee dev && git push github dev",
"update:version": "sucrase-node build/utils/version.ts",
"log": "conventional-changelog -p custom-config -i CHANGELOG.md -s -n ./changelog-option.js"
"log": "conventional-changelog -p custom-config -i CHANGELOG.md -s -n ./changelog-option.js",
"prepare": "husky install"
},
"bin": {
"gacm": "./dist/main.js"
Expand All @@ -29,8 +30,6 @@
"@rollup/plugin-typescript": "^8.3.1",
"@types/fs-extra": "^9.0.13",
"@types/gulp": "^4.0.9",
"@types/inquirer": "^8.2.0",
"@types/inquirer-autocomplete-prompt": "^1.3.3",
"@types/node": "^17.0.21",
"commitizen": "^4.1.2",
"compare-func": "^2.0.0",
Expand All @@ -39,8 +38,8 @@
"cz-conventional-changelog": "^3.2.0",
"fs-extra": "^10.1.0",
"gulp": "^4.0.2",
"husky": "^4.2.5",
"lint-staged": "^10.3.0",
"husky": "^8.0.1",
"lint-staged": "^10.5.4",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"rollup": "^2.70.1",
Expand All @@ -50,11 +49,10 @@
"typescript": "^4.6.3"
},
"dependencies": {
"chalk": "4.1.2",
"commander": "^9.1.0",
"figlet": "^1.5.2",
"inquirer": "^8.2.1",
"ora": "^5.1.0"
"commander": "^2.4.2",
"execa": "5.0.1",
"kolorist": "^1.5.1",
"minimist": "^1.2.6"
},
"config": {
"commitizen": {
Expand Down
7 changes: 1 addition & 6 deletions package/commands/baseAction/version.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { promisify } from 'util';
import pkg from '../../package.json';
import { log } from '../../utils/log';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const figlet = promisify(require('figlet'));

export const version = async () => {
const info = await figlet(`${pkg.name}`);
log.success(`${info} ${pkg.version}`);
log.success(`${pkg.version}`);
};
14 changes: 12 additions & 2 deletions package/commands/useAction/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-console */
import { resolve } from 'path';
import { green } from 'kolorist';
import { outputPath, registriesPath } from '../../config/path';
import { getFileUser, writeFileUser } from '../../utils/getUserList';
import { run } from '../../utils/shell';
import { execCommand, run } from '../../utils/shell';
import { geneDashLine, printMessages } from '../../utils/tools';
import { log } from '../../utils/log';
import type { AddCmd, UseCmd, UserInfoJson } from '../../type/shell.type';
Expand All @@ -27,10 +28,19 @@ export const lsAction = async () => {
const keys = Object.keys(userList);
const length = Math.max(...keys.map((key) => key.length)) + 3;
const prefix = ' ';
const currectUser = await execCommand('git', ['config', 'user.name']);
const messages = keys.map((key) => {
const registry = userList[key];
return prefix + registry.name + geneDashLine(key, length) + registry.email;
const currect = registry.name === currectUser ? `${green('*')}` : '';
return (
prefix +
currect +
registry.name +
geneDashLine(key, length) +
registry.email
);
});

printMessages(messages);
};

Expand Down
52 changes: 25 additions & 27 deletions package/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
{
"name": "gacm",
"version": "0.0.4",
"private": false,
"description": "git account manage",
"keywords": [
"git",
"account",
"manage"
],
"license": "MIT",
"author": "alqmc",
"bin": {
"gacm": "main.js"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"chalk": "4.1.2",
"commander": "^9.1.0",
"figlet": "^1.5.2",
"inquirer": "^8.2.1",
"ora": "^5.1.0",
"shelljs": "^0.8.5"
}
}
{
"name": "gacm",
"version": "0.0.5",
"private": false,
"description": "git account manage",
"keywords": [
"git",
"account",
"manage"
],
"license": "MIT",
"author": "alqmc",
"bin": {
"gacm": "main.js"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"execa": "5.0.1",
"kolorist": "^1.5.1",
"minimist": "^1.2.6",
"prompts": "^2.4.2"
}
}
2 changes: 1 addition & 1 deletion package/registries.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
10 changes: 4 additions & 6 deletions package/utils/log.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-disable no-console */
import chalk from 'chalk';

const { green, red, yellowBright, blueBright } = chalk;
import chalk from 'kolorist';
const { green, red, lightYellow, blue } = chalk;
const success = (msg: string) => console.log(green(msg));
const error = (msg: string) => console.log(red(msg));
const warning = (msg: string) => console.log(yellowBright(msg));
const info = (msg: string) => console.log(blueBright(msg));
const warning = (msg: string) => console.log(lightYellow(msg));
const info = (msg: string) => console.log(blue(msg));
export const log = {
success,
error,
Expand Down
8 changes: 7 additions & 1 deletion package/utils/shell.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawn } from 'child_process';
import { cwd } from 'process';
// run shell
import execa from 'execa';

export const run = (command: string, dir: string = cwd()) => {
const [cmd, ...args] = command.split(' ');
return new Promise<void>((resolve, reject) => {
Expand All @@ -10,6 +11,7 @@ export const run = (command: string, dir: string = cwd()) => {
shell: process.platform === 'win32',
});
const processExit = () => app.kill('SIGHUP');

app.on('close', (code) => {
process.removeListener('exit', processExit);
if (code === 0) resolve();
Expand All @@ -19,3 +21,7 @@ export const run = (command: string, dir: string = cwd()) => {
process.on('exit', processExit);
});
};
export const execCommand = async (cmd: string, args: string[]) => {
const res = await execa(cmd, args);
return res.stdout.trim();
};
Loading

0 comments on commit 41adefa

Please sign in to comment.