nx-serverless-cdk
Version:
nx-serverless-cdk is an Nx plugin for creating AWS CDK applications and libraries inside an Nx monorepo. It offers the possibility to test and debug CDK applications as well as AWS Lambda functions locally. The plugin provides the full flexibility of the
65 lines • 2.44 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.initGenerator = void 0;
const devkit_1 = require("@nx/devkit");
const use_inference_plugins_1 = require("../../utils/use-inference-plugins");
const versions_1 = require("../../utils/versions");
const addPlugin = (tree) => {
const nxJson = (0, devkit_1.readNxJson)(tree);
nxJson.plugins ??= [];
if (!nxJson.plugins.some((p) => typeof p === 'string'
? p === 'nx-serverless-cdk/plugin'
: p.plugin === 'nx-serverless-cdk/plugin')) {
const defaultOptions = {
cdkTargetName: 'cdk',
deployTargetName: 'deploy',
deployAllTargetName: 'deploy-all',
destroyTargetName: 'destroy',
diffTargetName: 'diff',
lsTargetName: 'ls',
synthTargetName: 'synth',
watchTargetName: 'watch',
generateEventTargetName: 'generate-event',
invokeTargetName: 'invoke',
startApiTargetName: 'start-api',
startLambdaTargetName: 'start-lambda',
};
nxJson.plugins.push({
plugin: 'nx-serverless-cdk/plugin',
options: defaultOptions,
});
}
(0, devkit_1.updateNxJson)(tree, nxJson);
};
const addInitDependencies = (tree, versions) => {
return (0, devkit_1.addDependenciesToPackageJson)(tree, {
// CDK dependencies
'aws-cdk-lib': versions['aws-cdk-lib'],
constructs: versions['constructs'],
'source-map-support': versions['source-map-support'],
// TypeScript dependencies
tslib: versions.tslib,
}, {
// CDK development dependencies
'aws-cdk': versions['aws-cdk'],
'tsconfig-paths': versions['tsconfig-paths'],
'ts-node': versions['ts-node'],
// TypeScript development dependencies
'@types/node': versions['@types/node'],
});
};
const initGenerator = async (tree, options) => {
const versions = (0, versions_1.getVersions)();
if ((0, use_inference_plugins_1.useInferencePlugins)(tree)) {
addPlugin(tree);
}
const tasks = [];
tasks.push(addInitDependencies(tree, versions));
if (!options.skipFormat) {
await (0, devkit_1.formatFiles)(tree);
}
return (0, devkit_1.runTasksInSerial)(...tasks);
};
exports.initGenerator = initGenerator;
exports.default = exports.initGenerator;
//# sourceMappingURL=generator.js.map
;