This commit is contained in:
Benjamin Toby
2025-02-21 09:00:49 +01:00
parent 7d71316b2c
commit 4540404522
15 changed files with 103 additions and 43 deletions
@@ -0,0 +1,3 @@
export default function grabDefaultDistName(): string {
return ".buncid-next-dist";
}
+1 -1
View File
@@ -25,4 +25,4 @@ const nextConfig: NextConfig = {
export default nextConfig;
```
That's it. This dynamically handles your distribution directory for both `dev` and `start` scripts. Your `development` environment uses the `.next` directory, while your `production` environment uses the `.dist` directory.
That's it. This dynamically handles your distribution directory for both `dev` and `start` scripts. Your `development` environment uses the `.next` directory, while your `production` environment uses the `.buncid-next-dist` (or any dist name of your chosing) directory.
+12 -6
View File
@@ -1,16 +1,22 @@
import fs from "fs";
import path from "path";
import grabDefaultDistName from "./(utils)/grab-default-dist-name";
const production = process.env.NODE_ENV == "production";
const isBuilding = process.env.BUILDING_APP;
type Param = {
distDir?: string;
};
/**
* # Grab the current distribution directory
* @description This returns the relative path from the CWD. Eg `./.dist/build-1`
* @returns {string | undefined}
*/
export default function grabDist(): string | undefined {
const DIST_DIR = path.resolve(process.cwd(), "./.dist");
export default function grabDist(params?: Param): string | undefined {
const distDirName = params?.distDir || grabDefaultDistName();
const DIST_DIR = path.join(process.cwd(), distDirName);
if (isBuilding) {
const distDir = (() => {
@@ -19,8 +25,8 @@ export default function grabDist(): string | undefined {
`${DIST_DIR}/BUILD`,
"utf-8"
);
return `.dist/build-${buildNumber}`;
} catch (/** @type {*} */ error: any) {
return `${distDirName}/build-${buildNumber}`;
} catch (error: any) {
console.log("Build Number Generation Error =>", error.message);
process.exit();
}
@@ -36,8 +42,8 @@ export default function grabDist(): string | undefined {
`${DIST_DIR}/BUILD`,
"utf-8"
);
return `.dist/build-${buildNumber}`;
} catch (/** @type {*} */ error: any) {
return `${distDirName}/build-${buildNumber}`;
} catch (error: any) {
console.log("Build Number Parse Error =>", error.message);
process.exit();
}
+21 -2
View File
@@ -1,18 +1,37 @@
#!/usr/bin/env bun
import path from "path";
import { parseArgs } from "util";
import fs from "fs";
import {
execSync,
spawnSync,
SpawnSyncOptionsWithStringEncoding,
} from "child_process";
import grabDefaultDistName from "./(utils)/grab-default-dist-name";
const DIST_DIR = path.resolve(process.cwd(), "./.dist");
const args = parseArgs({
args: process.argv,
options: {
maxBuilds: {
type: "string",
alias: "m",
},
distDir: {
type: "string",
alias: "d",
},
},
});
const distDirName = args.values.distDir || grabDefaultDistName();
const DIST_DIR = path.join(process.cwd(), distDirName);
let PREV_BUILD_NO = "0";
const MAX_BUILDS = process.env.BUNCID_MAX_BUILDS
? Number(process.env.BUNCID_MAX_BUILDS)
: args.values.maxBuilds
? Number(args.values.maxBuilds)
: 10;
if (
@@ -81,7 +100,7 @@ const build = spawnSync("bunx", ["next", "build"], spawnSyncOptions);
function grabNewDistDir(): string {
try {
const buildNumber = fs.readFileSync(`${DIST_DIR}/BUILD`, "utf-8");
return `.dist/build-${buildNumber}`;
return `${distDirName}/build-${buildNumber}`;
} catch (/** @type {*} */ error: any) {
console.log("Build Number Parse Error =>", error.message);
process.exit();