add changes from v0.3

This commit is contained in:
JJ Kasper
2018-11-24 00:23:32 -06:00
parent 73f05ce4a3
commit 111cf2ed35
133 changed files with 10768 additions and 7443 deletions

35
bin/genSecret.js Executable file
View File

@@ -0,0 +1,35 @@
#! /usr/bin/env node
const path = require('path')
const crypto = require('crypto')
const DB = require('../src/server/util/db')
const isDev = process.env.NODE_ENV !== 'production'
const configFile = (isDev ? 'default' : 'production') + '.json'
const configPath = path.join(__dirname, '../config', configFile)
const config = new DB(configPath)
config.loading
.then(() => {
const { secret } = config.data
if (!isDev && secret && !process.argv.some(arg => arg === '-f')) {
return console.log(
'Secret already exists, not updating. Use -f to force update'
)
}
config
.setData({
...config.data,
secret: crypto.randomBytes(256).toString('hex'),
})
.then(() => {
console.log(
`Authentication secret successfully updated in ${configPath}`
)
})
.catch(err => console.error(err))
})
.catch(err => {
console.error(err)
})

29
bin/genServiceWorker.js Normal file
View File

@@ -0,0 +1,29 @@
const path = require('path')
const fs = require('fs-extra')
const terser = require('terser')
const swPrecache = require('sw-precache')
const outputPath = path.resolve('public/sw.js')
async function main() {
let sw = await fs.readFile(path.resolve('src/client/util/offlineFallback.js'))
sw = sw.toString()
sw += await swPrecache.generate({
cacheId: 'mykb-cache',
stripPrefixMulti: {
[path.resolve('public/')]: '',
[path.resolve('.next/static/')]: '/_next/static',
},
staticFileGlobs: ['public/!(sw.js)', '.next/static/**/*'].map(p =>
path.resolve(p)
),
})
const precacheRegex = /var precacheConfig.*]];/
const precacheConfig = sw.match(precacheRegex)
sw = sw.replace(precacheRegex, '')
sw = precacheConfig[0] + sw
sw = terser.minify(sw).code
await fs.outputFile(outputPath, sw)
}
main()