Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xsduan committed Nov 25, 2018
2 parents 7be8d39 + b401460 commit bec71a7
Show file tree
Hide file tree
Showing 24 changed files with 1,802 additions and 4,509 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ jspm_packages/
config/default.yaml
*.sqlite

# autorun
autorun.sh

.vscode

# default "compiled" directories
dist
data
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,28 @@ it does various cool language things. currently:

- run `npm install` (`npm install --production` or `npm ci --only=production`
if you're not planning on doing any code changes)
- run `npm start` (or `npm run forever` if you want to run it in the background)
- run `npm start` (or `npm run forever` for production; see [pm2 docs] for
further configuration options)
- due to the fact `npx` prefers system commands, if you want to add config to
the process (eg log rotation) you should install pm2 globally beforehand.
how convenient for you!
- pray to whatever god that it doesn't nuke your computer

#### build script opts

```
usage: node build [-hsfn] [--no-install]
conniebot build script.
-h, --help print out this message and quit.
-s, --start watch files for development using nodemon.
-f, --forever run conniebot in production using pm2 (open source version).
-n, --name process name if running in forever mode. (default: conniebot)
--no-install pass `--no-install` to npx, so you don't waste time installing
nodemon or pm2.
```

### have a comment?

join me on discord: https://discord.gg/MvWMH3z
Expand All @@ -39,3 +58,4 @@ join me on discord: https://discord.gg/MvWMH3z
[oauth]: https://discordapp.com/developers/tools/oauth2-url-generator
[node]: https://nodejs.org/
[example config]: ./config/default-example.yaml
[pm2 docs]: https://pm2.io/doc/
75 changes: 75 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const spawn = require('child_process').spawn
const argv = require('minimist')(process.argv)
const c = require('config')

const { data, dist } = {
data: 'data',
dist: 'dist',
...c.get('dirs')
}

function run(command) {
console.log('>>', command)
const [file, ...args] = command.split(' ')
return new Promise((y, n) => {
let proc = spawn(file, args)
proc.stdout.on('data', b => process.stdout.write(`${b}`))
proc.stderr.on('data', b => process.stderr.write(`${b}`))
proc.on('close', code => code !== 0
? n(new Error(`Command ended with code ${code}`))
: y()
)
})
}

async function build() {
for (const command of [
`npx tsc --outDir ${dist}`,
`mkdir -pv ${data}`,
`cp -aRv x2i-data/ ${data}/${c.get('x2i')}/`,
]) {
await run(command)
}
}

function fmtNoInstall(str, noInstall) {
return str + (noInstall ? ' --no-install': '')
}

async function start() {
const start = argv.s || argv.start
const forever = argv.f || argv.forever
const noInstall = argv['no-install']

if (start && forever) {
throw new Error('Simultaneous start and forever. Pick one!!')
} else if (!start && !forever) {
return
} else if (start) {
return run(fmtNoInstall(
`npx nodemon --watch ${dist} --watch ${data} -x node ${dist}`, noInstall))
} else if (forever) {
const name = argv.n || argv.name || 'conniebot'
return run(fmtNoInstall(`npx pm2 start ${dist} -n ${name}`, noInstall))
}
}

(async () => {
if (argv.h || argv.help) {
return console.log(`
usage: node build [-hsfn] [--no-install]
conniebot build script.
-h, --help print out this message and quit.
-s, --start watch files for development using nodemon.
-f, --forever run conniebot in production using pm2 (open source version).
-n, --name process name if running in forever mode. (default: conniebot)
--no-install pass \`--no-install\` to npx, so you don't waste time installing
nodemon or pm2.
`.trim())
}

await build()
await start()
})()
22 changes: 13 additions & 9 deletions config/default-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ token: 000000000000000000000000.000000.000000000000000000000000000
activeMessage: x/help for info
prefix: x/

# relative to the cwd() of running process, which should usually be the top
# level of this repository.
dirs:
data: data
dist: dist

# owner id, only responds to admin commands if author is this person.
owner: '207600419659186176'
database: ./db.sqlite
database: db.sqlite

# which directory to keep x2i keys (sub dirs.data)
x2i: x2i

logColors:
info: 'green'
data: 'grey'
help: 'cyan'
warn: 'yellow'
debug: 'blue'
error: 'red'
# logging level; see npmlog.level
level: info

# embed options (ie the fancy posts only bots can do)
# they mess with e-readers and logging apparently so you might want to turn it =
# they mess with e-readers and logging apparently so you might want to turn it
# off if that's a thing you need to worry about
# (they look so pretty though…)
embeds:
Expand Down
18 changes: 0 additions & 18 deletions index.ts

This file was deleted.

Loading

0 comments on commit bec71a7

Please sign in to comment.