From eed8bd346e31802d69a190202cc8097013e42059 Mon Sep 17 00:00:00 2001 From: edsilv Date: Wed, 17 Jun 2015 11:05:03 +0100 Subject: [PATCH] reorganising build --- Gruntfile.js | 140 ++++----- ..._VersionTemplate._ts => VersionTemplate.ts | 0 build/localise.js | 117 -------- build/theme.js | 276 ------------------ build/utils/copyFiles.js | 21 -- build/utils/version.js | 52 ---- build/version.js | 38 --- examples | 2 +- src/lib/extensions.js | 160 ---------- 9 files changed, 75 insertions(+), 731 deletions(-) rename build/_VersionTemplate._ts => VersionTemplate.ts (100%) delete mode 100644 build/localise.js delete mode 100644 build/theme.js delete mode 100644 build/utils/copyFiles.js delete mode 100644 build/utils/version.js delete mode 100644 build/version.js delete mode 100644 src/lib/extensions.js diff --git a/Gruntfile.js b/Gruntfile.js index eb707fae6..5dbe176fc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,6 @@ -var version = require('./build/version'); -var localise = require('./build/localise'); -var theme = require('./build/theme'); +var version = require('./version'); +var localise = require('./localise'); +var theme = require('./theme'); module.exports = function (grunt) { @@ -8,26 +8,28 @@ module.exports = function (grunt) { function refresh() { packageJson = grunt.file.readJSON("package.json"); - var buildDir = 'build/uv-' + packageJson.version; - grunt.config.set('global.buildDir', buildDir); - var packageDirName = 'uv-' + packageJson.version; - grunt.config.set('global.packageDirName', packageDirName); - grunt.config.set('global.packageDir', 'build/' + packageDirName); + grunt.config.set('dirs.uv', 'uv-' + packageJson.version); } refresh(); grunt.initConfig({ + dirs: { + bower: './lib', + build: './build', + dist: './dist', + examples: './examples', + extensions: './src/extensions', + lib: './src/lib', + modules: './src/modules', + themes: './src/themes' + }, + global: { - bowerDir: './lib', - examplesDir: './examples', - extensionsDir: './src/extensions', minify: 'optimize=none', - modulesDir: './src/modules', - port: '8001', - themesDir: './src/themes' + port: '8001' }, pkg: packageJson, @@ -35,8 +37,8 @@ module.exports = function (grunt) { ts: { dev: { src: [ - './src/_Version.ts', - './src/*.ts', + //'./src/_Version.ts', + //'./src/*.ts', './src/**/*.ts' ], options: { @@ -62,9 +64,9 @@ module.exports = function (grunt) { }, clean: { - build : ['build/uv-*'], - package: ['<%= global.packageDir %>'], - examples: ['<%= global.examplesDir %>/build/uv-*'], + build : ['<%= dirs.build %>'], + dist: ['<%= dirs.dist %>'], + examples: ['<%= dirs.examples %>/build/'], cleanup: ['./src/extensions/*/config/*.js', './src/extensions/*/theme/*.css'] }, @@ -77,7 +79,7 @@ module.exports = function (grunt) { flatten: true, cwd: 'src', src: ['index.html', 'app.html'], - dest: '<%= global.buildDir %>' + dest: '<%= dirs.build %>' }, // js { @@ -85,13 +87,13 @@ module.exports = function (grunt) { flatten: true, cwd: 'src/lib', src: ['embed.js', 'easyXDM.min.js', 'easyxdm.swf', 'json2.min.js', 'require.js', 'l10n.js', 'base64.min.js'], - dest: '<%= global.buildDir %>/lib/' + dest: '<%= dirs.build %>/lib/' }, // extension configuration files { expand: true, src: ['src/extensions/**/config/*.config.js'], - dest: '<%= global.buildDir %>/lib/', + dest: '<%= dirs.build %>/lib/', rename: function(dest, src) { // get the extension name from the src string. @@ -107,7 +109,7 @@ module.exports = function (grunt) { { expand: true, src: ['src/extensions/**/dependencies.js'], - dest: '<%= global.buildDir %>/lib/', + dest: '<%= dirs.build %>/lib/', rename: function(dest, src) { // get the extension name from the src string. @@ -122,24 +124,24 @@ module.exports = function (grunt) { expand: true, flatten: true, src: ['src/extensions/**/lib/*'], - dest: '<%= global.buildDir %>/lib/' + dest: '<%= dirs.build %>/lib/' }, // anything in the module/js folders that isn't // a js file. could be swfs or supporting files // for a 3rd party library - { - expand: true, - flatten: true, - src: ['src/modules/**/lib/*.*', '!src/modules/**/lib/*.js'], - dest: '<%= global.buildDir %>/lib/' - }, + //{ + // expand: true, + // flatten: true, + // src: ['src/modules/**/lib/*.*', '!src/modules/**/lib/*.js'], + // dest: '<%= dirs.build %>/lib/' + //}, // l10n localisation files { expand: true, flatten: false, cwd: 'src/modules/', src: ['**/l10n/**/*.properties'], - dest: '<%= global.buildDir %>/l10n/', + dest: '<%= dirs.build %>/l10n/', rename: function(dest, src) { // get the locale and .properties files. var reg = /.*\/l10n\/(.*)/; @@ -152,7 +154,7 @@ module.exports = function (grunt) { { expand: true, src: ['src/modules/**/html/*'], - dest: '<%= global.buildDir %>/html/', + dest: '<%= dirs.build %>/html/', rename: function(dest, src) { var fileName = src.substr(src.lastIndexOf('/')); @@ -167,31 +169,31 @@ module.exports = function (grunt) { ] }, examples: { - // copy contents of /build to examples. + // copy contents of /build to /examples/build. files: [ { - cwd: '<%= global.buildDir %>', + cwd: '<%= dirs.build %>', expand: true, src: ['**'], - dest: '<%= global.examplesDir %>/<%= global.buildDir %>' + dest: '<%= dirs.examples %>/build' }, // misc { expand: true, flatten: true, src: ['favicon.ico'], - dest: '<%= global.examplesDir %>/' + dest: '<%= dirs.examples %>/' } ] }, - package: { - // copy contents of /build to packageDir. + dist: { + // copy contents of /build to /dist. files: [ { - cwd: '<%= global.buildDir %>', + cwd: '<%= dirs.build %>', expand: true, src: ['**'], - dest: '<%= global.packageDir %>' + dest: '<%= dirs.dist %>' } ] } @@ -202,24 +204,30 @@ module.exports = function (grunt) { files: [ { // extensions - cwd: '<%= global.bowerDir %>', + cwd: '<%= dirs.bower %>', expand: true, src: ['uv-*-extension/**'], - dest: '<%= global.extensionsDir %>' + dest: '<%= dirs.extensions %>' }, { // modules - cwd: '<%= global.bowerDir %>', + cwd: '<%= dirs.bower %>', expand: true, src: ['uv-*-module/**'], - dest: '<%= global.modulesDir %>' + dest: '<%= dirs.modules %>' }, { // themes - cwd: '<%= global.bowerDir %>', + cwd: '<%= dirs.bower %>', expand: true, src: ['uv-*-theme/**'], - dest: '<%= global.themesDir %>' + dest: '<%= dirs.themes %>' + }, + { + // all files that need to be copied from /lib to /src/lib post bower install + cwd: '<%= dirs.bower %>', + src: ['extensions/dist/extensions.js'], + dest: '<%= dirs.lib %>' } ] } @@ -228,27 +236,27 @@ module.exports = function (grunt) { compress: { zip: { options: { - archive: "build/releases/<%= global.packageDirName %>.zip", + archive: "<%= dirs.dist %>/<%= dirs.zip %>.zip", level: 9 }, files: [ { expand: true, cwd: "build/", - src: ["<%= global.packageDirName %>/**"] + src: ["<%= dirs.dist %>/**"] } ] }, tar: { options: { - archive: "build/releases/<%= global.packageDirName %>.tar.gz", + archive: "build/releases/<%= dirs.dist %>.tar.gz", level: 9 }, files: [ { expand: true, cwd: "build/", - src: ["<%= global.packageDirName %>/**" ] + src: ["<%= dirs.dist %>/**" ] } ] } @@ -257,14 +265,14 @@ module.exports = function (grunt) { exec: { // concatenate and compress with r.js build: { - cmd: 'node lib/r.js/dist/r.js -o baseUrl=src/ mainConfigFile=src/app.js name=app <%= global.minify %> out=<%= global.buildDir %>/lib/app.js' + cmd: 'node lib/r.js/dist/r.js -o baseUrl=src/ mainConfigFile=src/app.js name=app <%= global.minify %> out=<%= dirs.build %>/lib/app.js' } }, replace: { html: { - src: ['<%= global.buildDir %>/app.html'], + src: ['<%= dirs.build %>/app.html'], overwrite: true, replacements: [{ from: 'data-main="app"', @@ -274,7 +282,7 @@ module.exports = function (grunt) { js: { // replace window.DEBUG=true // todo: use a compiler flag when available - src: ['<%= global.buildDir %>/lib/app.js'], + src: ['<%= dirs.build %>/lib/app.js'], overwrite: true, replacements: [{ from: /window.DEBUG.*=.*true;/g, @@ -286,7 +294,7 @@ module.exports = function (grunt) { // ../../img/[module]/[image] moduleimages: { // replace img srcs to point to "../../img/[module]/[img]" - src: ['<%= global.buildDir %>/themes/*/css/*/theme.css'], + src: ['<%= dirs.build %>/themes/*/css/*/theme.css'], overwrite: true, replacements: [{ from: /\((?:'|"|)(?:.*modules\/(.*)\/img\/(.*.\w{3,}))(?:'|"|)\)/g, @@ -298,7 +306,7 @@ module.exports = function (grunt) { // ../../../img/[img] themeimages: { // replace img srcs to point to "../../img/[module]/[img]" - src: ['<%= global.buildDir %>/themes/*/css/*/theme.css'], + src: ['<%= dirs.build %>/themes/*/css/*/theme.css'], overwrite: true, replacements: [{ from: /\((?:'|"|)(?:.*themes\/(.*)\/img\/(.*.\w{3,}))(?:'|"|)\)/g, @@ -307,11 +315,11 @@ module.exports = function (grunt) { }, examples: { // replace script paths with latest build version - src: ['<%= global.examplesDir %>/index.html', '<%= global.examplesDir %>/noeditor.html', '<%= global.examplesDir %>/examples.js', '<%= global.examplesDir %>/uv.js'], + src: ['<%= dirs.examples %>/index.html', '<%= dirs.examples %>/noeditor.html', '<%= dirs.examples %>/examples.js', '<%= dirs.examples %>/uv.js'], overwrite: true, replacements: [{ from: /build\/uv.*?\//g, - to: '<%= global.buildDir %>/' + to: '<%= dirs.build %>/' }] } }, @@ -324,7 +332,7 @@ module.exports = function (grunt) { directory: '.', keepalive: true, open: { - target: 'http://localhost:<%= global.port %>/<%= global.examplesDir %>/' + target: 'http://localhost:<%= global.port %>/<%= dirs.examples %>/' } } } @@ -342,7 +350,7 @@ module.exports = function (grunt) { bump: { }, apply: { - src: './build/_VersionTemplate._ts', + src: './VersionTemplate.ts', dest: './src/_Version.ts' } }, @@ -384,9 +392,9 @@ module.exports = function (grunt) { theme(grunt); // to change version manually, edit package.json - grunt.registerTask('dist:upbuild', ['version:bump', 'version:apply', 'build']); - grunt.registerTask('dist:upminor', ['version:bump:minor', 'version:apply', 'build']); - grunt.registerTask('dist:upmajor', ['version:bump:major', 'version:apply', 'build']); + grunt.registerTask('bump:build', ['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', '', function(){ @@ -427,15 +435,15 @@ module.exports = function (grunt) { ); }); - // compress build into .zip package - grunt.registerTask('package', '', function() { + // compress build into .zip + grunt.registerTask('dist', '', function() { refresh(); grunt.task.run( - 'copy:package', + 'copy:dist', 'compress', - 'clean:package' + 'clean:dist' ); }); diff --git a/build/_VersionTemplate._ts b/VersionTemplate.ts similarity index 100% rename from build/_VersionTemplate._ts rename to VersionTemplate.ts diff --git a/build/localise.js b/build/localise.js deleted file mode 100644 index 1cf404d1b..000000000 --- a/build/localise.js +++ /dev/null @@ -1,117 +0,0 @@ -var path = require('path'); -var _ = require('lodash'); -var glob = require('glob'); -var globArray = require('glob-array'); - -module.exports = function (grunt) { - - var options, src; - - grunt.registerMultiTask('localise', 'Creates localised config files.', function () { - - options = this.data.options; - - var dirs = glob.sync('./src/extensions/*/l10n'); - - _.each(dirs, function(dir) { - - if (!grunt.file.isDir(dir)) return; - - localiseExtension(dir); - }); - }); - - function localiseExtension(dir) { - - var locales = getLocales(dir); - - // for each extension/l10n/xx-XX.json localisation file, find its counterpart extension/config/xx-XX.json config file. - // if none is found, fall back to en-GB.json - // extend the config file with the localisation file and locales object. - // copy it to the extension root naming it xx-XX.config.js - - var l10nFiles = getL10nFiles(dir); - - _.each(l10nFiles, function(file) { - var regex = (/(.*)\/l10n\/(.*).json/).exec(file); - - var parent = regex[1] + '/config/'; - var locale = regex[2]; - var path = parent + locale; - var config = path + '.json'; - var dest = path + '.config.js'; - - // check config counterpart exists, if not fall back to en-GB.json - if (!grunt.file.exists(config)){ - config = parent + options.default; - } - - var configJSON = grunt.file.readJSON(config); - var localeJSON = grunt.file.readJSON(file); - - if (configJSON.extends){ - var extJSON = grunt.file.readJSON(configJSON.extends); - configJSON = _.merge(extJSON, configJSON); - } - - if (localeJSON.extends){ - var extJSON = grunt.file.readJSON(localeJSON.extends); - localeJSON = _.merge(localeJSON, extJSON); - } - - var merged = _.merge(configJSON, localeJSON, locales); - - grunt.file.write(dest, JSON.stringify(merged)); - }); - } - - function getLocales(dir) { - // for each extension/l10n dir, get the contained - // l10n files and add them to a config.locales array - - var config = { - localisation:{ - locales: [] - } - }; - - var jsonFiles = getL10nFiles(dir); - - _.each(jsonFiles, function(file) { - - var localeJSON = grunt.file.readJSON(file); - - var localisation = localeJSON.localisation; - - if (!localisation) { - // if it extends another l10n file, get the localisation settings from that. - if (localeJSON.extends){ - var extJSON = grunt.file.readJSON(localeJSON.extends); - localisation = extJSON.localisation; - } - } - - var label = localisation.label; - //var isDefault = !!settings.default; - var baseName = path.basename(file); - var name = baseName.substring(0, baseName.lastIndexOf('.')); - - var locale = { - name: name, - label: label - }; - - //if (isDefault){ - // locale.default = true; - //} - - config.localisation.locales.push(locale); - }); - - return config; - } - - function getL10nFiles(dir){ - return globArray.sync([path.join(dir, '*.json'), '!' + path.join(dir, 'xx-XX.json')]); - } -}; \ No newline at end of file diff --git a/build/theme.js b/build/theme.js deleted file mode 100644 index b5f52ec12..000000000 --- a/build/theme.js +++ /dev/null @@ -1,276 +0,0 @@ -var path = require('path'); -var _ = require('lodash'); -var glob = require('glob'); -var async = require('async'); -var less = require('less'); -var chalk = require('chalk'); -var copyFiles = require('./utils/copyFiles'); - -module.exports = function (grunt) { - - grunt.registerMultiTask('theme', 'Creates themes.', function () { - - if (this.target === 'create') { - create.call(this); - } else if (this.target === 'dist') { - dist.call(this); - } - }); - - // for each theme, compile each extension's theme.less file passing the theme name - function create() { - - this.options = this.data.options || {}; - - var dirs = getThemeDirs(); - - var done = this.async(); - - var options = this.options; - - options.banner = ''; - - if (this.files.length < 1) { - grunt.verbose.warn('Destination not written because no source files were provided.'); - } - - var that = this; - - async.eachSeries(dirs, function(d, nextDirObj) { - var theme = path.basename(d); - - options.modifyVars = { - theme: theme - }; - - async.eachSeries(that.files, function (f, nextFileObj) { - var destFile = path.join(path.dirname(f.dest), theme + '.css'); - - var files = f.src.filter(function (filepath) { - // Warn on and remove invalid source files (if nonull was set). - if (!grunt.file.exists(filepath)) { - grunt.log.warn('Source file "' + filepath + '" not found.'); - return false; - } else { - return true; - } - }); - - if (files.length === 0) { - if (f.src.length < 1) { - grunt.log.warn('Destination ' + chalk.cyan(destFile) + ' not written because no source files were found.'); - } - - // No src files, goto next target. Warn would have been issued above. - return nextFileObj(); - } - - var compiled = []; - var i = 0; - - async.concatSeries(files, function (file, next) { - if (i++ > 0) { - options.banner = ''; - } - - compileLess(file, destFile, options) - .then(function (output) { - compiled.push(output.css); - if (options.sourceMap && !options.sourceMapFileInline) { - var sourceMapFilename = options.sourceMapFilename; - if (!sourceMapFilename) { - sourceMapFilename = destFile + '.map'; - } - grunt.file.write(sourceMapFilename, output.map); - grunt.log.writeln('File ' + chalk.cyan(sourceMapFilename) + ' created.'); - } - process.nextTick(next); - }, - function (err) { - nextFileObj(err); - }); - }, function () { - if (compiled.length < 1) { - grunt.log.warn('Destination ' + chalk.cyan(destFile) + ' not written because compiled files were empty.'); - } else { - var allCss = compiled.join(options.compress ? '' : grunt.util.normalizelf(grunt.util.linefeed)); - grunt.file.write(destFile, allCss); - grunt.log.writeln('File ' + chalk.cyan(destFile) + ' created'); - } - nextFileObj(); - }); - - }, nextDirObj); - }, done); - } - - function dist() { - this.options = this.data.options; - - var dirs = getThemeDirs(); - - _.each(dirs, function(dir) { - var theme = path.basename(dir); - - // ./src/themes/[theme]/img/[image] - // goes to - // [global.buildDir]/themes/[theme]/img/[image] - copyFiles('./src/themes/' + theme + '/img/*', path.join(getThemeDest(theme), 'img')); - - // ./src/extensions/*/theme/[theme].css - // goes to - // [global.buildDir]/themes/[theme]/css/[extension]/theme.css' - copyFiles('./src/extensions/*/theme/' + theme + '.css', path.join(getThemeDest(theme), 'css'), function(src, dest) { - - // get the extension name from the src string. - // ./src/extensions/[extension]/theme/styles.css - var extensionName = src.match(/extensions\/(.*)\/theme/)[1]; - - return path.join(dest, extensionName, 'theme.css'); - }); - - // ./src/modules/*/img/* - // goes to - // [global.buildDir]/themes/[theme]/img/[module]/', - copyFiles('./src/modules/*/img/*', path.join(getThemeDest(theme), 'img'), function(src, dest) { - var fileName = path.basename(src); - - // get the module name from the src string. - // ./src/modules/[module]/img - var moduleName = src.match(/modules\/(.*)\/img/)[1]; - - return path.join(dest, moduleName, fileName); - }); - }); - - //async.eachSeries(dirs, function (d, nextDirObj) { - // var theme = path.basename(d); - // - // grunt.config.set('global.theme', theme); - // - // preAndPostHook(grunt.task.run('copy:theme'), function() { - // nextDirObj(); - // }); - //}, done); - } - - function getThemeDest(theme) { - var buildDir = grunt.config('global.buildDir'); - return path.join(buildDir, 'themes', theme); - } - - //// todo: async, only copy if changed - //function copyFiles(glob, dest, renameFunc) { - // var files = grunt.file.expand(glob); - // - // _.each(files, function(src) { - // var fileName, fileDest; - // - // if (renameFunc){ - // fileDest = renameFunc(src, dest); - // } else { - // fileName = path.basename(src); - // fileDest = path.join(dest, fileName); - // } - // - // grunt.file.copy(src, fileDest); - // }); - //} - - function getThemeDirs() { - return glob.sync('./src/themes/*'); - } - - var compileLess = function(srcFile, destFile, options) { - options = _.assign({filename: srcFile}, options); - options.paths = options.paths || [path.dirname(srcFile)]; - - if (typeof options.paths === 'function') { - try { - options.paths = options.paths(srcFile); - } catch (e) { - grunt.fail.warn(wrapError(e, 'Generating @import paths failed.')); - } - } - - if (options.sourceMap && !options.sourceMapFileInline && !options.sourceMapFilename) { - options.sourceMapFilename = destFile + '.map'; - } - - if (typeof options.sourceMapBasepath === 'function') { - try { - options.sourceMapBasepath = options.sourceMapBasepath(srcFile); - } catch (e) { - grunt.fail.warn(wrapError(e, 'Generating sourceMapBasepath failed.')); - } - } - - if (typeof(options.sourceMap) === "boolean" && options.sourceMap) { - options.sourceMap = { - sourceMapBasepath: options.sourceMapBasepath, - sourceMapFilename: options.sourceMapFilename, - sourceMapInputFilename: options.sourceMapInputFilename, - sourceMapFullFilename: options.sourceMapFullFilename, - sourceMapURL: options.sourceMapURL, - sourceMapRootpath: options.sourceMapRootpath, - outputSourceFiles: options.outputSourceFiles, - sourceMapFileInline: options.sourceMapFileInline - }; - } - - var srcCode = grunt.file.read(srcFile); - - // Equivalent to --modify-vars option. - // Properties under options.modifyVars are appended as less variables - // to override global variables. - var modifyVarsOutput = parseVariableOptions(options['modifyVars']); - if (modifyVarsOutput) { - srcCode += '\n'; - srcCode += modifyVarsOutput; - } - - // Load custom functions - if (options.customFunctions) { - Object.keys(options.customFunctions).forEach(function(name) { - less.functions.functionRegistry.add(name.toLowerCase(), function() { - var args = [].slice.call(arguments); - args.unshift(less); - var res = options.customFunctions[name].apply(this, args); - return typeof res === 'object' ? res : new less.tree.Anonymous(res); - }); - }); - } - - return less.render(srcCode, options) - .catch(function(err) { - lessError(err, srcFile); - }); - }; - - var parseVariableOptions = function(options) { - var pairs = _.pairs(options); - var output = ''; - pairs.forEach(function(pair) { - output += '@' + pair[0] + ':' + pair[1] + ';'; - }); - return output; - }; - - var formatLessError = function(e) { - var pos = '[' + 'L' + e.line + ':' + ('C' + e.column) + ']'; - return e.filename + ': ' + pos + ' ' + e.message; - }; - - var lessError = function(e, file) { - var message = less.formatError ? less.formatError(e) : formatLessError(e); - - grunt.log.error(message); - grunt.fail.warn('Error compiling ' + file); - }; - - var wrapError = function (e, message) { - var err = new Error(message); - err.origError = e; - return err; - }; -}; \ No newline at end of file diff --git a/build/utils/copyFiles.js b/build/utils/copyFiles.js deleted file mode 100644 index 39c5082dd..000000000 --- a/build/utils/copyFiles.js +++ /dev/null @@ -1,21 +0,0 @@ -var path = require('path'); -var _ = require('lodash'); -var glob = require('glob'); -var grunt = require('grunt'); - -module.exports = function copyFiles(glob, dest, renameFunc) { - var files = grunt.file.expand(glob); - - _.each(files, function(src) { - var fileName, fileDest; - - if (renameFunc){ - fileDest = renameFunc(src, dest); - } else { - fileName = path.basename(src); - fileDest = path.join(dest, fileName); - } - - grunt.file.copy(src, fileDest); - }); -} diff --git a/build/utils/version.js b/build/utils/version.js deleted file mode 100644 index fb3cde452..000000000 --- a/build/utils/version.js +++ /dev/null @@ -1,52 +0,0 @@ -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/build/version.js b/build/version.js deleted file mode 100644 index 5541274e7..000000000 --- a/build/version.js +++ /dev/null @@ -1,38 +0,0 @@ -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 diff --git a/examples b/examples index 6647f2d3c..04df80a42 160000 --- a/examples +++ b/examples @@ -1 +1 @@ -Subproject commit 6647f2d3cad6a217297fbb726699abef730399e5 +Subproject commit 04df80a42ffc16c9c15a88fc4d17b04a688b80b2 diff --git a/src/lib/extensions.js b/src/lib/extensions.js deleted file mode 100644 index 563d96a53..000000000 --- a/src/lib/extensions.js +++ /dev/null @@ -1,160 +0,0 @@ -//###################################################### -// Array -//###################################################### -if (!Array.prototype.clone) { - Array.prototype.clone = function () { - return this.slice(0); - }; -} -if (!Array.prototype.contains) { - Array.prototype.contains = function (val) { - return this.indexOf(val) !== -1; - }; -} -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function (searchElement, fromIndex) { - var i = (fromIndex || 0); - var j = this.length; - for (i; i < j; i++) { - if (this[i] === searchElement) { - return i; - } - } - return -1; - }; -} -Array.prototype.indexOfTest = function (test, fromIndex) { - var i = (fromIndex || 0); - var j = this.length; - for (i; i < j; i++) { - if (test(this[i])) - return i; - } - return -1; -}; -Array.prototype.insert = function (item, index) { - this.splice(index, 0, item); -}; -if (!Array.prototype.last) { - Array.prototype.last = function () { - return this[this.length - 1]; - }; -} -Array.prototype.move = function (fromIndex, toIndex) { - this.splice(toIndex, 0, this.splice(fromIndex, 1)[0]); -}; -Array.prototype.remove = function (item) { - var index = this.indexOf(item); - if (index > -1) { - this.splice(index, 1); - } -}; -Array.prototype.removeAt = function (index) { - this.splice(index, 1); -}; -//###################################################### -// Math -//###################################################### -Math.clamp = function (value, min, max) { - return Math.min(Math.max(value, min), max); -}; -Math.constrain = function (value, low, high) { - return Math.clamp(value, low, high); -}; -Math.degreesToRadians = function (degrees) { - return Math.TAU * (degrees / 360); -}; -Math.distanceBetween = function (x1, y1, x2, y2) { - return Math.sqrt(Math.sq(x2 - x1) + Math.sq(y2 - y1)); -}; -Math.lerp = function (start, stop, amount) { - return start + (stop - start) * amount; -}; -Math.mag = function (a, b, c) { - return Math.sqrt(a * a + b * b + c * c); -}; -Math.map = function (value, start1, stop1, start2, stop2) { - return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1)); -}; -Math.normalise = function (num, min, max) { - return (num - min) / (max - min); -}; -Math.radiansToDegrees = function (radians) { - return (radians * 360) / Math.TAU; -}; -/** - * Get a random number between two numbers. - * If 'high' isn't passed, get a number from 0 to 'low'. - * @param {Number} low The low number. - * @param {Number} [high] The high number. - */ -Math.randomBetween = function (low, high) { - if (!high) { - high = low; - low = 0; - } - if (low >= high) - return low; - return low + (high - low) * Math.random(); -}; -Math.roundToDecimalPlace = function (num, dec) { - return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec); -}; -Math.sq = function (n) { - return n * n; -}; -Math.TAU = Math.PI * 2; -//###################################################### -// Number -//###################################################### -Number.prototype.isInt = function () { - return this % 1 === 0; -}; -//###################################################### -// String -//###################################################### -String.prototype.b64_to_utf8 = function () { - return decodeURIComponent(escape(window.atob(this))); -}; -String.prototype.contains = function (str) { - return this.indexOf(str) !== -1; -}; -String.prototype.endsWith = function (str) { - return this.indexOf(str, this.length - str.length) !== -1; -}; -String.format = function () { - var s = arguments[0]; - for (var i = 0; i < arguments.length - 1; i++) { - var reg = new RegExp("\\{" + i + "\\}", "gm"); - s = s.replace(reg, arguments[i + 1]); - } - return s; -}; -String.prototype.ltrim = function () { - return this.replace(/^\s+/, ''); -}; -String.prototype.rtrim = function () { - return this.replace(/\s+$/, ''); -}; -String.prototype.startsWith = function (str) { - return this.indexOf(str) == 0; -}; -String.prototype.toCssClass = function () { - return this.replace(/[^a-z0-9]/g, function (s) { - var c = s.charCodeAt(0); - if (c == 32) - return '-'; - if (c >= 65 && c <= 90) - return '_' + s.toLowerCase(); - return '__' + ('000' + c.toString(16)).slice(-4); - }); -}; -String.prototype.toFileName = function () { - return this.replace(/[^a-z0-9]/gi, '_').toLowerCase(); -}; -String.prototype.trim = function () { - return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); -}; -String.prototype.utf8_to_b64 = function () { - return window.btoa(unescape(encodeURIComponent(this))); -};