UNPKG

@wocker/ws

Version:

Docker workspace for web projects

144 lines (143 loc) 6.13 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProjectController = void 0; const core_1 = require("@wocker/core"); const utils_1 = require("@wocker/utils"); const path_1 = __importDefault(require("path")); const preset_1 = require("../../preset"); const ProjectService_1 = require("../services/ProjectService"); let ProjectController = class ProjectController { constructor(appConfigService, processService, projectService, presetService) { this.appConfigService = appConfigService; this.processService = processService; this.projectService = projectService; this.presetService = presetService; } async start(name, restart, build, attach) { const project = this.projectService.get(name); await this.projectService.start(project, restart, build, attach); } async stop(name) { const project = this.projectService.get(name); await this.projectService.stop(project); } async eject(name) { const project = this.projectService.get(name); const preset = this.presetService.get(project.preset); if (!preset) { throw new Error("Preset not found"); } const confirm = await (0, utils_1.promptConfirm)({ message: "Confirm eject", default: false }); if (!confirm) { return; } const copier = new core_1.FileSystemManager(preset.path, this.processService.pwd()); if (preset.dockerfile) { if (!copier.destination.exists(preset.dockerfile)) { copier.copy(preset.dockerfile); } project.type = "dockerfile"; project.dockerfile = preset.dockerfile; } const files = copier.source.readdir("", { recursive: true }); for (const path of files) { const stat = copier.source.stat(path), dir = path_1.default.dirname(path); if (stat.isFile() && path === "config.json") { continue; } if (stat.isFile() && path === preset.dockerfile) { continue; } if (copier.destination.exists(path)) { continue; } if (!copier.destination.exists(dir)) { copier.destination.mkdir(dir, { recursive: true }); } copier.copy(path); } delete project.preset; delete project.imageName; project.save(); } async exec(command, name) { const project = this.projectService.get(name); await this.projectService.exec(project, command); } }; exports.ProjectController = ProjectController; __decorate([ (0, core_1.Command)("start"), (0, core_1.Description)("Starting project"), __param(0, (0, core_1.Option)("name", "n")), __param(0, (0, core_1.Description)("The name of the project")), __param(1, (0, core_1.Option)("restart", "r")), __param(1, (0, core_1.Description)("Restarting project")), __param(2, (0, core_1.Option)("build", "b")), __param(2, (0, core_1.Description)("Build")), __param(3, (0, core_1.Option)("attach", "a")), __param(3, (0, core_1.Description)("Attach")), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Boolean, Boolean, Boolean]), __metadata("design:returntype", Promise) ], ProjectController.prototype, "start", null); __decorate([ (0, core_1.Command)("stop"), (0, core_1.Description)("Stopping project"), __param(0, (0, core_1.Option)("name", "n")), __param(0, (0, core_1.Description)("The name of the project")), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], ProjectController.prototype, "stop", null); __decorate([ (0, core_1.Command)("preset:eject"), (0, core_1.Description)("Eject preset files into the project"), __param(0, (0, core_1.Option)("name", "n")), __param(0, (0, core_1.Description)("The name of the project")), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], ProjectController.prototype, "eject", null); __decorate([ (0, core_1.Command)("exec [...command]"), __param(0, (0, core_1.Param)("command")), __param(1, (0, core_1.Option)("name", { type: "string", alias: "n", description: "The name of the project" })), __metadata("design:type", Function), __metadata("design:paramtypes", [Array, String]), __metadata("design:returntype", Promise) ], ProjectController.prototype, "exec", null); exports.ProjectController = ProjectController = __decorate([ (0, core_1.Controller)(), (0, core_1.Description)("Project commands"), __metadata("design:paramtypes", [core_1.AppConfigService, core_1.ProcessService, ProjectService_1.ProjectService, preset_1.PresetService]) ], ProjectController);