-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed717cd
commit 0767dd5
Showing
9 changed files
with
177 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Command } from "../deps.ts"; | ||
import { GlobalOpts, initProject } from "../common.ts"; | ||
import { cleanProject } from "../../project/project.ts"; | ||
|
||
export const cleanCommand = new Command<GlobalOpts>() | ||
.description("Removes all build artifacts") | ||
.action( | ||
async (opts) => { | ||
const project = await initProject(opts); | ||
await cleanProject(project); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Generates Prisma client libraries. | ||
// | ||
// Wrapper around `prisma generate` | ||
|
||
import { resolve } from "../deps.ts"; | ||
import { buildPrismaPackage } from "./build_prisma_esm.ts"; | ||
import { Module, Project } from "../project/mod.ts"; | ||
import { forEachPrismaSchema } from "./mod.ts"; | ||
|
||
export async function generateClient( | ||
project: Project, | ||
modules: Module[], | ||
) { | ||
await forEachPrismaSchema( | ||
project, | ||
modules, | ||
async ({ databaseUrl, tempDir, generatedClientDir }) => { | ||
// Generate migrations & client | ||
const status = await new Deno.Command("deno", { | ||
args: [ | ||
"run", | ||
"-A", | ||
"npm:prisma@5.9.1", | ||
"generate", | ||
], | ||
cwd: tempDir, | ||
stdin: "inherit", | ||
stdout: "inherit", | ||
stderr: "inherit", | ||
env: { | ||
DATABASE_URL: databaseUrl, | ||
PRISMA_CLIENT_FORCE_WASM: "true", | ||
}, | ||
}).output(); | ||
if (!status.success) { | ||
throw new Error("Failed to generate migrations"); | ||
} | ||
|
||
// Specify the path to the library & binary types | ||
for ( | ||
const filename of [ | ||
"index.d.ts", | ||
"default.d.ts", | ||
"wasm.d.ts", | ||
"edge.d.ts", | ||
] | ||
) { | ||
const filePath = resolve(generatedClientDir, filename); | ||
let content = await Deno.readTextFile(filePath); | ||
const replaceLineA = `import * as runtime from './runtime/library.js'`; | ||
const replaceLineB = `import * as runtime from './runtime/binary.js'`; | ||
content = content | ||
.replace( | ||
replaceLineA, | ||
`// @deno-types="./runtime/library.d.ts"\n${replaceLineA}`, | ||
) | ||
.replace( | ||
replaceLineB, | ||
`// @deno-types="./runtime/binary.d.ts"\n${replaceLineB}`, | ||
) | ||
.replace(/from '.\/default'/g, `from './default.d.ts'`); | ||
await Deno.writeTextFile(filePath, content); | ||
} | ||
|
||
// Compile the ESM library | ||
await buildPrismaPackage( | ||
generatedClientDir, | ||
resolve(generatedClientDir, "esm.js"), | ||
); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.