Skip to content
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 692054aa6194080b26d018c8bc5c70985f31ceec @davglass davglass committed Feb 25, 2013
Showing with 1,009 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +25 −0 LICENSE
  3. +32 −0 README.md
  4. +38 −0 package.json
  5. +9 −0 tasks/boot.js
  6. +12 −0 tasks/build.js
  7. +230 −0 tasks/dist.js
  8. +65 −0 tasks/help.js
  9. +162 −0 tasks/npm-build.js
  10. +258 −0 tasks/release.js
  11. +52 −0 tasks/test.js
  12. +16 −0 tasks/travis.js
  13. +58 −0 tasks/yogi-build.js
  14. +43 −0 tests/tasks.js
9 .gitignore
@@ -0,0 +1,9 @@
+**/node_modules/
+**/npm-debug.log
+node_modules/
+.DS_Store
+.*.swp
+.svn
+*~
+coverage
+
25 LICENSE
@@ -0,0 +1,25 @@
+Copyright 2013 Yahoo! Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Yahoo! Inc. nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
32 README.md
@@ -0,0 +1,32 @@
+Grunt YUI Contrib
+=================
+
+Various Grunt tasks used to within the YUI Project.
+
+Usage
+-----
+
+```
+>>
+>> Showing YUI specific help commands
+>>
+
+ build Build the entire library (and npm package) locally with yogi
+ release Build a release (dist, cdn and npm)
+ build-test Build and test the entire library
+ test Test the library with yogi
+ test-cli Test the library via CLI with yogi
+ travis Perform a travis build and test (uses enviroment vars to determine tests)
+ help Show this stuffs
+
+>> Options:
+
+ --release-version=<VERSION> Pass to set the version of the release (required for a release build)
+ --release-build=<BUILD> Pass to set the build number of the release, if not passed the git sha will be used.
+ --cache-build Cache the shifter build.
+```
+
+Build Status
+------------
+
+[![Build Status](https://secure.travis-ci.org/yui/grunt-yui-contrib.png?branch=master)](http://travis-ci.org/yui/grunt-yui-contrib)
38 package.json
@@ -0,0 +1,38 @@
+{
+ "name": "grunt-yui-contrib",
+ "description": "YUI Build Tasks",
+ "version": "0.0.1",
+ "dependencies": {
+ "cpr": "~0.0.6",
+ "timethat": "~0.0.2",
+ "rimraf": "~2.1.4",
+ "cssproc": "~0.0.1"
+ },
+ "peerDependencies": {
+ "grunt": "~0.4.0"
+ },
+ "devDependencies": {
+ "vows": "*",
+ "yui-lint": "~0.1.1",
+ "jshint": "~0.9.0",
+ "istanbul": "~0.1.8"
+ },
+ "keywords": [
+ "yui", "grunt"
+ ],
+ "scripts": {
+ "pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./tasks/*.js",
+ "test": "istanbul cover --print both vows -- --spec ./tests/*.js"
+ },
+ "bugs": { "url" : "http://github.com/yui/grunt-yui-contrib/issues" },
+ "licenses":[
+ {
+ "type" : "BSD",
+ "url" : "https://github.com/yui/grunt-yui-contrib/blob/master/LICENSE"
+ }
+ ],
+ "repository": {
+ "type":"git",
+ "url":"http://github.com/yui/grunt-yui-contrib.git"
+ }
+}
9 tasks/boot.js
@@ -0,0 +1,9 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+module.exports = function(grunt) {
+ grunt.registerTask('boot', 'Booting YUI with Grunt', ['help']);
+};
12 tasks/build.js
@@ -0,0 +1,12 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+module.exports = function(grunt) {
+ grunt.registerTask('build', 'Building YUI', ['yogi-build', 'npm']);
+ grunt.registerTask('build-test', 'Building and testing YUI', ['yogi-build', 'npm', 'test']);
+ grunt.registerTask('all', 'Building and testing YUI', ['build-test']);
+};
+
230 tasks/dist.js
@@ -0,0 +1,230 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+
+var path = require('path'),
+ fs = require('fs'),
+ exists = fs.existsSync || path.existsSync,
+ exec = require('child_process').spawn,
+ cpr = require('cpr').cpr;
+
+module.exports = function(grunt) {
+
+ var VERSION = grunt.option('release-version'),
+ STAMP = [
+ '/*',
+ '<%= buildtag %>',
+ '<%= copyright %>',
+ '<%= license %>',
+ '*/',
+ '',
+ ''
+ ].join('\n'),
+ start = path.join(process.cwd(), 'release', VERSION);
+
+
+ grunt.config.set('version', VERSION);
+
+ grunt.registerTask('dist', 'Create a YUI Dist Release', [
+ 'dist-tag',
+ 'dist-docs',
+ 'dist-api',
+ 'dist-releasenotes',
+ 'dist-tests',
+ 'dist-skins',
+ 'dist-extras'
+ ]);
+
+ grunt.registerTask('dist-tag', 'Tag files with copyright stamp', function() {
+ var stamp = grunt.template.process(STAMP),
+ count = 0;
+ grunt.log.ok('Adding build stamp and copyright');
+ grunt.log.ok('Adding the following stamp to all JS and CSS files');
+ grunt.log.writeln('\n' + stamp);
+ grunt.file.recurse(path.join(start, 'dist', 'build'), function(abs, root, part, file) {
+ if (path.extname(file) === '.js' || path.extname(file) === '.css') {
+ count++;
+ grunt.verbose.writeln(abs);
+ var data = grunt.file.read(abs);
+ grunt.file.write(abs, stamp + data);
+ }
+ });
+ grunt.log.ok('Finished processing ' + count + ' files.');
+ });
+
+ grunt.registerTask('dist-api', 'Dist Release API Docs', function() {
+ grunt.log.writeln('Using YUIDoc to generate docs');
+ var done = this.async(),
+ base = path.join(start, 'dist', 'api'),
+ yuidoc = path.join(process.cwd(), 'node_modules/yogi/node_modules/yuidocjs/lib/cli.js'),
+ fakeJSON = grunt.file.readJSON(path.join(process.cwd(), 'src/common/api/dist.json')),
+ docJSON = path.join(start, 'yuidoc-dist.json'),
+ child;
+
+ fakeJSON.version = VERSION;
+
+ grunt.file.write(docJSON, JSON.stringify(fakeJSON, null, 4) + '\n');
+
+ child = exec(process.execPath, [
+ yuidoc,
+ '--config',
+ docJSON,
+ '--outdir',
+ base
+ ], {
+ cwd: path.join(process.cwd(), 'src'),
+ env: process.env
+ });
+
+ child.on('exit', function(code) {
+ if (code) {
+ grunt.fail.fatal('YUIDoc exited with code ' + code, code);
+ }
+ grunt.log.ok('YUIDoc API Docs Complete');
+ fs.unlinkSync(docJSON);
+ done();
+ });
+ });
+
+ grunt.registerTask('dist-docs', 'Dist Release Docs', function() {
+
+ grunt.log.writeln('Using Selleck to generate docs');
+ var done = this.async(),
+ base = path.join(start, 'dist', 'docs'),
+ selleck = path.join(process.cwd(), 'node_modules/yogi/node_modules/selleck/bin/selleck'),
+ fakeJSON = grunt.file.readJSON(path.join(process.cwd(), 'src/common/docs/dist.json')),
+ selleckJSON = path.join(start, 'selleck-dist.json'),
+ child;
+
+ fakeJSON.yuiVersion = VERSION;
+ grunt.file.write(selleckJSON, JSON.stringify(fakeJSON, null, 4) + '\n');
+
+ child = exec(process.execPath, [
+ selleck,
+ '--meta',
+ selleckJSON,
+ '--out',
+ base
+ ], {
+ cwd: path.join(process.cwd(), 'src'),
+ env: process.env
+ });
+
+ child.on('exit', function(code) {
+ if (code) {
+ grunt.fail.fatal('Selleck exited with code ' + code, code);
+ }
+ grunt.log.ok('Selleck docs complete');
+ fs.unlinkSync(selleckJSON);
+ done();
+ });
+
+ });
+
+ grunt.registerTask('dist-extras', 'Adding extras to release', function() {
+ grunt.log.writeln('Adding extras to release');
+
+ var RM = path.join(process.cwd(), 'README.md'),
+ RRM = path.join(start, 'dist', 'README.md');
+ L = path.join(process.cwd(), 'LICENSE.md'),
+ RL = path.join(start, 'dist', 'LICENSE.md');
+
+ grunt.file.copy(RM, RRM);
+ grunt.file.copy(L, RL);
+
+ });
+
+ grunt.registerTask('dist-skins', 'Munging skins', function() {
+ grunt.log.writeln('Munging skins into the dist');
+ var done = this.async(),
+ base = path.join(start, 'dist', 'build'),
+ skinSrc = {};
+
+ grunt.log.writeln('Creating rollup skins');
+
+ cpr(path.join(process.cwd(), 'src/common/assets'),
+ path.join(base, 'assets'),
+ function() {
+ grunt.file.recurse(base, function(abs, root, part, file) {
+ var skinName, parts, dest;
+ if (grunt.file.isMatch('*/assets/skins/'+'*', part)) {
+ if (file.indexOf('-skin.css') > -1) {
+ skinName = path.basename(part);
+ skinSrc[skinName] = skinSrc[skinName] || [];
+ skinSrc[skinName].push(grunt.file.read(abs));
+ } else {
+ parts = part.split(path.sep);
+ parts.shift();
+ dest = path.resolve(root, parts.join(path.sep), file);
+ grunt.file.copy(abs, dest);
+ }
+ }
+ });
+
+ Object.keys(skinSrc).forEach(function(dir) {
+ var skinFile = path.join(base, 'assets/skin/', dir, 'skin.css');
+ grunt.log.ok('Writing compiled skin:' + skinFile);
+ grunt.file.write(skinFile, skinSrc[dir].join('\n'));
+ });
+ done();
+ });
+
+
+ });
+
+ grunt.registerTask('dist-releasenotes', 'Preparing Dist Release', function() {
+ grunt.log.writeln('Copying Release Notes for release');
+ var base = path.join(start, 'dist', 'releasenotes'),
+ root, dirs, count;
+
+ grunt.file.mkdir(base);
+ root = path.join(process.cwd(), 'src');
+ dirs = fs.readdirSync(root);
+ count = 0;
+ dirs.forEach(function(f) {
+ var history = path.join(root, f, 'HISTORY.md'),
+ newHist;
+ if (exists(history)) {
+ count++;
+ newHist = path.join(base, 'HISTORY.' + f + '.md');
+ grunt.file.copy(history, newHist);
+ }
+ });
+ grunt.log.writeln('Copied ' + count + ' history files.');
+ });
+
+ grunt.registerTask('dist-tests', 'Dist Release Tests', function() {
+ grunt.log.writeln('Copying tests for release');
+ var base = path.join(start, 'dist', 'tests'),
+ done = this.async(),
+ root = path.join(process.cwd(), 'src'),
+ dirs = fs.readdirSync(root),
+ count = 0,
+ complete = 0,
+ check = function() {
+ if (count === complete) {
+ grunt.log.writeln('Copied ' + count + ' test dirs.');
+ done();
+ }
+ };
+
+ grunt.file.mkdir(base);
+
+ dirs.forEach(function(f) {
+ var tests = path.join(root, f, 'tests'),
+ newTests;
+ if (exists(tests)) {
+ count++;
+ newTests = path.join(base, f, 'tests');
+ cpr(tests, newTests, function() {
+ complete++;
+ check();
+ });
+ }
+ });
+ });
+
+};
65 tasks/help.js
@@ -0,0 +1,65 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+/*jshint maxlen: 500 */
+
+module.exports = function(grunt) {
+
+ grunt.registerTask('yui', ['help']);
+
+ grunt.registerTask('help', 'Show YUI Grunt Help', function() {
+ grunt.log.ok('\nShowing YUI specific help commands\n'.white);
+ grunt.log.writeln('');
+ var help = [
+ ['build', 'Build the entire library (and npm package) locally with ' + 'yogi'.magenta],
+ ['release', 'Build a release (dist, cdn and npm)'],
+ ['build-test', 'Build and test the entire library'],
+ ['test', 'Test the library with ' + 'yogi'.magenta],
+ ['test-cli', 'Test the library via CLI with ' + 'yogi'.magenta],
+ ['travis', 'Perform a travis build and test (uses enviroment vars to determine tests)'],
+ ['help', 'Show this stuffs']
+ ], len = 0,
+ pad = function(line) {
+ for (var i = line.length; i < len; i++) {
+ line += ' ';
+ }
+ return ' ' + line.yellow + '\t';
+ }, opts = [
+ ['--release-version=<VERSION>', 'Pass to set the version of the release ' + '(required for a release build)'.red],
+ ['--release-build=<BUILD>', 'Pass to set the build number of the release, if not passed the git sha will be used.'],
+ ['--cache-build', 'Cache the ' + 'shifter'.magenta + ' build.'.white]
+ ];
+
+ help.forEach(function(item) {
+ var line = item[0];
+ if (line.length > len) {
+ len = line.length;
+ }
+ });
+
+ help.forEach(function(item) {
+ grunt.log.writeln(pad(item[0]) + item[1].white);
+ });
+
+ grunt.log.writeln('');
+ grunt.log.ok('Options:');
+ grunt.log.writeln('');
+ len = 0;
+
+ opts.forEach(function(item) {
+ var line = item[0];
+ if (line.length > len) {
+ len = line.length;
+ }
+ });
+
+ opts.forEach(function(item) {
+ grunt.log.writeln(pad(item[0]) + item[1].white);
+ });
+
+ });
+
+};
162 tasks/npm-build.js
@@ -0,0 +1,162 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+var fs = require('fs'),
+ path = require('path'),
+ rimraf = require('rimraf'),
+ cpr = require('cpr').cpr,
+ exists = fs.existsSync || path.existsSync,
+ BASE = process.cwd(),
+ start = path.join(BASE, './build-npm'),
+ debugIndex = 'exports.path = function() {' +
+ ' return __dirname;' +
+ '};\n' +
+ 'var YUI = require("./yui-nodejs/yui-nodejs-debug").YUI;\n' +
+ 'YUI.applyConfig({ debug: true, filter: "debug" });\n' +
+ 'exports.YUI = YUI;\n',
+
+ makeIndex = function(mod, p) {
+ var o = '../index', str;
+ if (p) {
+ o = './index';
+ }
+ str = 'var inst = require("' + o + '").getInstance();\n';
+ str += 'module.exports = inst.use("' + mod + '");\n';
+ return str;
+ },
+ makeDebug = function(mod, p) {
+ var o = '../index', str;
+ if (p) {
+ o = './index';
+ }
+
+ str = 'var inst = require("' + o + '").getInstance();\n';
+ str += 'inst.applyConfig({ debug: true, filter: "debug" });\n';
+ str += 'module.exports = inst.use("' + mod + '");\n';
+ return str;
+ };
+
+
+module.exports = function(grunt) {
+
+ var VERSION = grunt.option('release-version');
+
+ //Create the npm task
+ grunt.registerTask('npm', 'Building YUI npm package', ['npm-boot', 'npm-clean', 'npm-copy', 'npm-process', 'npm-package']);
+
+ grunt.registerTask('npm-boot', 'Bootstrapping npm package', function() {
+ var log = 'Creating development NPM build';
+ if (grunt.option('release')) {
+ log = 'Creating NPM Release Build';
+ start = path.join(BASE, 'release', VERSION, 'npm');
+ }
+ grunt.log.ok(log);
+ });
+
+ grunt.registerTask('npm-copy', 'Bootstrapping npm package', function() {
+ var done = this.async(),
+ from = path.join(process.cwd(), 'build/');
+
+ grunt.log.write('Copying to build dir');
+ cpr(from, start, function() {
+ grunt.log.writeln('...OK');
+ grunt.file.copy(path.join(process.cwd(), 'README.md'), path.join(start, 'README.md'));
+ grunt.file.copy(path.join(process.cwd(), 'package.json'), path.join(start, 'package.json'));
+ grunt.file.copy(path.join(process.cwd(), 'src/common/npm/package_index.js'), path.join(start, 'index.js'));
+ done();
+ });
+ });
+
+ grunt.registerTask('npm-clean', 'Cleaning npm package', function() {
+ grunt.log.write('Deleting old build-npm directory');
+ var done = this.async();
+ rimraf(start, function() {
+ grunt.log.writeln('...OK');
+ done();
+ });
+ });
+
+ grunt.registerTask('npm-package', 'Post-processing package.json file', function() {
+ grunt.log.writeln('Removing scripts flag from package.json file');
+ var done = this.async(),
+ jsonFile = path.join(start, 'package.json');
+
+ fs.readFile(jsonFile, 'utf8', function(err, json) {
+ json = JSON.parse(json);
+ delete json.scripts;
+
+ if (VERSION) {
+ grunt.log.writeln('Found version: ' + VERSION);
+ json.version = VERSION;
+ }
+
+ fs.writeFile(jsonFile, JSON.stringify(json, null, 4) + '\n', 'utf8', function() {
+ grunt.log.ok('package.json patched');
+ done();
+ });
+ });
+ });
+
+ grunt.registerTask('npm-process', 'Processing npm package', function() {
+ var done = this.async(),
+ Y, dirs, p,
+ YUI;
+
+ if (!exists(start)) {
+ grunt.fail.fatal('Out directory does not exist, exiting.. (' + start + ')');
+ }
+
+ YUI = require(path.join(start, 'yui/yui')).YUI;
+
+ YUI.Env.core = [];
+ Y = YUI(); //This makes YUI.Env.aliases valid
+
+
+ start = path.resolve(start);
+
+
+ process.chdir(start);
+
+ grunt.log.write('Writing index.js files');
+ dirs = fs.readdirSync(start);
+ dirs.forEach(function(mod) {
+ var p = path.join(start, mod, 'index.js'),
+ d = path.join(start, mod, 'debug.js'),
+ stat = fs.statSync(path.join(start, mod));
+
+ if (stat.isDirectory()) {
+ fs.writeFileSync(p, makeIndex(mod), 'utf8');
+ fs.writeFileSync(d, makeDebug(mod), 'utf8');
+ }
+ });
+ grunt.log.writeln('...OK');
+
+ grunt.log.write('Writing seed debug file');
+
+ p = path.join(start, 'debug.js');
+ fs.writeFileSync(p, debugIndex, 'utf8');
+ grunt.log.writeln('...OK');
+
+ grunt.log.write('Writing alias files');
+ Object.keys(YUI.Env.aliases).forEach(function(mod) {
+ var index = makeIndex(mod, true),
+ p = path.join(start, mod + '.js');
+
+ fs.writeFileSync(p, index, 'utf8');
+ });
+ grunt.log.writeln('...OK');
+
+ grunt.log.ok('NPM Release Ready');
+
+ //Change back to root dir
+ process.chdir(BASE);
+
+ done();
+
+ });
+
+};
+
258 tasks/release.js
@@ -0,0 +1,258 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+
+var path = require('path'),
+ fs = require('fs'),
+ timethat = require('timethat'),
+ cpr = require('cpr').cpr,
+ crypto = require('crypto'),
+ cssproc = require('cssproc'),
+ rimraf = require('rimraf');
+
+module.exports = function(grunt) {
+
+ var VERSION = grunt.option('release-version'),
+ BUILD = grunt.option('release-build'),
+ start = path.join(process.cwd(), 'release', VERSION),
+ startTime, head, sha;
+
+ if (VERSION && (!BUILD || BUILD === 'git' || BUILD === 'sha')) {
+ head = grunt.file.read('.git/HEAD').replace('ref: ', '').trim();
+ if (head) {
+ sha = grunt.file.read(path.join('.git/', head)).trim();
+ if (sha) {
+ sha = sha.substr(0, 7);
+ grunt.log.warn('No --release-build passed, using sha: ' + sha);
+ BUILD = sha;
+ grunt.config.set('build', BUILD);
+ }
+ }
+ }
+
+ grunt.config.set('version', VERSION);
+
+ grunt.registerTask('release', 'Create a YUI Release', [
+ 'release-boot',
+ 'release-prebuild',
+ 'release-prep',
+ 'release-clean',
+ 'build',
+ 'dist',
+ 'cdn',
+ 'cdn-ssl',
+ 'release-validate',
+ 'release-zip',
+ 'release-finish'
+ ]);
+ grunt.registerTask('release-prebuild', 'Build and test before prep', [
+ 'build',
+ 'test'
+ ]);
+
+ grunt.registerTask('release-validate', 'Validate the release before zipping', function() {
+ grunt.log.ok('Validating the Release files.');
+ /*
+ Only looks for common, predictable files to make sure the other
+ tasks did their job.
+ */
+ var dirs = [
+ 'cdn',
+ 'cdn/build',
+ 'cdn/build/yui',
+ 'cdn/build/yui/yui-min.js',
+ 'cdn-ssl',
+ 'cdn-ssl/build',
+ 'cdn-ssl/build/yui',
+ 'cdn-ssl/build/yui/yui-min.js',
+ 'npm',
+ 'npm/package.json',
+ 'npm/index.js',
+ 'npm/debug.js',
+ 'dist',
+ 'dist/api',
+ 'dist/api/index.html',
+ 'dist/api/data.json',
+ 'dist/docs',
+ 'dist/docs/index.html',
+ 'dist/releasenotes',
+ 'dist/releasenotes/HISTORY.yui.md',
+ 'dist/tests',
+ 'dist/tests/yui/tests/unit/index.html',
+ 'dist/README.md',
+ 'dist/LICENSE.md'
+ ],
+ fail = function(file) {
+ grunt.fail.fatal('Failed to find: ' + file);
+ },
+ base = path.join('release', VERSION);
+
+ if (!grunt.file.exists(base)) {
+ fail(base);
+ } else {
+ grunt.log.writeln('Found!: '.green + base.cyan);
+ }
+
+ dirs.forEach(function(d) {
+ var file = path.join(base, d);
+ if (!grunt.file.exists(file)) {
+ fail(file);
+ } else {
+ grunt.log.writeln('Found!: '.green + file.cyan);
+ }
+ });
+
+ });
+
+ grunt.registerTask('release-zip', 'Zipping up', [
+ 'compress:dist',
+ 'compress:cdn',
+ 'compress:cdn-ssl',
+ 'release-md5'
+ ]);
+
+ grunt.registerTask('release-md5', 'Create MD5 for release file', function() {
+ var done = this.async(),
+ file = path.join(start, 'archives', 'yui_' + VERSION + '.zip'),
+ md5File = file + '.MD5',
+ shasum = crypto.createHash('md5'),
+ s = fs.ReadStream(file),
+ finish = function() {
+ grunt.log.ok('Checking for release zips');
+ var files = [
+ 'akamai_' + VERSION + '.zip',
+ 'akamaissl_' + VERSION + '.zip',
+ 'yui_' + VERSION + '.zip',
+ 'yui_' + VERSION + '.zip.MD5'
+ ];
+ files.forEach(function(f) {
+ var file = path.join('release', VERSION, 'archives', f);
+ if (grunt.file.exists(file)) {
+ grunt.log.writeln('Found!: '.green + ' ' + file.cyan);
+ } else {
+ grunt.fail.fatal('Failed to find: ' + file.red);
+ }
+ });
+ done();
+ };
+
+ s.on('data', function(d) { shasum.update(d); });
+ s.on('end', function() {
+ var md5 = shasum.digest('hex');
+ grunt.log.ok('Setting MD5 for release to: ' + md5);
+ grunt.log.writeln('');
+ grunt.file.write(md5File, md5 + '\n');
+ finish();
+ });
+ });
+
+ grunt.registerTask('release-boot', 'Booting the YUI Release', function() {
+ startTime = new Date();
+
+ if (!VERSION) {
+ grunt.fail.fatal('No version found, use --release-version=x.y.z');
+ }
+
+ if (!BUILD) {
+ grunt.fail.fatal('No build number found, use --release-build=x.y.z');
+ }
+
+ grunt.log.ok('Preparing YUI release for ' + VERSION + ', building and testing raw');
+ });
+
+ grunt.registerTask('release-prep', 'Booting the YUI Release', function() {
+ grunt.cli.options.release = true;
+ grunt.log.ok('All tests passed, starting offical build now');
+ });
+
+ grunt.registerTask('release-finish', 'Complete the YUI Release', function() {
+ var endTime = new Date();
+ grunt.log.ok('YUI Release for ' + VERSION + ' completed in ' + timethat.calc(startTime, endTime));
+ });
+
+ grunt.registerTask('release-clean', 'Cleaning release', function() {
+ grunt.log.write('Deleting release directory');
+ var done = this.async();
+ rimraf(start, function() {
+ grunt.log.writeln('...OK');
+ done();
+ });
+ });
+
+ grunt.registerTask('cdn', 'Preparing CDN Release', function() {
+ grunt.log.writeln('Preparing CDN Release');
+ var done = this.async(),
+ source = path.join(start, 'dist', 'build'),
+ dest = path.join(start, 'cdn', 'build');
+
+ grunt.log.write('Copying build');
+
+ cpr(source, dest, function() {
+ grunt.log.writeln('...OK');
+ grunt.log.writeln('Processing CSS files');
+ var count = 0,
+ complete = 0;
+
+ grunt.file.recurse(dest, function(file) {
+ if (path.extname(file) === '.css') {
+ count++;
+ var str = grunt.file.read(file);
+ cssproc.parse({
+ root: path.join(dest, '../'),
+ path: file,
+ base: 'http:/'+'/yui.yahooapis.com/' + VERSION + '/'
+ }, str, function(err, data) {
+ if (str !== data) {
+ complete++;
+ grunt.file.write(file, data);
+ }
+ });
+ }
+ });
+
+ grunt.log.writeln('Processed ' + complete + ' of ' + count + ' css files.');
+ done();
+ });
+
+ });
+
+ grunt.registerTask('cdn-ssl', 'Preparing CDN SSL Release', function() {
+ grunt.log.writeln('Preparing CDN SSL Release');
+ var done = this.async(),
+ source = path.join(start, 'dist', 'build'),
+ dest = path.join(start, 'cdn-ssl', 'build');
+
+ grunt.log.write('Copying build');
+
+ cpr(source, dest, function() {
+ grunt.log.writeln('...OK');
+ grunt.log.writeln('Processing CSS files');
+ var count = 0,
+ complete = 0;
+
+ grunt.file.recurse(dest, function(file) {
+ if (path.extname(file) === '.css') {
+ count++;
+ var str = grunt.file.read(file);
+ cssproc.parse({
+ root: path.join(dest, '../'),
+ path: file,
+ base: 'https:/'+'/yui-s.yahooapis.com/' + VERSION + '/'
+ }, str, function(err, data) {
+ if (str !== data) {
+ complete++;
+ grunt.file.write(file, data);
+ }
+ });
+ }
+ });
+
+ grunt.log.writeln('Processed ' + complete + ' of ' + count + ' css files.');
+ done();
+ });
+ });
+
+};
52 tasks/test.js
@@ -0,0 +1,52 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+
+var exec = require('child_process').spawn,
+ path = require('path');
+
+module.exports = function(grunt) {
+ var CLI = false;
+
+ grunt.registerTask('test-cli', 'Testing YUI via the CLI', function() {
+ CLI = true;
+ grunt.task.run('test');
+
+ });
+
+ grunt.registerTask('test', 'Testing YUI', function() {
+ grunt.log.ok('Testing all modules with yogi');
+
+ var done = this.async(),
+ yogi = path.join(process.cwd(), 'node_modules/yogi/bin/yogi.js'),
+ args = [
+ yogi,
+ 'test'
+ ], child;
+
+ if (CLI) {
+ CLI = false;
+ args.push('--cli');
+ }
+
+ child = exec(process.execPath, args, {
+ cwd: path.join(process.cwd(), 'src'),
+ stdio: 'inherit',
+ env: process.env
+ });
+
+ child.on('exit', function(code) {
+ if (code) {
+ grunt.log.fail('yogi test exited with code: ' + code);
+ }
+ done();
+ });
+
+ });
+
+};
+
+
16 tasks/travis.js
@@ -0,0 +1,16 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+module.exports = function(grunt) {
+ grunt.registerTask('travis', 'Perform a travis build', function() {
+ grunt.task.run('build');
+ if (process.env.TRAVIS_NODE_VERSION === '0.8') {
+ grunt.task.run('test');
+ } else {
+ grunt.task.run('test-cli');
+ }
+ });
+};
58 tasks/yogi-build.js
@@ -0,0 +1,58 @@
+/*
+Copyright (c) 2013, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://yuilibrary.com/license/
+*/
+
+
+var exec = require('child_process').spawn,
+ path = require('path');
+
+module.exports = function(grunt) {
+
+ var VERSION = grunt.option('release-version');
+
+ grunt.registerTask('yogi-build', 'Building YUI', function() {
+ var done = this.async(),
+ line = 'Building all modules with yogi',
+ yogi = path.join(process.cwd(), 'node_modules/yogi/bin/yogi.js'),
+ args = [
+ yogi,
+ 'build',
+ '--istanbul'
+ ], child;
+
+ if (grunt.option('release')) {
+ line += ' for release ' + VERSION;
+ }
+ grunt.log.ok(line);
+
+
+ if (grunt.option('release')) {
+ args.push('--replace-version');
+ args.push(VERSION);
+ args.push('--build-dir');
+ args.push(path.join(process.cwd(), 'release/', VERSION, 'dist', 'build'));
+ } else {
+ if (grunt.option('cache-build')) {
+ args.push('--cache');
+ }
+ }
+
+ child = exec(process.execPath, args, {
+ cwd: path.join(process.cwd(), 'src'),
+ stdio: 'inherit',
+ env: process.env
+ });
+
+ child.on('exit', function(code) {
+ if (code) {
+ grunt.log.fail('yogi build exited with code: ' + code);
+ }
+ done();
+ });
+
+ });
+
+};
+
43 tests/tasks.js
@@ -0,0 +1,43 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ path = require('path'),
+ fs = require('fs'),
+ grunt = require('grunt');
+
+grunt.loadTasks(path.join(__dirname, '../tasks'));
+
+var tasks = [];
+
+grunt.task.init([], {help: true});
+Object.keys(grunt.task._tasks).forEach(function(name) {
+ tasks.push(name);
+});
+
+tasks.sort();
+
+//This is a placeholder to ensure we are exporting all defined tasks
+var tests = {
+ 'should export tasks': {
+ topic: function() {
+ return tasks.length;
+ },
+ 'and find 35 tasks': function(topic) {
+ assert.equal(35, topic);
+ }
+ }
+};
+
+
+tasks.forEach(function(name) {
+ tests['should have ' + name] = {
+ topic: function() {
+ return grunt.task._tasks[name]
+ },
+ 'should be an object': function(topic) {
+ assert.isObject(topic);
+ }
+ };
+});
+
+
+vows.describe('tasks').addBatch(tests).export(module);

0 comments on commit 692054a

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