Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

First commit of chromeify built on browseify

  • Loading branch information...
commit bf517c96a220cf60f243324be40a86732a619b62 0 parents
Paul Kinlan authored October 30, 2012
1  .gitignore
... ...
@@ -0,0 +1 @@
  1
+node_modules/
2  README.md
Source Rendered
... ...
@@ -0,0 +1,2 @@
  1
+Chromeify
  2
+=========
165  bin/cmd.js
... ...
@@ -0,0 +1,165 @@
  1
+#!/usr/bin/env node
  2
+
  3
+var browserify = require('browserify');
  4
+var fs = require('fs');
  5
+var resolve = require('resolve');
  6
+
  7
+var argv = require('optimist')
  8
+    .usage('Usage: browserify [entry files] {OPTIONS}')
  9
+    .wrap(80)
  10
+    .option('outfile', {
  11
+        alias : 'o',
  12
+        desc : 'Write the browserify bundle to this file.\n'
  13
+            + 'If unspecified, browserify prints to stdout.'
  14
+        ,
  15
+    })
  16
+    .option('require', {
  17
+        alias : 'r',
  18
+        desc : 'A module name or file to bundle.require()\n'
  19
+            + 'Optionally use a colon separator to set the target.'
  20
+        ,
  21
+    })
  22
+    .option('entry', {
  23
+        alias : 'e',
  24
+        desc : 'An entry point of your app'
  25
+    })
  26
+    .option('exports', {
  27
+        desc : 'Export these core objects, comma-separated list\n'
  28
+            + 'with any of: require, process. If unspecified, the\n'
  29
+            + 'export behavior will be inferred.\n'
  30
+    })
  31
+    .option('ignore', {
  32
+        alias : 'i',
  33
+        desc : 'Ignore a file'
  34
+    })
  35
+    .option('alias', {
  36
+        alias : 'a',
  37
+        desc : 'Register an alias with a colon separator: "to:from"\n'
  38
+            + "Example: --alias 'jquery:jquery-browserify'"
  39
+        ,
  40
+    })
  41
+    .option('cache', {
  42
+        alias : 'c',
  43
+        desc : 'Turn on caching at $HOME/.config/browserling/cache.json '
  44
+            + 'or use a file for caching.\n',
  45
+        default : true,
  46
+    })
  47
+    .option('debug', {
  48
+        alias : 'd',
  49
+        desc : 'Switch on debugging mode with //@ sourceURL=...s.',
  50
+        type : 'boolean'
  51
+    })
  52
+    .option('plugin', {
  53
+        alias : 'p',
  54
+        desc : 'Use a plugin.\n'
  55
+            + 'Example: --plugin aliasify'
  56
+        ,
  57
+    })
  58
+    .option('prelude', {
  59
+        default : true,
  60
+        type : 'boolean',
  61
+        desc : 'Include the code that defines require() in this bundle.'
  62
+    })
  63
+    .option('watch', {
  64
+        alias : 'w',
  65
+        desc : 'Watch for changes. The script will stay open and write updates '
  66
+            + 'to the output every time any of the bundled files change.\n'
  67
+            + 'This option only works in tandem with -o.'
  68
+        ,
  69
+    })
  70
+    .option('verbose', {
  71
+        alias : 'v',
  72
+        desc : 'Write out how many bytes were written in -o mode. '
  73
+            + 'This is especially useful with --watch.'
  74
+        ,
  75
+    })
  76
+    .option('help', {
  77
+        alias : 'h',
  78
+        desc : 'Show this message'
  79
+    })
  80
+    .check(function (argv) {
  81
+        if (argv.help) throw ''
  82
+        if (process.argv.length <= 2) throw 'Specify a parameter.'
  83
+    })
  84
+    .argv
  85
+;
  86
+
  87
+var bundle = browserify({
  88
+    watch : argv.watch,
  89
+    cache : argv.cache,
  90
+    debug : argv.debug,
  91
+    exports : argv.exports && argv.exports.split(','),
  92
+    require: [ "net-chromeify" ] ,
  93
+});
  94
+
  95
+bundle.alias("net", "net-chromeify");
  96
+
  97
+bundle.on('syntaxError', function (err) {
  98
+    console.error(err);
  99
+    if (!argv.watch) {
  100
+        process.exit(1);
  101
+    }
  102
+});
  103
+
  104
+if (argv.noprelude || argv.prelude === false) {
  105
+    bundle.files = [];
  106
+    bundle.prepends = [];
  107
+}
  108
+if (argv.ignore) bundle.ignore(argv.ignore);
  109
+
  110
+([].concat(argv.plugin || [])).forEach(function (plugin) {
  111
+    var resolved = resolve.sync(plugin, { basedir : process.cwd() });
  112
+    bundle.use(require(resolved));
  113
+});
  114
+
  115
+([].concat(argv.alias || [])).forEach(function (alias) {
  116
+    if (!alias.match(/:/)) {
  117
+        console.error('aliases require a colon separator');
  118
+        process.exit();
  119
+    }
  120
+    bundle.alias.apply(bundle, alias.split(':'));
  121
+});
  122
+
  123
+([].concat(argv.require || [])).forEach(function (req) {
  124
+    if (req.match(/:/)) {
  125
+        var s = req.split(':');
  126
+        bundle.require(s[0], { target : s[1] });
  127
+        return;
  128
+    }
  129
+    
  130
+    if (!/^[.\/]/.test(req)) {
  131
+        try {
  132
+            var res = resolve.sync(req, { basedir : process.cwd() });
  133
+        }
  134
+        catch (e) {
  135
+            return bundle.require(req);
  136
+        }
  137
+        return bundle.require(res, { target : req });
  138
+    }
  139
+    bundle.require(req);
  140
+});
  141
+
  142
+(argv._.concat(argv.entry || [])).forEach(function (entry) {
  143
+    bundle.addEntry(entry);
  144
+});
  145
+
  146
+if (argv.outfile) {
  147
+    function write () {
  148
+        var src = bundle.bundle();
  149
+        if (!bundle.ok) return;
  150
+        
  151
+        fs.writeFile(argv.outfile, src, function () {
  152
+            if (argv.verbose) {
  153
+                console.log(Buffer(src).length + ' bytes written');
  154
+            }
  155
+        });
  156
+    }
  157
+    
  158
+    write();
  159
+    if (argv.watch) bundle.on('bundle', write)
  160
+}
  161
+else {
  162
+    var src = bundle.bundle();
  163
+    if (bundle.ok) console.log(src);
  164
+}
  165
+
28  package.json
... ...
@@ -0,0 +1,28 @@
  1
+{
  2
+  "name": "chromeify",
  3
+  "version": "0.0.0",
  4
+  "description": "Tool for creating managing the creation of Chrome Apps with Browserify",
  5
+  "main": "index.js",
  6
+  "bin" : {
  7
+    "chromeify" : "bin/cmd.js"
  8
+  },
  9
+  "scripts": {
  10
+    "test": "echo \"Error: no test specified\" && exit 1"
  11
+  },
  12
+  "dependencies" : {
  13
+    "browserify": "1.16.x",
  14
+    "net-chromeify": "0.0.x",
  15
+    "optimist" : "*",
  16
+    "resolve" : "*"
  17
+  },
  18
+  "repository" : {
  19
+    "type" : "git",
  20
+    "url" : "http://github.com/GoogleChrome/chromeify.git"
  21
+  },
  22
+  "author" : {
  23
+    "name" : "Paul Kinlan",
  24
+    "email" : "paul.kinlan@gmail.com",
  25
+    "url" : "http://github.com/GoogleChrome"
  26
+  },
  27
+  "license": "Apache2"
  28
+}

0 notes on commit bf517c9

Please sign in to comment.
Something went wrong with that request. Please try again.