From 774683a30ce51c71d377bf4a651e57759619f10d Mon Sep 17 00:00:00 2001 From: tejas s p Date: Wed, 30 Nov 2016 12:58:55 +0530 Subject: [PATCH] AMC:UI:Build adding a front end Grunt build system --- Gruntfile.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 19 +++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 Gruntfile.js create mode 100644 package.json diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..4a89248 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,77 @@ +module.exports = function(grunt) { + grunt.initConfig({ + // pull in all of the dependencies of setup.js into one file + requirejs: { + compile: { + options: { + appDir: 'static', + baseUrl: './js', + dir: 'build/static', + optimize: 'none', + mainConfigFile: 'static/js/setup.js', + modules: [{ + name: 'setup', + }] + } + }, + }, + + // revision setup.js and css files based on content + filerev: { + options: { + algorithm: 'md5', + length: 8 + }, + js: { + src: 'build/static/js/setup.js', + }, + css: { + src: 'build/static/css/*.css', + }, + }, + + // replace filenames with revisioned file names + filerev_replace: { + options: { + assets_root: 'build', + }, + html: { + src: 'build/static/index.html', + }, + }, + + // filerev_replace does not replace data-main argument supplied to + // requirejs, doing that here + replace: { + requirejs: { + src: 'build/static/index.html', + overwrite: true, + replacements: [{ + // 1. replace data-main with the revisioned file name + from: 'static/js/setup', + to: function(match) { + var k, v; + for(k in grunt.filerev.summary) { + v = grunt.filerev.summary[k]; + if(k.indexOf('static/js/setup') !== -1) { + // remove prefix 'build/' and suffix '.js' + return v.slice('build/'.length, -1*'.js'.length); + } + } + return match; + } + }], + }, + }, + + }); + + // load modules + grunt.loadNpmTasks('grunt-contrib-requirejs'); + grunt.loadNpmTasks('grunt-filerev'); + grunt.loadNpmTasks('grunt-filerev-replace'); + grunt.loadNpmTasks('grunt-text-replace'); + + grunt.registerTask('default', ['requirejs', 'filerev', 'filerev_replace', 'replace']); +} + diff --git a/package.json b/package.json new file mode 100644 index 0000000..ceb15bd --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "amc", + "version": "3.7.0", + "description": "AMC client integrated with the new go server", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "tejas@aerospike.com", + "license": "AGPLv3", + "devDependencies": { + "grunt": "^1.0.1", + "grunt-cli": "^1.2.0", + "grunt-contrib-requirejs": "^1.0.0", + "grunt-filerev": "^2.3.1", + "grunt-filerev-replace": "^0.1.5", + "grunt-text-replace": "^0.4.0", + "requirejs": "^2.3.2" + } +}