11const fs = require ( 'fs' ) ;
2+ const { execSync } = require ( "child_process" ) ;
23
34const d = new Date ( ) ;
45const buildDate = d . toISOString ( ) . split ( 'T' ) [ 0 ] ;
@@ -13,6 +14,21 @@ const tzName = new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' })
1314
1415const t = d . getTime ( ) ;
1516
17+ // try {
18+ // const versionRegex = new RegExp("v[\d\.]+\b");
19+ // const stdout = execSync("npx next --version");
20+ // const result = versionRegex.exec(stdout.toString());
21+ // console.log(`Result: ${result}`);
22+ // nextJsVersion = result ? result[0] : "Unknown";
23+ // } catch (error) {
24+ // console.error(`Failed to get Next.js version: ${error.message}`);
25+ // }
26+
27+ const output = execSync ( "npx next --version" ) . toString ( ) . trim ( ) ;
28+ const versionRegex = new RegExp ( "v[\\d\\.]+\\b" ) ;
29+ const result = versionRegex . exec ( output . toString ( ) ) ;
30+ const nextJsVersion = result ? result [ 0 ] : "Unknown" ;
31+
1632const envContent = `
1733NEXT_PUBLIC_BUILD_DATETIME="${ buildDate } ${ buildTime } "
1834NEXT_PUBLIC_BUILD_DATE="${ buildDate } "
@@ -22,6 +38,7 @@ NEXT_PUBLIC_BUILD_TIME_LOCAL="${d.toLocaleTimeString('en-US', { hour12: true })}
2238NEXT_PUBLIC_TZ_LONG="${ tzLongName } "
2339NEXT_PUBLIC_TZ_SHORT="${ tzName } "
2440NEXT_PUBLIC_NODE_VERSION=${ process . version }
41+ NEXT_PUBLIC_NEXTJS_VERSION="${ nextJsVersion } "
2542` ;
2643
2744fs . writeFileSync ( '.env' , envContent . trim ( ) ) ;
0 commit comments