-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change script to add mikro-orm script in package.json
- Loading branch information
1 parent
f0558d5
commit 55cfd2a
Showing
2 changed files
with
13 additions
and
6 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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { existsSync } from "fs"; | ||
import { readFile, writeFile } from "fs/promises"; | ||
|
||
import { PackageJson } from "../util/package-json.util"; | ||
|
||
/** | ||
* Add a dotenv call to config. | ||
* Adds a `mikro-orm` script to package.json that calls dotenv. | ||
* See https://mikro-orm.io/docs/upgrading-v5-to-v6#env-files-are-no-longer-automatically-loaded. | ||
*/ | ||
export default async function addDotenvCallToConfig() { | ||
if (!existsSync("api/src/db/ormconfig.cli.ts")) { | ||
if (!existsSync("api/package.json")) { | ||
return; | ||
} | ||
|
||
let fileContent = await readFile("api/src/db/ormconfig.cli.ts", "utf-8"); | ||
const packageJson = new PackageJson("api/package.json"); | ||
|
||
fileContent = `import "dotenv/config";\n\n${fileContent}`; | ||
packageJson.addScript("mikro-orm", "dotenv -e .env.secrets -e .env.local -e .env -e .env.site-configs -- mikro-orm"); | ||
|
||
await writeFile("api/src/db/ormconfig.cli.ts", fileContent); | ||
packageJson.save(); | ||
} |