@flowaccount/nx-aws-cdk
Version:
aws-cdk executors and generators for nx workspace
74 lines • 3.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildTarget = void 0;
const tslib_1 = require("tslib");
const aws_cdk_core_1 = require("@flowaccount/aws-cdk-core");
const path_1 = require("path");
const aws_cdk_core_2 = require("@flowaccount/aws-cdk-core");
const devkit_1 = require("@nx/devkit");
function runSynthExecutor(options, context, awscdkClient = new aws_cdk_core_1.AwsCdkClient((0, aws_cdk_core_1.awsCdkFactory)())) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
devkit_1.logger.info(`Building the cdk application`);
const iterator = yield buildTarget(options, context);
const buildOutput = (yield iterator.next()).value;
if (!buildOutput.success) {
return {
success: false,
};
}
devkit_1.logger.info(`output file ${buildOutput.outfile}`);
devkit_1.logger.info('Preparing cdk synth command');
awscdkClient.cwd = context.cwd;
awscdkClient.printSdkVersion();
options.output = options.output
? (0, path_1.resolve)(context.root, options.output)
: (0, path_1.resolve)(context.root, 'dist/cdk.out');
const synthOptionFlag = options;
const cdkOptionFlag = options;
cdkOptionFlag.app = `node ${buildOutput.outfile}`;
const synthOption = (0, aws_cdk_core_2.getSynthOptions)(synthOptionFlag);
const cdkOption = (0, aws_cdk_core_2.getCdkOptions)(cdkOptionFlag);
const stackPrefix = context.configurationName
? context.configurationName
: 'dev';
awscdkClient.synth(`${stackPrefix}-${options.stackName}`, cdkOption, synthOption);
return {
success: true,
};
});
}
exports.default = runSynthExecutor;
function buildTarget(options, context) {
return tslib_1.__asyncGenerator(this, arguments, function* buildTarget_1() {
var _a, e_1, _b, _c;
try {
for (var _d = true, _e = tslib_1.__asyncValues(startBuild(options, context)), _f; _f = yield tslib_1.__await(_e.next()), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const event = _c;
if (!event.success) {
devkit_1.logger.error('There was an error with the build. See above.');
devkit_1.logger.info(`${event.outfile} was not restarted.`);
}
yield yield tslib_1.__await(event);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) yield tslib_1.__await(_b.call(_e));
}
finally { if (e_1) throw e_1.error; }
}
});
}
exports.buildTarget = buildTarget;
function startBuild(options, context) {
return tslib_1.__asyncGenerator(this, arguments, function* startBuild_1() {
const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget);
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(yield tslib_1.__await((0, devkit_1.runExecutor)(buildTarget, {
watch: options.watch,
}, context)))));
});
}
//# sourceMappingURL=synth.executor.js.map