Skip to content

Commit 4b42f76

Browse files
committed
feat: use native node typescript
1 parent 3cb3eca commit 4b42f76

File tree

28 files changed

+352
-105
lines changed

28 files changed

+352
-105
lines changed

packages/create-discord-bot/src/create-discord-bot.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { ExecException } from 'node:child_process';
2-
import { cp, glob, mkdir, stat, readdir, readFile, writeFile } from 'node:fs/promises';
2+
import { cp, mkdir, stat, readdir, readFile, writeFile } from 'node:fs/promises';
33
import path from 'node:path';
44
import process from 'node:process';
55
import { URL } from 'node:url';
66
import { styleText } from 'node:util';
77
import type { PackageManager } from './helpers/packageManager.js';
8-
import { install, isNodePackageManager } from './helpers/packageManager.js';
8+
import { install } from './helpers/packageManager.js';
99
import { GUIDE_URL } from './util/constants.js';
1010

1111
interface Options {
@@ -67,39 +67,18 @@ export async function createDiscordBot({ directory, installPackages, typescript,
6767

6868
process.chdir(root);
6969

70-
const newVSCodeSettings = await readFile('./.vscode/settings.json', {
71-
encoding: 'utf8',
72-
}).then((str) => {
73-
let newStr = str.replace('[REPLACE_ME]', deno || bun ? 'auto' : packageManager);
74-
if (deno) {
75-
// @ts-expect-error: This is fine
76-
newStr = newStr.replaceAll('"[REPLACE_BOOL]"', true);
77-
}
78-
79-
return newStr;
80-
});
81-
await writeFile('./.vscode/settings.json', newVSCodeSettings);
82-
83-
const globIterator = glob('./src/**/*.ts');
84-
for await (const file of globIterator) {
85-
const newData = await readFile(file, { encoding: 'utf8' }).then((str) =>
86-
str.replaceAll('[REPLACE_IMPORT_EXT]', typescript && !isNodePackageManager(packageManager) ? 'ts' : 'js'),
87-
);
88-
await writeFile(file, newData);
89-
}
70+
const newVSCodeSettings = await readFile('./.vscode/settings.json', { encoding: 'utf8' });
71+
await writeFile(
72+
'./.vscode/settings.json',
73+
newVSCodeSettings.replace(
74+
/"npm\.packageManager":\s*"[^"]+"/,
75+
`"npm.packageManager": "${deno || bun ? 'auto' : packageManager}"`,
76+
),
77+
);
9078

9179
if (!deno) {
92-
const newPackageJSON = await readFile('./package.json', {
93-
encoding: 'utf8',
94-
}).then((str) => {
95-
let newStr = str.replace('[REPLACE_ME]', directoryName);
96-
newStr = newStr.replaceAll(
97-
'[REPLACE_IMPORT_EXT]',
98-
typescript && !isNodePackageManager(packageManager) ? 'ts' : 'js',
99-
);
100-
return newStr;
101-
});
102-
await writeFile('./package.json', newPackageJSON);
80+
const newPackageJSON = await readFile('./package.json', { encoding: 'utf8' });
81+
await writeFile('./package.json', newPackageJSON.replace(/"name":\s*"[^"]+"/, `"name": "${directoryName}"`));
10382
}
10483

10584
if (installPackages) {

packages/create-discord-bot/src/helpers/packageManager.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { execSync } from 'node:child_process';
22
import process from 'node:process';
33
import { styleText } from 'node:util';
4-
import { DEFAULT_PACKAGE_MANAGER, NODE_PACKAGE_MANAGERS } from '../util/constants.js';
4+
import { DEFAULT_PACKAGE_MANAGER, type PACKAGE_MANAGERS } from '../util/constants.js';
55

66
/**
77
* A union of supported package managers.
88
*/
9-
export type PackageManager = 'bun' | 'deno' | 'npm' | 'pnpm' | 'yarn';
9+
export type PackageManager = (typeof PACKAGE_MANAGERS)[number];
1010

1111
/**
1212
* Resolves the package manager from `npm_config_user_agent`.
@@ -117,12 +117,3 @@ export function install(packageManager: PackageManager) {
117117
env,
118118
});
119119
}
120-
121-
/**
122-
* Whether the provided package manager is a Node package manager.
123-
*
124-
* @param packageManager - The package manager to check
125-
*/
126-
export function isNodePackageManager(packageManager: PackageManager): packageManager is 'npm' | 'pnpm' | 'yarn' {
127-
return NODE_PACKAGE_MANAGERS.includes(packageManager as any);
128-
}

packages/create-discord-bot/src/util/constants.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ export const DEFAULT_PROJECT_NAME = 'my-bot' as const;
1313
*/
1414
export const PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun', 'deno'] as const;
1515

16-
/**
17-
* The supported Node.js package managers.
18-
*/
19-
export const NODE_PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn'] as const;
20-
2116
/**
2217
* The URL to the guide.
2318
*/

packages/create-discord-bot/template/Bun/JavaScript/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
3-
"name": "[REPLACE_ME]",
3+
"name": "@discordjs/template-bun-javascript",
44
"version": "0.1.0",
55
"private": true,
66
"type": "module",
77
"scripts": {
8-
"lint": "prettier --check . && eslint --ext .[REPLACE_IMPORT_EXT] --format=pretty src",
9-
"deploy": "bun run src/util/deploy.[REPLACE_IMPORT_EXT]",
10-
"format": "prettier --write . && eslint --ext .[REPLACE_IMPORT_EXT] --fix --format=pretty src",
11-
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
8+
"lint": "prettier --check . && eslint --ext .js --format=pretty src",
9+
"deploy": "bun run src/util/deploy.js",
10+
"format": "prettier --write . && eslint --ext .js --fix --format=pretty src",
11+
"start": "bun run src/index.js"
1212
},
1313
"dependencies": {
1414
"@discordjs/core": "^2.3.0",

packages/create-discord-bot/template/Bun/TypeScript/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
3-
"name": "[REPLACE_ME]",
3+
"name": "@discordjs/template-bun-typescript",
44
"version": "0.1.0",
55
"private": true,
66
"type": "module",
77
"scripts": {
8-
"lint": "tsc && prettier --check . && eslint --ext .[REPLACE_IMPORT_EXT] --format=pretty src",
9-
"deploy": "bun run src/util/deploy.[REPLACE_IMPORT_EXT]",
10-
"format": "prettier --write . && eslint --ext .[REPLACE_IMPORT_EXT] --fix --format=pretty src",
11-
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
8+
"lint": "tsc && prettier --check . && eslint --ext .ts --format=pretty src",
9+
"deploy": "bun run src/util/deploy.ts",
10+
"format": "prettier --write . && eslint --ext .ts --fix --format=pretty src",
11+
"start": "bun run src/index.ts"
1212
},
1313
"dependencies": {
1414
"@discordjs/core": "^2.3.0",

packages/create-discord-bot/template/Bun/TypeScript/tsconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"$schema": "https://json.schemastore.org/tsconfig.json",
33
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"],
44
"compilerOptions": {
5+
"allowImportingTsExtensions": true,
56
"declaration": false,
67
"declarationMap": false,
7-
"module": "ESNext",
8-
"moduleResolution": "Bundler",
9-
"target": "ESNext",
10-
"outDir": "dist",
8+
"incremental": false,
9+
"module": "NodeNext",
10+
"moduleResolution": "NodeNext",
1111
"noEmit": true,
12-
"allowImportingTsExtensions": true,
12+
"target": "ESNext",
1313
"skipLibCheck": true
1414
}
1515
}

packages/create-discord-bot/template/Deno/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"editor.trimAutoWhitespace": false,
99
"files.insertFinalNewline": true,
1010
"files.eol": "\n",
11-
"deno.enable": "[REPLACE_BOOL]"
11+
"deno.enable": true
1212
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm-lock.yaml

packages/create-discord-bot/template/JavaScript/.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"recommendations": [
33
"esbenp.prettier-vscode",
44
"dbaeumer.vscode-eslint",
5-
"tamasfe.even-better-toml",
65
"codezombiech.gitignore",
76
"christian-kohler.npm-intellisense",
87
"christian-kohler.path-intellisense"

packages/create-discord-bot/template/JavaScript/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"editor.trimAutoWhitespace": false,
1010
"files.insertFinalNewline": true,
1111
"files.eol": "\n",
12-
"npm.packageManager": "[REPLACE_ME]"
12+
"npm.packageManager": "npm"
1313
}

0 commit comments

Comments
 (0)