Skip to content

Commit

Permalink
added versioning and release tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Jun 14, 2015
1 parent a783b9c commit 17c2f57
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -5,4 +5,5 @@ app/.build
app/lib
.DS_Store
npm-debug.log
dist
dist
releases
76 changes: 71 additions & 5 deletions Gruntfile.js
@@ -1,15 +1,19 @@
var path = require('path'),
connect_livereload = require('connect-livereload');
version = require('./version');

module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-typescript');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-typescript');

version(grunt);

var ports = {
server: 8000,
Expand All @@ -21,13 +25,23 @@ module.exports = function (grunt) {
build: 'app/.build',
dist: 'dist',
lib: 'app/lib',
releases: 'releases',
typings: 'app/typings'
};

var packageJson;

function refresh() {
packageJson = grunt.file.readJSON("package.json");
grunt.config.set('dirs.zip', path.join(dirs.releases, packageJson.version));
}

function mount(connect, dir) {
return connect.static(path.resolve(dir));
}

refresh();

grunt.initConfig({

ports: ports,
Expand Down Expand Up @@ -208,11 +222,63 @@ module.exports = function (grunt) {
minify: {
cmd: 'node app/lib/r.js/dist/r.js -o app.build.js'
}
},

compress: {
zip: {
options: {
mode: "zip",
archive: "<%= dirs.zip %>.zip",
level: 9
},
files: [
{
expand: true,
src: ["<%= dirs.dist %>/**"]
}
]
}
},

version: {
bump: {
},
apply: {
src: './VersionTemplate.ts',
dest: './app/_Version.ts'
}
}
});

grunt.registerTask('bump:patch', ['version:bump', 'version:apply']);
grunt.registerTask('bump:minor', ['version:bump:minor', 'version:apply']);
grunt.registerTask('bump:major', ['version:bump:major', 'version:apply']);
grunt.registerTask('default', ['typescript:build', 'copy:assets']);
grunt.registerTask('serve:dev', ['typescript:build', 'copy:assets', 'connect:dev', 'open', 'watch']);
grunt.registerTask('serve:dist', ['connect:dist', 'open']);
grunt.registerTask('dist', ['clean:dist', 'copy:dist', 'exec:minify', 'clean:minified', 'replace:minified']);

grunt.registerTask('dist', '', function() {

grunt.task.run('bump:patch');

refresh();

grunt.task.run(
'clean:dist',
'copy:dist',
'exec:minify',
'clean:minified',
'replace:minified'
);
});

grunt.registerTask('release', '', function() {

refresh();

grunt.task.run(
'compress:zip'
);
});

};
1 change: 1 addition & 0 deletions VersionTemplate.ts
@@ -0,0 +1 @@
export var Version = '%VERSION%';
2 changes: 1 addition & 1 deletion app/Blocks/Sources/Granular.ts
Expand Up @@ -77,7 +77,7 @@ class Granular extends Source {

console.log(track);
gran.WaveUrl = track.waveform_url;
$.getJSON("http://blobdust.azurewebsites.net/api/Wave64/", {url: gran.WaveUrl}, function(data) {
$.getJSON("http://blokdust.azurewebsites.net/api/Wave64/", {url: gran.WaveUrl}, function(data) {
var waveform;
waveform = new Image();
waveform.src = data.data;
Expand Down
2 changes: 1 addition & 1 deletion app/Operations/LoadOperation.ts
Expand Up @@ -13,7 +13,7 @@ class LoadOperation<String> implements IOperation
return new Promise((resolve) => {

$.ajax(<JQueryAjaxSettings>{
url: "http://blobdust.azurewebsites.net/api/anonymousblobs/" + this._Id,
url: "http://blokdust.azurewebsites.net/api/anonymousblobs/" + this._Id,
type: 'GET',
crossDomain: true,
dataType: 'json',
Expand Down
2 changes: 1 addition & 1 deletion app/Operations/SaveOperation.ts
Expand Up @@ -18,7 +18,7 @@ class SaveOperation<String> implements IOperation
return new Promise((resolve) => {

$.ajax(<JQueryAjaxSettings>{
url: "http://blobdust.azurewebsites.net/api/anonymousblobs",
url: "http://blokdust.azurewebsites.net/api/anonymousblobs",
type: 'POST',
crossDomain: true,
dataType: 'json',
Expand Down
1 change: 1 addition & 0 deletions app/_Version.ts
@@ -0,0 +1 @@
export var Version = '0.1.2';
4 changes: 2 additions & 2 deletions bower.json
@@ -1,6 +1,6 @@
{
"name": "BlokDust",
"version": "0.1.0",
"version": "0.1.2",
"dependencies": {
"fayde": "~0.16.15",
"fayde.controls": "~0.17.0",
Expand All @@ -21,4 +21,4 @@
"devDependencies": {
"r.js": "~2.1.16"
}
}
}
5 changes: 3 additions & 2 deletions package.json
@@ -1,11 +1,12 @@
{
"name": "BlokDust",
"version": "0.1.0",
"version": "0.1.2",
"main": "Gruntfile.js",
"devDependencies": {
"connect-livereload": "^0.4.0",
"grunt": "~0.4.4",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-compress": "^0.13.0",
"grunt-contrib-connect": "^0.8.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-watch": "^0.6.1",
Expand All @@ -14,4 +15,4 @@
"grunt-text-replace": "^0.4.0",
"grunt-typescript": "^0.6.1"
}
}
}
52 changes: 52 additions & 0 deletions utils/version.js
@@ -0,0 +1,52 @@
module.exports = Version;

function Version() {
if (arguments.length === 1) {
var parts = parse(arguments[0]);
this.major = parts[0];
this.minor = parts[1];
this.build = parts[2];
} else if (arguments.length === 3) {
this.major = Number(arguments[0]);
this.minor = Number(arguments[1]);
this.build = Number(arguments[2]);
}
}

Version.prototype.bump = function (type) {
switch (type) {
case 'major':
this.major++;
this.minor = 0;
this.build = 0;
break;
case 'minor':
this.minor++;
this.build = 0;
break;
default:
case 'build':
this.build++;
break;
}
};

Version.prototype.toString = function () {
return this.major + '.' + this.minor + '.' + this.build;
};

function parse(str) {
var tokens = str.split('.');
if (tokens.length !== 3)
throw 'Invalid version format.';
var major = parseInt(tokens[0]);
if (isNaN(major))
throw 'Invalid major version.';
var minor = parseInt(tokens[1]);
if (isNaN(minor))
throw 'Invalid minor version.';
var build = parseInt(tokens[2]);
if (isNaN(build))
throw 'Invalid build version.';
return [major, minor, build];
}
38 changes: 38 additions & 0 deletions version.js
@@ -0,0 +1,38 @@
var Version = require('./utils/version');

module.exports = function (grunt) {
grunt.registerMultiTask('version', 'Configures version.', function () {
if (this.target === 'bump') {
bump(this.data, arguments);
} else if (this.target === 'apply') {
apply(this.data, arguments);
}
});

function bump(data, args) {
try {
var pkg = grunt.file.readJSON('./package.json');
var bower = grunt.file.readJSON('./bower.json');

var vers = new Version(pkg.version);
grunt.log.writeln('Current version: ' + vers);
var part = args[0] || data.part;
vers.bump(part);
grunt.log.writeln('Updated version: ' + vers);

grunt.version = bower.version = pkg.version = vers.toString();
grunt.file.write('./package.json', JSON.stringify(pkg, undefined, 2));
grunt.file.write('./bower.json', JSON.stringify(bower, undefined, 2));
} catch (err) {
grunt.fail.fatal('Error bumping version:' + err);
}

}

function apply(data, args) {
var pkg = grunt.file.readJSON('./package.json');
var template = grunt.file.read(data.src);
var output = template.replace('%VERSION%', pkg.version);
grunt.file.write(data.dest, output);
}
};

0 comments on commit 17c2f57

Please sign in to comment.