Skip to content

feature: adds build response text; updates dependencies #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var gutil = require('gulp-util'),
requirejs = require('requirejs'),
PluginError = gutil.PluginError,
File = gutil.File,
es = require('event-stream')
es = require('event-stream'),
fs = require("fs");

// Consts
const PLUGIN_NAME = 'gulp-requirejs';
Expand Down Expand Up @@ -30,27 +31,45 @@ module.exports = function(opts) {

// just a small wrapper around the r.js optimizer, we write a new gutil.File (vinyl) to the Stream, mocking a file, which can be handled
// regular gulp plugins (i hope...).

// try {
optimize(opts, function(text) {
_s.write(new File({
path: _fName,
contents: new Buffer(text)
}));

optimize(opts, function(text, buildText) {
var newFile = new File({
path: _fName,
contents: new Buffer(text)
});
// } catch (err) {
// _s.emit('error', err);
// }
newFile.buildResponse = buildText;
_s.write(newFile);
});




// return the stream for chain .pipe()ing
return _s;
}

// a small wrapper around the r.js optimizer
function optimize(opts, cb) {
opts.out = cb;
var scriptName = opts.out,
buildResponse = false;

var callbackIfBuildResponse = function(text) {
if(buildResponse) {
cb(text, buildResponse);
} else {
process.nextTick(function() {
callbackIfBuildResponse(text);
})
}
}
opts.out = callbackIfBuildResponse;
opts.optimize = 'none';
requirejs.optimize(opts);
requirejs.optimize(opts, function(br) {
if(br) {
buildResponse = br.replace("FUNCTION", scriptName);
}
}, function(err) {
if(err) {
buildResponse = "error";
}
});
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
"repository": "git://github.com/robinthrift/gulp-requirejs.git",
"author": "Robin Thrift <[email protected]> (http://webbrickworks.com/)",
"main": "./index.js",
"keywords": [
],
"keywords": [],
"dependencies": {
"gulp-util": "~2.2.5",
"requirejs": "2.1.8",
"event-stream": "~3.0.20"
"event-stream": "^3.0.20",
"gulp-util": "^2.2.20",
"requirejs": "^2.1.8"
},
"devDependencies": {
"mocha": "*",
Expand All @@ -29,4 +28,4 @@
"url": "http://github.com/robinthrift/gulp-requirejs/raw/master/LICENSE"
}
]
}
}