Updates
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
export default function grabDefaultDistName(): string {
|
||||
return ".buncid-next-dist";
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user