prebuild scripts init

This commit is contained in:
3zachm 2023-02-07 01:48:13 -08:00
commit 2ef5765ae2
6 changed files with 477 additions and 6 deletions
scripts

43
scripts/runner.ts Normal file
View file

@ -0,0 +1,43 @@
// https://kontent.ai/blog/how-to-run-scripts-before-every-build-on-next-js/
import path from "path";
import fs from "fs";
import IScriptParams from "../interfaces/IScriptParams";
import { loadEnvConfig } from "@next/env";
loadEnvConfig(process.cwd());
const runAsync = async () => {
// find all scripts in subfolder
const files = fs
.readdirSync(path.join(__dirname, "pre-build"))
.filter((file) => file.endsWith(".ts"))
.sort();
for (const file of files) {
const {
default: defaultFunc,
}: { default: (params: IScriptParams) => void } = await import(
`./pre-build/${file}`
);
try {
console.log(`Running pre-build script '${file}'`);
await defaultFunc({ env: process.env });
} catch (e) {
console.error(
`SCRIPT RUNNER: failed to execute pre-build script '${file}'`
);
console.error(e);
}
}
};
// Self-invocation async function
(async () => {
await runAsync();
})().catch((err) => {
console.error(err);
throw err;
});
export default function execute() {
// do nothing
}