Skip to content

Commit

Permalink
feat: Add no-install option (discordjs#9604)
Browse files Browse the repository at this point in the history
* chore: no install option + fix type

* chore: apply suggestions

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

---------

Co-authored-by: Jaw0r3k <jaw0r3k.git@gmail.com>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
3 people authored and almeidx committed Sep 24, 2023
1 parent 5dd7629 commit 532d806
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
7 changes: 4 additions & 3 deletions packages/create-discord-bot/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ program
})
.option('--typescript', 'Whether to use the TypeScript template.')
.option('--javascript', 'Whether to use the JavaScript template.')
.option('--no-install', 'Whether to not automatically install the packages.')
.addOption(
new Option('--packageManager <packageManager>', 'The package manager to use.')
new Option('--package-manager <packageManager>', 'The package manager to use.')
.choices(PACKAGE_MANAGERS)
.default(resolvePackageManager()),
)
.allowUnknownOption()
.parse();

// eslint-disable-next-line prefer-const
let { typescript, javascript, packageManager } = program.opts();
let { typescript, javascript, packageManager, install: installPackages } = program.opts();

if (!projectDirectory) {
projectDirectory = (
Expand Down Expand Up @@ -100,4 +101,4 @@ if (!deno && typescript === undefined && javascript === undefined) {
typescript = useTypescript;
}

await createDiscordBot({ typescript, directory: projectDirectory, packageManager });
await createDiscordBot({ typescript, directory: projectDirectory, packageManager, installPackages });
25 changes: 14 additions & 11 deletions packages/create-discord-bot/src/create-discord-bot.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { GUIDE_URL } from './util/constants.js';

interface Options {
directory: string;
installPackages: boolean;
packageManager: PackageManager;
typescript?: boolean;
}

export async function createDiscordBot({ directory, typescript, packageManager }: Options) {
export async function createDiscordBot({ directory, installPackages, typescript, packageManager }: Options) {
const root = path.resolve(directory);
const directoryName = path.basename(root);

Expand Down Expand Up @@ -88,16 +89,18 @@ export async function createDiscordBot({ directory, typescript, packageManager }
});
await writeFile('./package.json', newPackageJSON);

try {
install(packageManager);
} catch (error) {
console.log();
const err = error as ExecException;
if (err.signal === 'SIGINT') {
console.log(red('Installation aborted.'));
} else {
console.error(red('Installation failed.'));
process.exit(1);
if (installPackages) {
try {
install(packageManager);
} catch (error) {
console.log();
const err = error as ExecException;
if (err.signal === 'SIGINT') {
console.log(red('Installation aborted.'));
} else {
console.error(red('Installation failed.'));
process.exit(1);
}
}
}

Expand Down

0 comments on commit 532d806

Please sign in to comment.