From 218ae5de18e40a3c3515c27a5f6150eaf2e9550e Mon Sep 17 00:00:00 2001 From: Lex Borisoff Date: Sun, 3 Aug 2025 19:31:32 -0400 Subject: [PATCH 1/2] refactor: moved args to the project root and created Option enum --- src/{utils => }/args.ts | 44 ++++++++++++++++++++--------------------- src/main.ts | 2 +- src/select-script.ts | 2 +- src/update-tmp.ts | 2 +- src/utils/get-args.ts | 2 +- 5 files changed, 25 insertions(+), 27 deletions(-) rename src/{utils => }/args.ts (76%) diff --git a/src/utils/args.ts b/src/args.ts similarity index 76% rename from src/utils/args.ts rename to src/args.ts index d50d11f..42f6501 100644 --- a/src/utils/args.ts +++ b/src/args.ts @@ -1,8 +1,8 @@ import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import { getConfigData } from '../config/get-config-data.js'; -import { PACKAGE_VERSION } from '../constants.js'; +import { getConfigData } from './config/get-config-data.js'; +import { PACKAGE_VERSION } from './constants.js'; const desc = { runWith(packageManager: string): string { @@ -16,22 +16,20 @@ const group = { config: 'Config Options:', }; -const options = [ - 'npm', - 'pnpm', - 'yarn', - 'bun', - 'select', - 'first', - 'default', - 'which', - 'rename', -] as const; - -type Option = (typeof options)[number]; +enum Option { + Npm = 'npm', + Pnpm = 'pnpm', + Yarn = 'yarn', + Bun = 'bun', + Select = 'select', + First = 'first', + Default = 'default', + Which = 'which', + Rename = 'rename', +} function noConflict(itself: Option, ...other: Option[]): Option[] { - return options.filter( + return Object.values(Option).filter( (option) => option !== itself && !other.includes(option), ); } @@ -45,28 +43,28 @@ const parsed = yargs(hideBin(process.argv)) description: desc.runWith('npm'), alias: 'n', group: group.script, - conflicts: noConflict('npm', 'select'), + conflicts: noConflict(Option.Npm, Option.Select), }) .option('pnpm', { type: 'boolean', description: desc.runWith('pnpm'), alias: 'p', group: group.script, - conflicts: noConflict('pnpm', 'select'), + conflicts: noConflict(Option.Pnpm, Option.Select), }) .option('yarn', { type: 'boolean', description: desc.runWith('yarn'), group: group.script, alias: 'y', - conflicts: noConflict('yarn', 'select'), + conflicts: noConflict(Option.Yarn, Option.Select), }) .option('bun', { type: 'boolean', description: desc.runWith('bun'), group: group.script, alias: 'b', - conflicts: noConflict('bun', 'select'), + conflicts: noConflict(Option.Bun, Option.Select), }) .option('select', { type: 'boolean', @@ -87,20 +85,20 @@ const parsed = yargs(hideBin(process.argv)) description: 'Set the default package manager', alias: 'd', group: group.packageManager, - conflicts: noConflict('default'), + conflicts: noConflict(Option.Default), }) .option('which', { type: 'boolean', description: 'Show which package which is currently used', alias: 'w', group: group.packageManager, - conflicts: noConflict('which'), + conflicts: noConflict(Option.Which), }) .option('rename', { type: 'string', description: 'Rename the command', group: group.config, - conflicts: noConflict('rename'), + conflicts: noConflict(Option.Rename), }) .help() .version(PACKAGE_VERSION) diff --git a/src/main.ts b/src/main.ts index c6ac5b2..e77c793 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ #!/usr/bin/env node +import { args } from './args.js'; import { renameCommand } from './create-app/rename-command.js'; import { currentPackageManager, @@ -7,7 +8,6 @@ import { } from './package-manager/index.js'; import { selectScript } from './select-script.js'; import { updateTmp } from './update-tmp.js'; -import { args } from './utils/args.js'; import { logger } from './utils/logger.js'; (async function main() { diff --git a/src/select-script.ts b/src/select-script.ts index 171546d..be802de 100644 --- a/src/select-script.ts +++ b/src/select-script.ts @@ -1,6 +1,6 @@ import $_ from '@lexjs/prompts'; -import { args } from './utils/args.js'; +import { args } from './args.js'; import { getArgs } from './utils/get-args.js'; import { getPackageJson } from './utils/get-package-json.js'; import { logger } from './utils/logger.js'; diff --git a/src/update-tmp.ts b/src/update-tmp.ts index daae88c..aa1310f 100644 --- a/src/update-tmp.ts +++ b/src/update-tmp.ts @@ -1,7 +1,7 @@ +import { args } from './args.js'; import { getConfigData } from './config/get-config-data.js'; import { useCoreHooks } from './hooks/use-core-hooks.js'; import { getProjectPm } from './package-manager/utils/get-project-pm.js'; -import { args } from './utils/args.js'; import { getArgs } from './utils/get-args.js'; const { passThroughArgs } = getArgs(); diff --git a/src/utils/get-args.ts b/src/utils/get-args.ts index 97ec404..81826a6 100644 --- a/src/utils/get-args.ts +++ b/src/utils/get-args.ts @@ -1,4 +1,4 @@ -import { args } from './args.js'; +import { args } from '../args.js'; const toString = (value: string | number): string => `${value}`; const _ = args._.map(toString); From 4e1a6aa4d30200f1e39e4bf13dfdc496520cbf48 Mon Sep 17 00:00:00 2001 From: Lex Borisoff Date: Sun, 3 Aug 2025 19:34:04 -0400 Subject: [PATCH 2/2] build: updated package scripts with better script names --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 26e082e..2ed7cc9 100644 --- a/package.json +++ b/package.json @@ -9,16 +9,16 @@ }, "scripts": { "prepack": "npm run build", - "build": "npm run compile", "prebuild": "npm run ci && rimraf ./dist", - "ci": "npm run check-style && npm run check-build", - "check-style": "npm run format:check && npm run lint", - "check-build": "npm run compile -- --noEmit", - "format": "prettier --write \"*.{js,cjs,mjs,ts,cts,mts}\" \"{src,test}/**/*.ts\"", + "build": "npm run compile", + "ci": "npm run style:check && npm run build:check", + "style:check": "npm run format:check && npm run lint:check", + "build:check": "npm run compile -- --noEmit", "format:check": "prettier --check \"*.{js,cjs,mjs,ts,cts,mts}\" \"{src,test}/**/*.ts\"", - "lint": "eslint \"{src,test}/**/*.{js,ts}\"", - "lint:fix": "npm run lint -- --fix", - "style": "npm run format && npm run lint:fix", + "lint:check": "eslint \"{src,test}/**/*.{js,ts}\"", + "style": "npm run format && npm run lint", + "format": "prettier --write \"*.{js,cjs,mjs,ts,cts,mts}\" \"{src,test}/**/*.ts\"", + "lint": "npm run lint:check -- --fix", "compile": "tsc -p tsconfig.json", "prepare": "husky" },