Skip to content

Instantly share code, notes, and snippets.

@gordonkristan
Last active August 29, 2015 14:02
Show Gist options
  • Save gordonkristan/0d3264dd1ee42087fe99 to your computer and use it in GitHub Desktop.
Save gordonkristan/0d3264dd1ee42087fe99 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var sh = require('execSync');
var FULL_RELEASE = [
'normalize-css',
'jquery',
'jquery-cookie',
'jquery.autoellipsis',
'pickadate',
'handlebars',
'ember',
'em-list-view',
'ember-widgets',
'ember-graph',
'moment',
'traceur-runtime',
'dropzone',
'trackjs'
];
var FULL_DEVELOP = FULL_RELEASE.concat([]);
FULL_DEVELOP.splice(FULL_DEVELOP.indexOf('trackjs'), 1);
var MINIMAL_RELEASE = ['normalize-css', 'jquery', 'trackjs'];
var MINIMAL_DEVELOP = ['normalize-css', 'jquery'];
var MAIN_FILES = {
'normalize-css': {
css: ['normalize.css']
},
'jquery': {
js: ['dist/jquery.js']
},
'jquery-cookie': {
js: ['jquery.cookie.js']
},
'jquery.autoellipsis': {
js: ['src/jquery.autoellipsis.js']
},
'pickadate': {
js: ['lib/compressed/picker.js', 'lib/compressed/picker.date.js'],
css: ['lib/compressed/themes/classic.css', 'lib/compressed/themes/classic.date.css']
},
'handlebars': {
js: ['handlebars.runtime.js']
},
'ember': {
js: ['ember.js']
},
'em-list-view': {
js: ['ember-list-view.js']
},
'ember-widgets': {
js: ['ember-widgets.js']
},
'ember-graph': {
js: ['ember-graph.js']
},
'ember-cloaking': {
js: ['ember-cloaking.js']
},
'moment': {
js: ['min/moment.min.js']
},
'traceur-runtime': {
js: ['traceur-runtime.js']
},
'qunit': {
js: ['qunit/qunit.js'],
css: ['qunit/qunit.css']
},
'dropzone': {
js: ['downloads/dropzone.js']
},
'trackjs': {
js: ['configuration.js', 'trackjs.min.js']
}
};
///////////////////////////////////////
var getFiles = function(include, minified) {
var files = {
js: [],
css: []
};
include.forEach(function(libraryName) {
files.js = files.js.concat((MAIN_FILES[libraryName].js || []).map(function(file) {
return 'lib/' + libraryName + '/' + file;
}));
files.css = files.css.concat((MAIN_FILES[libraryName].css || []).map(function(file) {
return 'lib/' + libraryName + '/' + file;
}));
});
if (minified) {
files.js = files.js.map(function(file) {
var min = file.replace(/\.js$/, '.min.js');
return (fs.existsSync(min) ? min : file);
});
files.css = files.css.map(function(file) {
var min = file.replace(/\.css$/, '.min.css');
return (fs.existsSync(min) ? min : file);
});
}
return files;
};
var concatCss = function(outputFile, include, minified) {
fs.writeFileSync('build/stylesheets/' + outputFile, '');
getFiles(include, minified).css.forEach(function(file) {
fs.appendFileSync('build/stylesheets/' + outputFile, fs.readFileSync(file, { encoding: 'utf8' }));
fs.appendFileSync('build/stylesheets/' + outputFile, '\n\n');
});
};
var concatJs = function(outputFile, include, minified) {
fs.writeFileSync('build/javascripts/' + outputFile, '');
getFiles(include, minified).js.forEach(function(file) {
fs.appendFileSync('build/javascripts/' + outputFile, fs.readFileSync(file, { encoding: 'utf8' }));
fs.appendFileSync('build/javascripts/' + outputFile, '\n\n');
});
};
///////////////////////////////////////
module.exports = function(grunt) {
grunt.registerTask('bower_develop', function() {
concatCss('vendor_full.css', FULL_DEVELOP, false);
concatCss('vendor_minimal.css', MINIMAL_DEVELOP, false);
concatJs('vendor_minimal.js', MINIMAL_DEVELOP, false);
var indexFile = 'build/index.html';
var template = grunt.file.read(indexFile);
grunt.file.write(indexFile, grunt.template.process(template, {
data: {
files: getFiles(FULL_DEVELOP, false).js.map(function(file) {
return '/' + file;
})
}
}));
sh.run('cp -r lib build/');
});
grunt.registerTask('bower_debug', function() {
concatCss('vendor_full.css', FULL_RELEASE, false);
concatJs('vendor_full.js', FULL_RELEASE, false);
concatCss('vendor_minimal.css', MINIMAL_RELEASE, false);
concatJs('vendor_minimal.js', MINIMAL_RELEASE, false);
var indexFile = 'build/index.html';
var template = grunt.file.read(indexFile);
grunt.file.write(indexFile, grunt.template.process(template, {
data: {
files: ['javascripts/vendor_full.js']
}
}));
});
grunt.registerTask('bower_release', function() {
concatCss('vendor_full.css', FULL_RELEASE, true);
concatJs('vendor_full.js', FULL_RELEASE, true);
concatCss('vendor_minimal.css', MINIMAL_RELEASE, true);
concatJs('vendor_minimal.js', MINIMAL_RELEASE, true);
var indexFile = 'build/index.html';
var template = grunt.file.read(indexFile);
grunt.file.write(indexFile, grunt.template.process(template, {
data: {
files: ['javascripts/vendor_full.js']
}
}));
});
};
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="stylesheets/vendor_full.css">
<link rel="stylesheet" href="stylesheets/style.css">
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<div id="app"></div>
<% _.each(files, function(filepath) { %>
<script src="<%= filepath %>"></script>
<% }); %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment