From 17c2f574d4a12ef7adeed759da45ebb541303630 Mon Sep 17 00:00:00 2001 From: edsilv Date: Sun, 14 Jun 2015 16:46:51 +0100 Subject: [PATCH] added versioning and release tasks --- .gitignore | 3 +- Gruntfile.js | 76 ++++++++++++++++++++++++++++++--- VersionTemplate.ts | 1 + app/Blocks/Sources/Granular.ts | 2 +- app/Operations/LoadOperation.ts | 2 +- app/Operations/SaveOperation.ts | 2 +- app/_Version.ts | 1 + bower.json | 4 +- package.json | 5 ++- utils/version.js | 52 ++++++++++++++++++++++ version.js | 38 +++++++++++++++++ 11 files changed, 173 insertions(+), 13 deletions(-) create mode 100644 VersionTemplate.ts create mode 100644 app/_Version.ts create mode 100644 utils/version.js create mode 100644 version.js diff --git a/.gitignore b/.gitignore index 043fa002..73b4d11d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ app/.build app/lib .DS_Store npm-debug.log -dist \ No newline at end of file +dist +releases \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 5ed43d43..eac1a454 100644 --- a/Gruntfile.js +++ b/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, @@ -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, @@ -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' + ); + }); + }; \ No newline at end of file diff --git a/VersionTemplate.ts b/VersionTemplate.ts new file mode 100644 index 00000000..f58f5e79 --- /dev/null +++ b/VersionTemplate.ts @@ -0,0 +1 @@ +export var Version = '%VERSION%'; \ No newline at end of file diff --git a/app/Blocks/Sources/Granular.ts b/app/Blocks/Sources/Granular.ts index a58b724c..f971bc61 100644 --- a/app/Blocks/Sources/Granular.ts +++ b/app/Blocks/Sources/Granular.ts @@ -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; diff --git a/app/Operations/LoadOperation.ts b/app/Operations/LoadOperation.ts index 2b2a6846..4d12f4e7 100644 --- a/app/Operations/LoadOperation.ts +++ b/app/Operations/LoadOperation.ts @@ -13,7 +13,7 @@ class LoadOperation implements IOperation return new Promise((resolve) => { $.ajax({ - url: "http://blobdust.azurewebsites.net/api/anonymousblobs/" + this._Id, + url: "http://blokdust.azurewebsites.net/api/anonymousblobs/" + this._Id, type: 'GET', crossDomain: true, dataType: 'json', diff --git a/app/Operations/SaveOperation.ts b/app/Operations/SaveOperation.ts index e7467f41..1e4273ad 100644 --- a/app/Operations/SaveOperation.ts +++ b/app/Operations/SaveOperation.ts @@ -18,7 +18,7 @@ class SaveOperation implements IOperation return new Promise((resolve) => { $.ajax({ - url: "http://blobdust.azurewebsites.net/api/anonymousblobs", + url: "http://blokdust.azurewebsites.net/api/anonymousblobs", type: 'POST', crossDomain: true, dataType: 'json', diff --git a/app/_Version.ts b/app/_Version.ts new file mode 100644 index 00000000..125406a1 --- /dev/null +++ b/app/_Version.ts @@ -0,0 +1 @@ +export var Version = '0.1.2'; \ No newline at end of file diff --git a/bower.json b/bower.json index 6a961956..1b60f15d 100644 --- a/bower.json +++ b/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", @@ -21,4 +21,4 @@ "devDependencies": { "r.js": "~2.1.16" } -} +} \ No newline at end of file diff --git a/package.json b/package.json index ce85c6d5..761dcb57 100644 --- a/package.json +++ b/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", @@ -14,4 +15,4 @@ "grunt-text-replace": "^0.4.0", "grunt-typescript": "^0.6.1" } -} +} \ No newline at end of file diff --git a/utils/version.js b/utils/version.js new file mode 100644 index 00000000..fb3cde45 --- /dev/null +++ b/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]; +} \ No newline at end of file diff --git a/version.js b/version.js new file mode 100644 index 00000000..5541274e --- /dev/null +++ b/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); + } +}; \ No newline at end of file