@acdf/build
Version:
Build dependency for Adobe Campaign Developer Framework projects
88 lines (74 loc) • 2.88 kB
JavaScript
const fs = require("fs");
const log = require("gulplog");
const path = require("path");
const handlebars = require("handlebars");
const { src, dest } = require("gulp");
const modifyFile = require("gulp-modify-file");
const merge = require("merge-stream");
const common = require("./common");
/**
*
* @param {*} glob
* @param {*} zipPrefix
* @param {*} destinationFolder
* @returns
*/
/**
* Creates a zip at the destinationFolder containing all the files in the glob provided.
*
* @param {object} env the environment object
* @param {object} installation the installation object
* @param {string} glob a glob representing the files to zip
* @param {string} zipPrefix the prefix identifier of the zip file
* @param {string} destinationFolder the folder in which to write the zip file
* @returns a gulp stream
*/
function compileTemplates(env, installation, glob, zipPrefix, destinationFolder) {
return src(glob)
// Compile using properties
.pipe(modifyFile(content => {
const template = handlebars.compile(content);
return template(installation.properties);
}))
// Send to environment-specific dist folder
.pipe(dest(path.resolve(destinationFolder, `${zipPrefix}.${installation.name}-${env.name}`)))
}
/**
* Compiles the configuration and wizard files per installation, per environment using the properties exported
* in the environment files.
*
* @returns the gulp stream
*/
function compileConfigTemplates() {
const envs = common.getEnvs();
// For each environment
const streams = envs.reduce((streams, env) => {
// For each installation
const stream = env.installations.map(installation => {
log.info(`Creating configuration and wizard files for: installation: ${installation.name}, environment: '${env.name}'`);
log.debug("Using properties: ", installation.properties);
const release = common.getRelease(installation.name);
return merge([{
glob: release.confGlobs,
prefix: "conf",
dir: common.paths.dist.absolute.CONF_DIR
},
{
glob: release.wizardGlobs,
prefix: "wizards",
dir: common.paths.dist.absolute.WIZARD_DIR
}]
.filter(artifact => artifact.glob)
.map(artifact => compileTemplates(env, installation, artifact.glob, artifact.prefix, artifact.dir))
);
});
streams.push(stream);
return streams;
}, [])
return merge(streams)
}
module.exports = {
compileConfigTemplates: compileConfigTemplates,
createPackageArtifact: () => common.createArtifact(common.paths.dist.absolute.CONF_DIR),
createWizardArtifact: () => common.createArtifact(common.paths.dist.absolute.WIZARD_DIR)
};