Skip to content

Commit

Permalink
added support for bun
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalbanese committed Sep 12, 2023
1 parent f281514 commit 4b16f35
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kirimase",
"version": "0.0.11",
"version": "0.0.13",
"description": "A Rails-like CLI for Nextjs and Drizzle ORM",
"main": "index.js",
"type": "module",
Expand Down
24 changes: 20 additions & 4 deletions src/commands/add/orm/drizzle/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ export type ComputerId = z.infer<typeof computerIdSchema>["id"];`;
createFile(path, finalDoc);
};

export const addScriptsToPackageJson = (libPath: string, driver: DBType) => {
export const addScriptsToPackageJson = (
libPath: string,
driver: DBType,
preferredPackageManager: PMType
) => {
// Define the path to package.json
const packageJsonPath = path.resolve("package.json");

Expand All @@ -420,7 +424,9 @@ export const addScriptsToPackageJson = (libPath: string, driver: DBType) => {

const newItems = {
"db:generate": `drizzle-kit generate:${driver}`,
"db:migrate": `tsx ${libPath}/db/migrate.ts`,
"db:migrate": `${
preferredPackageManager === "bun" ? "bun run" : "tsx"
} ${libPath}/db/migrate.ts`,
"db:drop": `drizzle-kit drop`,
"db:pull": `drizzle-kit introspect:${driver}`,
...(driver !== "pg" ? { "db:push": `drizzle-kit push:${driver}` } : {}),
Expand Down Expand Up @@ -473,11 +479,21 @@ export const installDependencies = async (
}
};

export const createDotEnv = (databaseUrl?: string) => {
export const createDotEnv = (
databaseUrl?: string,
usingPlanetscale: boolean = false
) => {
const dburl =
databaseUrl ?? "postgresql://postgres:postgres@localhost:5432/{DB_NAME}";

createFile(".env", `DATABASE_URL=${dburl}`);
createFile(
".env",
`${
usingPlanetscale
? `# When using the PlanetScale driver, your connection string must end with ?ssl={"rejectUnauthorized":true} instead of ?sslaccept=strict.\n`
: ""
}DATABASE_URL=${dburl}`
);
};

export const addToDotEnv = (items: { key: string; value: string }[]) => {
Expand Down
12 changes: 9 additions & 3 deletions src/commands/add/orm/drizzle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createFolder,
readConfigFile,
updateConfigFile,
wrapInParenthesis,
} from "../../../../utils.js";
import {
addScriptsToPackageJson,
Expand Down Expand Up @@ -38,7 +39,12 @@ export const addDrizzle = async () => {
{
name: "SQLite",
value: "sqlite",
// disabled: wrapInParenthesis("SQLite is not yet supported"),
disabled:
preferredPackageManager === "bun"
? wrapInParenthesis(
"Drizzle Kit doesn't support SQLite with Bun yet"
)
: false,
},
],
})) as DBType;
Expand Down Expand Up @@ -89,8 +95,8 @@ export const addDrizzle = async () => {
createDrizzleConfig(libPath, dbProvider);

// perhaps using push rather than migrate for sqlite?
addScriptsToPackageJson(libPath, dbType);
createDotEnv(databaseUrl);
addScriptsToPackageJson(libPath, dbType, preferredPackageManager);
createDotEnv(databaseUrl, dbProvider === "planetscale");
updateTsConfigTarget();

updateConfigFile({ driver: dbType, provider: dbProvider, orm: "drizzle" });
Expand Down
2 changes: 1 addition & 1 deletion src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function initProject() {
{ name: "NPM", value: "npm" },
{ name: "Yarn", value: "yarn" },
{ name: "PNPM", value: "pnpm" },
// { name: "Bun", value: "bun" },
{ name: "Bun", value: "bun" },
],
})) as PMType;
// console.log("installing dependencies with", preferredPackageManager);
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { consola } from "consola";

const program = new Command();
program.name("kirimase").description("Kirimase CLI").version("0.0.11");
program.name("kirimase").description("Kirimase CLI").version("0.0.13");

program
.command("init")
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type DBProviderOptions = {
mysql: DBProviderItem[];
sqlite: DBProviderItem[];
};
export type PMType = "npm" | "yarn" | "pnpm"; // | "bun";
export type PMType = "npm" | "yarn" | "pnpm" | "bun";

// export type FieldType =
// | "id"
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const pmInstallCommand = {
pnpm: "pnpm",
npm: "npx",
yarn: "npx",
// bun: "bunx",
bun: "bunx",
};

export async function installShadcnUIComponents(
Expand Down

0 comments on commit 4b16f35

Please sign in to comment.