Skip to content

Commit 9108ba7

Browse files
alqmcalqmc
authored andcommitted
feat: 别名与名称统一,所有操作基于别名
1 parent 5f694ca commit 9108ba7

File tree

11 files changed

+144
-231
lines changed

11 files changed

+144
-231
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: '🐛 Bug report'
2-
description: Create a report to help us improve vue-simple-json
2+
description: Create a report to help us improve gacm
33
title: '[Bug]: '
44
labels: ['bug']
55
body:
@@ -8,19 +8,12 @@ body:
88
value: |
99
Please fill out the following carefully in order to better fix the problem.
1010
- type: input
11-
id: vue-simple-json-version
11+
id: gacm-version
1212
attributes:
1313
label: Version
1414
description: |
1515
### **Check if the issue is reproducible with the latest stable version.**
16-
You can use the command `npm ls vue-simple-json` to view it
17-
placeholder: latest
18-
validations:
19-
required: true
20-
- type: input
21-
id: vue-version
22-
attributes:
23-
label: Vue Version
16+
You can use the command `npm ls gacm` to view it
2417
placeholder: latest
2518
validations:
2619
required: true

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ gacm use xxx ---local
5353

5454
gacm use xxx ---global
5555

56-
gacm add --name xxx --email xxx
56+
gacm add --name xxx --email xxx --alias xxx
57+
58+
gacm alias xxxx xxxx
5759

5860
gacm delate user
5961

dist/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<a href="https://npmcharts.com/compare/gacm?minimal=true">
1313
<img src="https://img.shields.io/npm/l/gacm.svg?color=blue">
1414
</a>
15-
<a href="https://github.com/alqmc/gacm" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/alqmc/mangosteen?style=social">
15+
<a href="https://github.com/alqmc/gacm" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/alqmc/gacm?style=social">
1616

1717
</a>
1818
<br>
@@ -53,7 +53,9 @@ gacm use xxx ---local
5353

5454
gacm use xxx ---global
5555

56-
gacm add --name xxx --email xxx
56+
gacm add --name xxx --email xxx --alias xxx
57+
58+
gacm alias xxxx xxxx
5759

5860
gacm delate user
5961

dist/main.js

Lines changed: 51 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
1414
var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
1515

1616
var name = "gacm";
17-
var version$1 = "1.1.0";
17+
var version$1 = "1.1.1";
1818
var description = "git account manage";
1919
var keywords = [
2020
"git",
@@ -48,10 +48,19 @@ var pkg = {
4848
dependencies: dependencies
4949
};
5050

51-
const success = (msg) => console.log(kolorist.green(msg));
52-
const error = (msg) => console.log(kolorist.red(msg));
53-
const warning = (msg) => console.log(kolorist.lightYellow(msg));
54-
const info = (msg) => console.log(kolorist.blue(msg));
51+
const PREFIX = "gacm";
52+
const success = (msg) => console.log(`
53+
${kolorist.bgLightGreen(PREFIX)}:${kolorist.green(msg)}
54+
`);
55+
const error = (msg) => console.log(`
56+
${kolorist.bgLightRed(PREFIX)}:${kolorist.red(msg)}
57+
`);
58+
const warning = (msg) => console.log(`
59+
${kolorist.bgLightYellow(PREFIX)}:${kolorist.lightYellow(msg)}
60+
`);
61+
const info = (msg) => console.log(`
62+
${kolorist.bgLightBlue(PREFIX)}:${kolorist.blue(msg)}
63+
`);
5564
const log = {
5665
success,
5766
error,
@@ -137,9 +146,9 @@ const useAction = async (name, cmd) => {
137146
return log.error(`${name} not found`);
138147
if (!userList.version)
139148
userList = transformData(userList);
140-
if (userList.users.every((x) => x.name !== name && x.alias !== name))
149+
if (userList.users.every((x) => x.alias !== name))
141150
return log.error(`${name} not found`);
142-
const useUser = userList.users.filter((x) => x.alias === name || x.name === name);
151+
const useUser = userList.users.filter((x) => x.alias === name);
143152
let env = "local";
144153
if (cmd.system)
145154
env = "system";
@@ -149,9 +158,7 @@ const useAction = async (name, cmd) => {
149158
env = "local";
150159
await run(`git config --${env} user.name ${useUser[0].name}`);
151160
await run(`git config --${env} user.email ${useUser[0].email}`);
152-
log.success(`
153-
git user changed [${env}]:${useUser[0].alias && `(${useUser[0].alias})`}${useUser[0].name}
154-
`);
161+
log.success(`git user changed [${env}]:${useUser[0].alias !== useUser[0].name ? `(${useUser[0].name})` : ""}${useUser[0].alias}`);
155162
};
156163
const lsAction = async () => {
157164
let userList = await getFileUser(registriesPath) || {};
@@ -168,14 +175,15 @@ const lsAction = async () => {
168175
userList.users.push({
169176
name: currectUser,
170177
email: currectEmail,
171-
alias: ""
178+
alias: currectUser
172179
});
173180
}
174-
const length = Math.max(...userList.users.map((user) => user.name.length + (user.alias ? user.alias.length : 0))) + 3;
181+
const length = Math.max(...userList.users.map((user) => user.alias.length + (user.alias !== user.name ? user.name.length : 0))) + 3;
175182
const prefix = " ";
176183
const messages = userList.users.map((user) => {
177184
const currect = user.name === currectUser && user.email === currectEmail ? `${kolorist.green("*")}` : "";
178-
return `${prefix + currect + user.name}${user.alias && `(${user.alias})`}${geneDashLine(user.name, length)}${user.email}`;
185+
const isSame = user.alias === user.name;
186+
return `${prefix + currect}${isSame ? user.alias : `${user.alias}(${kolorist.gray(user.name)})`}${geneDashLine(user.name, length)}${user.email}`;
179187
});
180188
printMessages(messages);
181189
};
@@ -184,31 +192,24 @@ const addAction = async (cmd) => {
184192
await insertUser(cmd.name, cmd.email, cmd.alias);
185193
}
186194
};
187-
const deleteAction = async (name, { alias }) => {
195+
const deleteAction = async (name) => {
188196
let userList = await getFileUser(registriesPath);
189197
if (!userList)
190198
return log.error(`no user`);
191199
if (!userList.version)
192200
userList = transformData(userList);
193-
const useUser = userList.users.filter((x) => x.name === name || alias && x.alias === name);
201+
const useUser = userList.users.filter((x) => x.alias === name || !x.alias && x.name === name);
194202
if (useUser.length === 0)
195203
return log.error(`${name} not found`);
196204
for (let i = 0; i < userList.users.length; i++) {
197-
if (alias && userList.users[i].alias === name) {
198-
log.success(`[delete]: ${userList.users[i].alias && `(${userList.users[i].alias})`}${userList.users[i].name}`);
205+
if (!userList.users[i].alias && userList.users[i].name === name || userList.users[i].alias === name) {
206+
log.success(`[delete]: ${userList.users[i].alias !== userList.users[i].name ? `(${userList.users[i].name})` : ""}${userList.users[i].alias}`);
199207
userList.users.splice(i, 1);
200-
} else if (userList.users[i].name === name) {
201-
if (!userList.users[i].alias) {
202-
log.success(`[delete]: ${userList.users[i].alias && `(${userList.users[i].alias})`}${userList.users[i].name}`);
203-
userList.users.splice(i, 1);
204-
} else {
205-
log.error(`${name} has alias, please use gacm delete <alias> -a to delete`);
206-
}
207208
}
208209
}
209210
await writeFileUser(registriesPath, userList);
210211
};
211-
const aliasAction = async (origin, target, { alias }) => {
212+
const aliasAction = async (origin, target) => {
212213
if (!origin || !target)
213214
return;
214215
let userList = await getFileUser(registriesPath);
@@ -218,73 +219,43 @@ const aliasAction = async (origin, target, { alias }) => {
218219
userList = transformData(userList);
219220
let changed = false;
220221
userList.users.forEach((x) => {
221-
if (alias) {
222-
if (x.alias === origin) {
223-
if (userList && !isExistAlias(userList.users, target)) {
224-
x.alias = target;
225-
log.success(`[update]:(${origin}=>${x.alias}) ${x.name}`);
226-
} else {
227-
log.error(`${target} is Exist, please enter another one `);
228-
}
229-
changed = true;
230-
}
231-
} else {
232-
if (x.name === origin) {
233-
if (!x.alias) {
234-
if (userList && !isExistAlias(userList.users, target)) {
235-
x.alias = target;
236-
log.success(`[update]:(${origin}=>${x.alias}) ${x.name}`);
237-
} else {
238-
log.error(`${target} is Exist, please enter another one `);
239-
}
240-
} else {
241-
log.error(`${x.name} has alias, please use gacm alias <alias> <target> -a to alias`);
242-
}
243-
changed = true;
222+
if (x.alias === origin) {
223+
if (userList && !isExistAlias(userList?.users, target)) {
224+
x.alias = target;
225+
log.success(`[update]:(${x.name}) ${origin}=>${x.alias}`);
226+
} else {
227+
log.error(`${target} is exist, please enter another one `);
244228
}
229+
changed = true;
245230
}
246231
});
247232
if (!changed)
248233
return log.error(`${origin} not found`);
249234
await writeFileUser(registriesPath, userList);
250235
};
251-
const insertUser = async (name, email, alias = "") => {
236+
const insertUser = async (name, email, alias = name) => {
252237
let userList = await getFileUser(registriesPath);
253238
if (!userList)
254239
userList = { version: version$1, users: [] };
255240
if (!userList.version)
256241
userList = transformData(userList);
257-
if (isExist(userList.users, name, email, alias)) {
242+
if (isExistAlias(userList.users, alias, name, email)) {
258243
userList.users.forEach((user) => {
259-
if (user.name === name && user.email === email || !alias && !user.alias && user.name === name || alias && user.alias === alias) {
260-
if (userList && !isExistAlias(userList.users, name)) {
261-
user.alias = alias || user.alias;
262-
user.email = email;
263-
user.name = name;
264-
log.success(`[update]:${user.alias && `(${user.alias})`} ${name}`);
265-
} else {
266-
log.error(`${name} is alias, please enter another one `);
267-
}
244+
if (user.alias === alias || !user.alias && user.name === alias || name && email && user.name === name && user.email === email) {
245+
user.alias = alias === name ? user.alias ? user.alias : alias : alias;
246+
user.email = email;
247+
user.name = name;
248+
log.success(`[update]:${user.alias !== name ? `(${user.name})` : ""} ${alias}`);
268249
}
269250
});
270251
} else {
271-
if (userList && !isExistAlias(userList.users, name)) {
272-
userList.users.push({
273-
name,
274-
email,
275-
alias
276-
});
277-
log.success(`[add]:${alias && `(${alias})`} ${name}`);
278-
} else {
279-
log.error(`${name} is alias, please enter another one `);
280-
}
252+
userList.users.push({
253+
name,
254+
email,
255+
alias
256+
});
257+
log.success(`[add]:${alias && `(${alias})`} ${name}`);
281258
}
282-
userList.users.filter((x) => {
283-
return userList && userList.users.filter((y) => x.name === y.name && x.email === y.email).length === 1;
284-
});
285-
userList.users = uniqueFunc(userList.users, (item) => {
286-
return `${item.name + item.email}`;
287-
});
288259
await writeFileUser(registriesPath, userList);
289260
};
290261
const transformData = (data) => {
@@ -293,27 +264,20 @@ const transformData = (data) => {
293264
userInfo.users.push({
294265
name: data[x].name,
295266
email: data[x].email,
296-
alias: ""
267+
alias: data[x].name
297268
});
298269
});
299270
return userInfo;
300271
};
301-
const isExist = (users, name, email, alias) => {
302-
return users.some((x) => x.name === name && x.email === email || !alias && !x.alias && x.name === name || alias && x.alias === alias);
303-
};
304-
const isExistAlias = (users, alias) => {
305-
return users.some((x) => x.alias === alias);
306-
};
307-
const uniqueFunc = (arr, uniId) => {
308-
const res = /* @__PURE__ */ new Map();
309-
return arr.filter((item) => !res.has(uniId(item)) && res.set(uniId(item), 1));
272+
const isExistAlias = (users, alias, name, email) => {
273+
return users.some((x) => x.alias === alias || !x.alias && x.name === alias || name && email && x.name === name && x.email === email);
310274
};
311275

312276
const program = new commander.Command();
313277
program.option("-v, --version", "\u67E5\u770B\u5F53\u524D\u7248\u672C").usage("command <option>").description("\u67E5\u770B\u5F53\u524D\u7248\u672C").action(baseAction);
314278
program.command("ls").description("\u5F53\u524D\u7528\u6237\u5217\u8868").action(lsAction);
315279
program.command("use <name>").option("-l, --local", "\u5F53\u524D\u7528\u6237").option("-g, --global", "\u5168\u5C40\u7528\u6237").option("-s, --system", "\u7CFB\u7EDF\u7528\u6237").description("\u5207\u6362\u7528\u6237").action(useAction);
316280
program.command("add").option("-n, --name <name>", "\u7528\u6237\u540D\u79F0").option("-e, --email <email>", "\u7528\u6237\u90AE\u7BB1").option("-a, --alias <alias>", "\u7528\u6237\u522B\u540D").description("\u6DFB\u52A0\u7528\u6237").action(addAction);
317-
program.command("alias <origin> <target>").option("-a, --alias", "\u662F\u5426\u6709\u522B\u540D").description("\u6DFB\u52A0\u522B\u540D").action(aliasAction);
318-
program.command("delete <name>").option("-a, --alias", "\u6309\u7167\u522B\u540D\u5220\u9664").description("\u5220\u9664\u7528\u6237").action(deleteAction);
281+
program.command("alias <origin> <target>").description("\u6DFB\u52A0\u522B\u540D").action(aliasAction);
282+
program.command("delete <name>").description("\u5220\u9664\u7528\u6237").action(deleteAction);
319283
program.parse(process.argv);

dist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gacm",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"private": false,
55
"description": "git account manage",
66
"keywords": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gacm",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "gacm",
55
"scripts": {
66
"build": "gulp --require sucrase/register/ts --gulpfile build/gulpfile.ts",

0 commit comments

Comments
 (0)