awesome-ipfs/scripts/dev.js

72 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-04-23 10:22:21 -04:00
const chokidar = require('chokidar')
const path = require('path')
const runAll = require('npm-run-all')
const dataFolder = path.join(__dirname, '../data')
const srcFolder = path.join(__dirname, '../src')
const cssPath = path.join(__dirname, '../src/css')
const jsPath = path.join(__dirname, '../src/js')
const http = require('http')
2018-07-18 02:38:29 -04:00
const options = {
stdout: process.stdout,
stderr: process.stderr
}
2018-07-17 09:55:34 -04:00
const runHugo = () => {
2018-07-18 02:38:29 -04:00
return runAll(['build:hugo'], options).catch(() => {})
2018-07-17 09:55:34 -04:00
}
2018-04-23 10:22:21 -04:00
const handler = (path) => {
if (path.startsWith(dataFolder)) {
2018-07-18 02:38:29 -04:00
runAll(['build:data'], options).then(runHugo)
2018-04-23 10:22:21 -04:00
} else if (path.startsWith(cssPath)) {
2018-07-18 02:38:29 -04:00
runAll(['build:css'], options).then(runHugo)
2018-04-23 10:22:21 -04:00
} else if (path.startsWith(jsPath)) {
2018-07-18 02:38:29 -04:00
runAll(['build:js'], options).then(runHugo)
2018-04-23 10:22:21 -04:00
} else {
runHugo()
}
}
async function run () {
console.log('Preparing fonts, css, js and data...')
2018-07-18 02:38:29 -04:00
await runAll(['build:fonts', 'build:css', 'build:js', 'build:icons', 'build:data'], {
stdout: process.stdout,
stderr: process.stderr,
parallel: true
})
2018-04-23 10:22:21 -04:00
await runHugo()
console.log('Starting server...')
const ecstatic = require('ecstatic')({
root: `${__dirname}/../public`,
showDir: true,
autoIndex: true
})
http.createServer(ecstatic).listen(8080)
const watcher = chokidar.watch([dataFolder, srcFolder], {
ignored: (string) => string.indexOf('src/content') !== -1 ||
string.indexOf('src/data') !== -1 ||
string.indexOf('src/resources') !== -1 ||
string.indexOf('src/layouts/partials/indexes') !== -1 ||
string.indexOf('src/static/fonts') !== -1 ||
string.indexOf('src/static/app.css') !== -1 ||
string.indexOf('src/static/app.js') !== -1,
persistent: true,
ignoreInitial: true,
awaitWriteFinish: true
})
watcher
2018-07-17 09:34:47 -04:00
.on('ready', () => console.log('Listening on :8080'))
2018-04-23 10:22:21 -04:00
.on('add', handler)
.on('change', handler)
.on('unlink', handler)
}
run()