forked from bluelinklabs/ctzn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.js
132 lines (128 loc) · 3.61 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env node
import subcommand from 'subcommand'
import * as db from './db/index.js'
import * as path from 'path'
import { fileURLToPath } from 'url'
import * as fs from 'fs'
import * as tui from './tui/index.js'
const PACKAGE_JSON_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), 'package.json')
import { start } from './index.js'
const match = subcommand({
commands: [
{
name: 'start',
command: args => {
start({
port: args.port,
domain: args.domain,
configDir: args.configDir,
hyperspaceHost: args.hyperspaceHost,
hyperspaceStorage: args.hyperspaceStorage
})
}
},
{
name: 'start-test',
command: args => {
if (!args.configDir) throw new Error('--configDir required')
if (!args.domain) throw new Error('--domain required')
start({
debugMode: true,
simulateHyperspace: true,
port: args.port,
configDir: args.configDir,
domain: args.domain
})
}
},
{
name: 'create-user',
command: async args => {
// TODO- this needs to work without starting the server
await start({
debugMode: true,
port: 3000,
domain: args.domain,
configDir: args.configDir,
hyperspaceHost: args.hyperspaceHost,
hyperspaceStorage: args.hyperspaceStorage
})
await db.createUser({
type: 'citizen',
username: args.username,
email: args.email,
password: args.password,
profile: {
displayName: args.displayName,
description: args.description
}
})
console.log(args.username, 'created')
process.exit(0)
}
},
{
name: 'create-test-users',
command: async args => {
// TODO- this needs to work without starting the server
await start({
debugMode: true,
port: 3000,
domain: args.domain,
configDir: args.configDir,
hyperspaceHost: args.hyperspaceHost,
hyperspaceStorage: args.hyperspaceStorage
})
for (let username of ['alice', 'bob', 'carla', 'dan', 'erica', 'finn']) {
await db.createUser({
type: 'citizen',
username: username,
email: `${username}@email.com`,
password: 'password',
profile: {
displayName: username.slice(0, 1).toUpperCase() + username.slice(1)
}
})
console.log(username, 'created')
}
process.exit(0)
}
},
{
name: 'create-community',
command: async args => {
// TODO- this needs to work without starting the server
await start({
debugMode: true,
port: 3000,
domain: args.domain,
configDir: args.configDir,
hyperspaceHost: args.hyperspaceHost,
hyperspaceStorage: args.hyperspaceStorage
})
await db.createUser({
type: 'community',
username: args.username,
profile: {
displayName: args.displayName,
description: args.description
}
})
console.log(args.username, 'created')
process.exit(0)
}
}
],
root: {
command: (args) => {
const packageJson = fs.readFileSync(PACKAGE_JSON_PATH, 'utf8')
const pkg = JSON.parse(packageJson)
if (args.v || args.version) {
console.log('CTZN', pkg.version)
} else {
tui.start({pkg})
}
}
}
})
const cmd = match(process.argv.slice(2))