fnspm
Version:
A unified command-line interface for managing packages across multiple package managers (npm, yarn, pnpm, bun, and deno) with macOS optimization for iCloud sync and automatic package manager detection.
69 lines (68 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const helpers_1 = require("../utils/helpers");
const helpers_2 = require("../utils/helpers");
class PackageManager {
async execute(args) {
const config = await (0, helpers_2.loadConfig)();
const fullCommand = `${this.name} ${args.join(' ')}`.trim();
const isInteractiveCommand = ['init', 'create', 'login'].some(cmd => args.includes(cmd));
if (config.debug.verbose || args.includes('--debug')) {
console.info(`Running command: ${fullCommand}`);
}
if (isInteractiveCommand) {
return new Promise((resolve, reject) => {
const [cmd, ...cmdArgs] = fullCommand.split(' ');
const childProcess = (0, child_process_1.spawn)(cmd, cmdArgs, {
stdio: 'inherit',
shell: true
});
childProcess.on('close', async (code) => {
if (code === 0) {
if (await (0, helpers_1.shouldCreateSymlink)()) {
(0, helpers_1.createSymlink)()
.then(resolve)
.catch((error) => {
console.error(`Error creating symlink: ${error}`);
resolve();
});
}
else {
resolve();
}
}
else {
reject(new Error(`Command failed with code ${code}`));
}
});
childProcess.on('error', (error) => {
reject(error);
});
});
}
return new Promise((resolve, reject) => {
(0, child_process_1.exec)(fullCommand, async (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${stderr}`);
reject(error);
}
else {
console.log(stdout);
if (await (0, helpers_1.shouldCreateSymlink)()) {
(0, helpers_1.createSymlink)().then(() => {
resolve();
}).catch((error) => {
console.error(`Error creating symlink: ${error}`);
resolve();
});
}
else {
resolve();
}
}
});
});
}
}
exports.default = PackageManager;