Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/create-app/get-command-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import $_ from '@lexjs/prompts';

import { INITIAL_COMMAND } from '../constants.js';

export async function getCommandName(): Promise<string | undefined> {
const { command } = await $_.text({
name: 'command',
message: 'What should be the command name?',
initial: INITIAL_COMMAND,
});

return command;
}
18 changes: 5 additions & 13 deletions src/create-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import chalk from 'chalk';
import 'dotenv/config';

import { updateConfig } from '../config/update-config.js';
import {
CONFIG_FILE,
INITIAL_COMMAND,
PACKAGE_MANAGERS,
PACKAGE_NAME,
} from '../constants.js';
import { CONFIG_FILE, PACKAGE_MANAGERS, PACKAGE_NAME } from '../constants.js';
import { useCoreHooks } from '../hooks/use-core-hooks.js';
import {
selectPackageManager,
Expand All @@ -20,6 +15,7 @@ import { logger } from '../utils/logger.js';
import { parseData } from '../utils/parse-data.js';

import { createScriptFiles } from './create-script-files.js';
import { getCommandName } from './get-command-name.js';
import { initializeApp } from './initialize-app.js';
import { linkDist } from './link-dist.js';

Expand Down Expand Up @@ -66,17 +62,13 @@ function isEmpty(str: string | undefined): str is undefined | '' {
}

if (isEmpty(command) || renameCommand) {
const result = await $_.text({
name: 'command',
message: 'What should be the command name?',
initial: INITIAL_COMMAND,
});
const commandName = await getCommandName();

if (result.command == null) {
if (commandName == null) {
return;
}

command = result.command;
command = commandName;
}

if (
Expand Down
15 changes: 15 additions & 0 deletions src/create-app/rename-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { colors, logger } from '../utils/logger.js';

import { createScriptFiles } from './create-script-files.js';
import { getCommandName } from './get-command-name.js';

export async function renameCommand(arg: string): Promise<void> {
const command = arg !== '' ? arg : await getCommandName();

if (command == null) {
return;
}

await createScriptFiles(command);
logger.log(`Renamed to ${colors.yellow(command)}`);
}
10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

import { renameCommand } from './create-app/rename-command.js';
import {
currentPackageManager,
defaultPackageManager,
Expand All @@ -11,13 +12,18 @@ import { logger } from './utils/logger.js';

(async function main() {
try {
if (args.which) {
currentPackageManager();
return;
}

if (args.default != null) {
await defaultPackageManager(args.default);
return;
}

if (args.which) {
currentPackageManager();
if (args.rename != null) {
await renameCommand(args.rename);
return;
}

Expand Down
10 changes: 9 additions & 1 deletion src/utils/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const desc = {
const group = {
script: 'Script Options:',
packageManager: 'Package Manager Options:',
config: 'Config Options:',
};

const options = [
Expand All @@ -23,6 +24,7 @@ const options = [
'first',
'default',
'which',
'rename',
] as const;

type Option = (typeof options)[number];
Expand All @@ -35,7 +37,7 @@ function noConflict(itself: Option, ...other: Option[]): Option[] {

const parsed = yargs(hideBin(process.argv))
.scriptName(getConfigData().command)
.usage(`Usage: $0 [OPTION]... [ARG]...`)
.usage(`Usage: $0 [ARG...] [OPTION...]`)
.usage(`Interactively select and run scripts using any package manager`)
.option('npm', {
type: 'boolean',
Expand Down Expand Up @@ -93,6 +95,12 @@ const parsed = yargs(hideBin(process.argv))
group: group.packageManager,
conflicts: noConflict('which'),
})
.option('rename', {
type: 'string',
description: 'Rename the command',
group: group.config,
conflicts: noConflict('rename'),
})
.help()
.version()
.hide('help')
Expand Down
Loading