@dev-thought/nx-deploy-it
Version:
[](https://www.npmjs.com/package/@dev-thought/nx-deploy-it) [](http://opensource.
131 lines • 6.24 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.AngularUniversalAdapter = 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 path_1 = require("path");
const questions_1 = require("../../utils/questions");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const workspace_1 = require("../../utils/workspace");
const deployment_type_enum_1 = require("./deployment-type.enum");
const fs_1 = require("fs");
class AngularUniversalAdapter 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 = [];
questions.push(questions_1.QUESTIONS.angularUniversal);
if (options.provider === provider_1.PROVIDER.GOOGLE_CLOUD_PLATFORM) {
if (!options.customDomainName)
questions.push(questions_1.QUESTIONS.customDomainName);
if (!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();
dependencies.push({ name: 'mime', version: '2.4.4' });
if (this.options.provider === provider_1.PROVIDER.AWS) {
dependencies.push({
name: 'aws-serverless-express',
version: '^3.3.6'
});
}
if (this.options.provider === provider_1.PROVIDER.AZURE) {
dependencies.push({ name: '@azure/arm-cdn', version: '^4.2.0' }, {
name: 'azure-aws-serverless-express',
version: '^0.1.5'
});
}
return dependencies;
}
getApplicationTypeTemplate() {
const buildTarget = this.project.targets.get('build');
return schematics_1.applyTemplates({
getRootDirectory: () => '',
buildPath: path_1.join(`../../../${buildTarget.options.outputPath}`),
projectName: this.options.project
});
}
getApplicationTemplatePath() {
return `${super.getApplicationTemplatePath()}/angular-universal/`;
}
getDeployActionConfiguration() {
const config = super.getDeployActionConfiguration();
config.options.pulumi.useCdn = false;
config.configurations = {
production: { pulumi: { useCdn: true } }
};
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 deploymentType = targetOptions.pulumi.angularUniversalDeploymentType;
let baseHref = '/';
switch (this.options.provider) {
case provider_1.PROVIDER.AWS:
baseHref = `/${context.target.configuration || 'dev'}/`;
break;
default:
break;
}
let build$;
switch (deploymentType) {
case deployment_type_enum_1.ANGULAR_UNIVERSAL_DEPLOYMENT_TYPE.PRERENDERING:
build$ = rxjs_1.from(context
.scheduleTarget({
target: 'prerender',
project: context.target.project,
configuration: context.target.configuration || undefined
})
.then(build => build.result));
break;
case deployment_type_enum_1.ANGULAR_UNIVERSAL_DEPLOYMENT_TYPE.SERVER_SIDE_RENDERING:
build$ = rxjs_1.from(Promise.all([
context.scheduleTarget({
target: 'build',
project: context.target.project,
configuration: context.target.configuration || undefined
}, {
baseHref
}),
context.scheduleTarget({
target: 'server',
project: context.target.project,
configuration: context.target.configuration || undefined
}, {
main: path_1.resolve(infrastructureFolder, 'functions/main/index.ts'),
tsConfig: path_1.resolve(infrastructureFolder, 'tsconfig.json')
})
]).then(([build, server]) => Promise.all([build.result, server.result]))).pipe(operators_1.switchMap(() => {
if (this.options.provider === provider_1.PROVIDER.GOOGLE_CLOUD_PLATFORM) {
fs_1.copyFileSync(path_1.join(context.workspaceRoot, `${project.architect.server.options.outputPath}/main.js`), path_1.join(context.workspaceRoot, `${project.architect.server.options.outputPath}/index.js`));
}
return rxjs_1.of({ success: true });
}));
break;
default:
throw new Error('Unknown deployment type! Supported types are: ["prerendering", "ssr"]');
}
return build$.pipe(operators_1.switchMap(() => this.up(cwd, options, configuration, targetOptions, distributationPath, context.target.project)));
}
}
exports.AngularUniversalAdapter = AngularUniversalAdapter;
//# sourceMappingURL=angular-universal.adapter.js.map
;