Skip to content

Commit

Permalink
Fix create script
Browse files Browse the repository at this point in the history
should now work with bun and node
  • Loading branch information
Didas-git committed Dec 7, 2023
1 parent 6833360 commit 3766b70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lilybird/create",
"version": "0.1.3",
"version": "0.1.7",
"description": "Create a new template bot using lilybird",
"main": "./dist/index.js",
"author": "DidaS",
Expand Down
16 changes: 10 additions & 6 deletions packages/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,26 @@ process.chdir(root);

await writeFile("package.json", packageJSON);
await writeFile("README.md", generateREADME(pm, type));
await writeFile(".env", "TOKEN=")
await writeFile(".env", "TOKEN=");

if (type === "ts") await writeFile("globals.d.ts", generateGlobalTypes())

if (type === "ts") await writeFile("globals.d.ts", generateGlobalTypes(pm))
if (config !== null) await writeFile("tsconfig.json", generateTSConfig(config, pm));

await mkdir("src");
process.chdir(resolve("src"));
await cp(new URL("./index-template.ts", import.meta.url), `./index.${type}`);

execSync(`${pm} install ${dependencies.join(" ")}`, {
stdio: "inherit"
});

if (pm === "bun") devDeps.push("bun-types");
else devDeps.push("ts-node", "@types/node");

if (devDeps.length > 0) execSync(`${pm} install -D ${devDeps.join(" ")}`)
execSync(`${pm} install -D ${devDeps.join(" ")}`, {
stdio: "inherit"
})

await mkdir("src");
process.chdir(resolve("src"));
await cp(new URL("./index-template.ts", import.meta.url), `${root}/index.${type}`)

console.log(c.green("All done!"));
21 changes: 15 additions & 6 deletions packages/create/src/templates.cts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export function generateTSConfig(type: string, pm: string): string {
const temp: {
extends: string | undefined,
compilerOptions: {
target: string,
module: string,
moduleResolution: string,
outDir: string,
baseUrl: string,
strict: true,
Expand All @@ -37,6 +40,9 @@ export function generateTSConfig(type: string, pm: string): string {
} = {
extends: undefined,
compilerOptions: {
target: "ESNext",
module: "Node16",
moduleResolution: "Node16",
outDir: "dist",
baseUrl: ".",
strict: true,
Expand All @@ -52,12 +58,15 @@ export function generateTSConfig(type: string, pm: string): string {
return JSON.stringify(temp, null, 4);
}

export function generateGlobalTypes(): string {
return `declare global {
namespace NodeJS {
interface ProcessEnv {
TOKEN: string;
}
export function generateGlobalTypes(pm: string): string {
return pm === "bun" ? `declare module "bun" {
interface Env {
TOKEN: string
}
}`
: `declare namespace NodeJS {
interface ProcessEnv {
TOKEN: string
}
}`;
}

0 comments on commit 3766b70

Please sign in to comment.