Skip to content

Commit

Permalink
Merge pull request #74 from marionebl/fix/ensure-lts-compatibility
Browse files Browse the repository at this point in the history
fix: ensure node 4 compat
  • Loading branch information
marionebl authored Sep 4, 2016
2 parents 30f702b + 94a832d commit ae58fc0
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 28 deletions.
26 changes: 9 additions & 17 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const bankai = require('../')
const path = require('path')
'use strict'

const resolveEntry = require('../lib/resolve-entry')
const browserify = require('browserify')
const resolve = require('resolve')
const xtend = require('xtend')
const fs = require('fs')
const mkdirp = require('mkdirp')
const parallel = require('run-parallel')
const mkdirp = require('mkdirp')
const xtend = require('xtend')
const bankai = require('../')
const path = require('path')
const pump = require('pump')
const fs = require('fs')

module.exports = build

Expand All @@ -19,23 +21,13 @@ const defaults = {
js: {}
}

const cwd = process.cwd()

// resolve a path according to require.resolve algorithm
// string -> string
function resolveEntryFile (relativePath) {
const first = relativePath.charAt(0)
const entry = ['.', '/'].includes(first) ? relativePath : './' + relativePath
return resolve.sync(entry, {basedir: cwd})
}

function build (options, cb) {
const assets = bankai({ optimize: true })

const settings = xtend({}, defaults, options)
const callback = cb || function () {}

const entryFile = resolveEntryFile(settings.entry)
const entryFile = resolveEntry(settings.entry)
const outputDir = settings.dir

// Register css & html if specified. Register js no matter what
Expand Down
14 changes: 4 additions & 10 deletions bin/start.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

const resolveEntry = require('../lib/resolve-entry')
const stringToStream = require('string-to-stream')
const getServerPort = require('get-server-port')
const serverRouter = require('server-router')
const browserify = require('browserify')
const resolve = require('resolve')
const xtend = require('xtend')
const http = require('http')
const path = require('path')
Expand Down Expand Up @@ -32,7 +34,7 @@ function start (options, cb) {
const opts = xtend({}, defaults, options)
const callback = cb || function () {}

const entryFile = resolveEntryFile(opts.entry)
const entryFile = resolveEntry(opts.entry)
const relativeEntry = path.relative(cwd, entryFile)

const routes = []
Expand Down Expand Up @@ -86,11 +88,3 @@ function start (options, cb) {
callback()
})
}

// resolve a path according to require.resolve algorithm
// string -> string
function resolveEntryFile (relativePath) {
const first = relativePath.charAt(0)
const entry = ['.', '/'].includes(first) ? relativePath : './' + relativePath
return resolve.sync(entry, {basedir: cwd})
}
2 changes: 2 additions & 0 deletions handler-css.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const assert = require('assert')
const stream = require('readable-stream')

Expand Down
2 changes: 2 additions & 0 deletions handler-html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const createHtml = require('create-html')
const xtend = require('xtend')
const stringToStream = require('string-to-stream')
Expand Down
2 changes: 2 additions & 0 deletions handler-js.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const assert = require('assert')
const bl = require('bl')
const cssExtract = require('css-extract')
Expand Down
13 changes: 13 additions & 0 deletions lib/resolve-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const resolve = require('resolve')
const cwd = process.cwd()

module.exports = resolveEntry

// resolve a path according to require.resolve algorithm
// string -> string
function resolveEntry (id) {
const entry = ['.', '/'].indexOf(id.charAt(0)) > -1 ? id : './' + id
return resolve.sync(entry, {basedir: cwd})
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@
"dependency-check": "^2.6.0",
"is-html": "^1.0.0",
"istanbul": "^0.4.4",
"openport": "0.0.4",
"standard": "^8.0.0",
"tape": "^4.6.0"
},
"files": [
"index.js",
"bin/*",
"lib/*",
"client-hmr.js",
"handler-*"
]
Expand Down
47 changes: 46 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict'

const childProcess = require('child_process')
const getPort = require('get-server-port')
const browserify = require('browserify')
const concat = require('concat-stream')
const openport = require('openport')
const isHtml = require('is-html')
const bankai = require('../')
const http = require('http')
const path = require('path')
const test = require('tape')
const bankai = require('../')

test('html', function (t) {
t.test('returns data', function (t) {
Expand Down Expand Up @@ -85,6 +89,30 @@ test('js', function (t) {
})
})

test('start', function (t) {
t.test('start does not throw', function (t) {
t.plan(1)

openport.find(function (err, p) {
const port = err ? 1337 : p

const args = ['start', '--entry=./fixture', `--port=${port}`]

bin(args, function (error, data, child) {
child.kill()

if (error) {
return t.fail(error)
}

const actual = data.toString().split('\n')[0]
const expected = `Started bankai for fixture.js on http://localhost:${port}`
t.equal(actual, expected, 'start logs success')
})
})
})
})

test('__END__', function (t) {
t.on('end', function () {
setTimeout(function () {
Expand All @@ -93,3 +121,20 @@ test('__END__', function (t) {
})
t.end()
})

function bin (args, cb) {
const file = path.resolve(__dirname, '../bin/index.js')

const child = childProcess.spawn(file, args, {
cwd: __dirname,
env: process.env
})

child.stdout.once('data', function (data) {
cb(null, data, child)
})

child.stderr.once('data', function (error) {
cb(new Error(error), null, child)
})
}

0 comments on commit ae58fc0

Please sign in to comment.