use-multiple-gits
Version:
CLI tool to manage multiple git configurations (user.name, user.email, SSH keys) with easy switching between identities
103 lines ⢠4.45 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initCommand = void 0;
const inquirer_1 = __importDefault(require("inquirer"));
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs"));
const fs_1 = require("../utils/fs");
const paths_1 = require("../utils/paths");
const configStorage_1 = require("../utils/configStorage");
const zshrc_1 = require("../utils/zshrc");
const errors_1 = require("../utils/errors");
const initCommand = async () => {
try {
console.log(chalk_1.default.blue('\nš Initializing Multi-Git Configuration System\n'));
const alreadyInitialized = await (0, configStorage_1.isInitialized)();
if (alreadyInitialized) {
const { proceed } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'proceed',
message: 'Multi-Git is already initialized. Re-initialize?',
default: false,
},
]);
if (!proceed) {
console.log(chalk_1.default.yellow('Cancelled.'));
return;
}
}
await (0, fs_1.ensureDir)(paths_1.BIN_DIR);
const zshrcExists = fs.existsSync(paths_1.ZSHRC_PATH);
if (!zshrcExists) {
console.log(chalk_1.default.yellow(`ā ļø ${paths_1.ZSHRC_PATH} not found. Creating it...`));
fs.writeFileSync(paths_1.ZSHRC_PATH, '');
}
const zshrcContent = await (0, zshrc_1.readZshrc)();
const hasBinInPath = zshrcContent.includes('$HOME/.bin') || zshrcContent.includes('~/.bin');
if (!hasBinInPath) {
const currentContent = fs.readFileSync(paths_1.ZSHRC_PATH, 'utf-8');
const pathExport = '\nexport PATH="$HOME/.bin:$PATH"\n';
if (!currentContent.includes(pathExport.trim())) {
fs.appendFileSync(paths_1.ZSHRC_PATH, pathExport);
console.log(chalk_1.default.green('ā
Added ~/.bin to PATH'));
}
}
else {
console.log(chalk_1.default.green('ā
~/.bin already in PATH'));
}
await (0, configStorage_1.setInitialized)();
console.log(chalk_1.default.green('\nā
Multi-Git initialized successfully!\n'));
console.log(chalk_1.default.cyan('Next steps:'));
console.log(' 1. Run: source ~/.zshrc');
console.log(' 2. Add a configuration: multiGit add <name>');
console.log(' 3. Example: multiGit add work\n');
}
catch (error) {
if (error instanceof errors_1.FileSystemError) {
console.error(chalk_1.default.red(`\nā ${error.message}\n`));
}
else {
console.error(chalk_1.default.red(`\nā Unexpected error: ${error.message}\n`));
}
process.exit(1);
}
};
exports.initCommand = initCommand;
//# sourceMappingURL=init.js.map