Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/elouangrimm/dotstop. Interactive CLI wizard for generating Linux .desktop launchers
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136const path = require('node:path');const arg = require('arg');const chalk = require('chalk');const boxenModule = require('boxen');const { runWizard } = require('./wizard');const pkg = require('../package.json');
const boxen = boxenModule.default || boxenModule;
function toPositiveInteger(value, fallback) { if (value === undefined || value === null) { return fallback; }
const parsed = Number(value); if (!Number.isFinite(parsed) || parsed <= 0) { return fallback; }
return Math.floor(parsed);}
function parseCli() { return arg( { '--help': Boolean, '--version': Boolean, '--dry-run': Boolean, '--cwd': String, '--output': String, '--max-depth': Number, '--max-files': Number, '-h': '--help', '-v': '--version', '-o': '--output', }, { permissive: true, }, );}
function getHelpText() { const repository = typeof pkg.repository === 'object' && pkg.repository && pkg.repository.url ? pkg.repository.url.replace(/^git\+/, '').replace(/\.git$/, '') : pkg.homepage || 'https://github.com/elouangrimm/dotstop';
const title = `${chalk.bold.cyan('dotstop')} ${chalk.bold.white(`v${pkg.version}`)}`;
return [ title, chalk.dim('Interactive desktop-entry wizard for Linux apps'), '', chalk.bold('USAGE'), ` ${chalk.cyan('dotstop')} Launch wizard in current directory`, ` ${chalk.cyan('dotstop ./my-app')} Launch wizard for another folder`, ` ${chalk.cyan('dotstop --output ./app.desktop')} Preselect output path`, ` ${chalk.cyan('dotstop --dry-run')} Generate preview without writing file`, '', chalk.bold('OPTIONS'), ` ${chalk.yellow('-h, --help')} Show help`, ` ${chalk.yellow('-v, --version')} Show version`, ` ${chalk.yellow('--dry-run')} Build desktop entry preview only`, ` ${chalk.yellow('--cwd <path>')} Project directory to scan`, ` ${chalk.yellow('-o, --output <path>')} Write path or target directory`, ` ${chalk.yellow('--max-depth <number>')} Scan depth for icon/binary detection`, ` ${chalk.yellow('--max-files <number>')} Max files to inspect while scanning`, '', chalk.bold('WHAT DOTSTOP AUTO-DETECTS'), ' - existing .desktop files in your project', ' - likely launch commands from package.json, bin/, and scripts', ' - icon candidates from png/svg/xpm/ico and files named icon/logo', '', `${chalk.bold('Docs:')} ${chalk.underline(repository)}`, ].join('\n');}
function getStartupBox(cwd, dryRun) { const lines = [ chalk.hex('#06b6d4').bold('dotstop setup wizard'), '', `${chalk.bold('- CWD:')} ${cwd}`, `${chalk.bold('- Mode:')} ${dryRun ? 'dry-run (preview only)' : 'interactive write mode'}`, `${chalk.bold('- Goal:')} create a polished Linux .desktop launcher`, ];
return boxen(lines.join('\n'), { padding: 1, margin: 1, borderStyle: 'single', borderColor: '#06b6d4', });}
async function run() { const parsed = parseCli();
if (parsed['--help']) { console.log(getHelpText()); return; }
if (parsed['--version']) { console.log(pkg.version); return; }
const positional = parsed._.slice(); const positionalCwd = positional[0] ? String(positional[0]) : '';
const cwd = path.resolve(parsed['--cwd'] || positionalCwd || process.cwd()); const dryRun = Boolean(parsed['--dry-run']); const outputArg = parsed['--output'] ? String(parsed['--output']) : undefined; const maxDepth = toPositiveInteger(parsed['--max-depth'], 4); const maxFiles = toPositiveInteger(parsed['--max-files'], 6000);
if (!process.stdout.isTTY) { throw new Error('dotstop requires an interactive TTY. Use --help for non-interactive mode.'); }
console.log(getStartupBox(cwd, dryRun));
await runWizard({ cwd, dryRun, outputArg, maxDepth, maxFiles, });}
module.exports = { run,};