Commit 1958cd15 authored by Philipp Nowinski's avatar Philipp Nowinski

[FEATURE] allow multiple targets for abovethefold task

parent 011e3655
......@@ -285,28 +285,39 @@ module.exports = class Css extends Task {
resolve();
return;
}
const filename = path.basename(this._config.abovethefold.template);
try {
let html = await inlineSource(this._config.abovethefold.template, {
compress: false
});
let configs;
if (this._config.abovethefold.hasOwnProperty(0)) {
configs = this._config.abovethefold;
} else {
configs = [this._config.abovethefold];
}
await Promise.all(configs.map(async (config) => {
return new Promise(async (resolve) => {
const filename = path.basename(config.template);
try {
let html = await inlineSource(config.template, {
compress: false
});
let distDirectory = this._config.abovethefold.dest;
if (!fs.existsSync(distDirectory)) {
console.log(`${distDirectory} 'does not exist. Create now!'`);
fs.mkdirSync(distDirectory);
}
let distDirectory = config.dest;
if (!fs.existsSync(distDirectory)) {
console.log(`${distDirectory} 'does not exist. Create now!'`);
fs.mkdirSync(distDirectory);
}
await this._writeFile(path.join(distDirectory, filename), html);
} catch (_error) {
if (_error.message.indexOf('ENOENT: no such file') >= 0) {
this._logger.info(`Could not find abovethefold assets for ${this.extensionName}. Skip task.`);
await this._writeFile(path.join(distDirectory, filename), html);
} catch (_error) {
if (_error.message.indexOf('ENOENT: no such file') >= 0) {
this._logger.info(`Could not find abovethefold assets for ${this.extensionName}. Skip task.`);
resolve();
} else {
this._handleError(_error.message);
}
}
this._logger.success(`Written ${chalk.white(path.basename(filename))}`);
resolve();
} else {
this._handleError(_error.message);
}
}
this._logger.success(`Written ${chalk.white(path.basename(filename))}`);
});
}));
resolve();
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment