@nu-art/commando
Version:
53 lines (52 loc) • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Commando_NVM = void 0;
const BaseCommando_1 = require("../core/BaseCommando");
const programming_1 = require("./programming");
const class_merger_1 = require("../core/class-merger");
const basic_1 = require("./basic");
const ts_common_1 = require("@nu-art/ts-common");
const tools_1 = require("../tools");
const Super = (0, class_merger_1.MergeClass)(BaseCommando_1.BaseCommando, programming_1.Commando_Programming, basic_1.Commando_Basic);
class Commando_NVM extends Super {
constructor() {
super(...arguments);
this.getInstalledNodeVersions = async () => {
function extractInstalledVersions(rawOutput) {
const cleanedOutput = (0, tools_1.removeAnsiCodes)(rawOutput);
const lines = cleanedOutput.split('\n');
const filteredVersionLines = lines
.filter(line => !!line && line.match(/v\d+\.\d+\.\d+/) && !line.includes('N/A'));
return (0, ts_common_1.filterDuplicates)(filteredVersionLines
.map(line => { var _a; return (_a = line.match(/v(\d+\.\d+\.\d+)/)) === null || _a === void 0 ? void 0 : _a[1]; }));
}
const versionsAsString = this.append('nvm ls').execute((stdout) => stdout);
return extractInstalledVersions((await versionsAsString));
};
}
applyNVM() {
this.append('export NVM_DIR="$HOME/.nvm"')
.append('[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm')
.append('nvm use');
return this;
}
async install(version) {
this.append(`curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/v${version}/install.sh" | bash`);
await this.execute((stdout, stderr, exitCode) => {
if (exitCode !== 0)
throw new ts_common_1.Exception(`Error installing NVM - exit code (${exitCode})`);
});
return this;
}
async getVersion() {
return this.if('[[ -x "$(command -v nvm)" ]]', (commando) => {
commando.append('nvm --version');
}).execute((stdout) => stdout);
}
async installNodeVersion(requiredVersion) {
await this.append(`nvm install ${requiredVersion}`)
.execute();
return this;
}
}
exports.Commando_NVM = Commando_NVM;