UNPKG

@nu-art/commando

Version:
73 lines (72 loc) 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PNPM = exports.Cli_PNPM = void 0; const fs_1 = require("fs"); const ts_common_1 = require("@nu-art/ts-common"); const tools_1 = require("../tools"); class Cli_PNPM extends ts_common_1.Logger { constructor() { super(); this._expectedVersion = '9.1.0'; this._homeEnvVar = 'PNPM_HOME'; this.install = async (commando) => { if (this.isInstalled()) { const version = (await commando.getVersion()); if (this._expectedVersion === version) return; await this.uninstall(); } this.logDebug(`installing PNPM version ${this._expectedVersion}`); await commando.install(this._expectedVersion); return this; }; this.isInstalled = () => !!process.env[this._homeEnvVar]; this.installPackages = async (commando) => { return await commando.installPackages(); }; this.uninstall = async () => { this.logDebug('Uninstalling PNPM'); const absolutePathToPNPM_Home = process.env[this._homeEnvVar]; if (!absolutePathToPNPM_Home) return; return fs_1.promises.rm(absolutePathToPNPM_Home, { recursive: true, force: true }); }; /** * Asynchronously creates a workspace file with a list of packages. * Each package is listed under the 'packages:' section in the file. * * @param listOfLibs An array of library names to include in the workspace. * @param pathToWorkspaceFile The filesystem path where the workspace file will be written. * @example * await createWorkspace(['pack1', 'pack2'], './path/to/workspace.yaml'); */ this.createWorkspace = async (listOfLibs, pathToWorkspaceFile = (0, tools_1.convertToFullPath)('./pnpm-workspace.yaml')) => { try { let workspace = 'packages:\n'; listOfLibs.forEach(lib => { workspace += ` - '${lib}'\n`; }); await fs_1.promises.writeFile(pathToWorkspaceFile, workspace, 'utf8'); this.logDebug(`Workspace file created at ${pathToWorkspaceFile}`); } catch (error) { this.logError('Failed to create workspace file:', error); } }; this.setMinLevel(ts_common_1.LogLevel.Verbose); } get homeEnvVar() { return this._homeEnvVar; } set homeEnvVar(value) { this._homeEnvVar = value; } get expectedVersion() { return this._expectedVersion; } set expectedVersion(value) { this._expectedVersion = value; } } exports.Cli_PNPM = Cli_PNPM; exports.PNPM = new Cli_PNPM();