This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
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
16 changed files
with
218 additions
and
240 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "cea", | ||
"version": "0.0.1", | ||
"description": "cea", | ||
"main": "lib/src/index.js", | ||
"types": "lib/src/index.d.ts", | ||
"files": [ | ||
"lib/src/**/*.[tj]s" | ||
], | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"cea-core": "^0.1.1", | ||
"enquirer": "^2.3.6" | ||
}, | ||
"devDependencies": {} | ||
} |
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,129 @@ | ||
#!/usr/bin/env node | ||
import { | ||
sstore, | ||
UsersConf, | ||
UserConfOpts, | ||
getSchoolInfos, | ||
loadConfFromToml, | ||
} from 'cea-core' | ||
import { UserAction } from './constants' | ||
import { prompt } from 'enquirer' | ||
;(async () => { | ||
const argv = process.argv[2] || '' | ||
const argv2 = process.argv[3] | ||
|
||
switch (argv) { | ||
case 'user': { | ||
await promptToGetConf() | ||
break | ||
} | ||
case 'rm': { | ||
if (argv2 === 'all') { | ||
sstore.clear() | ||
} else { | ||
sstore.del(argv2) | ||
} | ||
break | ||
} | ||
case 'sign': { | ||
break | ||
} | ||
case 'load': { | ||
loadConfFromToml() | ||
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() | ||
})() | ||
|
||
export async function promptToGetConf(): Promise<void> { | ||
const loadedUsers = sstore.get('users') as UsersConf | ||
|
||
const actionNaire = { | ||
type: 'list', | ||
name: 'actionType', | ||
message: `用户编辑(已有用户:${loadedUsers.reduce((s, e) => { | ||
const userInfo = e.alias | ||
return s + ' ' + userInfo | ||
}, '')})`, | ||
choices: [ | ||
{ | ||
name: UserAction.CREATE, | ||
}, | ||
{ | ||
name: UserAction.DELETE, | ||
}, | ||
{ | ||
name: UserAction.CANCEL, | ||
}, | ||
], | ||
} | ||
const { actionType } = (await prompt([actionNaire])) as { | ||
actionType: UserAction | ||
} | ||
|
||
switch (actionType) { | ||
case UserAction.CREATE: { | ||
const form = { | ||
type: 'form', | ||
name: 'addUser', | ||
message: 'Please provide the following information:', | ||
choices: [ | ||
{ name: 'username', message: '请输入用户名', initial: '1913030099' }, | ||
{ name: 'password', message: '请输入密码', initial: '081312' }, | ||
{ | ||
name: 'alias', | ||
message: '请输入用户别名', | ||
initial: 'foo', | ||
}, | ||
{ | ||
name: 'school', | ||
message: | ||
'学校的英文简称(推荐,仅部分学校支持使用简称)\n请参阅 https://github.com/beetcb/cea/blob/master/docs/abbrList.sh 自行判断\n或中文全称(备用选项,所有学校均支持):', | ||
initial: 'whu', | ||
}, | ||
{ | ||
name: 'addr', | ||
message: | ||
'签到地址数组,留空使用学校地址签到,自定义签到地址:经度, 纬度, 中文地址', | ||
initial: '', | ||
}, | ||
], | ||
} | ||
const { addUser } = (await prompt([form])) as { addUser: UserConfOpts } | ||
sstore.set('users', [...loadedUsers, addUser]) | ||
break | ||
} | ||
case UserAction.DELETE: { | ||
const deleteUserNaire = { | ||
type: 'select', | ||
name: 'deleteUser', | ||
message: '请选择删除用户', | ||
choices: loadedUsers.map((e) => e.alias), | ||
} | ||
const res = (await prompt([deleteUserNaire])) as { deleteUser: string } | ||
sstore.set('users', [ | ||
...loadedUsers.filter((val) => val.alias !== res.deleteUser), | ||
]) | ||
break | ||
} | ||
case UserAction.CANCEL: | ||
return | ||
} | ||
const schools = await getSchoolInfos(sstore.get('users')) | ||
sstore.set('schools', schools!) | ||
} |
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,5 @@ | ||
export enum UserAction { | ||
CREATE = '添加用户', | ||
DELETE = '删除用户', | ||
CANCEL = '取消', | ||
} |
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,6 @@ | ||
{ | ||
"extends": "../tsconfig.base", | ||
"compilerOptions": { | ||
"outDir": "lib/" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.