MCPcopy
hub / github.com/blitz-js/blitz / codegen

Function codegen

packages/blitz-next/scripts/postinstall.js:28–341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 Adapted from https://github.com/prisma/prisma/blob/974cbeff4a7f616137ce540d0ec88a2a86365892/src/packages/client/scripts/postinstall.js
27*/
28function codegen() {
29 async function main() {
30 if (process.env.INIT_CWD) {
31 process.chdir(process.env.INIT_CWD) // necessary, because npm chooses __dirname as process.cwd()
32 // in the postinstall hook
33 }
34 await ensureEmptyDotBlitz()
35
36 const localPath = getLocalPackagePath()
37
38 // Only execute if !localpath
39 const installedGlobally = localPath ? undefined : await isInstalledGlobally()
40
41 debug({
42 localPath,
43 installedGlobally,
44 init_cwd: process.env.INIT_CWD,
45 })
46 try {
47 if (localPath) {
48 await run("node", [
49 localPath,
50 "codegen",
51 "--postinstall",
52 doubleQuote(getPostInstallTrigger()),
53 ])
54 return
55 }
56
57 if (installedGlobally) {
58 await run("blitz", ["codegen", "--postinstall", doubleQuote(getPostInstallTrigger())])
59 return
60 }
61 } catch (e) {
62 // if exit code = 1 do not print
63 if (e && e !== 1) {
64 console.error(e)
65 }
66 debug(e)
67 }
68
69 if (!localPath && !installedGlobally) {
70 console.error(`Please install Blitz CLI. You can install it with "npm add -D blitz".`)
71 }
72 }
73
74 function getLocalPackagePath() {
75 try {
76 const packagePath = require.resolve("blitz/package.json")
77 if (packagePath) {
78 const blitzPkg = require.resolve("blitz/dist/index.cjs")
79 if (blitzPkg.includes(".pnpm")) {
80 return path.join(blitzPkg, "../../../../../../blitz/dist/index.cjs")
81 } else {
82 return path.join(blitzPkg)
83 }
84 }
85 } catch (e) {

Callers 1

postinstall.jsFile · 0.70

Calls 3

getPostInstallTriggerFunction · 0.85
errorMethod · 0.80
mainFunction · 0.70

Tested by

no test coverage detected