最后,最简单且最容易理解的解决方案是创建额外的custom 文件夹。
资产
除了普通的应用程序文件之外,我现在得到了带有 2 个子文件夹的 custom 文件夹:A 和 B 每个都包含仅对应于具体项目的 assets (css, img)。
在gulp 中,我使用了yargs 模块,它允许传递参数。从输入中读取项目名称后,我可以查看custom 文件夹中是否有我感兴趣的资源(我刚刚将custom 文件夹添加到资源路径中)。
var customPath = './custom/' + app.name;
exports.paths = {
web: {
//Resources
styles: ['./app/**/*.css', './app/**/*.scss', customPath + '/**/*.css', customPath + '/**/*.scss'],
...
构建任务的调用现在看起来像这样:gulp build --name A。
配置
对包含常量的 AngularJS 的配置文件做了另一件事。我使用了gulp-ng-config 插件,它允许动态构建AngularJS 配置(常量)文件。在我的流程中,首先我检查 custom 配置文件是否存在于我使用的 custom 文件夹中,如果没有,我使用来自应用程序的默认配置文件。
var getAppScripts = function() {
return $.eventStream.merge(
gulp.src(config.paths.web.scripts)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
//.pipe($.eslint())
.pipe($.eslint.format()),
getAppConfig())
.pipe($.angularFilesort());
};
var getAppConfig = function() {
var configFile = config.paths.web.custom + "/app.config.yaml";
if (fs.existsSync(configFile)) {
return gulp.src(configFile)
.pipe($.ngConfig(config.app.name, {
parser: 'yml',
createModule: false
}));
}
else {
return gulp.src(config.paths.web.config);
}
}