UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

79 lines 3.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const EventCacheService_1 = __importDefault(require("../features/event/services/EventCacheService")); const RemoteService_1 = __importDefault(require("../features/event/services/RemoteService")); const SchemaService_1 = __importDefault(require("../features/schema/services/SchemaService")); const VsCodeService_1 = __importDefault(require("../features/vscode/services/VsCodeService")); const BuildService_1 = __importDefault(require("./BuildService")); const CommandService_1 = __importDefault(require("./CommandService")); const DependencyService_1 = __importDefault(require("./DependencyService")); const ImportService_1 = __importDefault(require("./ImportService")); const LintService_1 = __importDefault(require("./LintService")); const PkgService_1 = __importDefault(require("./PkgService")); const TypeCheckerService_1 = __importDefault(require("./TypeCheckerService")); class ServiceFactory { static serviceClassOverides = {}; static setServiceClass(name, Class) { this.serviceClassOverides[name] = Class; } Service(cwd, type) { const Class = ServiceFactory.serviceClassOverides[type]; switch (type) { case 'auth': return spruce_skill_utils_1.AuthService.Auth(cwd); case 'pkg': return new PkgService_1.default(cwd, this.Service(cwd, 'command')); case 'env': return new spruce_skill_utils_1.EnvService(cwd); case 'vsCode': return new VsCodeService_1.default(cwd); case 'schema': return new SchemaService_1.default({ cwd, command: new CommandService_1.default(cwd), }); case 'lint': return new (Class ?? LintService_1.default)(cwd, () => this.Service(cwd, 'command')); case 'command': { return new CommandService_1.default(cwd); } case 'remote': return new RemoteService_1.default(new spruce_skill_utils_1.EnvService(cwd)); case 'typeChecker': return new TypeCheckerService_1.default(this.buildImportService(cwd)); case 'settings': //@ts-ignore return new (Class ?? spruce_skill_utils_1.SettingsService)(cwd); case 'dependency': return new DependencyService_1.default(new spruce_skill_utils_1.SettingsService(cwd)); case 'import': return this.buildImportService(cwd); case 'build': { const commandService = new CommandService_1.default(cwd); return new BuildService_1.default(commandService, this.Service(cwd, 'lint')); } case 'eventCache': return new (Class ?? EventCacheService_1.default)(new spruce_skill_utils_1.SettingsService(cwd)); default: throw new Error(`Service "${type}" not found`); } } buildImportService(cwd) { return new ImportService_1.default({ cwd, command: new CommandService_1.default(cwd), }); } static reset() { this.serviceClassOverides = {}; } static setFactoryClass(name, Class) { this.serviceClassOverides[name] = Class; } } exports.default = ServiceFactory; //# sourceMappingURL=ServiceFactory.js.map