ngx-deploy-docker
Version:
Publish your angular projects to a docker registry by just run `ng deploy your-app`
79 lines • 4.29 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngAdd = void 0;
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const utils_1 = require("../utils");
const core_1 = require("@angular-devkit/core");
function addDeployBuilderToProject(tree, host, workspace, options) {
var _a, _b;
if (!options.project) {
if (workspace.extensions.defaultProject) {
options.project = workspace.extensions.defaultProject;
}
else {
throw new schematics_1.SchematicsException('No Angular project selected and no default project in the workspace');
}
}
const project = workspace.projects.get(options.project);
if (!project) {
throw new schematics_1.SchematicsException('The specified Angular project is not defined in this workspace');
}
if (project.extensions.projectType !== 'application') {
throw new schematics_1.SchematicsException(`Deploy requires an Angular project type of "application" in angular.json`);
}
if (!((_b = (_a = project.targets.get('build')) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.outputPath)) {
throw new schematics_1.SchematicsException(`Cannot read the output path (architect.build.options.outputPath) of the Angular project "${options.project}" in angular.json`);
}
project.targets.add({
name: 'deploy',
builder: 'ngx-deploy-docker:deploy',
options: {
account: options.account,
},
});
core_1.workspaces.writeWorkspace(workspace, host);
return tree;
}
function prepareDockerFiles(tree, workspace, options) {
var _a, _b, _c;
const sourceTemplates = (0, schematics_1.url)('./files');
const outputPath = ((_c = (_b = (_a = workspace.projects.get(options.project)) === null || _a === void 0 ? void 0 : _a.targets.get('build')) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.outputPath) || '';
const version = (0, utils_1.getVersionFromPackageJson)(tree);
const sourceParametrizedTemplates = (0, schematics_1.apply)(sourceTemplates, [
(0, schematics_1.template)({
outputPath,
version,
}),
]);
return (0, schematics_1.mergeWith)(sourceParametrizedTemplates);
}
const ngAdd = (options) => (tree, context) => __awaiter(void 0, void 0, void 0, function* () {
const host = (0, utils_1.createHost)(tree);
const { workspace } = yield core_1.workspaces.readWorkspace('/', host);
const version = (0, utils_1.getLibraryVersion)();
(0, utils_1.addPackageToPackageJson)(tree, 'ngx-deploy-docker', `^${version}`);
context.logger.log('info', `🐳 Added "ngx-deploy-docker@^${version}" into devDependencies`);
if (options.skipInstall) {
context.logger.log('warn', `❗️ The "--skip-install" flag was present, don't forget to install package manually`);
}
else {
context.logger.log('info', `📦 Installing added packages...`);
context.addTask(new tasks_1.NodePackageInstallTask());
}
addDeployBuilderToProject(tree, host, workspace, options);
context.logger.log('info', `🚀 Deploy Builder added to your project`);
context.logger.log('info', 'Preparing some 🐳 files...');
return (0, schematics_1.chain)([prepareDockerFiles(tree, workspace, options)]);
});
exports.ngAdd = ngAdd;
//# sourceMappingURL=index.js.map
;