@@ -14,9 +14,11 @@ const DEFAULT_PATH = ".";
1414const DEFAULT_OUTPUT_FALLBACK = "create-gen-app-output" ;
1515const DEFAULT_TOOL_NAME = "create-gen-app-test" ;
1616const DEFAULT_TTL = 604800000 ; // 1 week
17+ const DEFAULT_TTL_DAYS = DEFAULT_TTL / ( 24 * 60 * 60 * 1000 ) ;
1718
1819// Import package.json for version
1920import * as createGenPackageJson from "create-gen-app/package.json" ;
21+ const PACKAGE_NAME = createGenPackageJson . name ?? "@launchql/cli" ;
2022const PACKAGE_VERSION = createGenPackageJson . version ?? "0.0.0" ;
2123
2224const RESERVED_ARG_KEYS = new Set ( [
@@ -41,6 +43,8 @@ const RESERVED_ARG_KEYS = new Set([
4143 "n" ,
4244 "clear-cache" ,
4345 "c" ,
46+ "ttl" ,
47+ "no-ttl" ,
4448] ) ;
4549
4650export interface CliResult {
@@ -63,9 +67,10 @@ export async function runCli(
6367 v : "version" ,
6468 n : "no-tty" ,
6569 c : "clear-cache" ,
70+ // no alias for ttl to keep it explicit
6671 } ,
67- string : [ "repo" , "branch" , "path" , "template" , "output" ] ,
68- boolean : [ "force" , "help" , "version" , "no-tty" , "clear-cache" ] ,
72+ string : [ "repo" , "branch" , "path" , "template" , "output" , "ttl" ] ,
73+ boolean : [ "force" , "help" , "version" , "no-tty" , "clear-cache" , "no-ttl" ] ,
6974 default : {
7075 repo : DEFAULT_REPO ,
7176 path : DEFAULT_PATH ,
@@ -84,21 +89,23 @@ export async function runCli(
8489
8590 // Check for updates
8691 try {
87- const versionCheck = await checkNpmVersion ( "create-gen-app" , PACKAGE_VERSION ) ;
92+ const versionCheck = await checkNpmVersion ( PACKAGE_NAME , PACKAGE_VERSION ) ;
8893 if ( versionCheck . isOutdated && versionCheck . latestVersion ) {
8994 console . warn (
9095 `\n⚠️ New version available: ${ versionCheck . currentVersion } → ${ versionCheck . latestVersion } `
9196 ) ;
92- console . warn ( ` Run: npm install -g create-gen-app @latest\n` ) ;
97+ console . warn ( ` Run: npm install -g ${ PACKAGE_NAME } @latest\n` ) ;
9398 }
9499 } catch {
95100 // Silently ignore version check failures
96101 }
97102
103+ const ttl = resolveTtlOption ( args ) ;
104+
98105 // Initialize modules
99106 const cacheManager = new CacheManager ( {
100107 toolName : DEFAULT_TOOL_NAME ,
101- ttl : DEFAULT_TTL ,
108+ ttl,
102109 } ) ;
103110
104111 // Handle --clear-cache
@@ -139,7 +146,7 @@ export async function runCli(
139146 if ( args . branch ) {
140147 console . log ( `Using branch ${ args . branch } ` ) ;
141148 }
142- const tempDest = path . join ( cacheManager [ 'reposDir' ] , cacheKey ) ;
149+ const tempDest = path . join ( cacheManager . getReposDir ( ) , cacheKey ) ;
143150 gitCloner . clone ( normalizedUrl , tempDest , { branch : args . branch , depth : 1 } ) ;
144151 cacheManager . set ( cacheKey , tempDest ) ;
145152 templateDir = tempDest ;
@@ -213,7 +220,7 @@ export async function runCli(
213220 answers : answerOverrides ,
214221 noTty,
215222 toolName : DEFAULT_TOOL_NAME ,
216- ttl : DEFAULT_TTL ,
223+ ttl,
217224 } ) ;
218225
219226 console . log ( `\n✨ Done! Project ready at ${ outputDir } ` ) ;
@@ -238,6 +245,8 @@ Options:
238245 -o, --output <dir> Output directory (defaults to ./<template>)
239246 -f, --force Overwrite the output directory if it exists
240247 -c, --clear-cache Clear the template cache and exit
248+ --ttl <ms> Set cache TTL in milliseconds (flag alone uses 1 week)
249+ --no-ttl Disable TTL (cache never expires)
241250 -v, --version Show CLI version
242251 -n, --no-tty Disable TTY mode for prompts
243252 -h, --help Show this help message
@@ -246,7 +255,7 @@ You can also pass variable overrides, e.g.:
246255 node cli --template module --PROJECT_NAME my-app
247256
248257Cache is stored at: ~/.${ DEFAULT_TOOL_NAME } /cache/repos
249- TTL: ${ DEFAULT_TTL / ( 24 * 60 * 60 * 1000 ) } days
258+ TTL: none by default; use --ttl to enable (default ${ DEFAULT_TTL_DAYS } days when flag provided)
250259` ) ;
251260}
252261
@@ -317,3 +326,26 @@ if (require.main === module) {
317326 process . exitCode = 1 ;
318327 } ) ;
319328}
329+
330+ function resolveTtlOption ( args : ParsedArgs ) : number | undefined {
331+ const disableTtl = Boolean ( args [ "no-ttl" ] ?? ( args as Record < string , unknown > ) . noTtl ) ;
332+ if ( disableTtl ) {
333+ return undefined ;
334+ }
335+
336+ if ( args . ttl === undefined ) {
337+ return undefined ;
338+ }
339+
340+ // Support --ttl with no value to use the default 1-week TTL
341+ if ( args . ttl === true ) {
342+ return DEFAULT_TTL ;
343+ }
344+
345+ const ttlMs = Number ( args . ttl ) ;
346+ if ( Number . isNaN ( ttlMs ) || ttlMs < 0 ) {
347+ throw new Error ( "TTL must be a non-negative number of milliseconds" ) ;
348+ }
349+
350+ return ttlMs === 0 ? undefined : ttlMs ;
351+ }
0 commit comments