Skip to content

Commit 6c3c446

Browse files
committed
update for spike 1.0+
1 parent 23fd9a0 commit 6c3c446

File tree

7 files changed

+2291
-1068
lines changed

7 files changed

+2291
-1068
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@ This is a standard [webpack](https://webpack.github.io/) plugin, but is built fo
2222
```js
2323
// app.js
2424
const Rooftop = require('spike-rooftop')
25-
const htmlStandards = require('spike-html-standards')
25+
const htmlStandards = require('reshape-standard')
2626
const locals = {}
2727

2828
module.exports = {
2929
plugins: [
3030
new Rooftop({ addDataTo: locals, name: 'xxx', apiToken: 'xxx' })
3131
],
32-
reshape: (ctx) => {
33-
return htmlStandards({
34-
locals: { locals }
35-
})
36-
}
32+
reshape: htmlStandards({ locals: () => locals })
3733
}
3834
```
3935

@@ -134,7 +130,7 @@ new Rooftop({
134130
apiToken: 'xxx',
135131
contentTypes: [{
136132
name: 'posts',
137-
template: : {
133+
template: {
138134
path: 'templates/post.html',
139135
output: (post) => { return `posts/${post.slug}.html` }
140136
}

lib/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const path = require('path')
66
const node = require('when/node')
77
const reshape = require('reshape')
88
const loader = require('reshape-loader')
9+
const SpikeUtil = require('spike-util')
910

1011
class Rooftop {
1112
constructor (opts) {
@@ -15,6 +16,7 @@ class Rooftop {
1516
}
1617

1718
apply (compiler) {
19+
this.util = new SpikeUtil(compiler.options)
1820
compiler.plugin('run', this.run.bind(this, compiler))
1921
compiler.plugin('watch-run', this.run.bind(this, compiler))
2022
compiler.plugin('emit', (compilation, done) => {
@@ -31,7 +33,7 @@ class Rooftop {
3133
})
3234

3335
W.map(templateContent, (ct) => {
34-
return writeTemplate(ct, compiler, compilation, this.addDataTo, done)
36+
return writeTemplate.call(this, ct, compiler, compilation, this.addDataTo, done)
3537
}).done(() => done(), done)
3638
})
3739
}
@@ -155,7 +157,7 @@ function writeTemplate (ct, compiler, compilation, addDataTo, cb) {
155157
// webpack context is used by default in spike for plugins, so we need
156158
// to mock it so that plugins dont crash
157159
const fakeContext = { addDependency: (x) => x, resourcePath: filePath }
158-
const options = loader.parseOptions.call(fakeContext, compiler.options.reshape)
160+
const options = loader.parseOptions.call(fakeContext, this.util.getSpikeOptions().reshape)
159161

160162
// W.map fires events as quickly as possible, so the locals will be
161163
// swapped for the last item unless bound to the result function

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@
99
},
1010
"bugs": "https://github.com/static-dev/spike-rooftop/issues",
1111
"dependencies": {
12-
"joi": "^10.2.0",
12+
"joi": "^10.6.0",
1313
"reshape": "^0.4.0",
14-
"reshape-loader": "^0.4.0",
14+
"reshape-loader": "^1.0.0",
1515
"rooftop-client": "^0.2.1",
16-
"when": "^3.7.7"
16+
"spike-util": "^1.2.0",
17+
"when": "^3.7.8"
1718
},
1819
"devDependencies": {
19-
"ava": "^0.19.0",
20-
"coveralls": "^2.11.15",
20+
"ava": "^0.20.0",
21+
"coveralls": "^2.13.1",
2122
"dotenv": "^4.0.0",
22-
"nyc": "^10.1.2",
23-
"rimraf": "^2.5.2",
24-
"snazzy": "^6.0.0",
25-
"spike-core": "^0.13.3",
23+
"nyc": "^11.0.3",
24+
"rimraf": "^2.6.1",
25+
"snazzy": "^7.0.0",
26+
"spike-core": "^2.0.0",
2627
"spike-html-standards": "^0.3.4",
27-
"standard": "^9.0.0"
28+
"standard": "^10.0.2"
2829
},
2930
"engines": {
3031
"node": ">= 6.0.0"

test/fixtures/default/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const locals = {}
44

55
module.exports = {
66
matchers: { html: '*(**/)*.sgr' },
7-
reshape: (ctx) => htmlStandards({ webpack: ctx, locals }),
7+
reshape: htmlStandards({ locals: () => locals }),
88
plugins: [new Rooftop({
99
url: process.env.url,
1010
apiToken: process.env.token,

test/fixtures/json/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const locals = {}
44

55
module.exports = {
66
matchers: { html: '*(**/)*.sgr' },
7-
reshape: (ctx) => htmlStandards({ webpack: ctx, locals }),
7+
reshape: htmlStandards({ locals: () => locals }),
88
plugins: [new Rooftop({
99
url: process.env.url,
1010
apiToken: process.env.token,

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ test.cb('accepts template object and generates html', (t) => {
194194
const projectPath = path.join(__dirname, 'fixtures/default')
195195
const project = new Spike({
196196
root: projectPath,
197-
reshape: (ctx) => htmlStandards({ webpack: ctx, locals }),
197+
reshape: htmlStandards({ locals: () => locals }),
198198
entry: { main: [path.join(projectPath, 'main.js')] },
199199
plugins: [rooftop]
200200
})
@@ -231,7 +231,7 @@ test.cb('generates error if template has an error', (t) => {
231231
const projectPath = path.join(__dirname, 'fixtures/default')
232232
const project = new Spike({
233233
root: projectPath,
234-
reshape: (ctx) => htmlStandards({ webpack: ctx, locals }),
234+
reshape: htmlStandards({ locals: () => locals }),
235235
entry: { main: [path.join(projectPath, 'main.js')] },
236236
plugins: [rooftop]
237237
})

0 commit comments

Comments
 (0)