node-version-use
Version:
Cross-platform solution for using multiple versions of node. Useful for compatibility testing
64 lines • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, /**
* nvu list
*
* List all installed Node versions.
*/ "default", {
enumerable: true,
get: function() {
return listCmd;
}
});
var _exitcompat = /*#__PURE__*/ _interop_require_default(require("exit-compat"));
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
var _compatts = require("../compat.js");
var _constantsts = require("../constants.js");
var _compareVersionsts = /*#__PURE__*/ _interop_require_default(require("../lib/compareVersions.js"));
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function listCmd(_args) {
var versionsPath = _path.default.join(_constantsts.storagePath, 'installed');
// Check if versions directory exists
if (!_fs.default.existsSync(versionsPath)) {
console.log('No Node versions installed.');
console.log('Install a version: nvu install <version>');
(0, _exitcompat.default)(0);
return;
}
// Read all directories in versions folder
var entries = (0, _compatts.readdirWithTypes)(versionsPath);
var versions = entries.filter(function(entry) {
return entry.isDirectory();
}).map(function(entry) {
return entry.name;
});
if (versions.length === 0) {
console.log('No Node versions installed.');
console.log('Install a version: nvu install <version>');
(0, _exitcompat.default)(0);
return;
}
// Get the current default
var defaultFilePath = _path.default.join(_constantsts.storagePath, 'default');
var defaultVersion = '';
if (_fs.default.existsSync(defaultFilePath)) {
defaultVersion = _fs.default.readFileSync(defaultFilePath, 'utf8').trim();
}
console.log('Installed Node versions:');
versions.sort(_compareVersionsts.default);
for(var i = 0; i < versions.length; i++){
var version = versions[i];
var isDefault = version === defaultVersion || "v".concat(version) === defaultVersion || version === "v".concat(defaultVersion);
var marker = isDefault ? ' (default)' : '';
console.log(" ".concat(version).concat(marker));
}
(0, _exitcompat.default)(0);
}
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }