Permalink
Browse files

joining relative paths with __dirname in generated build script"

  • Loading branch information...
1 parent 59181c6 commit e01b277e8c8554abbc56e451ba5d45ecd7ec983a @thlorenz committed Dec 30, 2012
View
@@ -17,9 +17,10 @@
* var fs = require('fs');
*
* var bundled = browserify({ debug: true })
- * .use(shim({ alias: 'jquery', path: './js/vendor/jquery.js', export: '$' }))
- * .use(shim.addEntry('./js/entry.js'))
- * .bundle();
+ * .use(shim({ alias: 'jquery', path: './js/vendor/jquery.js', exports: '$' }))
+ * .addEntry('./js/entry.js')
+ * .bundle()
+ * .shim();
*
* fs.writeFileSync(bundleFile, bundled, 'utf-8');
*/
@@ -49,6 +50,10 @@ module.exports = function generate(config, bundleFile, entryPath) {
function quoted(s) {
return format('%s%s%s',quote, s, quote);
}
+
+ function pathJoinedAndQuoted(s) {
+ return format('path.join(__dirname, %s)', quoted(s));
+ }
function generateRequire(assign, name) {
return format('var %s = require(%s);\n', assign, quoted(name));
@@ -60,11 +65,11 @@ module.exports = function generate(config, bundleFile, entryPath) {
function generateShim(shim) {
var exp = shim.exports ? quoted(shim.exports) : 'null';
- return format('%s.use(shim({ alias: %s, path: %s, export: %s }))\n', tab, quoted(shim.alias), quoted(shim.path), exp);
+ return format('%s.use(shim({ alias: %s, path: %s, exports: %s }))\n', tab, quoted(shim.alias), quoted(shim.path), exp);
}
function generateAddEntry() {
- return format('%s.addEntry(%s)\n', tab, quoted(entryPath));
+ return format('%s.addEntry(%s)\n', tab, pathJoinedAndQuoted(entryPath));
}
function generateBundleFoot() {
@@ -74,13 +79,14 @@ module.exports = function generate(config, bundleFile, entryPath) {
}
function generateWriteBundle() {
- return format('fs.writeFileSync(%s, %s, %s);\n', quoted(bundleFile), 'bundled', quoted('utf-8'));
+ return format('fs.writeFileSync(%s, %s, %s);\n', pathJoinedAndQuoted(bundleFile), 'bundled', quoted('utf-8'));
}
var requires = '';
+ requires += generateRequire('fs', 'fs');
+ requires += generateRequire('path', 'path');
requires += generateRequire('browserify', 'browserify');
requires += hasShims ? generateRequire('shim', 'browserify-shim') : '';
- requires += generateRequire('fs', 'fs');
var shimCode = hasShims
? shims.map(generateShim).join('')
@@ -1,12 +1,13 @@
+var fs = require('fs');
+var path = require('path');
var browserify = require('browserify');
var shim = require('browserify-shim');
-var fs = require('fs');
var bundled = browserify({ debug: true })
- .use(shim({ alias: 'jquery', path: './js/vendor/jquery.js', export: '$' }))
- .use(shim({ alias: 'underscore', path: './js/vendor/underscore.js', export: null }))
- .addEntry('./js/entry.js')
+ .use(shim({ alias: 'jquery', path: './js/vendor/jquery.js', exports: '$' }))
+ .use(shim({ alias: 'underscore', path: './js/vendor/underscore.js', exports: null }))
+ .addEntry(path.join(__dirname, './js/entry.js'))
.bundle()
.shim();
-fs.writeFileSync('./build/bundle.js', bundled, 'utf-8');
+fs.writeFileSync(path.join(__dirname, './build/bundle.js'), bundled, 'utf-8');
@@ -1,8 +1,9 @@
-var browserify = require("browserify");
var fs = require("fs");
+var path = require("path");
+var browserify = require("browserify");
var bundled = browserify({ debug: true })
- .addEntry("./js/entry.js")
+ .addEntry(path.join(__dirname, "./js/entry.js"))
.bundle();
-fs.writeFileSync("./build/bundle.js", bundled, "utf-8");
+fs.writeFileSync(path.join(__dirname, "./build/bundle.js"), bundled, "utf-8");
@@ -1,8 +1,9 @@
-var browserify = require('browserify');
var fs = require('fs');
+var path = require('path');
+var browserify = require('browserify');
var bundled = browserify({ debug: true })
- .addEntry('./js/entry.js')
+ .addEntry(path.join(__dirname, './js/entry.js'))
.bundle();
-fs.writeFileSync('./build/bundle.js', bundled, 'utf-8');
+fs.writeFileSync(path.join(__dirname, './build/bundle.js'), bundled, 'utf-8');

0 comments on commit e01b277

Please sign in to comment.