d1fa039a by Adam Heath

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

hierarchy.
1 parent a78bd6c7
{
"name": "grunt-monty-python",
"version": "2016.05.27-0",
"version": "2016.05.27-1",
"ignore": [
"**/.*",
"node_modules",
......
......@@ -44,6 +44,20 @@ module.exports = function (grunt) {
});
grunt.registerTask('fixRequireConfig', function fixRequireConfig() {
function compressPaths(paths, result) {
var prop, value, ptr, i, token, tokens, last;
for (prop in paths) {
ptr = result;
tokens = prop.split('/');
last = tokens.pop();
for (i in tokens) {
token = tokens[i];
ptr = ptr[token] || (ptr[token] = {});
}
ptr[last] = paths[prop].replace(/^(?:.*\/)?([a-f0-9]+)\..*$/, '$1');
}
return result;
}
var config = grunt.config('montyPython.config');
var featureFlags = grunt.config('montyPython.featureFlags');
var segment = {}, segments = {};
......@@ -75,7 +89,7 @@ module.exports = function (grunt) {
grunt.log.oklns('map: ' + id + ' -> ' + file);
segment[id] = file;
});
segments.paths = segment;
segments.paths = compressPaths(segment, {});
segment = {};
}
}
......@@ -113,9 +127,22 @@ module.exports = function (grunt) {
if (notEmptyCount) {
lines = [
'(function(require, overlay) {',
' function expandPaths(paths, prefix, result) {',
' var prop, value;',
' for (prop in paths) {',
' value = paths[prop];',
' if (typeof value === "string") {',
' result[prefix + prop] = prefix + value + "." + prop;',
' } else {',
' expandPaths(value, prefix + prop + "/", result);',
' }',
' }',
' return result;',
' }',
' var prop, value, ptr, i, list, container;',
' for (prop in overlay) {',
' value = overlay[prop];',
' if (prop === "paths") value = expandPaths(value, "", {});',
' ptr = require;',
' list = prop.split(".");',
' for (i = 0; i < list.length; i++) {',
......
{
"name": "grunt-monty-python",
"version": "2016.05.27-0",
"version": "2016.05.27-1",
"description": "Build system for grunt",
"license": "BSD",
"repository": {
......