Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs')
- const path = require('path')
- // page{location}(content) => posthtml [inline-assets] w/ postcss
- const page = require('./page.js')
- // watch system with deduping and some other fancy stuff
- const dispatch = require('./dispatch')
- const globby = require('globby')
- const cwd = process.cwd()
- let readFile
- let writeFile
- let mkdir
- let source
- let filename
- var Promise = require('bluebird')
- readFile = Promise.promisify(fs.readFile)
- writeFile = Promise.promisify(fs.writeFile)
- mkdir = Promise.promisify(fs.mkdir)
- async function main () {
- let paths
- let files
- let filename
- files = await globby(['public/**/*.html', '!**/script/**'])
- for (filename of files) {
- try {
- await build(filename)
- } catch (e) {}
- }
- }
- async function write (filename, content) {
- let options
- options = {encoding: 'utf8'}
- try {
- await mkdir(path.dirname(filename))
- } catch (e) {}
- await writeFile(filename, content, options)
- }
- async function build (it) {
- let $it
- let input
- let output
- let compile
- let that
- $it = it.replace(/^public/, 'page')
- input = path.resolve(cwd, it)
- output = path.resolve(cwd, $it)
- compile = page.bind({location: input})
- process.stdout.write(`${it} `)
- that = await read(input)
- process.stdout.write('=> ')
- try {
- that = await compile(that)
- }
- catch (error) {
- console.log(`[${error.constructor.name}] ${error.message}`)
- return
- }
- finally {}
- try {
- await mkdir(path.dirname(output))
- }
- catch (error) {}
- finally {}
- try {
- await writeFile(output, that)
- process.stdout.write($it)
- }
- catch (error) {}
- finally {
- console.log('')
- }
- }
- process.nextTick(main)
- async function read (filename) {
- let options
- options = {encoding: 'utf8'}
- return await readFile(filename, options)
- }
Add Comment
Please, Sign In to add comment