-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
172 additions
and
137 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
#!/usr/bin/env node | ||
import { | ||
log, | ||
sstore, | ||
UsersConf, | ||
UserConfOpts, | ||
getSchoolInfos, | ||
loadConfFromToml, | ||
} from 'cea-core' | ||
import { checkIn } from 'cea-check-in' | ||
import { prompt } from 'enquirer' | ||
import { UserAction } from './constants' | ||
;(async () => { | ||
const argv = process.argv[2] || '' | ||
const argv2 = process.argv[3] | ||
|
||
switch (argv) { | ||
case 'user': { | ||
const users = await promptToGetConf() | ||
await confSet(users) | ||
break | ||
} | ||
case 'rm': { | ||
if (argv2 === 'all') { | ||
sstore.clear() | ||
} else { | ||
sstore.del(argv2) | ||
} | ||
break | ||
} | ||
case 'sign': { | ||
await checkIn() | ||
break | ||
} | ||
case 'load': { | ||
const users = loadConfFromToml() | ||
await confSet(users) | ||
break | ||
} | ||
|
||
default: { | ||
console.log(` | ||
Usage: cea <command> | ||
All Commands: | ||
user create|delete user | ||
school config your school info | ||
sign campusphere check in | ||
load load config info from conf.toml | ||
rm remove stored config feilds | ||
`) | ||
break | ||
} | ||
} | ||
|
||
sstore.close() | ||
})() | ||
|
||
async function confSet(users: UsersConf | null) { | ||
if (users) { | ||
const schoolInfos = await getSchoolInfos(users) | ||
if (schoolInfos) { | ||
sstore.set('schools', schoolInfos) | ||
} | ||
sstore.set('users', users) | ||
} | ||
} | ||
|
||
async function promptToGetConf(): Promise<UsersConf | null> { | ||
const loadedUsers = (sstore.get('users') as UsersConf) || [] | ||
|
||
const actionNaire = { | ||
type: 'select', | ||
name: 'actionType', | ||
message: `用户编辑(已有用户:${loadedUsers.reduce((s, e) => { | ||
const userInfo = e.alias | ||
return s + ' ' + userInfo | ||
}, '')})`, | ||
choices: [ | ||
{ | ||
name: UserAction.CREATE, | ||
value: UserAction.CREATE, | ||
}, | ||
{ | ||
name: UserAction.DELETE, | ||
value: UserAction.DELETE, | ||
}, | ||
{ | ||
name: UserAction.CANCEL, | ||
value: UserAction.CANCEL, | ||
}, | ||
], | ||
} | ||
const { actionType } = (await prompt([actionNaire]).catch((_) => _)) as { | ||
actionType: UserAction | ||
} | ||
|
||
switch (actionType) { | ||
case UserAction.CREATE: { | ||
const form = { | ||
type: 'form', | ||
name: 'addUser', | ||
message: '请填写如下信息:', | ||
choices: [ | ||
{ name: 'username', message: '用户名', initial: '1913030099' }, | ||
{ name: 'password', message: '密码', initial: '081312' }, | ||
{ | ||
name: 'alias', | ||
message: '用户别名', | ||
initial: 'foo', | ||
}, | ||
{ | ||
name: 'school', | ||
message: '学校简称', | ||
initial: 'whu', | ||
}, | ||
], | ||
} | ||
const { addUser } = (await prompt([form]).catch((_) => _)) as { | ||
addUser: UserConfOpts | ||
} | ||
|
||
const list = { | ||
type: 'list', | ||
name: 'addr', | ||
message: '签到地址', | ||
initial: [''], | ||
} | ||
const { addr } = (await prompt([list]).catch((_) => _)) as { | ||
addr: Array<string> | ||
} | ||
addUser.addr = addr | ||
if (!loadedUsers.some((e) => e.alias === addUser.alias)) { | ||
log.success({ message: '成功加载用户', suffix: `@${addUser.alias}` }) | ||
return Array.from(new Set([...loadedUsers, addUser])) | ||
} else { | ||
log.error({ message: '用户已存在' }) | ||
return null | ||
} | ||
} | ||
case UserAction.DELETE: { | ||
if (loadedUsers.length === 0) { | ||
log.error({ message: '无用户可删除' }) | ||
return null | ||
} | ||
const deleteUserNaire = { | ||
type: 'select', | ||
name: 'deleteUser', | ||
message: '请选择删除用户', | ||
choices: loadedUsers.map((e) => e.alias), | ||
} | ||
const res = (await prompt([deleteUserNaire]).catch((_) => _)) as { | ||
deleteUser: string | ||
} | ||
return [...loadedUsers.filter((val) => val.alias !== res.deleteUser)] | ||
} | ||
default: | ||
return null | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"packages": ["core", "cea", "plugins/*"], | ||
"packages": ["core", "internal", "plugins/*"], | ||
"version": "independent" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
}, | ||
{ | ||
"path": "./core/" | ||
} | ||
}, | ||
{ "path": "./internal" } | ||
] | ||
} |