feat(create-discord-bot): bun/deno templates (#9795)

This commit is contained in:
Noel
2023-08-21 22:48:13 +02:00
committed by GitHub
parent 8eb978d32c
commit dd5e7453e8
46 changed files with 700 additions and 115 deletions

View File

@@ -1,12 +1,12 @@
import { execSync } from 'node:child_process';
import process from 'node:process';
import chalk from 'chalk';
import { yellow } from 'picocolors';
import { DEFAULT_PACKAGE_MANAGER } from '../util/constants.js';
/**
* A union of supported package managers.
*/
export type PackageManager = 'npm' | 'pnpm' | 'yarn';
export type PackageManager = 'bun' | 'deno' | 'npm' | 'pnpm' | 'yarn';
/**
* Resolves the package manager from `npm_config_user_agent`.
@@ -32,7 +32,7 @@ export function resolvePackageManager(): PackageManager {
}
console.error(
chalk.yellow(
yellow(
`Detected an unsupported package manager (${npmConfigUserAgent}). Falling back to ${DEFAULT_PACKAGE_MANAGER}.`,
),
);
@@ -47,21 +47,62 @@ export function resolvePackageManager(): PackageManager {
* @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;
}
let installCommand: string[] | string = `${packageManager} install`;
console.log(`Installing dependencies with ${packageManager}...`);
switch (packageManager) {
case 'yarn':
console.log();
installCommand = [
`${packageManager} set version stable`,
`${packageManager} config set nodeLinker node-modules`,
`${packageManager} config set logFilters --json '[{ "code": "YN0002", "level": "discard" }, { "code": "YN0013", "level": "discard" }, { "code": "YN0032", "level": "discard" }, { "code": "YN0060", "level": "discard" }]'`,
`${packageManager} plugin import interactive-tools`,
`${packageManager} plugin import workspace-tools`,
installCommand,
];
break;
case 'deno':
installCommand = `${packageManager} cache --reload src/index.ts`;
break;
case 'pnpm':
case 'bun':
console.log();
break;
default:
break;
}
const env = {
...process.env,
ADBLOCK: '1',
NODE_ENV: 'development',
DISABLE_OPENCOLLECTIVE: '1',
};
if (Array.isArray(installCommand)) {
for (const [index, command] of installCommand.entries()) {
if (index === installCommand.length - 1) {
execSync(command, {
stdio: 'inherit',
env,
});
break;
}
execSync(command, {
stdio: 'ignore',
env,
});
}
return;
}
execSync(installCommand, {
stdio: 'inherit',
env,
});
}