Permalink
Browse files

Moved command line logic over to yui3.rls()

  • Loading branch information...
1 parent 7a92cd4 commit e6ca4af7de55459e38278caafc7d85b584f4b03c @davglass committed Jan 21, 2011
Showing with 54 additions and 48 deletions.
  1. +1 −0 .gitignore
  2. +49 −45 lib/yui-cli.js
  3. +4 −3 package.json
View
@@ -0,0 +1 @@
+combined.*
View
@@ -1,16 +1,20 @@
#!/usr/bin/env node
-var YUI = require('yui3').YUI;
-var fs = require('fs');
-
-var cli = require('cli');
+var yui3 = require('yui3'),
+ fs = require('fs'),
+ cli = require('cli'),
+ start = (new Date()).getTime();
cli.enable('status', 'help');
cli.parse({
- use: ['u', 'Required: Comma seperated list of modules to pass to YUI().use()', 'string'],
- type: ['t', 'The file type to produce: debug, raw, min', 'string', 'min'],
- file: [false, 'File to save output to', 'file', './combined.js'],
- joinwith: ['j', 'The character to join the files with', 'string', '\n']
+ modules: ['m', 'Required: Comma seperated list of modules to pass to YUI().use()', 'string'],
+ filter: ['f', 'The file type to produce: debug, raw, min', 'string', 'min'],
+ file: [false, 'File to save JS output to', 'file', './combined.js'],
+ cssfile: [false, 'File to save CSS output to', 'file', './combined.css'],
+ version: ['v', 'The YUI version to use', 'string', '3.3.0'],
+ gversion: ['gv', 'The Gallery version to use', 'string'],
+ yui2: ['yui2', 'The YUI2 version to use', 'string', '2.8.0'],
+ env: ['e', 'Modules that are already on the page.', 'string']
});
var parseUse = function(u) {
@@ -19,50 +23,50 @@ var parseUse = function(u) {
}
cli.main(function() {
- if (!this.options.use) {
+ if (!this.options.modules) {
cli.getUsage();
return;
}
- this.options.use = parseUse(this.options.use);
-
- delete YUI.GlobalConfig.modules;
- YUI.GlobalConfig.debug = false;
- YUI.GlobalConfig.loaderPath = YUI.GlobalConfig.loaderPath.replace('-debug', '-min');
- var files = [YUI.GlobalConfig.base + 'yui/yui-min.js'];
- var content = [];
var opts = this.options;
- var inc = YUI.include;
- YUI.include = function(file, cb) {
- files.push(file);
- if (file.indexOf('loader') > 0) {
- inc(file, function(err, data) {
- cb(null, function() {});
+ var config = {
+ m: opts.modules,
+ v: opts.version,
+ parse: true,
+ filt: opts.filter,
+ '2in3v': opts.yui2
+ };
+ if (opts.env) {
+ config.env = opts.env;
+ }
+ if (opts.gversion) {
+ config.gv = opts.gversion;
+ }
+ yui3.rls(config, function(js, css, data) {
+ var sizes = {
+ js: 0,
+ css: 0
+ };
+ if (opts.file) {
+ var d = [];
+ js.forEach(function(k) {
+ sizes.js += data[k].length;
+ d.push(data[k]);
});
- } else {
- cb(null, function() {});
+ fs.writeFileSync(opts.file, d.join('\n'), encoding='utf8');
}
- }
-
- cli.info('Using the following modules: ' + this.options.use.join(','));
- var u = this.options.use;
- u.push(function(Y) {
- cli.debug('Use callback finished');
- files.forEach(function(v, k) {
- if (opts.type) {
- cli.debug('Converting file to: ' + opts.type);
- var r = ((opts.type === 'raw') ? '' : '-' + opts.type);
- v = v.replace('-min', r);
- }
- cli.debug(v);
- content.push(fs.readFileSync(v, 'utf-8'));
- });
- fs.writeFileSync(opts.file, content.join(opts.joinwith), 'utf-8');
- cli.ok('File (' + opts.file + ') written.');
+ if (opts.cssfile) {
+ var d = [];
+ css.forEach(function(k, v) {
+ sizes.css += data[k].length;
+ d.push(data[k]);
+ });
+ fs.writeFileSync(opts.cssfile, d.join('\n'), encoding='utf8');
+ }
+ console.log('Combined %s JS files ~(%s bytes) saved to: %s', js.length, sizes.js, opts.file);
+ console.log('Combined %s CSS files ~(%s bytes) saved to: %s', css.length, sizes.css, opts.cssfile);
+ console.log('Build Time: %sms', (new Date()).getTime() - start);
});
- cli.debug('Creating YUI Instance');
- var Y = YUI();
- cli.debug('Calling Use');
- Y.use.apply(Y, u);
+
});
View
@@ -1,17 +1,18 @@
{
"name": "yui-cli",
"description": "YUI file combiner",
- "version": "0.0.1",
+ "version": "0.0.2",
"author": "Dav Glass <davglass@gmail.com>",
"bugs": { "web" : "http://github.com/davglass/yui-cli/issues" },
"contributors": [
{ "name": "Dav Glass", "email": "davglass@gmail.com" }
],
"bin": { "yui-cli": "./lib/yui-cli.js" },
- "engines": { "node": ">= 0.1.199" },
+ "engines": { "node": ">= 0.2.0" },
"dependencies": {
"cli": ">=0.2.0",
- "yui3": ">=0.5.17"
+ "yui3": ">=0.5.19"
+ "yui3": "3.3.0"
},
"licenses":[
{

0 comments on commit e6ca4af

Please sign in to comment.