@jefiozie/ngx-aws-deploy
Version:
Deploy an Angular app to Amazon S3 directly from the Angular CLI
69 lines • 2.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngAdd = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
function createVirtualHost(tree) {
return {
readFile(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const buffer = tree.read(path);
if (!buffer) {
throw new Error(`File "${path}" not found.`);
}
return core_1.virtualFs.fileBufferToString(buffer);
});
},
writeFile(path, data) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
tree.overwrite(path, data);
});
},
isDirectory(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return !tree.exists(path) && tree.getDir(path).subfiles.length > 0;
});
},
isFile(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return tree.exists(path);
});
},
};
}
function getWorkspace(tree, path = '/') {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const host = createVirtualHost(tree);
const { workspace } = yield core_1.workspaces.readWorkspace(path, host);
return { host, workspace };
});
}
const ngAdd = (options) => (tree, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
var _a;
const { host, workspace } = yield getWorkspace(tree);
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.`);
}
const buildTarget = project.targets.get('build');
if (!buildTarget) {
throw new schematics_1.SchematicsException('Project target "build" not found.');
}
const outputPath = (_a = buildTarget.options) === null || _a === void 0 ? void 0 : _a.outputPath;
if (!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: '@jefiozie/ngx-aws-deploy:deploy',
options: {},
});
yield core_1.workspaces.writeWorkspace(workspace, host);
return tree;
});
exports.ngAdd = ngAdd;
//# sourceMappingURL=index.js.map