@dev-thought/nx-deploy-it
Version:
[](https://www.npmjs.com/package/@dev-thought/nx-deploy-it) [](http://opensource.
103 lines • 4.7 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestJSAdapter = void 0;
const tslib_1 = require("tslib");
const base_adapter_1 = require("../base.adapter");
const provider_1 = require("../../utils/provider");
const enquirer_1 = require("enquirer");
const schematics_1 = require("@angular-devkit/schematics");
const questions_1 = require("../../utils/questions");
const workspace_1 = require("../../utils/workspace");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const path_1 = require("path");
const ncc = require("@vercel/ncc");
const fs_extra_1 = require("fs-extra");
const fs_1 = require("fs");
class NestJSAdapter extends base_adapter_1.BaseAdapter {
extendOptionsByUserInput() {
const _super = Object.create(null, {
extendOptionsByUserInput: { get: () => super.extendOptionsByUserInput }
});
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield _super.extendOptionsByUserInput.call(this);
const options = this.options;
const questions = [];
if (options.provider === provider_1.PROVIDER.GOOGLE_CLOUD_PLATFORM &&
!options['gcp:region']) {
questions.push(questions_1.QUESTIONS.gcpRegionCloudFunctions);
}
const anwsers = yield enquirer_1.prompt(questions);
this.options = Object.assign(Object.assign({}, options), anwsers);
});
}
addRequiredDependencies() {
const dependencies = super.addRequiredDependencies();
if (this.options.provider === provider_1.PROVIDER.AZURE) {
dependencies.push({
name: '@nestjs/azure-func-http',
version: '^0.4.2'
}, {
name: '@azure/functions',
version: '^1.2.0'
});
}
if (this.options.provider === provider_1.PROVIDER.AWS) {
dependencies.push({
name: 'aws-serverless-express',
version: '^3.3.6'
});
}
return dependencies;
}
getApplicationTypeTemplate() {
return schematics_1.applyTemplates({
rootDir: 'src',
getRootDirectory: () => 'src',
stripTsExtension: (s) => s.replace(/\.ts$/, ''),
getRootModuleName: () => 'AppModule',
getRootModulePath: () => 'app/app.module',
projectName: this.options.project
});
}
getApplicationTemplatePath() {
return `${super.getApplicationTemplatePath()}/nestjs/`;
}
getDeployActionConfiguration() {
const config = super.getDeployActionConfiguration();
// TODO: use in deploy & destroy via angular.json config
// if (options.provider === PROVIDER.GOOGLE_CLOUD_PLATFORM && options.region) {
// args.push('-c', `gcp:region=${options.region}`);
// }
return config;
}
getDestroyActionConfiguration() {
const config = super.getDestroyActionConfiguration();
return config;
}
deploy(context, cwd, options, configuration, targetOptions) {
const distributationPath = workspace_1.getDistributionPath(context);
const project = workspace_1.getProjectConfig(context);
const infrastructureFolder = path_1.resolve(context.workspaceRoot, project.root, 'infrastructure');
const processCwd = process.cwd();
process.chdir(infrastructureFolder);
const build$ = rxjs_1.from(ncc(path_1.resolve(infrastructureFolder, 'functions/main/index.ts'), {
cache: path_1.resolve(infrastructureFolder, 'buildcache')
})).pipe(operators_1.map((buildResult) => {
process.chdir(processCwd);
fs_extra_1.ensureDirSync(path_1.resolve(infrastructureFolder, 'functions/dist/main'));
// compiled javascript
fs_1.writeFileSync(path_1.resolve(infrastructureFolder, 'functions/dist/main/index.js'), buildResult.code);
// assets
for (const file in buildResult.asset) {
const content = buildResult.asset[file];
fs_extra_1.ensureFileSync(path_1.resolve(infrastructureFolder, `functions/dist/main/${file}`));
fs_1.writeFileSync(path_1.resolve(infrastructureFolder, `functions/dist/main/${file}`), content.source.toString());
}
return { success: true };
}));
return build$.pipe(operators_1.switchMap(() => this.up(cwd, options, configuration, targetOptions, distributationPath, context.target.project)));
}
}
exports.NestJSAdapter = NestJSAdapter;
//# sourceMappingURL=nestjs.adapter.js.map
;