Skip to content

Instantly share code, notes, and snippets.

@Arkellys
Last active October 21, 2022 08:08
Show Gist options
  • Select an option

  • Save Arkellys/cb20d535daaf54ed7bb3b72cfbef1d93 to your computer and use it in GitHub Desktop.

Select an option

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.
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