|
1 | 1 | import type { ExecException } from 'node:child_process'; |
2 | | -import { cp, stat, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'; |
| 2 | +import { cp, glob, mkdir, stat, readdir, readFile, writeFile } from 'node:fs/promises'; |
3 | 3 | import path from 'node:path'; |
4 | 4 | import process from 'node:process'; |
5 | 5 | import { URL } from 'node:url'; |
6 | | -import glob from 'fast-glob'; |
7 | | -import picocolors from 'picocolors'; |
| 6 | +import { styleText } from 'node:util'; |
8 | 7 | import type { PackageManager } from './helpers/packageManager.js'; |
9 | 8 | import { install, isNodePackageManager } from './helpers/packageManager.js'; |
10 | 9 | import { GUIDE_URL } from './util/constants.js'; |
@@ -35,15 +34,16 @@ export async function createDiscordBot({ directory, installPackages, typescript, |
35 | 34 | // If the directory is actually a file or if it's not empty, throw an error. |
36 | 35 | if (!directoryStats.isDirectory() || (await readdir(root)).length > 0) { |
37 | 36 | console.error( |
38 | | - picocolors.red( |
39 | | - `The directory ${picocolors.yellow(`"${directoryName}"`)} is either not a directory or is not empty.`, |
| 37 | + styleText( |
| 38 | + 'red', |
| 39 | + `The directory ${styleText('yellow', `"${directoryName}"`)} is either not a directory or is not empty.`, |
40 | 40 | ), |
41 | 41 | ); |
42 | | - console.error(picocolors.red(`Please specify an empty directory.`)); |
| 42 | + console.error(styleText('red', `Please specify an empty directory.`)); |
43 | 43 | process.exit(1); |
44 | 44 | } |
45 | 45 |
|
46 | | - console.log(`Creating ${directoryName} in ${picocolors.green(root)}.`); |
| 46 | + console.log(`Creating ${directoryName} in ${styleText('green', root)}.`); |
47 | 47 | const deno = packageManager === 'deno'; |
48 | 48 | await cp(new URL(`../template/${deno ? 'Deno' : typescript ? 'TypeScript' : 'JavaScript'}`, import.meta.url), root, { |
49 | 49 | recursive: true, |
@@ -80,8 +80,8 @@ export async function createDiscordBot({ directory, installPackages, typescript, |
80 | 80 | }); |
81 | 81 | await writeFile('./.vscode/settings.json', newVSCodeSettings); |
82 | 82 |
|
83 | | - const globStream = glob.stream('./src/**/*.ts'); |
84 | | - for await (const file of globStream) { |
| 83 | + const globIterator = glob('./src/**/*.ts'); |
| 84 | + for await (const file of globIterator) { |
85 | 85 | const newData = await readFile(file, { encoding: 'utf8' }).then((str) => |
86 | 86 | str.replaceAll('[REPLACE_IMPORT_EXT]', typescript && !isNodePackageManager(packageManager) ? 'ts' : 'js'), |
87 | 87 | ); |
@@ -109,15 +109,15 @@ export async function createDiscordBot({ directory, installPackages, typescript, |
109 | 109 | console.log(); |
110 | 110 | const err = error as ExecException; |
111 | 111 | if (err.signal === 'SIGINT') { |
112 | | - console.log(picocolors.red('Installation aborted.')); |
| 112 | + console.log(styleText('red', 'Installation aborted.')); |
113 | 113 | } else { |
114 | | - console.error(picocolors.red('Installation failed.')); |
| 114 | + console.error(styleText('red', 'Installation failed.')); |
115 | 115 | process.exit(1); |
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 |
|
120 | 120 | console.log(); |
121 | | - console.log(picocolors.green('All done! Be sure to read through the discord.js guide for help on your journey.')); |
122 | | - console.log(`Link: ${picocolors.cyan(GUIDE_URL)}`); |
| 121 | + console.log(styleText('green', 'All done! Be sure to read through the discord.js guide for help on your journey.')); |
| 122 | + console.log(`Link: ${styleText('cyan', GUIDE_URL)}`); |
123 | 123 | } |
0 commit comments