Skip to content

Commit

Permalink
fixed bug with missing lucia provider for turso
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalbanese committed Dec 26, 2023
1 parent b237199 commit afc6f3b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 40 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.38",
"version": "0.0.39",
"description": "A Rails-like CLI for building full-stack Next.js apps faster",
"main": "index.js",
"type": "module",
Expand Down
12 changes: 12 additions & 0 deletions src/commands/add/auth/lucia/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ export const generateDrizzleAdapterDriverMappings = () => {
{ removeExtension: true, prefix: "alias" }
)}"`,
},
turso: {
adapter: `adapter: libsql(sqlite, {
user: "user",
key: "user_key",
session: "user_session"
})`,
adapterPackage: "@lucia-auth/adapter-sqlite",
import: `import { libsql } from "@lucia-auth/adapter-sqlite";\nimport { sqlite } from "${formatFilePath(
dbIndex,
{ removeExtension: true, prefix: "alias" }
)}"`,
},
},
};
return DrizzleAdapterDriverMappings;
Expand Down
48 changes: 24 additions & 24 deletions src/commands/add/orm/drizzle/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export default {
? `url: env.DATABASE_URL,
authToken: env.DATABASE_AUTH_TOKEN`
: provider === "better-sqlite3"
? "url: env.DATABASE_URL"
: "connectionString: env.DATABASE_URL"
? "url: env.DATABASE_URL"
: "connectionString: env.DATABASE_URL"
}${provider === "vercel-pg" ? '.concat("?sslmode=require")' : ""},
}
} satisfies Config;`,
} satisfies Config;`
);
};

Expand Down Expand Up @@ -205,12 +205,12 @@ import { env } from "${formatFilePath(envMjs, {
prefix: "alias",
})}";
const client = createClient({
export const sqlite = createClient({
url: env.DATABASE_URL,
authToken: env.DATABASE_AUTH_TOKEN,
});
export const db = drizzle(client);
export const db = drizzle(sqlite);
`;
break;
// case "bun-sqlite":
Expand All @@ -227,14 +227,14 @@ export const db = drizzle(client);

createFile(
formatFilePath(dbIndex, { prefix: "rootPath", removeExtension: false }),
indexTS,
indexTS
);
};

export const createMigrateTs = (
libPath: string,
dbType: DBType,
dbProvider: DBProvider,
dbProvider: DBProvider
) => {
const {
drizzle: { dbMigrate, migrationsDir },
Expand Down Expand Up @@ -423,7 +423,7 @@ runMigrate().catch((err) => {

createFile(
formatFilePath(dbMigrate, { prefix: "rootPath", removeExtension: false }),
template,
template
);
};

Expand Down Expand Up @@ -521,7 +521,7 @@ export type ComputerId = z.infer<typeof computerIdSchema>["id"];`;
export const addScriptsToPackageJson = (
libPath: string,
driver: DBType,
preferredPackageManager: PMType,
preferredPackageManager: PMType
) => {
// Define the path to package.json
const packageJsonPath = path.resolve("package.json");
Expand Down Expand Up @@ -557,7 +557,7 @@ export const addScriptsToPackageJson = (

export const installDependencies = async (
dbType: DBProvider,
preferredPackageManager: PMType,
preferredPackageManager: PMType
) => {
const packages: { [key in DBProvider]: { regular: string; dev: string } } = {
postgresjs: { regular: "postgres", dev: "pg" },
Expand All @@ -583,7 +583,7 @@ export const installDependencies = async (
regular: `drizzle-orm drizzle-zod @t3-oss/env-nextjs zod ${dbSpecificPackage.regular}`,
dev: `drizzle-kit tsx dotenv ${dbSpecificPackage.dev}`,
},
preferredPackageManager,
preferredPackageManager
);
}
};
Expand All @@ -593,7 +593,7 @@ export const createDotEnv = (
preferredPackageManager: PMType,
databaseUrl?: string,
usingPlanetscale: boolean = false,
rootPathOld: string = "",
rootPathOld: string = ""
) => {
const {
shared: {
Expand All @@ -612,7 +612,7 @@ export const createDotEnv = (
orm === "drizzle" && usingPlanetscale
? `# When using the PlanetScale driver with Drizzle, your connection string must end with ?ssl={"rejectUnauthorized":true} instead of ?sslaccept=strict.\n`
: ""
}DATABASE_URL=${dburl}`,
}DATABASE_URL=${dburl}`
);

const envmjsfilePath = formatFilePath(envMjs, {
Expand All @@ -627,7 +627,7 @@ export const createDotEnv = (
export const addToDotEnv = (
items: DotEnvItem[],
rootPathOld?: string,
excludeDbUrlIfBlank = false,
excludeDbUrlIfBlank = false
) => {
const { orm, preferredPackageManager } = readConfigFile();
const {
Expand Down Expand Up @@ -658,7 +658,7 @@ export const addToDotEnv = (
if (!envMjsExists)
createFile(
envmjsfilePath,
generateEnvMjs(preferredPackageManager, orm, excludeDbUrlIfBlank),
generateEnvMjs(preferredPackageManager, orm, excludeDbUrlIfBlank)
);
let envmjsfileContents = fs.readFileSync(envmjsfilePath, "utf-8");

Expand Down Expand Up @@ -694,7 +694,7 @@ export const addToDotEnv = (
const runtimeEnvRegex = /experimental__runtimeEnv: {\n/s;
envmjsfileContents = envmjsfileContents.replace(
runtimeEnvRegex,
`experimental__runtimeEnv: {\n ${runtimeEnvItems}`,
`experimental__runtimeEnv: {\n ${runtimeEnvItems}`
);
// Write the updated contents back to the file
fs.writeFileSync(envmjsfilePath, envmjsfileContents);
Expand All @@ -708,7 +708,7 @@ export async function updateTsConfigTarget() {
fs.readFile(tsConfigPath, "utf8", (err, data) => {
if (err) {
console.error(
`An error occurred while reading the tsconfig.json file: ${err}`,
`An error occurred while reading the tsconfig.json file: ${err}`
);
return;
}
Expand All @@ -726,14 +726,14 @@ export async function updateTsConfigTarget() {
// Write the updated content back to the file
replaceFile(tsConfigPath, updatedContent);
consola.success(
"Updated tsconfig.json target to esnext to support Drizzle-Kit.",
"Updated tsconfig.json target to esnext to support Drizzle-Kit."
);
});
}

export function createQueriesAndMutationsFolders(
libPath: string,
driver: DBType,
driver: DBType
) {
const dbIndex = getDbIndexPath("drizzle");
// create computers queries
Expand All @@ -744,7 +744,7 @@ export function createQueriesAndMutationsFolders(
import { eq } from "drizzle-orm";
import { computerIdSchema, computers, ComputerId } from "${formatFilePath(
"lib/db/schema/computers.ts",
{ removeExtension: true, prefix: "alias" },
{ removeExtension: true, prefix: "alias" }
)}";
export const getComputers = async () => {
Expand All @@ -766,7 +766,7 @@ export const getComputerById = async (id: ComputerId) => {
import { eq } from "drizzle-orm";
import { NewComputer, insertComputerSchema, computers, computerIdSchema, ComputerId } from "${formatFilePath(
"lib/db/schema/computers.ts",
{ removeExtension: true, prefix: "alias" },
{ removeExtension: true, prefix: "alias" }
)}";
export const createComputer = async (computer: NewComputer) => {
Expand Down Expand Up @@ -826,21 +826,21 @@ export const deleteComputer = async (id: ComputerId) => {
removeExtension: false,
prefix: "rootPath",
}),
query,
query
);
createFile(
formatFilePath(`lib/api/computers/mutations.ts`, {
prefix: "rootPath",
removeExtension: false,
}),
mutation,
mutation
);
}

const generateEnvMjs = (
preferredPackageManager: PMType,
ormType: ORMType,
blank = false,
blank = false
) => {
return `import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";${
Expand Down
28 changes: 14 additions & 14 deletions src/commands/add/orm/drizzle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ export const addDrizzle = async (initOptions?: InitOptions) => {
{
name: "SQLite",
value: "sqlite",
disabled:
preferredPackageManager === "bun"
? wrapInParenthesis(
"Drizzle Kit doesn't support SQLite with Bun yet",
)
: false,
// disabled:
// preferredPackageManager === "bun"
// ? wrapInParenthesis(
// "Drizzle Kit doesn't support SQLite with Bun yet",
// )
// : false,
},
],
})) as DBType);

// const dbProviders = DBProviders[dbType].filter((p) => {
// if (preferredPackageManager === "bun") return p.value !== "better-sqlite3";
// else return p.value !== "bun-sqlite";
// });
const dbProviders = DBProviders[dbType].filter((p) => {
if (preferredPackageManager === "bun") return p.value !== "better-sqlite3";
else return p.value !== "bun-sqlite";
});

const dbProvider =
initOptions?.dbProvider ||
((await select({
message: "Please choose your DB Provider",
choices: DBProviders[dbType],
// choices: dbProviders,
// choices: DBProviders[dbType],
choices: dbProviders,
})) as DBProvider);

let databaseUrl = "";
Expand Down Expand Up @@ -109,7 +109,7 @@ export const addDrizzle = async (initOptions?: InitOptions) => {
preferredPackageManager,
databaseUrl,
dbProvider === "planetscale",
hasSrc ? "src/" : "",
hasSrc ? "src/" : ""
);
if (dbProvider === "vercel-pg")
addToDotEnv(
Expand All @@ -121,7 +121,7 @@ export const addDrizzle = async (initOptions?: InitOptions) => {
{ key: "POSTGRES_PASSWORD", value: "" },
{ key: "POSTGRES_DATABASE", value: "" },
],
rootPath,
rootPath
);
if (dbProvider === "turso")
addToDotEnv([{ key: "DATABASE_AUTH_TOKEN", value: "" }], rootPath);
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buildSchema } from "./commands/generate/index.js";
import { addPackage } from "./commands/add/index.js";

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

addCommonOptions(program.command("init"))
.description("initialise and configure kirimase within directory")
Expand Down

0 comments on commit afc6f3b

Please sign in to comment.