Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Output path respects the hierarchy of the input file. #297 #412

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/configwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ ConfigWriter.prototype.process = function (file, config) {
lfile = new File(file);
}

var relativePath = self.root ? '' : lfile.dir.split('/').splice(1).join('/');

lfile.blocks.forEach(function (block) {

// FIXME: support several searchPath...
var context = {
inDir: self.root || lfile.searchPath[0],
Expand All @@ -165,7 +168,9 @@ ConfigWriter.prototype.process = function (file, config) {

// If this is the last writer of the pipe, we need to output
// in the destination directory
context.outDir = last ? self.dest : path.join(self.staging, writer.name);
context.outDir = last ? path.join(self.dest, relativePath) :
path.join(self.staging, writer.name, relativePath);

context.last = last;
config[writer.name] = config[writer.name] || {};
config[writer.name].generated = config[writer.name].generated || {};
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/relative_path_parent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<head>
</head>
<body>

<!-- build:js ../scripts/thisthat.js -->
<script src="../scripts/this.js"></script>
<script src="../scripts/that.js"></script>
<!-- endbuild -->

</body>
</html>
28 changes: 28 additions & 0 deletions test/test-usemin.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,34 @@ describe('useminPrepare', function () {
});
});

describe('relative path', function () {
it('should have the correct root for generated path', function () {
grunt.log.muted = true;
grunt.config.init();
grunt.config('useminPrepare', { html: 'app/foo/index.html' });
grunt.file.mkdir('app/foo');
grunt.file.copy(path.join(__dirname, 'fixtures/relative_path_parent.html'), 'app/foo/index.html');

grunt.task.run('useminPrepare');
grunt.task.start();

var concat = grunt.config('concat');
assert.ok(concat);
assert.ok(concat.generated);
assert.equal(concat.generated.files.length, 1);
var files = concat.generated.files[0];

assert.equal(files.dest, '.tmp/concat/scripts/thisthat.js');
assert.equal(files.src.length, 2);
assert.equal(files.src[0], 'app/scripts/this.js');

var uglify = grunt.config('uglify');
assert.equal(uglify.generated.files.length, 1);
files = uglify.generated.files[0];
assert.equal(files.dest, 'dist/scripts/thisthat.js');
});
});

it('should take dest option into consideration', function () {
grunt.log.muted = true;
grunt.config.init();
Expand Down