Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test passing, bugs with css and min:false fixed
  • Loading branch information
daomry committed Jan 16, 2013
1 parent 19f3c2e commit e16a604
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 40 deletions.
79 changes: 42 additions & 37 deletions tasks/Aggregation.js
Expand Up @@ -60,26 +60,39 @@ module.exports = function (grunt) {

function setMin(min, aggregation, aggregationFiles, manifest, debugManifest) {
var files = aggregationFiles.filter(js);
if (aggregation.min && files.length) {
var dest = utils.unixpath(aggregation.dest + ".min.js", aggregation.targetDir);
var sources = utils.cleanArray(files, aggregation.sourceDir + "/" + aggregation.package);
if (sources.length) {
min[aggregation.targetDir + '/' + aggregation.package + '#' + aggregation.id] = {
src:sources,
dest:dest
};
if (!aggregation.excludeFromManifest) {
var entry = createManifestEntry(aggregation);
entry.url = utils.unixpath(path.relative(aggregation.manifestPath, dest));
manifest.push(entry);
var dest = utils.unixpath(aggregation.dest + ".min.js", aggregation.targetDir);
var debugEntry = createManifestEntry(aggregation);

if (files.length) {
if (aggregation.min) {

var debugEntry = createManifestEntry(aggregation);
var sources = utils.cleanArray(files, aggregation.sourceDir + "/" + aggregation.package);
if (sources.length) {
min[aggregation.targetDir + '/' + aggregation.package + '#' + aggregation.id] = {
src: sources,
dest: dest
};
}
}
if (!aggregation.excludeFromManifest) {
if (aggregation.copy) {
debugEntry.url = utils.unixpath(path.relative(aggregation.manifestPath, aggregation.targetDir + "/" + aggregation.package));
debugEntry.resources = files.map(function (url) {
return {url:url};
return {url: url};
});
debugManifest.push(debugEntry);
}

if (aggregation.min) {
var entry = createManifestEntry(aggregation);
entry.url = utils.unixpath(path.relative(aggregation.manifestPath, dest));

manifest.push(entry);
} else {
if (aggregation.copy) {
manifest.push(debugEntry);
}
}
}
}
}
Expand All @@ -92,15 +105,15 @@ module.exports = function (grunt) {
if (sources.length) {
sources.forEach(function (script, index) {
min['manymin#' + aggregation.id + '#' + script] = {
src:script,
dest:targets[index]
src: script,
dest: targets[index]
};
});
if (!aggregation.excludeFromManifest) {
var entry = createManifestEntry(aggregation);
entry.url = utils.unixpath(aggregation.package);
entry.resources = files.map(function (url) {
return {url:url};
return {url: url};
});
manifest.push(entry);
debugManifest.push(entry);
Expand All @@ -116,19 +129,19 @@ module.exports = function (grunt) {
var dest = utils.unixpath(aggregation.dest + ".min.css", aggregation.targetDir);
if (src.length > 0) {
mincss[aggregation.targetDir + '/' + aggregation.package + '#' + aggregation.id] = {
files:{
files: {
}
};
mincss[aggregation.targetDir + '/' + aggregation.package + '#' + aggregation.id]
.files[dest] = src;
}
if (!aggregation.excludeFromManifest) {
var entry = createManifestEntry(aggregation, '#css');
entry.url = utils.unixpath(aggregation.package);
entry.resources = files.map(function (url) {
return {url:url};
var debugEntry = createManifestEntry(aggregation, '#css');
debugEntry.url = utils.unixpath(path.relative(aggregation.manifestPath, aggregation.targetDir + "/" + aggregation.package));
debugEntry.resources = files.map(function (url) {
return {url: url};
});
debugManifest.push(entry);
debugManifest.push(debugEntry);

var minEntry = createManifestEntry(aggregation, '#css');
minEntry.url = utils.unixpath(aggregation.dest + ".min.css", aggregation.package);
Expand All @@ -140,21 +153,13 @@ module.exports = function (grunt) {
function setCopy(copy, aggregation, aggregationFiles, manifest, debugManifest) {
if (aggregation.copy) {
var _id = aggregation.targetDir + '/' + aggregation.package + '#' + aggregation.id;
copy[_id] = {files:{}};
copy[_id] = {files: {}};

aggregationFiles.forEach(function (file) {
var src = utils.unixpath(file, aggregation.sourceDir + "/" + aggregation.package);
var target = utils.unixpath(file, aggregation.targetDir + "/" + aggregation.package);
copy[_id].files[target] = src;
});
if (!aggregation.min && !aggregation.manymin && !aggregation.excludeFromManifest) {
var entry = createManifestEntry(aggregation);
entry.url = utils.unixpath(aggregation.targetDir + "/" + aggregation.package);
entry.resources = aggregationFiles.map(function (url) {
return {url:url};
});
debugManifest.push(entry);
}
}
}

Expand All @@ -164,7 +169,7 @@ module.exports = function (grunt) {
var entry = createManifestEntry(aggregation);
entry.url = utils.unixpath(path.relative(aggregation.manifestPath, aggregation.targetDir + "/" + aggregation.package));
entry.resources = aggregationFiles.map(function (url) {
return {url:url};
return {url: url};
});
debugManifest.push(entry);
}
Expand All @@ -183,8 +188,8 @@ module.exports = function (grunt) {

function createManifestEntry(aggregation, idPostFix) {
var entry = {
id:aggregation.id + (idPostFix || ''),
tags:aggregation.tags
id: aggregation.id + (idPostFix || ''),
tags: aggregation.tags
};
if (aggregation.atPhase) {
entry.atPhase = aggregation.atPhase;
Expand Down Expand Up @@ -255,7 +260,6 @@ module.exports = function (grunt) {
function runMin(manifest, min) {
if (options.manymin || options.min) {
if (Object.keys(min).length > 0) {
writeManifest(manifest);
grunt.config.set('min', min);
grunt.verbose.write("Minifying files. ");
grunt.verbose.writeln(JSON.stringify(grunt.config.get('min'), null, 4).cyan);
Expand All @@ -266,7 +270,6 @@ module.exports = function (grunt) {

function runMinCss(manifest, mincss) {
if (options.min && Object.keys(mincss).length > 0) {
writeManifest(manifest);
grunt.config.set('mincss', mincss);
grunt.verbose.write("Minifying CSS files. ");
grunt.verbose.writeln(JSON.stringify(grunt.config.get('mincss'), null, 4).cyan);
Expand Down Expand Up @@ -347,6 +350,8 @@ module.exports = function (grunt) {
});

writeDebugManifest(debugManifest);
writeManifest(manifest);

runLint(lint);
runCopy(copy);
runMin(manifest, min);
Expand Down
25 changes: 25 additions & 0 deletions test/expected/no-min.json
@@ -0,0 +1,25 @@
[
{
"tags": ["all", "dir1", "dir2"],
"id": "all",
"atPhase": "PHASE.ALL",
"url": "no-min",
"resources": [
{
"url": "dir1/subdir1_1/a.js"
},
{
"url": "dir1/subdir1_1/b.js"
},
{
"url": "dir1/subdir1_2/a.js"
},
{
"url": "dir2/a.js"
},
{
"url": "dir2/b.js"
}
]
}
]
4 changes: 2 additions & 2 deletions test/javascript/Aggregation.spec.js
Expand Up @@ -38,11 +38,11 @@ describe("Aggregation manifest grunt plugin", function () {
done();
});

it("should generate a manifest index file", function (done) {
it("should generate a manifest file (no-min.json) when min flag is false", function (done) {
expect('target/no-min.json').toHaveSameParsedContentAs('test/expected/no-min.json', done);
});

it("should generate a manifest debug index file", function (done) {
it("should generate a manifest debug index file (no-min.debug.json) when min flag is false", function (done) {
expect('target/no-min.debug.json').toHaveSameParsedContentAs('test/expected/no-min.debug.json', done);
});
});
Expand Down
4 changes: 3 additions & 1 deletion test/resources/no-min.json
@@ -1,5 +1,6 @@
[
{
"min":false,
"id":"all",
"atPhase":"PHASE.ALL",
"tags":["all", "dir1", "dir2"],
Expand All @@ -11,7 +12,8 @@
],
"exclude":[
"**/exclude.js",
"css/*"
"css/*" ,
"manymin/*"
]
}
]

0 comments on commit e16a604

Please sign in to comment.