Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring tasks code #236

Merged
merged 3 commits into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ node_modules

.DS_Store

components/oc.json
components/base-component-handlebars/_package
components/base-component-jade/_package
src/components/oc.json
src/components/base-component-handlebars/_package
src/components/base-component-jade/_package
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
grunt-tasks
tasks
test
.jshintrc
.travis.yml
appveyor.yml
Gruntfile.js
12 changes: 1 addition & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

var _ = require('underscore');

var customTasks = {
build: require('./grunt-tasks/support/task-build'),
generateCliDoc: require('./grunt-tasks/support/task-generate-cli-doc'),
version: require('./grunt-tasks/support/task-version')
};

module.exports = function(grunt){

var taskObject = { pkg: grunt.file.readJSON('package.json') };

grunt.file.expand('grunt-tasks/*.js', '!grunt-tasks/_*.js').forEach(function(file) {
grunt.file.expand('tasks/*.js', '!tasks/_*.js').forEach(function(file) {
var name = file.split('/');
name = name[name.length - 1].replace('.js', '');
var task = require('./' + file);
Expand Down Expand Up @@ -40,8 +34,4 @@ module.exports = function(grunt){
'gitadd:changelog',
'gitcommit:changelog'
]);

grunt.registerTask('build', 'Builds and minifies the oc-client component', customTasks.build(grunt, taskObject));
grunt.registerTask('generate-cli-doc', 'Automatically updates the cli.md file', customTasks.generateCliDoc);
grunt.registerTask('version', 'Does the version upgrade', customTasks.version(grunt, taskObject));
};
15 changes: 0 additions & 15 deletions grunt-tasks/support/task-generate-cli-doc.js

This file was deleted.

24 changes: 0 additions & 24 deletions grunt-tasks/support/task-version.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/oc-client/_package/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"oc-client","description":"The OpenComponents client-side javascript client","version":"0.30.3","repository":"https://github.com/opentable/oc/tree/master/components/oc-client","author":"Matteo Figus <matteofigus@gmail.com>","oc":{"container":false,"renderInfo":false,"minify":false,"parameters":{},"files":{"template":{"type":"handlebars","hashKey":"bb774de6a2b7280c2b66103bd36d7e708a1b7541","src":"template.js"},"static":["src"],"dataProvider":{"type":"node.js","hashKey":"ffb0e43eaf72f55fa13dc1e7262019c14c3dfc81","src":"server.js"}},"version":"0.30.3","packaged":true,"date":1461936963577}}
{"name":"oc-client","description":"The OpenComponents client-side javascript client","version":"0.30.3","repository":"https://github.com/opentable/oc/tree/master/components/oc-client","author":"Matteo Figus <matteofigus@gmail.com>","oc":{"container":false,"renderInfo":false,"minify":false,"parameters":{},"files":{"template":{"type":"handlebars","hashKey":"bb774de6a2b7280c2b66103bd36d7e708a1b7541","src":"template.js"},"static":["src"],"dataProvider":{"type":"node.js","hashKey":"ffb0e43eaf72f55fa13dc1e7262019c14c3dfc81","src":"server.js"}},"version":"0.30.3","packaged":true,"date":1461939548142}}
16 changes: 9 additions & 7 deletions grunt-tasks/support/task-build.js → tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ var fs = require('fs-extra');
var path = require('path');
var uglifyJs = require('uglify-js');

module.exports = function(grunt, taskObject){
var packageJson = require('../package');

return function(){
module.exports = function(grunt){

grunt.registerTask('build', 'Builds and minifies the oc-client component', function(){

var done = this.async(),
version = taskObject.pkg.version,
clientComponentDir = '../../src/components/oc-client/',
version = packageJson.version,
clientComponentDir = '../src/components/oc-client/',
licenseRow = '/*! OpenComponents client v{0} | (c) 2015-{1} OpenTable, Inc. | {2} */',
licenseLink = 'https://github.com/opentable/oc/tree/master/src/components/oc-client/LICENSES',
license = format(licenseRow, version, new Date().getFullYear(), licenseLink),
Expand All @@ -32,14 +34,14 @@ module.exports = function(grunt, taskObject){

fs.writeFileSync(path.join(__dirname, clientComponentDir, 'src/oc-client.min.js'), compressedCode);
fs.writeFileSync(path.join(__dirname, clientComponentDir, 'src/oc-client.min.map'), compressed.map);
fs.writeFileSync(path.join(__dirname, '../../client/src/oc-client.min.js'), compressedCode);
fs.writeFileSync(path.join(__dirname, '../client/src/oc-client.min.js'), compressedCode);

var Local = require('../../src/cli/domain/local'),
var Local = require('../src/cli/domain/local'),
local = new Local({ logger: { log: grunt.log.writeln }});

local.package(path.join(__dirname, clientComponentDir), function(err, res){
grunt.log[!!err ? 'error' : 'ok'](!!err ? err : 'Client has been built and packaged');
done();
});
};
});
};
File renamed without changes.
18 changes: 18 additions & 0 deletions tasks/generate-cli-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

var fs = require('fs-extra');
var path = require('path');

var commandsParser = require('./support/cli-commands-parser');

module.exports = function(grunt){

grunt.registerTask('generate-cli-doc', 'Automatically updates the cli.md file', function(){

var parsed = commandsParser.parse(),
data = fs.readFileSync(path.join(__dirname, 'support/cli-template.md'), 'utf8'),
newFileData = data.replace('[commands-shortlist]', parsed.commandList).replace('[commands-detailed]', parsed.detailedCommandList);

fs.writeFileSync(path.join(__dirname, '../docs/cli.md'), newFileData);
});
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion grunt-tasks/jshint.js → tasks/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = {
options: {
jshintrc: 'grunt-tasks/support/.jshintrc',
jshintrc: 'tasks/support/.jshintrc',
ignores: [
'node_modules',
'client/src/oc-client.min.js',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions tasks/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

var fs = require('fs-extra');
var path = require('path');
var semver = require('semver');

var packageJson = require('../package');

module.exports = function(grunt, taskObject){

grunt.registerTask('version', 'Does the version upgrade', function(versionType){

packageJson.version = semver.inc(packageJson.version, versionType);
grunt.config.set('version', packageJson.version);

grunt.log.ok('Package version upgrading to: ' + packageJson.version);

fs.writeJsonSync(path.join(__dirname, '../package.json'), packageJson, {spaces: 2});

grunt.task.run([
'test-local-silent',
'generate-cli-doc',
'build',
'git-stage'
]);
});
};