@jalasem/dss
Version:
Dev Spaces Switcher (DSS) - Seamlessly manage isolated development environments with separate SSH keys and Git configurations. Enhanced UI with beautiful tables and improved documentation.
47 lines (46 loc) • 2.31 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateSSHKey = void 0;
const ssh_keygen_1 = __importDefault(require("ssh-keygen"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
function generateSSHKey(spaceName, email) {
return __awaiter(this, void 0, void 0, function* () {
// Construct the path for ~/.dss/spaces
const dssPath = path_1.default.join(os_1.default.homedir(), '.dss', 'spaces');
const spaceFolderPath = path_1.default.join(dssPath, spaceName);
// Ensure the space's folder exists
yield fs_extra_1.default.ensureDir(spaceFolderPath);
// Path for the new SSH key within the space's folder
const keyPath = path_1.default.join(spaceFolderPath, 'id_rsa');
return new Promise((resolve, reject) => {
(0, ssh_keygen_1.default)({
location: keyPath,
comment: email,
password: '',
read: true,
}, function (err) {
if (err) {
console.error('SSH key generation failed:', err);
return reject(err);
}
console.log('Generated SSH key at:', keyPath);
resolve(keyPath); // Return the full path to the generated key
});
});
});
}
exports.generateSSHKey = generateSSHKey;