d1fa039a by Adam Heath

Add a path compressor to the requirejs output, so the filesystem

hierarchy.
1 parent a78bd6c7
1 { 1 {
2 "name": "grunt-monty-python", 2 "name": "grunt-monty-python",
3 "version": "2016.05.27-0", 3 "version": "2016.05.27-1",
4 "ignore": [ 4 "ignore": [
5 "**/.*", 5 "**/.*",
6 "node_modules", 6 "node_modules",
......
...@@ -44,6 +44,20 @@ module.exports = function (grunt) { ...@@ -44,6 +44,20 @@ module.exports = function (grunt) {
44 }); 44 });
45 45
46 grunt.registerTask('fixRequireConfig', function fixRequireConfig() { 46 grunt.registerTask('fixRequireConfig', function fixRequireConfig() {
47 function compressPaths(paths, result) {
48 var prop, value, ptr, i, token, tokens, last;
49 for (prop in paths) {
50 ptr = result;
51 tokens = prop.split('/');
52 last = tokens.pop();
53 for (i in tokens) {
54 token = tokens[i];
55 ptr = ptr[token] || (ptr[token] = {});
56 }
57 ptr[last] = paths[prop].replace(/^(?:.*\/)?([a-f0-9]+)\..*$/, '$1');
58 }
59 return result;
60 }
47 var config = grunt.config('montyPython.config'); 61 var config = grunt.config('montyPython.config');
48 var featureFlags = grunt.config('montyPython.featureFlags'); 62 var featureFlags = grunt.config('montyPython.featureFlags');
49 var segment = {}, segments = {}; 63 var segment = {}, segments = {};
...@@ -75,7 +89,7 @@ module.exports = function (grunt) { ...@@ -75,7 +89,7 @@ module.exports = function (grunt) {
75 grunt.log.oklns('map: ' + id + ' -> ' + file); 89 grunt.log.oklns('map: ' + id + ' -> ' + file);
76 segment[id] = file; 90 segment[id] = file;
77 }); 91 });
78 segments.paths = segment; 92 segments.paths = compressPaths(segment, {});
79 segment = {}; 93 segment = {};
80 } 94 }
81 } 95 }
...@@ -113,9 +127,22 @@ module.exports = function (grunt) { ...@@ -113,9 +127,22 @@ module.exports = function (grunt) {
113 if (notEmptyCount) { 127 if (notEmptyCount) {
114 lines = [ 128 lines = [
115 '(function(require, overlay) {', 129 '(function(require, overlay) {',
130 ' function expandPaths(paths, prefix, result) {',
131 ' var prop, value;',
132 ' for (prop in paths) {',
133 ' value = paths[prop];',
134 ' if (typeof value === "string") {',
135 ' result[prefix + prop] = prefix + value + "." + prop;',
136 ' } else {',
137 ' expandPaths(value, prefix + prop + "/", result);',
138 ' }',
139 ' }',
140 ' return result;',
141 ' }',
116 ' var prop, value, ptr, i, list, container;', 142 ' var prop, value, ptr, i, list, container;',
117 ' for (prop in overlay) {', 143 ' for (prop in overlay) {',
118 ' value = overlay[prop];', 144 ' value = overlay[prop];',
145 ' if (prop === "paths") value = expandPaths(value, "", {});',
119 ' ptr = require;', 146 ' ptr = require;',
120 ' list = prop.split(".");', 147 ' list = prop.split(".");',
121 ' for (i = 0; i < list.length; i++) {', 148 ' for (i = 0; i < list.length; i++) {',
......
1 { 1 {
2 "name": "grunt-monty-python", 2 "name": "grunt-monty-python",
3 "version": "2016.05.27-0", 3 "version": "2016.05.27-1",
4 "description": "Build system for grunt", 4 "description": "Build system for grunt",
5 "license": "BSD", 5 "license": "BSD",
6 "repository": { 6 "repository": {
......