diff --git a/lib/core/config.js b/lib/core/config.js index a28d41272..be23c6744 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -2,6 +2,7 @@ var fs = require('./fs.js'); var File = require('./file.js'); var Plugins = require('./plugins.js'); var utils = require('../utils/utils.js'); +var path = require('path'); var Config = function(options) { this.env = options.env; @@ -188,6 +189,18 @@ Config.prototype.loadChainTrackerFile = function() { this.chainTracker = fs.readJSONSync(this.chainsFile); }; +function findMatchingExpression(filename, filesExpressions) { + for (let fileExpression of filesExpressions) { + var matchingFiles = utils.filesMatchingPattern(fileExpression); + for (matchFile of matchingFiles) { + if (matchFile === filename) { + return path.dirname(fileExpression).replace(/\*/g, '') + } + } + } + return path.dirname(filename) +} + Config.prototype.loadFiles = function(files) { var self = this; var originalFiles = utils.filesMatchingPattern(files); @@ -196,7 +209,8 @@ Config.prototype.loadFiles = function(files) { originalFiles.filter(function(file) { return (file[0] === '$' || file.indexOf('.') >= 0); }).filter(function(file) { - readFiles.push(new File({filename: file, type: "dapp_file", path: file})); + let basedir = findMatchingExpression(file, files); + readFiles.push(new File({filename: file, type: "dapp_file", basedir: basedir, path: file})); }); var filesFromPlugins = []; diff --git a/lib/core/file.js b/lib/core/file.js index adce6ab0c..98e49c0c5 100644 --- a/lib/core/file.js +++ b/lib/core/file.js @@ -6,6 +6,7 @@ class File { this.filename = options.filename; this.type = options.type; this.path = options.path; + this.basedir = options.basedir; this.resolver = options.resolver; } diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index d0eb8aef9..de1a9565e 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -111,12 +111,12 @@ class Pipeline { return fileCb("couldn't find file: " + file.filename); } let fileContent = fs.readFileSync('./.embark/' + file.filename).toString(); - fileCb(null, {content: fileContent, filename: file.filename, path: file.path, modified: true}); + fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true}); }); } else { file.content(function(fileContent) { - return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, modified: true}); + return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true}); }); } @@ -138,8 +138,7 @@ class Pipeline { } contentFiles.map(function (file) { - let filename = file.filename.replace('app/', ''); - filename = filename.replace(targetDir, ''); + let filename = file.filename.replace(file.basedir + '/', ''); self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim); fs.copySync(file.path, self.buildDir + targetDir + filename, {overwrite: true});