UNPKG

@polyfill-io-aot/builder

Version:

This is the builder module for polyfill-io-aot.

59 lines 2.1 kB
"use strict"; const Bluebird = require("bluebird"); const fs = require("fs-extra"); const path_1 = require("path"); const Executor_1 = require("../Executor"); const BuildEvent_1 = require("../interfaces/BuildEvent"); const symbols_1 = require("../symbols"); /** @internal */ class ValidateSourceDirsExecutor extends Executor_1.Executor { execute() { this.emit(BuildEvent_1.BuildEvent.VALIDATE_DIRS_BEGIN); this._ora.start('Validating source directories'); Bluebird .map(this.builder[symbols_1.COPY_DIRS], (dir) => { return this.map(dir); }) .then(() => { this.emit(BuildEvent_1.BuildEvent.VALIDATE_DIRS_OK); this._ora.succeed('Validated source dirs'); }, (e) => { this._ora.fail(`Failed to validate source dirs: ${this.formatError(e)}`); this.onError(e); }); } innerMap(dir, df) { const statDir = path_1.join(dir.absolute, df); return fs.stat(statDir) .then(stat => { if (stat.isDirectory()) { throw new Error(`Directory ${dir} contains a subdirectory: ${df}`); } this._ora.text = `Validated ${dir}`; }); } map(dir) { this.emit(BuildEvent_1.BuildEvent.VALIDATE_DIR_BEGIN, dir); return fs.stat(dir.absolute) .then(stat => { if (!stat.isDirectory()) { throw new Error(`${dir} is not a directory`); } return fs.readdir(dir.absolute); }) .then((dirFiles) => { if (!dirFiles.includes('config.json')) { throw new Error(`${dir} does not include config.json`); } return Bluebird.map(dirFiles, (df) => { return this.innerMap(dir, df); }); }) .catch((e) => { this.emit(BuildEvent_1.BuildEvent.VALIDATE_DIR_ERR, dir, e); throw e; }); } } module.exports = ValidateSourceDirsExecutor; //# sourceMappingURL=ValidateSourceDirsExecutor.js.map