mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
build: pnpm (#9806)
This commit is contained in:
@@ -4,7 +4,7 @@ import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { URL } from 'node:url';
|
||||
import glob from 'fast-glob';
|
||||
import { red, yellow, green, cyan } from 'picocolors';
|
||||
import picocolors from 'picocolors';
|
||||
import type { PackageManager } from './helpers/packageManager.js';
|
||||
import { install } from './helpers/packageManager.js';
|
||||
import { GUIDE_URL } from './util/constants.js';
|
||||
@@ -34,12 +34,16 @@ export async function createDiscordBot({ directory, installPackages, typescript,
|
||||
|
||||
// If the directory is actually a file or if it's not empty, throw an error.
|
||||
if (!directoryStats.isDirectory() || (await readdir(root)).length > 0) {
|
||||
console.error(red(`The directory ${yellow(`"${directoryName}"`)} is either not a directory or is not empty.`));
|
||||
console.error(red(`Please specify an empty directory.`));
|
||||
console.error(
|
||||
picocolors.red(
|
||||
`The directory ${picocolors.yellow(`"${directoryName}"`)} is either not a directory or is not empty.`,
|
||||
),
|
||||
);
|
||||
console.error(picocolors.red(`Please specify an empty directory.`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Creating ${directoryName} in ${green(root)}.`);
|
||||
console.log(`Creating ${directoryName} in ${picocolors.green(root)}.`);
|
||||
const deno = packageManager === 'deno';
|
||||
await cp(new URL(`../template/${deno ? 'Deno' : typescript ? 'TypeScript' : 'JavaScript'}`, import.meta.url), root, {
|
||||
recursive: true,
|
||||
@@ -82,12 +86,14 @@ export async function createDiscordBot({ directory, installPackages, typescript,
|
||||
await writeFile(file, newData);
|
||||
}
|
||||
|
||||
const newPackageJSON = await readFile('./package.json', { encoding: 'utf8' }).then((str) => {
|
||||
let newStr = str.replace('[REPLACE_ME]', directoryName);
|
||||
newStr = newStr.replaceAll('[REPLACE_IMPORT_EXT]', typescript ? 'ts' : 'js');
|
||||
return newStr;
|
||||
});
|
||||
await writeFile('./package.json', newPackageJSON);
|
||||
if (!deno) {
|
||||
const newPackageJSON = await readFile('./package.json', { encoding: 'utf8' }).then((str) => {
|
||||
let newStr = str.replace('[REPLACE_ME]', directoryName);
|
||||
newStr = newStr.replaceAll('[REPLACE_IMPORT_EXT]', typescript ? 'ts' : 'js');
|
||||
return newStr;
|
||||
});
|
||||
await writeFile('./package.json', newPackageJSON);
|
||||
}
|
||||
|
||||
if (installPackages) {
|
||||
try {
|
||||
@@ -96,15 +102,15 @@ export async function createDiscordBot({ directory, installPackages, typescript,
|
||||
console.log();
|
||||
const err = error as ExecException;
|
||||
if (err.signal === 'SIGINT') {
|
||||
console.log(red('Installation aborted.'));
|
||||
console.log(picocolors.red('Installation aborted.'));
|
||||
} else {
|
||||
console.error(red('Installation failed.'));
|
||||
console.error(picocolors.red('Installation failed.'));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log();
|
||||
console.log(green('All done! Be sure to read through the discord.js guide for help on your journey.'));
|
||||
console.log(`Link: ${cyan(GUIDE_URL)}`);
|
||||
console.log(picocolors.green('All done! Be sure to read through the discord.js guide for help on your journey.'));
|
||||
console.log(`Link: ${picocolors.cyan(GUIDE_URL)}`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import process from 'node:process';
|
||||
import { yellow } from 'picocolors';
|
||||
import picocolors from 'picocolors';
|
||||
import { DEFAULT_PACKAGE_MANAGER } from '../util/constants.js';
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ export function resolvePackageManager(): PackageManager {
|
||||
}
|
||||
|
||||
console.error(
|
||||
yellow(
|
||||
picocolors.yellow(
|
||||
`Detected an unsupported package manager (${npmConfigUserAgent}). Falling back to ${DEFAULT_PACKAGE_MANAGER}.`,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user