@dev-thought/nx-deploy-it
Version:
[](https://www.npmjs.com/package/@dev-thought/nx-deploy-it) [](http://opensource.
136 lines • 5.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseAdapter = void 0;
const tslib_1 = require("tslib");
const path_1 = require("path");
const provider_1 = require("../utils/provider");
const questions_1 = require("../utils/questions");
const enquirer_1 = require("enquirer");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const workspace_1 = require("../utils/workspace");
const child_process_1 = require("child_process");
class BaseAdapter {
constructor(project, options, applicationType) {
this.project = project;
this.options = options;
this.applicationType = applicationType;
}
extendOptionsByUserInput() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const options = this.options;
const questions = [];
if (options.provider === provider_1.PROVIDER.AWS) {
if (!options['aws:region']) {
questions.push(questions_1.QUESTIONS.awsRegion);
}
if (!options['aws:profile']) {
questions.push(questions_1.QUESTIONS.awsProfile);
}
}
if (options.provider === provider_1.PROVIDER.AZURE && !options['azure:location']) {
questions.push(questions_1.QUESTIONS.azureLocation);
}
if (options.provider === provider_1.PROVIDER.GOOGLE_CLOUD_PLATFORM &&
!options['gcp:project']) {
questions.push(questions_1.QUESTIONS.gcpProjectId);
}
const anwsers = yield enquirer_1.prompt(questions);
this.options = Object.assign(Object.assign({}, options), anwsers);
});
}
addRequiredDependencies() {
const dependencies = [];
return dependencies;
}
getApplicationTypeTemplate() {
throw new Error('implement me');
}
getApplicationTemplatePath() {
return `${this.options.provider}/`;
}
getDeployActionConfiguration() {
const architectOptions = {
main: path_1.join(this.project.root, 'infrastructure', 'index.ts'),
provider: this.options.provider
};
const mergeOptions = Object.assign({}, this.options);
delete mergeOptions.project;
delete mergeOptions.provider;
return {
builder: '@dev-thought/nx-deploy-it:deploy',
options: Object.assign(Object.assign({}, architectOptions), { pulumi: mergeOptions }),
configurations: {}
};
}
getDestroyActionConfiguration() {
const architectOptions = {
main: path_1.join(this.project.root, 'infrastructure', 'index.ts'),
provider: this.options.provider
};
return {
builder: '@dev-thought/nx-deploy-it:destroy',
options: Object.assign({}, architectOptions),
configurations: {}
};
}
deploy(context, cwd, options, configuration, targetOptions) {
const distributationPath = workspace_1.getDistributionPath(context);
const build$ = rxjs_1.from(context
.scheduleTarget({
target: 'build',
project: context.target.project,
configuration: context.target.configuration || ''
})
.then(target => target.result));
return build$.pipe(operators_1.switchMap(() => this.up(cwd, options, configuration, targetOptions, distributationPath, context.target.project)));
}
up(cwd, options, configuration, targetOptions, distPath, projectName, additionArgs = []) {
const args = [
'up',
'--cwd',
cwd,
'--stack',
`${configuration}-${projectName}`
];
if (options.nonInteractive) {
args.push('--non-interactive', '--yes');
}
if (targetOptions.pulumi) {
for (const key in targetOptions.pulumi) {
const value = targetOptions.pulumi[key];
if (value) {
args.push('-c', `${key}=${value}`);
}
}
}
args.push('-c', `distPath=${distPath}`);
args.push('-c', `projectName=${projectName}`);
args.push(...additionArgs);
const up = child_process_1.spawnSync(workspace_1.getPulumiBinaryPath(), args, {
env: Object.assign(Object.assign({}, process.env), { PULUMI_SKIP_UPDATE_CHECK: '1' }),
stdio: 'inherit'
});
if (up.error) {
return rxjs_1.of({ success: false, error: up.error.message });
}
return rxjs_1.of({ success: true });
}
getStackOutput(cwd, configuration, projectName) {
const args = [
'stack',
'output',
'--cwd',
cwd,
'--stack',
`${configuration}-${projectName}`,
'--json'
];
const output = child_process_1.spawnSync(workspace_1.getPulumiBinaryPath(), args, {
env: Object.assign(Object.assign({}, process.env), { PULUMI_SKIP_UPDATE_CHECK: '1' })
});
return JSON.parse(output.stdout.toString());
}
}
exports.BaseAdapter = BaseAdapter;
//# sourceMappingURL=base.adapter.js.map