UNPKG

@berenddeboer/nx-aws-cdk

Version:

Nx self-inferring plugin for AWS CDK stacks

96 lines 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createNodesV2 = void 0; const devkit_1 = require("@nx/devkit"); const fs_1 = require("fs"); const path_1 = require("path"); // File glob to find all the configuration files for this plugin const cdkConfigGlob = "**/cdk.json"; // Entry function that Nx calls to modify the graph exports.createNodesV2 = [ cdkConfigGlob, async (configFiles, options, context) => { return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context), configFiles, options, context); }, ]; async function createNodesInternal(configFilePath, options, context) { const projectRoot = (0, path_1.dirname)(configFilePath); const fullPath = (0, path_1.join)(context.workspaceRoot, projectRoot); // Bail early if directory doesn't exist if (!(0, fs_1.existsSync)(fullPath)) { return {}; } // Do not create a project if package.json or project.json isn't there. const siblingFiles = (0, fs_1.readdirSync)(fullPath); if (!siblingFiles.includes("package.json") && !siblingFiles.includes("project.json")) { return {}; } // Inferred task final output const synthTarget = { command: `npx cdk synth`, options: { cwd: projectRoot }, cache: true, inputs: [ "default", { externalDependencies: ["aws-cdk"], }, ], outputs: [`{projectRoot}/dist/${projectRoot}`], }; const cdkTarget = { command: `npx cdk`, options: { cwd: projectRoot }, inputs: [ "default", { externalDependencies: ["aws-cdk"], }, ], outputs: [`{projectRoot}/dist/${projectRoot}`], }; const deployTarget = { ...cdkTarget, command: `npx cdk deploy`, }; const diffTarget = { ...cdkTarget, command: `npx cdk diff`, }; const rollbackTarget = { ...cdkTarget, command: `npx cdk rollback`, }; const watchTarget = { ...cdkTarget, command: `npx cdk watch`, }; const destroyTarget = { ...cdkTarget, command: `npx cdk destroy`, }; // Project configuration to be merged into the rest of the Nx configuration const targets = {}; if (options.cdkTargetName) targets[options.cdkTargetName] = cdkTarget; if (options.synthTargetName) targets[options.synthTargetName] = synthTarget; if (options.deployTargetName) targets[options.deployTargetName] = deployTarget; if (options.diffTargetName) targets[options.diffTargetName] = diffTarget; if (options.rollbackTargetName) targets[options.rollbackTargetName] = rollbackTarget; if (options.watchTargetName) targets[options.watchTargetName] = watchTarget; if (options.destroyTargetName) targets[options.destroyTargetName] = destroyTarget; return { projects: { [projectRoot]: { targets, }, }, }; } //# sourceMappingURL=plugin.js.map