UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

88 lines 3.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils"); const isCi_1 = __importDefault(require("../utilities/isCi")); class PkgService extends spruce_skill_utils_1.PkgService { commandService; constructor(cwd, commandService) { super(cwd); this.commandService = commandService; } async install(pkg, options) { const shouldCleanupLockFiles = options?.shouldCleanupLockFiles !== false; const deleteLockFile = shouldCleanupLockFiles ? this.deleteLockFile.bind(this) : () => { }; if (!pkg) { await this.commandService.execute('yarn', { args: ['install'] }); deleteLockFile(); return { totalInstalled: -1, totalSkipped: -1 }; } deleteLockFile(); const packages = Array.isArray(pkg) ? pkg : [pkg]; const toInstall = []; const labsModules = []; let totalInstalled = 0; let totalSkipped = 0; for (const thisPackage of packages) { const isInstalled = !options?.shouldForceInstall && this.isInstalled(thisPackage); if (thisPackage.startsWith('@sprucelabs/') || !isInstalled) { toInstall.push(this.stripLatest(thisPackage)); totalInstalled++; } else { totalSkipped++; } } if (totalInstalled > 0) { const { executable, args } = PkgService.buildCommandAndArgs(toInstall, options); const isInWorkspace = this.get('workspaces')?.length > 0; if (isInWorkspace) { args.push('-W'); } await this.commandService.execute(executable, { args, }); } else if (!spruce_skill_utils_1.diskUtil.doesDirExist(path_1.default.join(this.cwd, 'node_modules'))) { await this.commandService.execute('yarn', { args: ['install'] }); } deleteLockFile(); this._parsedPkg = undefined; return { totalInstalled: totalInstalled + labsModules.length, totalSkipped, }; } static buildCommandAndArgs(toInstall, options) { const args = [ (0, isCi_1.default)() && '--cache-folder', (0, isCi_1.default)() && spruce_skill_utils_1.diskUtil.createRandomTempDir(), 'add', ...toInstall, ].filter((a) => !!a); if (options?.isDev) { args.push('-D'); } const executable = 'yarn'; return { executable, args }; } getSkillNamespace() { return this.get('skill.namespace'); } async uninstall(pkg) { const packages = Array.isArray(pkg) ? pkg : [pkg]; const args = ['uninstall', ...packages]; await this.commandService.execute('npm', { args, }); this._parsedPkg = undefined; await this.install(); } } exports.default = PkgService; //# sourceMappingURL=PkgService.js.map