prebuild scripts init
This commit is contained in:
parent
03cbc4456f
commit
2ef5765ae2
6 changed files with 477 additions and 6 deletions
scripts
43
scripts/runner.ts
Normal file
43
scripts/runner.ts
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue