@lenne.tech/cli
Version:
lenne.Tech CLI: lt
105 lines (104 loc) • 4.5 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = require("path");
/**
* Install all bash helper scripts to /usr/local/bin
*/
const NewCommand = {
alias: ['is'],
description: 'Install bash helper scripts',
hidden: false,
name: 'install-scripts',
run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () {
const { helper, print: { error, info, spin, success }, system: { run, startTimer }, } = toolbox;
// Start timer
const timer = startTimer();
const targetDir = '/usr/local/bin';
// Check if target directory exists
if (!(0, fs_1.existsSync)(targetDir)) {
error(`Target directory not found: ${targetDir}`);
info('You may need to create it first: sudo mkdir -p /usr/local/bin');
return 'install-scripts: target not found';
}
// Collect scripts from all subdirectories
const baseDir = (0, path_1.join)(__dirname, '..', '..', 'templates', 'bash-scripts');
const scriptDirs = ['tools'];
const descriptions = {
pcf: 'pnpm run check:fix (fallback: check)',
};
const installed = [];
const failed = [];
for (const dir of scriptDirs) {
const sourceDir = (0, path_1.join)(baseDir, dir);
if (!(0, fs_1.existsSync)(sourceDir)) {
continue;
}
const scripts = (0, fs_1.readdirSync)(sourceDir).filter((file) => !file.startsWith('.'));
for (const script of scripts) {
const sourcePath = (0, path_1.join)(sourceDir, script);
const targetPath = (0, path_1.join)(targetDir, script);
const spinner = spin(`Installing ${script}`);
try {
(0, fs_1.copyFileSync)(sourcePath, targetPath);
(0, fs_1.chmodSync)(targetPath, 0o755);
spinner.succeed(`Installed ${script}`);
installed.push(script);
}
catch (err) {
spinner.fail(`Failed to install ${script}`);
if (err.code === 'EACCES') {
error(` Permission denied. Try running with sudo: sudo lt tools install-scripts`);
}
else {
error(` ${err.message}`);
}
failed.push(script);
}
}
}
// Install git scripts
info('');
const gitSpinner = spin('Installing git scripts...');
try {
yield run('lt git install-scripts');
gitSpinner.succeed('Git scripts installed');
}
catch (err) {
gitSpinner.fail('Failed to install git scripts');
error(` ${err.message}`);
error(' Try running with sudo: sudo lt git install-scripts');
}
// Summary
info('');
if (failed.length === 0) {
success(`All scripts installed in ${helper.msToMinutesAndSeconds(timer())}m.`);
}
else {
error(`${installed.length} installed, ${failed.length} failed.`);
}
if (installed.length > 0) {
info('');
info('Installed scripts:');
for (const script of installed) {
const desc = descriptions[script] || 'run from anywhere in terminal';
info(` ${script} - ${desc}`);
}
}
info('');
if (!toolbox.parameters.options.fromGluegunMenu) {
process.exit();
}
return failed.length > 0 ? `scripts installed with ${failed.length} failures` : 'scripts installed';
}),
};
exports.default = NewCommand;