jetup
Version:
Jetup: JavaScript Project Setup! Jetting-up your next JS project in seconds with one command, using fully modular, customizable presets, instantly ready to code!.
110 lines • 3.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runCommand = runCommand;
exports.runCommandInSilent = runCommandInSilent;
exports.runCommandInAlternateScreen = runCommandInAlternateScreen;
const child_process_1 = require("child_process");
const cwd_1 = require("./cwd");
async function runCommand(command) {
return new Promise((resolve, reject) => {
const [cmd, ...args] = command.split(' ');
const child = (0, child_process_1.spawn)(cmd, args, {
stdio: 'inherit',
shell: true,
cwd: cwd_1.CWD.value,
});
child.on('error', err => {
console.error(`Failed to start command: ${command}`);
reject(err);
});
child.on('close', code => {
if (code === 0) {
resolve();
}
else {
reject(new Error(`Command "${command}" exited with code ${code}`));
}
});
});
}
async function runCommandInSilent(command) {
return new Promise((resolve, reject) => {
const [cmd, ...args] = command.split(' ');
const child = (0, child_process_1.spawn)(cmd, args, {
stdio: 'ignore',
cwd: cwd_1.CWD.value,
});
child.on('error', err => {
console.error(`Failed to start command: ${command}`);
reject(err);
});
child.on('close', code => {
if (code === 0) {
resolve();
}
else {
reject(new Error(`Command "${command}" exited with code ${code}`));
}
});
});
}
async function runCommandInAlternateScreen(command) {
return new Promise((resolve, reject) => {
enterAlternateScreen({ header: `executing:\n${command}` });
const [cmd, ...args] = command.split(' ');
const child = (0, child_process_1.spawn)(cmd, args, {
stdio: 'inherit',
shell: true,
cwd: cwd_1.CWD.value,
});
child.on('error', err => {
exitAlternateScreen();
console.error(`Failed to start command: ${command}`);
reject(err);
});
child.on('close', code => {
exitAlternateScreen();
if (code === 0) {
resolve();
}
else {
reject(new Error(`Command "${command}" exited with code ${code}`));
}
});
});
}
function enterAlternateScreen(params) {
process.stdout.write('\x1b[?1049h');
if (params.title)
setTerminalTitle(params.title);
if (params.header)
drawBoxedTitle(params.header);
}
function exitAlternateScreen() {
process.stdout.write('\x1b[?1049l');
}
function setTerminalTitle(title) {
process.stdout.write(`\x1b]0;${title}\x07`);
}
function drawBoxedTitle(title, padding = {}) {
var _a, _b;
const hPadding = (_a = padding.horizontal) !== null && _a !== void 0 ? _a : 5;
const vPadding = (_b = padding.vertical) !== null && _b !== void 0 ? _b : 1;
const rawLines = title.split('\n');
const contentWidth = Math.max(...rawLines.map(line => line.length)) + hPadding * 2;
const border = '─'.repeat(contentWidth);
const emptyLine = ' '.repeat(contentWidth);
const paddedLines = rawLines.map(line => {
const padded = ' '.repeat(hPadding) + line + ' '.repeat(hPadding);
return padded.padEnd(contentWidth);
});
const allLines = [
...Array(vPadding).fill(emptyLine),
...paddedLines,
...Array(vPadding).fill(emptyLine),
];
const boxed = [`╭${border}╮`, ...allLines.map(line => `│${line}│`), `╰${border}╯`];
console.log(boxed.join('\n'));
console.log();
}
//# sourceMappingURL=cmd.js.map