Permalink
Browse files

First commit of chromeify built on browseify

  • Loading branch information...
0 parents commit bf517c96a220cf60f243324be40a86732a619b62 @PaulKinlan PaulKinlan committed Oct 31, 2012
Showing with 196 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 README.md
  3. +165 −0 bin/cmd.js
  4. +28 −0 package.json
1 .gitignore
@@ -0,0 +1 @@
+node_modules/
2 README.md
@@ -0,0 +1,2 @@
+Chromeify
+=========
165 bin/cmd.js
@@ -0,0 +1,165 @@
+#!/usr/bin/env node
+
+var browserify = require('browserify');
+var fs = require('fs');
+var resolve = require('resolve');
+
+var argv = require('optimist')
+ .usage('Usage: browserify [entry files] {OPTIONS}')
+ .wrap(80)
+ .option('outfile', {
+ alias : 'o',
+ desc : 'Write the browserify bundle to this file.\n'
+ + 'If unspecified, browserify prints to stdout.'
+ ,
+ })
+ .option('require', {
+ alias : 'r',
+ desc : 'A module name or file to bundle.require()\n'
+ + 'Optionally use a colon separator to set the target.'
+ ,
+ })
+ .option('entry', {
+ alias : 'e',
+ desc : 'An entry point of your app'
+ })
+ .option('exports', {
+ desc : 'Export these core objects, comma-separated list\n'
+ + 'with any of: require, process. If unspecified, the\n'
+ + 'export behavior will be inferred.\n'
+ })
+ .option('ignore', {
+ alias : 'i',
+ desc : 'Ignore a file'
+ })
+ .option('alias', {
+ alias : 'a',
+ desc : 'Register an alias with a colon separator: "to:from"\n'
+ + "Example: --alias 'jquery:jquery-browserify'"
+ ,
+ })
+ .option('cache', {
+ alias : 'c',
+ desc : 'Turn on caching at $HOME/.config/browserling/cache.json '
+ + 'or use a file for caching.\n',
+ default : true,
+ })
+ .option('debug', {
+ alias : 'd',
+ desc : 'Switch on debugging mode with //@ sourceURL=...s.',
+ type : 'boolean'
+ })
+ .option('plugin', {
+ alias : 'p',
+ desc : 'Use a plugin.\n'
+ + 'Example: --plugin aliasify'
+ ,
+ })
+ .option('prelude', {
+ default : true,
+ type : 'boolean',
+ desc : 'Include the code that defines require() in this bundle.'
+ })
+ .option('watch', {
+ alias : 'w',
+ desc : 'Watch for changes. The script will stay open and write updates '
+ + 'to the output every time any of the bundled files change.\n'
+ + 'This option only works in tandem with -o.'
+ ,
+ })
+ .option('verbose', {
+ alias : 'v',
+ desc : 'Write out how many bytes were written in -o mode. '
+ + 'This is especially useful with --watch.'
+ ,
+ })
+ .option('help', {
+ alias : 'h',
+ desc : 'Show this message'
+ })
+ .check(function (argv) {
+ if (argv.help) throw ''
+ if (process.argv.length <= 2) throw 'Specify a parameter.'
+ })
+ .argv
+;
+
+var bundle = browserify({
+ watch : argv.watch,
+ cache : argv.cache,
+ debug : argv.debug,
+ exports : argv.exports && argv.exports.split(','),
+ require: [ "net-chromeify" ] ,
+});
+
+bundle.alias("net", "net-chromeify");
+
+bundle.on('syntaxError', function (err) {
+ console.error(err);
+ if (!argv.watch) {
+ process.exit(1);
+ }
+});
+
+if (argv.noprelude || argv.prelude === false) {
+ bundle.files = [];
+ bundle.prepends = [];
+}
+if (argv.ignore) bundle.ignore(argv.ignore);
+
+([].concat(argv.plugin || [])).forEach(function (plugin) {
+ var resolved = resolve.sync(plugin, { basedir : process.cwd() });
+ bundle.use(require(resolved));
+});
+
+([].concat(argv.alias || [])).forEach(function (alias) {
+ if (!alias.match(/:/)) {
+ console.error('aliases require a colon separator');
+ process.exit();
+ }
+ bundle.alias.apply(bundle, alias.split(':'));
+});
+
+([].concat(argv.require || [])).forEach(function (req) {
+ if (req.match(/:/)) {
+ var s = req.split(':');
+ bundle.require(s[0], { target : s[1] });
+ return;
+ }
+
+ if (!/^[.\/]/.test(req)) {
+ try {
+ var res = resolve.sync(req, { basedir : process.cwd() });
+ }
+ catch (e) {
+ return bundle.require(req);
+ }
+ return bundle.require(res, { target : req });
+ }
+ bundle.require(req);
+});
+
+(argv._.concat(argv.entry || [])).forEach(function (entry) {
+ bundle.addEntry(entry);
+});
+
+if (argv.outfile) {
+ function write () {
+ var src = bundle.bundle();
+ if (!bundle.ok) return;
+
+ fs.writeFile(argv.outfile, src, function () {
+ if (argv.verbose) {
+ console.log(Buffer(src).length + ' bytes written');
+ }
+ });
+ }
+
+ write();
+ if (argv.watch) bundle.on('bundle', write)
+}
+else {
+ var src = bundle.bundle();
+ if (bundle.ok) console.log(src);
+}
+
28 package.json
@@ -0,0 +1,28 @@
+{
+ "name": "chromeify",
+ "version": "0.0.0",
+ "description": "Tool for creating managing the creation of Chrome Apps with Browserify",
+ "main": "index.js",
+ "bin" : {
+ "chromeify" : "bin/cmd.js"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "dependencies" : {
+ "browserify": "1.16.x",
+ "net-chromeify": "0.0.x",
+ "optimist" : "*",
+ "resolve" : "*"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "http://github.com/GoogleChrome/chromeify.git"
+ },
+ "author" : {
+ "name" : "Paul Kinlan",
+ "email" : "paul.kinlan@gmail.com",
+ "url" : "http://github.com/GoogleChrome"
+ },
+ "license": "Apache2"
+}

0 comments on commit bf517c9

Please sign in to comment.