Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add no-install option #9604

Merged
merged 5 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 3 additions & 2 deletions packages/create-discord-bot/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ program
})
.option('--typescript', 'Whether to use the TypeScript template.')
.option('--javascript', 'Whether to use the JavaScript template.')
.option('--noInstall', 'Whether to not automatically install the packages.')
jaw0r3k marked this conversation as resolved.
Show resolved Hide resolved
.addOption(
new Option('--packageManager <packageManager>', 'The package manager to use.')
.choices(PACKAGE_MANAGERS)
Expand All @@ -49,7 +50,7 @@ program
.parse();

// eslint-disable-next-line prefer-const
let { typescript, javascript, packageManager } = program.opts();
let { typescript, javascript, packageManager, noInstall } = 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, noInstall });
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;
noInstall?: boolean;
packageManager: PackageManager;
typescript?: boolean;
}

export async function createDiscordBot({ directory, typescript, packageManager }: Options) {
export async function createDiscordBot({ directory, noInstall, 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 (!noInstall) {
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