From 00ee2b754694b069726d44584856a7531a7d4c7e Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Wed, 21 Aug 2013 17:18:41 -0700 Subject: [PATCH] use recursive build for polymer --- .gitignore | 1 + build.json | 26 ++++++++++++++ gruntfile.js | 98 +++++++++++++++++++++------------------------------- package.json | 5 +-- 4 files changed, 69 insertions(+), 61 deletions(-) create mode 100644 build.json diff --git a/.gitignore b/.gitignore index 0160c94aa8..a4c0557ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ local.json polymer.min* polymer.sandbox* polymer.native* +polymer.concat* diff --git a/build.json b/build.json new file mode 100644 index 0000000000..53f8aa6a3c --- /dev/null +++ b/build.json @@ -0,0 +1,26 @@ +[ + "../platform/build.json", + "src/polymer.js", + "src/boot.js", + "src/lib/lang.js", + "src/lib/job.js", + "src/lib/dom.js", + "src/lib/super.js", + "src/lib/deserialize.js", + "src/api.js", + "src/instance/utils.js", + "src/instance/events.js", + "src/instance/attributes.js", + "src/instance/properties.js", + "src/instance/mdv.js", + "src/instance/base.js", + "src/instance/styles.js", + "src/declaration/path.js", + "src/declaration/styles.js", + "src/declaration/events.js", + "src/declaration/properties.js", + "src/declaration/attributes.js", + "src/declaration/prototype.js", + "src/declaration/polymer-element.js", + "src/deprecated.js" +] diff --git a/gruntfile.js b/gruntfile.js index 0c25bb3709..45c6dab550 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -5,45 +5,26 @@ */ module.exports = function(grunt) { var banner = [grunt.file.read('LICENSE'), '// @version ' + grunt.file.readJSON('package.json').version, ''].join(grunt.util.linefeed); - Platform = [ - '../platform/platform.min.js' - ]; - - PlatformNative = [ - '../platform/platform.native.min.js' - ]; - PlatformSandbox = [ - '../platform/platform.sandbox.min.js' - ]; - - Polymer = [ - "polymer.js", - "boot.js", - "lib/lang.js", - "lib/job.js", - "lib/dom.js", - "lib/super.js", - "lib/deserialize.js", - "api.js", - "instance/utils.js", - "instance/events.js", - "instance/attributes.js", - "instance/properties.js", - "instance/mdv.js", - "instance/base.js", - "instance/styles.js", - "declaration/path.js", - "declaration/styles.js", - "declaration/events.js", - "declaration/properties.js", - "declaration/attributes.js", - "declaration/prototype.js", - "declaration/polymer-element.js", - "deprecated.js" - ].map(function(n) { - return "src/" + n; - }); + // recursive module builder + var path = require('path'); + function readManifest(filename, modules) { + modules = modules || []; + var lines = grunt.file.readJSON(filename); + var dir = path.dirname(filename); + lines.forEach(function(line) { + var fullpath = path.join(dir, line); + if (line.slice(-5) == '.json') { + // recurse + readManifest(fullpath, modules); + } else { + modules.push(fullpath); + } + }); + return modules; + } + + Polymer = readManifest('build.json'); // karma setup var browsers; @@ -81,6 +62,16 @@ module.exports = function(grunt) { browsers: browsers } }, + concat_sourcemap: { + Polymer: { + options: { + sourcesContent: true + }, + files: { + 'polymer.concat.js': Polymer + } + } + }, uglify: { options: { banner: banner, @@ -89,27 +80,11 @@ module.exports = function(grunt) { Polymer: { options: { sourceMap: 'polymer.min.js.map', + sourceMapIn: 'polymer.concat.js.map' //mangle: false, beautify: true, compress: false }, files: { - 'polymer.min.js': [].concat(Platform, Polymer) - } - }, - PolymerNative: { - options: { - sourceMap: 'polymer.native.min.js.map' - }, - files: { - 'polymer.native.min.js': [].concat(PlatformNative, Polymer) - } - }, - PolymerSandbox: { - options: { - sourceMap: 'polymer.sandbox.min.js.map', - //mangle: false, beautify: true, compress: false - }, - files: { - 'polymer.sandbox.min.js': [].concat(PlatformSandbox, Polymer) + 'polymer.min.js': 'polymer.concat.js' } } }, @@ -150,8 +125,6 @@ module.exports = function(grunt) { dest: 'build.log', src: [ 'polymer.min.js', - 'polymer.native.min.js', - 'polymer.sandbox.min.js' ] } }, @@ -161,11 +134,18 @@ module.exports = function(grunt) { // plugins grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-yuidoc'); + grunt.loadNpmTasks('grunt-concat-sourcemap'); grunt.loadNpmTasks('grunt-karma'); grunt.loadNpmTasks('grunt-audit'); // tasks - grunt.registerTask('default', ['uglify', 'audit']); + grunt.registerTask('sourcemap_copy', 'Copy sourcesContent between sourcemaps', function(source, dest) { + var sourceMap = grunt.file.readJSON(source); + var destMap = grunt.file.readJSON(dest); + destMap.sourcesContent = sourceMap.sourcesContent; + grunt.file.write(dest, JSON.stringify(destMap)); + }); + grunt.registerTask('default', ['concat_sourcemap', 'uglify', 'sourcemap_copy:polymer.concat.js.map:polymer.min.js.map', 'audit']); grunt.registerTask('minify', ['uglify']); grunt.registerTask('docs', ['yuidoc']); grunt.registerTask('test', ['karma:polymer']); diff --git a/package.json b/package.json index 39bb0fd305..fa4e36214b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "devDependencies": { "mocha": "*", "chai": "*", - "grunt": "*", + "grunt": "~0.4.1", "grunt-contrib-uglify": "*", "grunt-contrib-yuidoc": "*", "grunt-karma": "*", @@ -12,6 +12,7 @@ "karma-ie-launcher": "*", "karma-script-launcher": "*", "karma-crbot-reporter": "*", - "grunt-audit": "~0.0.1" + "grunt-audit": "~0.0.1", + "grunt-concat-sourcemap": "~0.3.0" } }