static-dev / spike-records Goto Github PK
View Code? Open in Web Editor NEW:dvd: Spike plugin to load async locals into your views
License: Other
:dvd: Spike plugin to load async locals into your views
License: Other
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.travis.yml
package.json
files, so that was left aloneIf you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didn’t already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
Branch | Build failing 🚨 |
---|---|
Dependency | coveralls |
Current Version | 2.13.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As coveralls is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
The new version differs by 1 commits0.
b9032a1
better Jenkins detection
false
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Branch | Build failing 🚨 |
---|---|
Dependency | nyc |
Current Version | 10.2.2 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As nyc is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
The new version differs by 4 commits ahead by 4, behind by 2.
55e826d
chore(release): 10.3.0
89dc7a6
chore: explicit update of istanbul dependnecies (#562)
1887d1c
feat: add support for --no-clean, to disable deleting raw coverage output (#558)
ff73b18
fix: source-maps were not being cached in the parent process when --all was being used (#556)
false
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
const path = require('path')
const HardSourcePlugin = require('hard-source-webpack-plugin')
const htmlStandards = require('reshape-standard')
const cssStandards = require('spike-css-standards')
const jsStandards = require('babel-preset-latest')
const pageId = require('spike-page-id')
const Records = require('spike-records')
const locals = {}
module.exports = {
devtool: 'source-map',
matchers: {
html: '*(**/)*.sgr',
css: '*(**/)*.sss'
},
ignore: ['**/layout.sgr', '**/layouts/*', '**/test/*', '**/includes/*', '**/_*', '**/.*', '_cache/**', 'readme.md'],
reshape: (ctx) => {
return htmlStandards({
webpack: ctx,
locals: Object.assign({ pageId: pageId(ctx), foo: 'bar' }, locals)
})
},
/*reshape: (ctx) => htmlStandards({ locals }),*/
postcss: (ctx) => {
return cssStandards({ webpack: ctx })
},
babel: { presets: [jsStandards] },
plugins: [
new HardSourcePlugin({
environmentPaths: { root: __dirname },
recordsPath: path.join(__dirname, '_cache/records.json'),
cacheDirectory: path.join(__dirname, '_cache/hard_source_cache')
}),
new Records({
addDataTo: locals,
staff: {
url: 'http://api.bycarrot.com/staff',
template: {
transform: (data) => { return data.data },
path: 'views/_article_detail.sml',
output: (staff) => { return `post/${staff.id}`}
}
}
})
],
server: { open: false }
}
➜ test-project spike watch
Potentially unhandled rejection [1] TypeError: Cannot read property 'context' of undefined
at pageId (/Users/tomato/Sites/spike-test/test-project/node_modules/spike-page-id/lib/index.js:2:49)
at Object.reshape (/Users/tomato/Sites/spike-test/test-project/app.js:28:39)
at Object.parseOptions (/Users/tomato/Sites/spike-test/test-project/node_modules/reshape-loader/lib/index.js:51:55)
at W.map (/Users/tomato/Sites/spike-test/test-project/node_modules/spike-records/lib/index.js:86:45)
at tryCatch2 (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:833:12)
at mapAt (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:227:40)
at traverseAt (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:247:6)
at traverseWith (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:216:5)
at Function.traverse [as _traverse] (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:198:11)
at Function.map (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/decorators/array.js:197:19)
at /Users/tomato/Sites/spike-test/test-project/node_modules/when/when.js:207:19
at tryCatchReject (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:804:4)
at Fulfilled.when (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:592:4)
at ContinuationTask.run (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/makePromise.js:702:24)
at Scheduler._drain (/Users/tomato/Sites/spike-test/test-project/node_modules/when/lib/Scheduler.js:62:19)
compiled (0.663s)
▸ External IP: http://192.168.12.104:1111
// app.js
const htmlStandards = require('reshape-standard')
const cssStandards = require('spike-css-standards')
const jsStandards = require('spike-js-standards')
const pageId = require('spike-page-id')
const env = process.env.NODE_ENV
const Records = require('spike-records')
const locals = {}
module.exports = {
devtool: 'source-map',
ignore: ['**/layout.html', '**/_*', '**/.*', 'readme.md', 'yarn.lock'],
plugins: [
new Records({
addDataTo: locals,
three: { data: { foo2: 'bar2' } }
})
],
reshape: htmlStandards({
locals: (ctx) => {
return {
pageId: pageId(ctx),
foo: 'bar'
}
},
minify: env === 'production'
}),
postcss: cssStandards({
minify: env === 'production',
warnForDuplicates: env !== 'production'
}),
babel: jsStandards()
}
<!-- index.html -->
<extends src='layout.html'>
<block name='content'>
<h2>Hello World!</h2>
<p>Thanks for using <a href='https://github.com/static-dev/spike'>spike</a></p>
<p>Example of locals: {{ three.foo2 }}</p>
<p mdi> Example of **markdown**</p>
<p>Example of "smart quotes" -- and dashes</p>
<hr>
<h3>Getting Started</h3>
<h4>The Stack:</h4>
<ul>
<li><a href="https://reshape.ml">reshape</a> for HTML transforms</li>
<li><a href="https://babeljs.io">babel</a> for JS transforms</li>
<li><a href="http://postcss.org">postcss</a> for CSS transforms</li>
<li><a href="http://webpack.github.io">webpack</a> for JS bundling</li>
</ul>
<p>Customize your settings by editing the <a href="https://spike.readme.io/docs/appjs">app.js</a> file or simply start by editing this view</p>
</block>
</extends>
$ spike watch
✗ ERROR
{ ModuleBuildError: Module build failed: TypeError: Cannot read property 'foo2' of undefined
at eval (eval at module.exports (/Users/tink/Desktop/tinker/spike/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:157)
at eval (eval at module.exports (/Users/tink/Desktop/tinker/spike/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:171)
at evalNode (/Users/tink/Desktop/tinker/spike/node_modules/reshape-eval-code/lib/index.js:27:72)
at util.modifyNodes (/Users/tink/Desktop/tinker/spike/node_modules/reshape-eval-code/lib/index.js:21:40)
at when.resolve.then (/Users/tink/Desktop/tinker/spike/node_modules/reshape-plugin-util/lib/index.js:26:29)
at tryCatchReject (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:804:4)
at Fulfilled.when (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:592:4)
at ContinuationTask.run (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:702:24)
at Scheduler._drain (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/Scheduler.js:62:19)
at runLoaders (/Users/tink/Desktop/tinker/spike/node_modules/webpack/lib/NormalModule.js:194:19)
at /Users/tink/Desktop/tinker/spike/node_modules/loader-runner/lib/LoaderRunner.js:364:11
at /Users/tink/Desktop/tinker/spike/node_modules/loader-runner/lib/LoaderRunner.js:230:18
at context.callback (/Users/tink/Desktop/tinker/spike/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at tryCatchReject (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:804:4)
at Rejected.when (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:625:4)
at Pending.run (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:483:13)
at Scheduler._drain (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/Scheduler.js:62:19)
at Scheduler.drain (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/Scheduler.js:27:9) id: '79c9335f' }
⚠ WARNING
{ ModuleBuildError: Module build failed: TypeError: Cannot read property 'foo2' of undefined
at eval (eval at module.exports (/Users/tink/Desktop/tinker/spike/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:157)
at eval (eval at module.exports (/Users/tink/Desktop/tinker/spike/node_modules/reshape-code-gen/lib/scoped_eval.js:9:10), <anonymous>:1:171)
at evalNode (/Users/tink/Desktop/tinker/spike/node_modules/reshape-eval-code/lib/index.js:27:72)
at util.modifyNodes (/Users/tink/Desktop/tinker/spike/node_modules/reshape-eval-code/lib/index.js:21:40)
at when.resolve.then (/Users/tink/Desktop/tinker/spike/node_modules/reshape-plugin-util/lib/index.js:26:29)
at tryCatchReject (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:804:4)
at Fulfilled.when (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:592:4)
at ContinuationTask.run (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:702:24)
at Scheduler._drain (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/Scheduler.js:62:19)
at runLoaders (/Users/tink/Desktop/tinker/spike/node_modules/webpack/lib/NormalModule.js:194:19)
at /Users/tink/Desktop/tinker/spike/node_modules/loader-runner/lib/LoaderRunner.js:364:11
at /Users/tink/Desktop/tinker/spike/node_modules/loader-runner/lib/LoaderRunner.js:230:18
at context.callback (/Users/tink/Desktop/tinker/spike/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
at tryCatchReject (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:804:4)
at Rejected.when (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:625:4)
at Pending.run (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/makePromise.js:483:13)
at Scheduler._drain (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/Scheduler.js:62:19)
at Scheduler.drain (/Users/tink/Desktop/tinker/spike/node_modules/when/lib/Scheduler.js:27:9) id: '79c9335f' }
Not sure if I'm including the plugins
array at the right place or if it needs to go into reshape.webpack
or something.
I'm using a thirdparty api to provide data in the records. None of the existing methods seem to fit this use case.
I added a line to allow a function as data in the run function
if (this.opts[k].cb) { tasks[k] = this.opts[k].cb() }
then I just construct my record like this:
new Records({
apidata: { cb: function_to_call_api_then_return_data_as_promise },
...
}
This seems to be cleaner than getting the data separately and then construct the record.
I simply added this plugin to the default spike template and found that the template file is interpreted as if they are in the project root.
1. Normal views/papers.sgr
worked correctly as expected.
extends(src='layout.sgr')
block(name='content')
h2 Simple paper view
ul
each(loop='paper of papers')
li: a(href='/papers/{{ paper.slug }}') {{ paper.title }}
2. When I added new views/paper.sgr
as a template it prompted an error.
extends(src='layout.sgr')
block(name='content')
h2 {{ item.title }}
The error log was as follow:
{ Error: ENOENT: no such file or directory, open 'D:\Users\...\project-root\layout.sgr'
at Error (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.readFileSync (fs.js:509:33)
at tree.reduce (D:\Users\...\project-root\node_modules\reshape-layouts\lib\index.js:41:27)
at Array.reduce (native)
at handleExtendsNodes (D:\Users\...\project-root\node_modules\reshape-layouts\lib\index.js:26:15)
at layoutsPlugin (D:\Users\...\project-root\node_modules\reshape-layouts\lib\index.js:16:12)
at W.reduce (D:\Users\...\project-root\node_modules\reshape\lib\index.js:47:60)
at tryCatchResolve (D:\Users\...\project-root\node_modules\when\lib\apply.js:46:23)
at callAndResolve (D:\Users\...\project-root\node_modules\when\lib\apply.js:30:12) id: 'c08d682d'
}
Done in 13.77s.
3. I modified views/paper.sgr
as follow, and the error had been solved
I added views/
in front of layout.sgr
.
extends(src='views/layout.sgr')
block(name='content')
h2 {{ item.title }}
This is not a fatal issue, but I'm curious whether this is an intended behavior. In my opinion, it would be better to find such imported files based on template file's location rather than the project root. It would be more consistent with other files in views
folder.
Best regards,
Youngjae
Not sure if this is an issue with spike-core or spike-records.
My records config looks something like this:
const records = new Records({
addDataTo: locals,
posts: {
url: 'https://url-to-some.com/post.json',
template: {
transform: (data) => { return data.items },
path: 'views/post.sgr',
output: (post) => { return `/post/${post.fields.slug}.html` }
}
}
})
But every time I edit views/post.sgr
I have to restart the server with spike watch
which is actually for me an npm script npm start
. But it happens if I run it as an npm script or globally.
I'm using spike-records to create blog posts dynamically from an API endpoint, but it seems that the 'item' local is not available to my template. There is a blog
field in my locals variable that lists all the posts, and the post views are indeed being created in the public/blog/ folder, but can't figure out how to get to the data specific to each post. Here's my app.js file, am I doing something wrong? BTW I generated this project yesterday so everything should be brand new.
const Records = require('spike-records')
const htmlStandards = require('reshape-standard')
const cssStandards = require('spike-css-standards')
const jsStandards = require('spike-js-standards')
const pageId = require('spike-page-id')
const env = process.env.NODE_ENV
const locals = {}
module.exports = {
devtool: 'source-map',
matchers: { html: '*(**/)*.sgr', css: '*(**/)*.sss' },
ignore: ['**/layout.sgr', '**/_*', '**/.*', 'readme.md', 'yarn.lock'],
reshape: htmlStandards({
root: './views',
locals: (ctx) => Object.assign(locals, { pageId: pageId(ctx) }),
minify: env === 'production'
}),
postcss: cssStandards({
minify: env === 'production',
warnForDuplicates: env !== 'production'
}),
plugins: [
new Records({
addDataTo: locals,
blog: {
url: 'URL to API that returns an array of objects',
template: {
path: 'views/post.sgr',
output: (post) => { return `blog/${post.slug}.html` }
}
},
})
],
babel: jsStandards(),
server: {
open: false
}
}
app.js
const path = require('path')
const HardSourcePlugin = require('hard-source-webpack-plugin')
const htmlStandards = require('reshape-standard')
const cssStandards = require('spike-css-standards')
const jsStandards = require('babel-preset-latest')
const pageId = require('spike-page-id')
const Records = require('spike-records')
const locals = {}
module.exports = {
devtool: 'source-map',
matchers: {
html: '*(**/)*.sgr',
css: '*(**/)*.sss'
},
ignore: ['**/layout.sgr', '**/_*', '**/.*', '_cache/**', 'readme.md'],
reshape: (ctx) => {
return htmlStandards({
webpack: ctx,
> locals: { pageId: pageId(ctx), foo: 'bar' }
> //locals
})
},
/*reshape: (ctx) => htmlStandards({ locals }),*/
postcss: (ctx) => {
return cssStandards({ webpack: ctx })
},
babel: { presets: [jsStandards] },
plugins: [
new HardSourcePlugin({
environmentPaths: { root: __dirname },
recordsPath: path.join(__dirname, '_cache/records.json'),
cacheDirectory: path.join(__dirname, '_cache/hard_source_cache')
}),
new Records({
addDataTo: locals,
three: { data: { food: 'bread' } },
})
]
}
inde.sgr
p {{ pageId }}
p {{ three }}
p {{ foo }}
p {{ JSON.stringify(locals) }}
result1:
about undefined bar {"pageId":"about","foo":"bar"}
result2:
undefined [object Object] undefined {"three":{"food":"bread"}}
Branch | Build failing 🚨 |
---|---|
Dependency | spike-util |
Current Version | 1.1.0 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
spike-util is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Branch | Build failing 🚨 |
---|---|
Dependency | spike-core |
Current Version | 1.0.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As spike-core is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
Hi, i get an error when try to render.
this is my setup
module.exports = {
root: '/Users/ettorepanini/Sites/prima-automotive/',
devtool: 'source-map',
matchers: {
html: '*(**/)*.sgr',
css: '*(**/)*.scss',
js: '*(**/)*.js'
},
ignore: ['**/_*', '**/.*', '_cache/**', 'readme.md', ],
reshape: (ctx) => {
return htmlStandards({
webpack: ctx,
locals: {
pageId: pageId(ctx),
foo: 'bar',
productsCategory: productsCategory,
newsList: newsList
}
})
},
postcss: (ctx) => {
return {
webpack: ctx,
plugins: [
require('postcss-import'),
require('postcss-cssnext'),
require('postcss-mixins'),
require('postcss-extend'),
require('postcss-simple-vars'),
require('postcss-nested'),
]
}
},
babel: { presets: [jsStandards] },
plugins: [
new Records({
addDataTo: locals,
blog: {
url: url that return an array,
template: {
transform: (data) => {console.log(data); return data },
path: 'views/_product.sgr',
output: (product) => { return `product/${product.slug}.html` }
}
}
}),
new HardSourcePlugin({
environmentPaths: { root: __dirname },
recordsPath: path.join(__dirname, '_cache/records.json'),
cacheDirectory: path.join(__dirname, '_cache/hard_source_cache')
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
]
}
i got this error when i try to render product.sgr that on the first line has
extends(src='_layout.sgr')
why it try to found _layout.sgr in /assest/js/partials/?
i have done all the front-end and now i have started to add api for render all the page but now i got the error.
Help me :)
for the url
types (although it likely is a good idea for all types), we should have some kind of cache: true
where we simply return the data right off the compiler.options.locals
if it already exists. this will give us a cache so we won't have network overhead for each compile (like if you updated a css file).
i should note, i didn't look up whether the webpack run
hook runs every time or just on the first compile, which would make this issue moot.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.