adamayres / gulp-wrap Goto Github PK
View Code? Open in Web Editor NEWA gulp plugin to wrap the stream contents with a lodash template.
Home Page: https://www.npmjs.com/package/gulp-wrap
License: MIT License
A gulp plugin to wrap the stream contents with a lodash template.
Home Page: https://www.npmjs.com/package/gulp-wrap
License: MIT License
Consider using consolidate.js to render the template, giving the user their own choice of which template engine to use - without worrying about different engine's APIs.
Similar to contents
, when:
file.path => path/to/foo.png
expose:
dirname => to
basename => foo.png
filename => foo
extension => png
Parsing this inside templates is super awkward, yet these properties are really useful.
I get:
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError in plugin 'gulp-wrap'
message: 'processPartialName is not defined'
When doing this:
.pipe( wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, Handlebars.template(<%= contents %>));', {}, {
imports: {
processPartialName: function ( fileName ) {
// Strip the extension and the underscore
// Escape the output with JSON.stringify
return JSON.stringify( path.basename( fileName, '.js' ).substr(1) );
}
}
}));
Anyone else get this? And how to fix it?
Maybe i have missed something here but how can i get the file name only. I do not want the full path, just the file name (including or excluding the extension, i dont mind)
I raised an issue over at the gulp-handlebars
repo. They give the following example in their documentation which makes use of gulp-wrap
:
gulp.task('templates', function(){
gulp.src('source/templates/*.hbs')
.pipe(handlebars({
handlebars: require('handlebars')
}))
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'MyApp.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('build/js/'));
});
I've been using gulp-handlebars
4.0.0, handlebars
4.0.5, and gulp-wrap
0.11.0 together for a while now. Everything plays nice. Just started a new project with the above and gulp-wrap
0.12.0 and I got the following error:
{ [TypeError: tmpl is not a function]
name: 'TypeError',
message: 'tmpl is not a function',
stack: 'TypeError: tmpl is not a function\n
at /Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/consolidate/lib/consolidate.js:779:16\n
at /Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/consolidate/lib/consolidate.js:143:5\n
at Promise._execute (/Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/bluebird/js/release/debuggability.js:272:9)\n
at Promise._resolveFromExecutor (/Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/bluebird/js/release/promise.js:473:18)\n
at new Promise (/Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/bluebird/js/release/promise.js:77:14)\n
at promisify (/Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/consolidate/lib/consolidate.js:136:10)\n
at Function.exports.lodash.render (/Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/consolidate/lib/consolidate.js:775:10)\n
at /Users/aaron.cordova/Projects/Sandbox/walmart-search/node_modules/gulp-wrap/index.js:73:37\n
at process._tickCallback (node.js:401:9)',
showStack: false,
showProperties: true,
plugin: 'gulp-wrap' }
Just wanted to make your team aware. Thanks.
promise in node seems to be well supported now from version 4+, perhaps we can remove it now?
feels unnecessary to include dependencies that you don't need when running node 6.1.0+
Users can always install it and set it as global if they are running an older version. And i don't think people don't mind to update if they see a warning if you put "node": ">=4.0.0"
in the package.json
I need some back-end java variables such as ${appId}
in my scripts, when I run gulp-wrap, it throw me the error oppeid is not defined
and stop. Can I solve it?
Show exception if data doesn't exist
gulpWrap('<%= data.value %>')
crashes without warning
The following is incorrect but illustrates what I'm trying to do: pull the value set for template
in each of the source file's front matter and pass it src
of the wrap. Is this doable?
gulp.task('build', function() {
gulp.src('./content/**/*.md')
.pipe(frontMatter({
property: 'data'
}))
.pipe(wrap({
src: <% data.template %>
}))
.pipe(gulp.dest(paths.build))
});
Could you git tag your last release ?
Thanks
Is it possible with gulp-wrap to convert amd modules to commonjs and standard js modules? That conversion is not just about wrapping, it should parse the amd file and read the required dependencies...
我遇到这种情况;
在gulp-watch中需要对js文件添加defined包裹,watch结束时,需要去掉define,
请问有没有办法使用呢?
谢谢!
I encountered such a situation;
In gulp-watch need to add define
to the JS file, the end of watch, need to remove define
Is there any way to use?
Thanks!
Trying to get a bunch of markdown files converted into html, wrapped with a Nunjucks template, and then saved into a folder (where they can then be processed and turned into public files).
The gulp-wrap process will create an HTML file, but only duplicating the template over. It will not populate due to gulp errors with Nunjucks - specifically, how my existing gulpfile wants 'extends' written, and how gulp-wrap wants it formatted (in this case, the full file path, rather that local filepath).
Is there a way to disable the Nunjucks render so that gulp-wrap only replaces the relevant information on the template?
gulp-util
has been deprecated recently. Continuing to use this dependency may prevent the use of your library with the latest release of Gulp 4 so it is important to replace gulp-util
.
The README.md lists alternatives for all the components so a simple replacement should be enough.
Your package is one of the most popular packages still relying on gulp-util
, it would be good to publish a fixed version to npm as soon as possible.
See:
Hi, @adamayres.
I found that you're not watching this project anymore. You have no interest to maintain this project any more, right?
If you could transfer this repository to my account, I can keep on maintaining this project with more motivations :)
What do you think?
HI there,
it would be super cool if lib had a possibility to filter files.
Hey,
I am a happy user of your library, but as my project grows we have a lot of dependencies.
We could save a lot of space if you added .npmignore
file to your project.
I even found tool that can help you with it: https://github.com/inikulin/dmn
Thanks!
Is it possible to add support for Sourcemaps (gulp-sourcemaps)?
Template has a new lien at the end, but when compiled with the content, new lien gets removed.
Any suggestions?
Hi,
gulp-wrap throws an exception when i use it.
Here ir the piece of code in my gulpfile.js:
gulp.task('build:word-merge', function() {
return gulp.src('word-merge/*.js')
.pipe(concat('word-merge.js'))
.pipe(wrap('(function(){\n"use strict";\n<%= contents %>\n})();')
.pipe(gulp.dest(buildPath))
.pipe(uglify())
.pipe(rename('word-merge.min.js'))
.pipe(gulp.dest(buildPath));
});
And here the console log:
Unhandled rejection TypeError: tmpl is not a function
at D:\Proyectos\openxml.js\node_modules\consolidate\lib\consolidate.js:779:16
at D:\Proyectos\openxml.js\node_modules\consolidate\lib\consolidate.js:143:5
at Promise._execute (D:\Proyectos\openxml.js\node_modules\bluebird\js\release\debuggability.js:272:9)
at Promise._resolveFromExecutor (D:\Proyectos\openxml.js\node_modules\bluebird\js\release\promise.js:473:18)
at new Promise (D:\Proyectos\openxml.js\node_modules\bluebird\js\release\promise.js:77:14)
at promisify (D:\Proyectos\openxml.js\node_modules\consolidate\lib\consolidate.js:136:10)
at Function.exports.lodash.render (D:\Proyectos\openxml.js\node_modules\consolidate\lib\consolidate.js:775:10)
at D:\Proyectos\openxml.js\node_modules\gulp-wrap\index.js:73:37
at process._tickCallback (node.js:412:9)
For more info, I'm using the version 5.9.1 of node.js
Thanks
PS: sorry about my horrible english
Check json format with JSON.parse (or other method), rather than a file extension, because I can generate json-object as js- or coffee-file then to wrap it in js or coffee.
If I use inner object I get [object Object]
. You need to Stringify data in plugin
F.e.
gulp.src('configs/')
.pipe(generateConfigFiles('<%= projectName %>/config.js'))
.pipe(wrap('define(["app"], function(app) {app.constant("config", <%= contents.public %>);});')))
.pipe(gulp.dest('compiled/configs/'))
I use wrap in my code like this:
var _config = gulp.src('pkg/seajs/organization.json')
.pipe(wrap('seajs.config(<%= contents %>);'))
.pipe(gulp.dest('js', {cwd : config.dist}))
}
but the output is
seajs.config([object Object]);
the contents is not correct
As per suggestion by the gulp-data plugin, merge data found on the vinyl object's data
property with the user-supplied data.
It would be nice to have ability to pass template contents as a stream.
For example if my template is in jade format and I use gulp-jade to compile it. Something like:
var templateStream = gulp.src("./src/template.jade").pipe(jade());
gulp.src("./src/*.json")
.pipe(wrap({ stream: templateStream }))
.pipe(gulp.dest("./dist"));
What do you think?
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.