diff --git a/lib/configwriter.js b/lib/configwriter.js index 929d5de..1c4f5c5 100644 --- a/lib/configwriter.js +++ b/lib/configwriter.js @@ -192,6 +192,8 @@ ConfigWriter.prototype.process = function (file, config) { } else if (context.inDir.indexOf('/' + self.srcStrip) > -1){ regexp = new RegExp('/' + self.srcStrip + '$'); strippedInDir = context.inDir.replace(regexp,''); + } else if (context.inDir === self.srcStrip){ + strippedInDir = ''; } } diff --git a/test/test-config-writer.js b/test/test-config-writer.js index 080d7e0..f50aaa0 100644 --- a/test/test-config-writer.js +++ b/test/test-config-writer.js @@ -151,6 +151,117 @@ describe('ConfigWriter', function () { assert.deepEqual(config, expected); }); + it('should allow removing one level of directory', function () { + var flow = new Flow({ + steps: { + js: ['concat', 'uglifyjs'] + } + }); + + var file = helpers.createFile('foo', 'app', blocks); + var c = new ConfigWriter(flow, { + srcStrip: 'app', + input: 'app', + dest: 'dist', + staging: 'staging' + }); + var config = c.process(file); + var expected = helpers.normalize({ + concat: { + generated: { + files: [{ + dest: 'staging/scripts/site.js', + src: ['app/foo.js', 'app/bar.js', 'app/baz.js'] + }] + } + }, + uglify: { + generated: { + files: [{ + dest: 'dist/scripts/site.js', + src: ['staging/scripts/site.js'] + }] + } + } + }); + + assert.deepEqual(config, expected); + }); + + it('should allow removing parts of directory', function () { + var flow = new Flow({ + steps: { + js: ['concat', 'uglifyjs'] + } + }); + + var file = helpers.createFile('foo', 'app/in/some/dir', blocks); + var c = new ConfigWriter(flow, { + srcStrip: 'app/in', + input: 'app', + dest: 'dist', + staging: 'staging' + }); + var config = c.process(file); + var expected = helpers.normalize({ + concat: { + generated: { + files: [{ + dest: 'staging/some/dir/scripts/site.js', + src: ['app/in/some/dir/foo.js', 'app/in/some/dir/bar.js', 'app/in/some/dir/baz.js'] + }] + } + }, + uglify: { + generated: { + files: [{ + dest: 'dist/some/dir/scripts/site.js', + src: ['staging/some/dir/scripts/site.js'] + }] + } + } + }); + + assert.deepEqual(config, expected); + }); + + it('should allow removing middle parts of directory', function () { + var flow = new Flow({ + steps: { + js: ['concat', 'uglifyjs'] + } + }); + + var file = helpers.createFile('foo', 'app/in/some/dir', blocks); + var c = new ConfigWriter(flow, { + srcStrip: 'in/some', + input: 'app', + dest: 'dist', + staging: 'staging' + }); + var config = c.process(file); + var expected = helpers.normalize({ + concat: { + generated: { + files: [{ + dest: 'staging/app/dir/scripts/site.js', + src: ['app/in/some/dir/foo.js', 'app/in/some/dir/bar.js', 'app/in/some/dir/baz.js'] + }] + } + }, + uglify: { + generated: { + files: [{ + dest: 'dist/app/dir/scripts/site.js', + src: ['staging/app/dir/scripts/site.js'] + }] + } + } + }); + + assert.deepEqual(config, expected); + }); + it('should allow for single step flow', function () { var flow = new Flow({ steps: {