mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
feat: create-discord-bot (#9420)
* feat: basic initialisation * fix: no scope * chore: add options for issues * feat: good word, Monbrey * feat: basic README.md * fix: no documentation for this * feat: install for them * chore: update licencing * chore: fix year * fix: build tsup * feat: add TypeScript option * feat: add `name` option * chore: ignore annoying errors * chore: add tsconfig.json * refactor: remove name We can just use the name of the directory instead. * chore: update cliff jumper rc * chore: bump dependencies * chore: bump dependencies * fix: build in prepack * fix: configure ESLint correctly * feat: infer package manager * docs(packageManager): document `install()` * fix(packageManager): do not emit a warning for `npm` * refactor: change project name colour to yellow * docs(constants): basic documentation * feat: add link * chore: add `verbatimModuleSyntax` * chore: bump discord.js * refactor: switch to @sapphire/ts-config * refactor: file name changes * refactor: tweak description * chore: update yarn.lock * fix: add .env * chore: bump dependencies * feat: event handler * refactor: use `default` * refactor: simpler event * chore: bump discord.js * fix: add release script and reorder * style: reorder package.json * chore: remove unneeded ignores * chore: bump minimum Node.js version * chore: add @types/node to TypeScript package.json * chore: apply requested changes Co-authored-by: Noel <buechler.noel@outlook.com> * style: run ESLint + Prettier * refactor: prefer "the" * refactor: remove some comments * feat: add ESLint + Prettier * chore: requested changes Co-authored-by: Noel <buechler.noel@outlook.com> * chore: more requested changes Co-authored-by: Noel <buechler.noel@outlook.com> --------- Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
64
packages/create-discord-bot/src/helpers/packageManager.ts
Normal file
64
packages/create-discord-bot/src/helpers/packageManager.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import process from 'node:process';
|
||||
import chalk from 'chalk';
|
||||
import { DEFAULT_PACKAGE_MANAGER } from '../util/constants.js';
|
||||
|
||||
/**
|
||||
* A union of supported package managers.
|
||||
*/
|
||||
export type PackageManager = 'npm' | 'pnpm' | 'yarn';
|
||||
|
||||
/**
|
||||
* Resolves the package manager from `npm_config_user_agent`.
|
||||
*/
|
||||
export function resolvePackageManager(): PackageManager {
|
||||
const npmConfigUserAgent = process.env.npm_config_user_agent;
|
||||
|
||||
// If this is not present, return the default package manager.
|
||||
if (!npmConfigUserAgent) {
|
||||
return DEFAULT_PACKAGE_MANAGER;
|
||||
}
|
||||
|
||||
if (npmConfigUserAgent.startsWith('npm')) {
|
||||
return 'npm';
|
||||
}
|
||||
|
||||
if (npmConfigUserAgent.startsWith('yarn')) {
|
||||
return 'yarn';
|
||||
}
|
||||
|
||||
if (npmConfigUserAgent.startsWith('pnpm')) {
|
||||
return 'pnpm';
|
||||
}
|
||||
|
||||
console.error(
|
||||
chalk.yellow(
|
||||
`Detected an unsupported package manager (${npmConfigUserAgent}). Falling back to ${DEFAULT_PACKAGE_MANAGER}.`,
|
||||
),
|
||||
);
|
||||
|
||||
// Fallback to the default package manager.
|
||||
return DEFAULT_PACKAGE_MANAGER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs with a provided package manager.
|
||||
*
|
||||
* @param packageManager - The package manager to use
|
||||
*/
|
||||
export function install(packageManager: PackageManager) {
|
||||
let installCommand;
|
||||
|
||||
switch (packageManager) {
|
||||
case 'npm':
|
||||
case 'pnpm':
|
||||
installCommand = `${packageManager} install`;
|
||||
break;
|
||||
case 'yarn':
|
||||
installCommand = packageManager;
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(`Installing dependencies with ${packageManager}...`);
|
||||
execSync(installCommand);
|
||||
}
|
||||
Reference in New Issue
Block a user