Created
August 1, 2012 17:22
-
-
Save jshirley/3228961 to your computer and use it in GitHub Desktop.
This is a setup I'm using with a YUI_config to leverage Y.Loader to build static rollup files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is the Node.js file, it will export files directly to | |
`tdp-bundle-min.js` which obviously won't work well for you! | |
This relies on having a YUI_config that can be parsed and | |
passed into Y.Loader. Everything you need should be in this | |
gist, though. You may need to change the path to your | |
YUI_config file (mine is named `bundle.js`). | |
However, it's an easy change, just scroll down and edit it. | |
*/ | |
var config = require('./config/config'), | |
path = require('path'), | |
YUI = require('yui').YUI, | |
Y = YUI(global.config.yui.server), | |
Queue = require('buildy').Queue; | |
Y.use('loader', 'oop'); | |
//Y.log( global.config.bundle.groups ); | |
var loader = new Y.Loader({ | |
base: './node_modules/yui/', | |
ignoreRegistered: true, | |
require: [ 'tdp' ], | |
fetchCSS: false, | |
groups : { | |
'tdp' : Y.merge( | |
Y.clone(global.config.bundle.groups.tdp), | |
{ | |
base : path.join(config.pubDir, config.yui.server.base), | |
combine : false | |
} | |
), | |
'template' : Y.merge( | |
Y.clone(global.config.bundle.groups.template), | |
{ | |
base : path.join(config.pubDir, config.yui.server.base, 'template/'), | |
combine : false, | |
filter : 'min' | |
} | |
) | |
} | |
}); | |
var requirements = loader.resolve(true), | |
file_list = [], | |
queue; | |
/* | |
I have to translate the path that Loader expects to where I want them on disk. | |
This changes tdp-(model|view|whatever)/tdp-(model|view|whatever)-component.js into simply /model/component.js | |
*/ | |
Y.Array.each( requirements.js, function(file) { | |
if ( file.match('tdp-') ) { | |
//console.log("Modifying file: " + file); | |
file = file.replace(/tdp-(\w+).*?\//, '$1/'); | |
file = file.replace(/tdp-(\w+)-/, ''); | |
file = file.replace(/tdp-/, ''); | |
//console.log(" -> " + file); | |
} | |
file_list.push( file ); | |
}); | |
new Queue('build TDP') | |
.task('files', file_list) | |
//.task('jslint') | |
.task('concat') | |
//.task('replace', { regex: "^.*?(?:logger|Y.log).*?(?:;|\\).*;|(?:\r?\n.*?)*?\\).*;).*;?.*?\r?\n", replace: '', flags: 'mg' }) | |
.task('jsminify') | |
//.task('inspect') | |
.task('write', { name: './tdp-bundle-min.js' }) | |
.run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(module) { | |
var comboBase = '/combo?', | |
filter = ( typeof window !== 'undefined' && window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'; | |
// YUI Config. | |
YUI_config = { | |
filter : filter, | |
combine : filter === 'min', | |
allowRollup: false, | |
fetchCSS : false, | |
gallery : /* whatever gallery version you want in the live app, the builder looks at config.json */ | |
modules : { | |
/* Snip */ | |
}, | |
groups : { | |
/* Snip */ | |
} | |
}; | |
// Export if under node.js | |
if ( module ) { | |
module.exports = YUI_config; | |
} | |
}(typeof module !== 'undefined' ? module : null)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Much of this file is taken from Eric Ferraiuolo's wonderful photosnear.me app. | |
http://github.com/ericf/photosnear.me | |
*/ | |
var fs = require('fs'), | |
path = require('path'), | |
Y = require('yui/oop'), | |
// The path to the file you define your YUI_config | |
bundle = require('../root/static/scripts/bundle'), | |
CONFIG_FILE = 'config.json', | |
NODE_ENV = process.env.NODE_ENV, | |
ENV = { | |
development : NODE_ENV !== 'production', | |
production : NODE_ENV === 'production' | |
}; | |
appRoot = process.cwd(), | |
configFile = path.join(__dirname, CONFIG_FILE), | |
config = path.existsSync(configFile) && JSON.parse( fs.readFileSync(configFile, 'utf8') ); | |
//Y.log(bundle); | |
config.bundle = bundle; | |
config.yui.server = { | |
useSync : true, | |
filter : ENV.production ? 'min' : 'raw', | |
base : '/scripts/', | |
gallery : config.yui.gallery, | |
groups : { | |
/* | |
server : Y.merge( | |
Y.clone(config.yui.server), | |
{ | |
base : path.join(config.pubDir, config.yui.server.base), | |
combine : false | |
} | |
), | |
tab : Y.merge( | |
Y.clone(config.yui.tab), | |
{ | |
base : path.join(config.pubDir, config.yui.tab.base), | |
combine : false | |
} | |
) | |
*/ | |
} | |
}; | |
global.config = module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment