Skip to content

Commit c2baa37

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

File tree

32 files changed

+401
-105
lines changed

32 files changed

+401
-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
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import common from 'eslint-config-neon/common';
2+
import node from 'eslint-config-neon/node';
3+
import prettier from 'eslint-config-neon/prettier';
4+
5+
const config = [
6+
{
7+
ignores: [],
8+
},
9+
...common,
10+
...node,
11+
...prettier,
12+
{
13+
rules: {
14+
'jsdoc/check-tag-names': 0,
15+
'jsdoc/no-undefined-types': 0,
16+
'jsdoc/valid-types': 0,
17+
},
18+
},
19+
];
20+
21+
export default config;

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",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import common from 'eslint-config-neon/common';
2+
import node from 'eslint-config-neon/node';
3+
import prettier from 'eslint-config-neon/prettier';
4+
import typescript from 'eslint-config-neon/typescript';
5+
6+
const config = [
7+
{
8+
ignores: [],
9+
},
10+
...common,
11+
...node,
12+
...typescript,
13+
...prettier,
14+
{
15+
languageOptions: {
16+
parserOptions: {
17+
project: ['./tsconfig.eslint.json'],
18+
},
19+
},
20+
rules: {
21+
'import/extensions': 0,
22+
},
23+
},
24+
];
25+
26+
export default config;

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",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

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
}

0 commit comments

Comments
 (0)