@storm-software/pulumi-tools
Version:
Tools for managing Pulumi infrastructure within a Nx workspace.
134 lines (117 loc) • 3.92 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _chunkQDPXTR73js = require('./chunk-QDPXTR73.js');
var _chunkMVIY32YGjs = require('./chunk-MVIY32YG.js');
// src/generators/init/generator.ts
var _devkit = require('@nx/devkit');
var _fs = require('fs');
var _path = require('path');
async function initGeneratorFn(tree, options, config) {
const task = _chunkMVIY32YGjs.initGenerator.call(void 0, tree, options);
_devkit.addProjectConfiguration.call(void 0, tree, options.name || "deployment", {
root: options.directory || "./deployment",
projectType: "application",
sourceRoot: options.directory || "./deployment",
targets: {
up: {
executor: "@nx-extend/pulumi:up",
options: {}
},
preview: {
executor: "@nx-extend/pulumi:preview",
options: {}
},
refresh: {
executor: "@nx-extend/pulumi:refresh",
options: {}
},
import: {
executor: "@nx-extend/pulumi:import",
options: {}
}
},
tags: ["infra:pulumi"]
});
await _devkit.runTasksInSerial.call(void 0,
generateNewPulumiProject(tree, options, config),
loginToPulumi(tree, options, config),
addPulumiDeps(tree, options),
cleanupProject(tree, options)
)();
if (!options.skipFormat) {
await _devkit.formatFiles.call(void 0, tree);
}
return task;
}
var generator_default = _chunkMVIY32YGjs.withRunGenerator.call(void 0,
"Initialize Storm Pulumi workspace",
initGeneratorFn
);
function generateNewPulumiProject(tree, options, config) {
return () => {
const template = _chunkQDPXTR73js.getCloudTemplateName.call(void 0, options.provider);
_chunkMVIY32YGjs.run.call(void 0,
config,
[
`pulumi new ${template}`,
`--name=${options.name || "deployment"}`,
`--dir=${options.directory || "./deployment"}`,
options.secretsProvider && `--secrets-provider=${options.secretsProvider}`,
"--generate-only",
"--yes",
"--force"
].filter(Boolean).join(" "),
_path.join.call(void 0, config.workspaceRoot, options.directory || "./deployment"),
"inherit"
);
};
}
function loginToPulumi(tree, options, config) {
return () => {
if (!options.login) {
return;
}
if (options.login.startsWith("file://")) {
options.login = `file://${tree.root}/${options.directory || "./deployment"}/${options.login.replace("file://", "")}`;
}
_chunkMVIY32YGjs.run.call(void 0,
config,
["pulumi login", options.login].filter(Boolean).join(" "),
_path.join.call(void 0, config.workspaceRoot, options.directory || "./deployment"),
"inherit",
{
...process.env,
PULUMI_EXPERIMENTAL: "true"
}
);
};
}
function addPulumiDeps(tree, options) {
return () => {
const packageJson = _devkit.readJsonFile.call(void 0, `${options.directory}/package.json`);
if (packageJson) {
_devkit.addDependenciesToPackageJson.call(void 0, tree, {}, packageJson.dependencies || {})();
}
};
}
function cleanupProject(tree, options) {
return () => {
const indexTsLocation = _path.join.call(void 0,
tree.root,
`${options.directory || "./deployment"}/index.ts`
);
tree.write(
`${options.directory}/pulumi.ts`,
_fs.readFileSync.call(void 0, indexTsLocation).toString()
);
_fs.unlinkSync.call(void 0,
_path.join.call(void 0, tree.root, `${options.directory || "./deployment"}/.gitignore`)
);
_fs.unlinkSync.call(void 0,
_path.join.call(void 0, tree.root, `${options.directory || "./deployment"}/package.json`)
);
_fs.unlinkSync.call(void 0,
_path.join.call(void 0, tree.root, `${options.directory || "./deployment"}/tsconfig.json`)
);
};
}
exports.initGeneratorFn = initGeneratorFn; exports.generator_default = generator_default;