refactor: join duplicated code
This commit is contained in:
parent
62d4dd456d
commit
5ee99a1e5a
|
@ -111,59 +111,13 @@ class Pipeline {
|
||||||
return fileCb("couldn't find file: " + file.filename);
|
return fileCb("couldn't find file: " + file.filename);
|
||||||
}
|
}
|
||||||
let fileContent = fs.readFileSync('./.embark/' + file.filename).toString();
|
let fileContent = fs.readFileSync('./.embark/' + file.filename).toString();
|
||||||
|
self.runPlugins(file, fileContent, fileCb);
|
||||||
let pipelinePlugins = self.plugins.getPluginsFor('pipeline');
|
|
||||||
|
|
||||||
if (pipelinePlugins.length > 0) {
|
|
||||||
async.eachSeries(pipelinePlugins, function(plugin, pluginCB) {
|
|
||||||
if (file.options && file.options.skipPipeline) {
|
|
||||||
return pluginCB();
|
|
||||||
}
|
|
||||||
|
|
||||||
fileContent = plugin.runPipeline({targetFile: file.filename, source: fileContent});
|
|
||||||
file.modified = true;
|
|
||||||
pluginCB();
|
|
||||||
},
|
|
||||||
function (err) {
|
|
||||||
if (err) {
|
|
||||||
self.logger.error(err.message);
|
|
||||||
}
|
|
||||||
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
let pipelinePlugins = self.plugins.getPluginsFor('pipeline');
|
|
||||||
if (pipelinePlugins.length > 0) {
|
|
||||||
file.content(function(fileContent) {
|
|
||||||
async.eachSeries(pipelinePlugins, function(plugin, pluginCB) {
|
|
||||||
if (file.options && file.options.skipPipeline) {
|
|
||||||
return pluginCB();
|
|
||||||
}
|
|
||||||
|
|
||||||
fileContent = plugin.runPipeline({targetFile: file.filename, source: fileContent});
|
|
||||||
file.modified = true;
|
|
||||||
pluginCB();
|
|
||||||
},
|
|
||||||
function (err) {
|
|
||||||
if (err) {
|
|
||||||
self.logger.error(err.message);
|
|
||||||
}
|
|
||||||
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
file.content(function(fileContent) {
|
file.content(function(fileContent) {
|
||||||
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
self.runPlugins(file, fileContent, fileCb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
function (err, contentFiles) {
|
function (err, contentFiles) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -208,6 +162,31 @@ class Pipeline {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runPlugins(file, fileContent, fileCb) {
|
||||||
|
const self = this;
|
||||||
|
let pipelinePlugins = self.plugins.getPluginsFor('pipeline');
|
||||||
|
if (pipelinePlugins.length <= 0) {
|
||||||
|
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
||||||
|
}
|
||||||
|
async.eachSeries(pipelinePlugins,
|
||||||
|
function(plugin, pluginCB) {
|
||||||
|
if (file.options && file.options.skipPipeline) {
|
||||||
|
return pluginCB();
|
||||||
|
}
|
||||||
|
|
||||||
|
fileContent = plugin.runPipeline({targetFile: file.filename, source: fileContent});
|
||||||
|
file.modified = true;
|
||||||
|
pluginCB();
|
||||||
|
},
|
||||||
|
function (err) {
|
||||||
|
if (err) {
|
||||||
|
self.logger.error(err.message);
|
||||||
|
}
|
||||||
|
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
webpackRun(filename, options, includeModules, importsList, detectErrors, callback) {
|
webpackRun(filename, options, includeModules, importsList, detectErrors, callback) {
|
||||||
let defaultOptions = {
|
let defaultOptions = {
|
||||||
entry: utils.joinPath(fs.dappPath(), filename),
|
entry: utils.joinPath(fs.dappPath(), filename),
|
||||||
|
|
Loading…
Reference in New Issue