Skip to content

Commit

Permalink
fixes for node v7 and new spike error structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Jan 12, 2017
1 parent 53b6931 commit c85c270
Show file tree
Hide file tree
Showing 4 changed files with 793 additions and 714 deletions.
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const fs = require('fs')
const path = require('path')
const reshape = require('reshape')
const loader = require('reshape-loader')
const bindAll = require('es6bindall')

// this needs to be a function that returns a function
module.exports = class Records {
constructor (opts) {
this.opts = opts
bindAll(this, ['apply'])
}

apply (compiler) {
Expand Down Expand Up @@ -85,11 +87,11 @@ function writeTemplates (compilation, compiler, _data, k) {
const root = compiler.options.context

if (!tpl) { return _data }
if (!tpl.path) { throw 'missing template.path' } // eslint-disable-line
if (!tpl.output) { throw 'missing template.output' } // eslint-disable-line
if (!tpl.path) { throw new Error('missing template.path') }
if (!tpl.output) { throw new Error('missing template.output') }

const data = tpl.transform ? tpl.transform(_data) : _data
if (!Array.isArray(data)) { throw 'template data is not an array' } // eslint-disable-line
if (!Array.isArray(data)) { throw new Error('template data is not an array') }

return node.call(fs.readFile.bind(fs), path.join(root, tpl.path), 'utf8')
.then((template) => {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"bugs": "https://github.com/static-dev/spike-records/issues",
"dependencies": {
"es6bindall": "^0.0.9",
"reshape": "^0.3.0",
"reshape-loader": "^0.3.0",
"rest": "^2.0.0",
Expand All @@ -20,7 +21,7 @@
"nyc": "^10.0.0",
"posthtml-exp": "^0.9.0",
"rimraf": "^2.5.4",
"spike-core": "^0.12.0",
"spike-core": "^0.13.1",
"spike-html-standards": "^0.3.0",
"standard": "^8.0.0"
},
Expand Down
14 changes: 7 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test.cb('single template errors with no "path" param', (t) => {
project.on('warning', t.end)
project.on('compile', t.end)
project.on('error', (err) => {
t.is(err.message, 'missing template.path')
t.is(err.toString(), 'Error: missing template.path')
t.end()
})

Expand All @@ -109,7 +109,7 @@ test.cb('single template errors with no "output" param', (t) => {
project.on('warning', t.end)
project.on('compile', t.end)
project.on('error', (err) => {
t.is(err.message, 'missing template.output')
t.is(err.toString(), 'Error: missing template.output')
t.end()
})

Expand All @@ -122,15 +122,15 @@ test.cb('single template errors with non-array data', (t) => {
addDataTo: locals,
posts: {
data: 'foo',
template: { path: 'template.sml', output: () => { return 'wow.html' } }
template: { path: 'template.sgr', output: () => { return 'wow.html' } }
},
locals
})

project.on('warning', t.end)
project.on('compile', t.end)
project.on('error', (err) => {
t.is(err.message, 'template data is not an array')
t.is(err.toString(), 'Error: template data is not an array')
t.end()
})

Expand Down Expand Up @@ -202,13 +202,13 @@ function configProject (fixturePath, recordsConfig, locals) {
const projectPath = path.join(fixturesPath, fixturePath)
const project = new Spike({
root: projectPath,
entry: { main: [path.join(projectPath, 'app.js')] },
entry: { main: path.join(projectPath, 'app.js') },
matchers: { html: '*(**/)*.sgr' },
reshape: (ctx) => htmlStandards({ webpack: ctx, locals }),
ignore: ['template.sml'],
ignore: ['template.sgr'],
plugins: [new Records(recordsConfig)]
})
return { projectPath: projectPath, project: project }
return { projectPath, project }
}

function compileProject (project, t, cb) {
Expand Down
Loading

0 comments on commit c85c270

Please sign in to comment.