Updates
This commit is contained in:
		
							parent
							
								
									7d71316b2c
								
							
						
					
					
						commit
						4540404522
					
				| @ -132,4 +132,4 @@ const nextConfig: NextConfig = { | |||||||
| export default 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
									
								
								dist/rebuilds/next-js/(utils)/grab-default-dist-name.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								dist/rebuilds/next-js/(utils)/grab-default-dist-name.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | export default function grabDefaultDistName(): string; | ||||||
							
								
								
									
										6
									
								
								dist/rebuilds/next-js/(utils)/grab-default-dist-name.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								dist/rebuilds/next-js/(utils)/grab-default-dist-name.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | "use strict"; | ||||||
|  | Object.defineProperty(exports, "__esModule", { value: true }); | ||||||
|  | exports.default = grabDefaultDistName; | ||||||
|  | function grabDefaultDistName() { | ||||||
|  |     return ".buncid-next-dist"; | ||||||
|  | } | ||||||
							
								
								
									
										6
									
								
								dist/rebuilds/next-js/grabDist.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								dist/rebuilds/next-js/grabDist.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -1,6 +1,10 @@ | |||||||
|  | type Param = { | ||||||
|  |     distDir?: string; | ||||||
|  | }; | ||||||
| /** | /** | ||||||
|  * # Grab the current distribution directory |  * # Grab the current distribution directory | ||||||
|  * @description This returns the relative path from the CWD. Eg `./.dist/build-1` |  * @description This returns the relative path from the CWD. Eg `./.dist/build-1` | ||||||
|  * @returns {string | undefined} |  * @returns {string | undefined} | ||||||
|  */ |  */ | ||||||
| export default function grabDist(): string | undefined; | export default function grabDist(params?: Param): string | undefined; | ||||||
|  | export {}; | ||||||
|  | |||||||
							
								
								
									
										14
									
								
								dist/rebuilds/next-js/grabDist.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								dist/rebuilds/next-js/grabDist.js
									
									
									
									
										vendored
									
									
								
							| @ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); | |||||||
| exports.default = grabDist; | exports.default = grabDist; | ||||||
| const fs_1 = __importDefault(require("fs")); | const fs_1 = __importDefault(require("fs")); | ||||||
| const path_1 = __importDefault(require("path")); | const path_1 = __importDefault(require("path")); | ||||||
|  | const grab_default_dist_name_1 = __importDefault(require("./(utils)/grab-default-dist-name")); | ||||||
| const production = process.env.NODE_ENV == "production"; | const production = process.env.NODE_ENV == "production"; | ||||||
| const isBuilding = process.env.BUILDING_APP; | const isBuilding = process.env.BUILDING_APP; | ||||||
| /** | /** | ||||||
| @ -13,15 +14,16 @@ const isBuilding = process.env.BUILDING_APP; | |||||||
|  * @description This returns the relative path from the CWD. Eg `./.dist/build-1` |  * @description This returns the relative path from the CWD. Eg `./.dist/build-1` | ||||||
|  * @returns {string | undefined} |  * @returns {string | undefined} | ||||||
|  */ |  */ | ||||||
| function grabDist() { | function grabDist(params) { | ||||||
|     const DIST_DIR = path_1.default.resolve(process.cwd(), "./.dist"); |     const distDirName = (params === null || params === void 0 ? void 0 : params.distDir) || (0, grab_default_dist_name_1.default)(); | ||||||
|  |     const DIST_DIR = path_1.default.join(process.cwd(), distDirName); | ||||||
|     if (isBuilding) { |     if (isBuilding) { | ||||||
|         const distDir = (() => { |         const distDir = (() => { | ||||||
|             try { |             try { | ||||||
|                 const buildNumber = fs_1.default.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); |                 const buildNumber = fs_1.default.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); | ||||||
|                 return `.dist/build-${buildNumber}`; |                 return `${distDirName}/build-${buildNumber}`; | ||||||
|             } |             } | ||||||
|             catch ( /** @type {*} */error) { |             catch (error) { | ||||||
|                 console.log("Build Number Generation Error =>", error.message); |                 console.log("Build Number Generation Error =>", error.message); | ||||||
|                 process.exit(); |                 process.exit(); | ||||||
|             } |             } | ||||||
| @ -32,9 +34,9 @@ function grabDist() { | |||||||
|         const distDir = (() => { |         const distDir = (() => { | ||||||
|             try { |             try { | ||||||
|                 const buildNumber = fs_1.default.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); |                 const buildNumber = fs_1.default.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); | ||||||
|                 return `.dist/build-${buildNumber}`; |                 return `${distDirName}/build-${buildNumber}`; | ||||||
|             } |             } | ||||||
|             catch ( /** @type {*} */error) { |             catch (error) { | ||||||
|                 console.log("Build Number Parse Error =>", error.message); |                 console.log("Build Number Parse Error =>", error.message); | ||||||
|                 process.exit(); |                 process.exit(); | ||||||
|             } |             } | ||||||
|  | |||||||
							
								
								
									
										22
									
								
								dist/rebuilds/next-js/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										22
									
								
								dist/rebuilds/next-js/index.js
									
									
									
									
										vendored
									
									
								
							| @ -6,12 +6,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | |||||||
| var _a; | var _a; | ||||||
| Object.defineProperty(exports, "__esModule", { value: true }); | Object.defineProperty(exports, "__esModule", { value: true }); | ||||||
| const path_1 = __importDefault(require("path")); | const path_1 = __importDefault(require("path")); | ||||||
|  | const util_1 = require("util"); | ||||||
| const fs_1 = __importDefault(require("fs")); | const fs_1 = __importDefault(require("fs")); | ||||||
| const child_process_1 = require("child_process"); | const child_process_1 = require("child_process"); | ||||||
| const DIST_DIR = path_1.default.resolve(process.cwd(), "./.dist"); | const grab_default_dist_name_1 = __importDefault(require("./(utils)/grab-default-dist-name")); | ||||||
|  | const args = (0, util_1.parseArgs)({ | ||||||
|  |     args: process.argv, | ||||||
|  |     options: { | ||||||
|  |         maxBuilds: { | ||||||
|  |             type: "string", | ||||||
|  |             alias: "m", | ||||||
|  |         }, | ||||||
|  |         distDir: { | ||||||
|  |             type: "string", | ||||||
|  |             alias: "d", | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|  | }); | ||||||
|  | const distDirName = args.values.distDir || (0, grab_default_dist_name_1.default)(); | ||||||
|  | const DIST_DIR = path_1.default.join(process.cwd(), distDirName); | ||||||
| let PREV_BUILD_NO = "0"; | let PREV_BUILD_NO = "0"; | ||||||
| const MAX_BUILDS = process.env.BUNCID_MAX_BUILDS | const MAX_BUILDS = process.env.BUNCID_MAX_BUILDS | ||||||
|     ? Number(process.env.BUNCID_MAX_BUILDS) |     ? Number(process.env.BUNCID_MAX_BUILDS) | ||||||
|  |     : args.values.maxBuilds | ||||||
|  |         ? Number(args.values.maxBuilds) | ||||||
|         : 10; |         : 10; | ||||||
| if (MAX_BUILDS < 1 || | if (MAX_BUILDS < 1 || | ||||||
|     Number.isNaN(MAX_BUILDS) || |     Number.isNaN(MAX_BUILDS) || | ||||||
| @ -67,7 +85,7 @@ const build = (0, child_process_1.spawnSync)("bunx", ["next", "build"], spawnSyn | |||||||
| function grabNewDistDir() { | function grabNewDistDir() { | ||||||
|     try { |     try { | ||||||
|         const buildNumber = fs_1.default.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); |         const buildNumber = fs_1.default.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); | ||||||
|         return `.dist/build-${buildNumber}`; |         return `${distDirName}/build-${buildNumber}`; | ||||||
|     } |     } | ||||||
|     catch ( /** @type {*} */error) { |     catch ( /** @type {*} */error) { | ||||||
|         console.log("Build Number Parse Error =>", error.message); |         console.log("Build Number Parse Error =>", error.message); | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								dist/tsconfig.tsbuildinfo
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/tsconfig.tsbuildinfo
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										4
									
								
								dist/utils/kill-child.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								dist/utils/kill-child.js
									
									
									
									
										vendored
									
									
								
							| @ -31,11 +31,11 @@ function killChild(childProcess, port) { | |||||||
|                 if (typeof port == "object" && (port === null || port === void 0 ? void 0 : port[0])) { |                 if (typeof port == "object" && (port === null || port === void 0 ? void 0 : port[0])) { | ||||||
|                     for (let i = 0; i < port.length; i++) { |                     for (let i = 0; i < port.length; i++) { | ||||||
|                         const singlePort = port[i]; |                         const singlePort = port[i]; | ||||||
|                         yield (0, kill_port_1.default)(Number(singlePort)); |                         yield (0, kill_port_1.default)(Number(singlePort), "tcp"); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 else if (port) { |                 else if (port) { | ||||||
|                     yield (0, kill_port_1.default)(Number(port)); |                     yield (0, kill_port_1.default)(Number(port), "tcp"); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             catch (error) { } |             catch (error) { } | ||||||
|  | |||||||
							
								
								
									
										35
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								package.json
									
									
									
									
									
								
							| @ -1,34 +1,35 @@ | |||||||
| { | { | ||||||
|     "name": "@moduletrace/buncid", |     "name": "@moduletrace/buncid", | ||||||
|     "version": "1.0.8", |     "version": "1.0.9", | ||||||
|     "description": "Simple CI/CD process For Bun runtime", |     "author": "Benjamin Toby", | ||||||
|  |     "repository": { | ||||||
|  |         "type": "git", | ||||||
|  |         "url": "https://git.tben.me/Moduletrace/buncid.git" | ||||||
|  |     }, | ||||||
|     "main": "dist/index.js", |     "main": "dist/index.js", | ||||||
|  |     "devDependencies": { | ||||||
|  |         "@types/bun": "latest", | ||||||
|  |         "@types/kill-port": "^2.0.3", | ||||||
|  |         "@types/node": "^22.10.7" | ||||||
|  |     }, | ||||||
|  |     "peerDependencies": { | ||||||
|  |         "typescript": "^5.0.0" | ||||||
|  |     }, | ||||||
|     "bin": { |     "bin": { | ||||||
|         "buncid": "./dist/buncid.js", |         "buncid": "./dist/buncid.js", | ||||||
|         "buncid-builds-next": "./dist/rebuilds/next-js/index.js" |         "buncid-builds-next": "./dist/rebuilds/next-js/index.js" | ||||||
|     }, |     }, | ||||||
|     "scripts": { |     "description": "Simple CI/CD process For Bun runtime", | ||||||
|         "compile": "bun build --compile --minify --sourcemap --bytecode index.ts --outfile bin/buncid" |  | ||||||
|     }, |  | ||||||
|     "keywords": [ |     "keywords": [ | ||||||
|         "CI/CD", |         "CI/CD", | ||||||
|         "Continuous Integration", |         "Continuous Integration", | ||||||
|         "Continous Deployment" |         "Continous Deployment" | ||||||
|     ], |     ], | ||||||
|     "repository": { |  | ||||||
|         "type": "git", |  | ||||||
|         "url": "https://git.tben.me/Moduletrace/buncid.git" |  | ||||||
|     }, |  | ||||||
|     "author": "Benjamin Toby", |  | ||||||
|     "license": "MIT", |     "license": "MIT", | ||||||
|  |     "scripts": { | ||||||
|  |         "compile": "bun build --compile --minify --sourcemap --bytecode index.ts --outfile bin/buncid" | ||||||
|  |     }, | ||||||
|     "dependencies": { |     "dependencies": { | ||||||
|         "kill-port": "^2.0.1" |         "kill-port": "^2.0.1" | ||||||
|     }, |  | ||||||
|     "devDependencies": { |  | ||||||
|         "@types/bun": "latest", |  | ||||||
|         "@types/node": "^22.10.7" |  | ||||||
|     }, |  | ||||||
|     "peerDependencies": { |  | ||||||
|         "typescript": "^5.0.0" |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								rebuilds/next-js/(utils)/grab-default-dist-name.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								rebuilds/next-js/(utils)/grab-default-dist-name.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | export default function grabDefaultDistName(): string { | ||||||
|  |     return ".buncid-next-dist"; | ||||||
|  | } | ||||||
| @ -25,4 +25,4 @@ const nextConfig: NextConfig = { | |||||||
| export default 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 fs from "fs"; | ||||||
| import path from "path"; | import path from "path"; | ||||||
|  | import grabDefaultDistName from "./(utils)/grab-default-dist-name"; | ||||||
| 
 | 
 | ||||||
| const production = process.env.NODE_ENV == "production"; | const production = process.env.NODE_ENV == "production"; | ||||||
| const isBuilding = process.env.BUILDING_APP; | const isBuilding = process.env.BUILDING_APP; | ||||||
| 
 | 
 | ||||||
|  | type Param = { | ||||||
|  |     distDir?: string; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * # Grab the current distribution directory |  * # Grab the current distribution directory | ||||||
|  * @description This returns the relative path from the CWD. Eg `./.dist/build-1` |  * @description This returns the relative path from the CWD. Eg `./.dist/build-1` | ||||||
|  * @returns {string | undefined} |  * @returns {string | undefined} | ||||||
|  */ |  */ | ||||||
| export default function grabDist(): string | undefined { | export default function grabDist(params?: Param): string | undefined { | ||||||
|     const DIST_DIR = path.resolve(process.cwd(), "./.dist"); |     const distDirName = params?.distDir || grabDefaultDistName(); | ||||||
|  |     const DIST_DIR = path.join(process.cwd(), distDirName); | ||||||
| 
 | 
 | ||||||
|     if (isBuilding) { |     if (isBuilding) { | ||||||
|         const distDir = (() => { |         const distDir = (() => { | ||||||
| @ -19,8 +25,8 @@ export default function grabDist(): string | undefined { | |||||||
|                     `${DIST_DIR}/BUILD`, |                     `${DIST_DIR}/BUILD`, | ||||||
|                     "utf-8" |                     "utf-8" | ||||||
|                 ); |                 ); | ||||||
|                 return `.dist/build-${buildNumber}`; |                 return `${distDirName}/build-${buildNumber}`; | ||||||
|             } catch (/** @type {*} */ error: any) { |             } catch (error: any) { | ||||||
|                 console.log("Build Number Generation Error =>", error.message); |                 console.log("Build Number Generation Error =>", error.message); | ||||||
|                 process.exit(); |                 process.exit(); | ||||||
|             } |             } | ||||||
| @ -36,8 +42,8 @@ export default function grabDist(): string | undefined { | |||||||
|                     `${DIST_DIR}/BUILD`, |                     `${DIST_DIR}/BUILD`, | ||||||
|                     "utf-8" |                     "utf-8" | ||||||
|                 ); |                 ); | ||||||
|                 return `.dist/build-${buildNumber}`; |                 return `${distDirName}/build-${buildNumber}`; | ||||||
|             } catch (/** @type {*} */ error: any) { |             } catch (error: any) { | ||||||
|                 console.log("Build Number Parse Error =>", error.message); |                 console.log("Build Number Parse Error =>", error.message); | ||||||
|                 process.exit(); |                 process.exit(); | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -1,18 +1,37 @@ | |||||||
| #!/usr/bin/env bun | #!/usr/bin/env bun | ||||||
| 
 | 
 | ||||||
| import path from "path"; | import path from "path"; | ||||||
|  | import { parseArgs } from "util"; | ||||||
| import fs from "fs"; | import fs from "fs"; | ||||||
| import { | import { | ||||||
|     execSync, |     execSync, | ||||||
|     spawnSync, |     spawnSync, | ||||||
|     SpawnSyncOptionsWithStringEncoding, |     SpawnSyncOptionsWithStringEncoding, | ||||||
| } from "child_process"; | } 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"; | let PREV_BUILD_NO = "0"; | ||||||
| 
 | 
 | ||||||
| const MAX_BUILDS = process.env.BUNCID_MAX_BUILDS | const MAX_BUILDS = process.env.BUNCID_MAX_BUILDS | ||||||
|     ? Number(process.env.BUNCID_MAX_BUILDS) |     ? Number(process.env.BUNCID_MAX_BUILDS) | ||||||
|  |     : args.values.maxBuilds | ||||||
|  |     ? Number(args.values.maxBuilds) | ||||||
|     : 10; |     : 10; | ||||||
| 
 | 
 | ||||||
| if ( | if ( | ||||||
| @ -81,7 +100,7 @@ const build = spawnSync("bunx", ["next", "build"], spawnSyncOptions); | |||||||
| function grabNewDistDir(): string { | function grabNewDistDir(): string { | ||||||
|     try { |     try { | ||||||
|         const buildNumber = fs.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); |         const buildNumber = fs.readFileSync(`${DIST_DIR}/BUILD`, "utf-8"); | ||||||
|         return `.dist/build-${buildNumber}`; |         return `${distDirName}/build-${buildNumber}`; | ||||||
|     } catch (/** @type {*} */ error: any) { |     } catch (/** @type {*} */ error: any) { | ||||||
|         console.log("Build Number Parse Error =>", error.message); |         console.log("Build Number Parse Error =>", error.message); | ||||||
|         process.exit(); |         process.exit(); | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| import { ChildProcess } from "child_process"; | import { ChildProcess } from "child_process"; | ||||||
| import colors from "./console-colors"; | import colors from "./console-colors"; | ||||||
| import kill from "kill-port"; | import killPort from "kill-port"; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * ## Kill Child Process Function |  * ## Kill Child Process Function | ||||||
| @ -21,10 +21,10 @@ export default async function killChild( | |||||||
|             if (typeof port == "object" && port?.[0]) { |             if (typeof port == "object" && port?.[0]) { | ||||||
|                 for (let i = 0; i < port.length; i++) { |                 for (let i = 0; i < port.length; i++) { | ||||||
|                     const singlePort = port[i]; |                     const singlePort = port[i]; | ||||||
|                     await kill(Number(singlePort)); |                     await killPort(Number(singlePort), "tcp"); | ||||||
|                 } |                 } | ||||||
|             } else if (port) { |             } else if (port) { | ||||||
|                 await kill(Number(port)); |                 await killPort(Number(port), "tcp"); | ||||||
|             } |             } | ||||||
|         } catch (error) {} |         } catch (error) {} | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Benjamin Toby
						Benjamin Toby