Last active
October 21, 2022 08:08
-
-
Save Arkellys/cb20d535daaf54ed7bb3b72cfbef1d93 to your computer and use it in GitHub Desktop.
Script to change the entry point (main) in `package.json` using an environment variable.
This file contains hidden or 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
| const { readFileSync, writeFileSync } = require("fs"); | |
| try { | |
| const filePath = "./package.json"; | |
| const entryPath = process.env.ENTRY_PATH; | |
| let data = readFileSync(filePath, "utf8"); | |
| data = JSON.parse(data); | |
| if (data.main !== entryPath) { | |
| data.main = entryPath; | |
| writeFileSync(filePath, JSON.stringify(data, null, "\t")); | |
| console.log("\x1b[32m%s\x1b[0m", "The entry point was successfully changed to:", entryPath); | |
| } | |
| } catch (error) { | |
| console.error("Error while changing entry point:"); | |
| throw new Error(error); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment