1414 * npm run bundle
1515 *
1616 * Environment variables:
17- * AGENTCORE_CDK_PATH — absolute path to the agentcore-l3-cdk-constructs repo
17+ * AGENTCORE_CDK_PATH — path to the agentcore-l3-cdk-constructs repo.
18+ * Falls back to ../agentcore-l3-cdk-constructs, then clones from GitHub.
19+ * AGENTCORE_TARBALL_OUTPUT — output path (without .tgz) for the GA tarball.
20+ * Preview tarball gets '-preview' appended. Relative to cwd.
21+ * AGENTCORE_TARBALL_VERSION_SUFFIX — version prerelease suffix (e.g. "abc12-def34").
22+ * Defaults to a timestamp if not set.
1823 */
1924import { execFileSync } from 'node:child_process' ;
2025import * as fs from 'node:fs' ;
@@ -83,7 +88,12 @@ log('Starting bundle process...');
8388
8489const now = new Date ( ) ;
8590const timestamp = now . toISOString ( ) . replace ( / [ - : T ] / g, '' ) . slice ( 0 , 14 ) ;
86- log ( `Bundle timestamp: ${ timestamp } ` ) ;
91+ const versionSuffix = process . env . AGENTCORE_TARBALL_VERSION_SUFFIX || timestamp ;
92+ if ( ! / ^ [ \w . - ] + $ / . test ( versionSuffix ) ) {
93+ console . error ( `ERROR: Invalid version suffix: ${ versionSuffix } ` ) ;
94+ process . exit ( 1 ) ;
95+ }
96+ log ( `Bundle version suffix: ${ versionSuffix } ` ) ;
8797
8898// Helper to bump a package version with a unique e2e timestamp tag.
8999// Saves the original version so it can be restored after packing.
@@ -93,7 +103,7 @@ function bumpVersion(pkgDir) {
93103 const originalVersion = pkg . version ;
94104 const baseVersion = originalVersion . split ( '-' ) [ 0 ] ;
95105 const prerelease = originalVersion . includes ( '-' ) ? originalVersion . split ( '-' ) . slice ( 1 ) . join ( '-' ) : '' ;
96- const tag = prerelease ? `${ prerelease } -${ timestamp } ` : timestamp ;
106+ const tag = prerelease ? `${ prerelease } -${ versionSuffix } ` : versionSuffix ;
97107 pkg . version = `${ baseVersion } -${ tag } ` ;
98108 fs . writeFileSync ( pkgJsonPath , JSON . stringify ( pkg , null , 2 ) + '\n' ) ;
99109 log ( `Bumped ${ pkg . name } version: ${ originalVersion } -> ${ pkg . version } ` ) ;
@@ -106,6 +116,18 @@ function restoreVersion({ pkgJsonPath, originalVersion }) {
106116 fs . writeFileSync ( pkgJsonPath , JSON . stringify ( pkg , null , 2 ) + '\n' ) ;
107117}
108118
119+ /**
120+ * If AGENTCORE_TARBALL_OUTPUT is set, return a resolved path using it as base.
121+ * Appends '-preview' suffix for preview builds. Always appends .tgz.
122+ */
123+ function resolveTarballPath ( tarballPath , { preview = false } = { } ) {
124+ const envPath = process . env . AGENTCORE_TARBALL_OUTPUT ;
125+ if ( ! envPath ) return tarballPath ;
126+ const suffix = preview ? '-preview' : '' ;
127+ const base = envPath . replace ( / \. t g z $ / , '' ) ;
128+ return path . resolve ( `${ base } ${ suffix } .tgz` ) ;
129+ }
130+
109131// Step 1: Resolve and build CDK constructs
110132const cdkPath = resolveCdkPath ( ) ;
111133
@@ -160,11 +182,16 @@ if (!fs.existsSync(cliTarballPath)) {
160182 console . error ( `ERROR: Expected GA tarball at ${ cliTarballPath } but not found.` ) ;
161183 process . exit ( 1 ) ;
162184}
163- log ( `Done! GA Tarball: ${ cliTarballPath } ` ) ;
164- log ( `Install with: npm install -g ${ cliTarballPath } ` ) ;
165- log ( 'When you run agentcore create, the bundled CDK constructs will be installed automatically.' ) ;
166185
167- const gaTarballPath = cliTarballPath ;
186+ const gaTarballPath = resolveTarballPath ( cliTarballPath ) ;
187+ if ( gaTarballPath !== cliTarballPath ) {
188+ fs . mkdirSync ( path . dirname ( gaTarballPath ) , { recursive : true } ) ;
189+ fs . renameSync ( cliTarballPath , gaTarballPath ) ;
190+ log ( `Renamed tarball to: ${ gaTarballPath } ` ) ;
191+ }
192+ log ( `Done! GA Tarball: ${ gaTarballPath } ` ) ;
193+ log ( `Install with: npm install -g ${ gaTarballPath } ` ) ;
194+ log ( 'When you run agentcore create, the bundled CDK constructs will be installed automatically.' ) ;
168195
169196// Step 6: Rebuild CLI with BUILD_PREVIEW=1
170197log ( 'Rebuilding CLI with BUILD_PREVIEW=1 for preview tarball...' ) ;
@@ -176,7 +203,7 @@ function bumpPreviewVersion(pkgDir) {
176203 const pkg = JSON . parse ( fs . readFileSync ( pkgJsonPath , 'utf8' ) ) ;
177204 const originalVersion = pkg . version ;
178205 const baseVersion = originalVersion . split ( '-' ) [ 0 ] ;
179- pkg . version = `${ baseVersion } -preview-${ timestamp } ` ;
206+ pkg . version = `${ baseVersion } -preview-${ versionSuffix } ` ;
180207 fs . writeFileSync ( pkgJsonPath , JSON . stringify ( pkg , null , 2 ) + '\n' ) ;
181208 log ( `Bumped ${ pkg . name } version: ${ originalVersion } -> ${ pkg . version } ` ) ;
182209 return { pkgJsonPath, originalVersion, bumpedVersion : pkg . version } ;
@@ -200,9 +227,16 @@ if (!fs.existsSync(previewTarballPath)) {
200227 process . exit ( 1 ) ;
201228}
202229
230+ const finalPreviewPath = resolveTarballPath ( previewTarballPath , { preview : true } ) ;
231+ if ( finalPreviewPath !== previewTarballPath ) {
232+ fs . mkdirSync ( path . dirname ( finalPreviewPath ) , { recursive : true } ) ;
233+ fs . renameSync ( previewTarballPath , finalPreviewPath ) ;
234+ log ( `Renamed tarball to: ${ finalPreviewPath } ` ) ;
235+ }
236+
203237// Final output
204238log ( `GA tarball: ${ gaTarballPath } ` ) ;
205- log ( `Preview tarball: ${ previewTarballPath } ` ) ;
239+ log ( `Preview tarball: ${ finalPreviewPath } ` ) ;
206240log ( `Install GA: npm install -g ${ gaTarballPath } ` ) ;
207- log ( `Install Preview: npm install -g ${ previewTarballPath } ` ) ;
241+ log ( `Install Preview: npm install -g ${ finalPreviewPath } ` ) ;
208242log ( 'When you run agentcore create, the bundled CDK constructs will be installed automatically.' ) ;
0 commit comments