@@ -3,11 +3,12 @@ import { context, trace } from "@opentelemetry/api";
3
3
import { GetProjectResponseBody , flattenAttributes } from "@trigger.dev/core/v3" ;
4
4
import { recordSpanException } from "@trigger.dev/core/v3/workers" ;
5
5
import chalk from "chalk" ;
6
- import { Command } from "commander" ;
6
+ import { Command , Option as CommandOption } from "commander" ;
7
7
import { applyEdits , findNodeAtLocation , getNodeValue , modify , parseTree } from "jsonc-parser" ;
8
8
import { writeFile } from "node:fs/promises" ;
9
9
import { join , relative , resolve } from "node:path" ;
10
10
import { addDependency , detectPackageManager } from "nypm" ;
11
+ import { resolveTSConfig } from "pkg-types" ;
11
12
import { z } from "zod" ;
12
13
import { CliApiClient } from "../apiClient.js" ;
13
14
import {
@@ -22,25 +23,24 @@ import {
22
23
} from "../cli/common.js" ;
23
24
import { loadConfig } from "../config.js" ;
24
25
import { CLOUD_API_URL } from "../consts.js" ;
25
- import { cliLink , prettyError } from "../utilities/cliOutput.js" ;
26
+ import { cliLink } from "../utilities/cliOutput.js" ;
26
27
import {
27
28
createFileFromTemplate ,
28
29
generateTemplateUrl ,
29
30
} from "../utilities/createFileFromTemplate.js" ;
30
31
import { createFile , pathExists , readFile } from "../utilities/fileSystem.js" ;
31
32
import { printStandloneInitialBanner } from "../utilities/initialBanner.js" ;
32
33
import { logger } from "../utilities/logger.js" ;
33
- import { cliRootPath } from "../utilities/resolveInternalFilePath.js" ;
34
34
import { spinner } from "../utilities/windows.js" ;
35
35
import { login } from "./login.js" ;
36
- import { resolveTSConfig } from "pkg-types" ;
37
36
38
37
const InitCommandOptions = CommonCommandOptions . extend ( {
39
38
projectRef : z . string ( ) . optional ( ) ,
40
39
overrideConfig : z . boolean ( ) . default ( false ) ,
41
40
tag : z . string ( ) . default ( "beta" ) ,
42
41
skipPackageInstall : z . boolean ( ) . default ( false ) ,
43
42
pkgArgs : z . string ( ) . optional ( ) ,
43
+ gitRef : z . string ( ) . default ( "main" ) ,
44
44
} ) ;
45
45
46
46
type InitCommandOptions = z . infer < typeof InitCommandOptions > ;
@@ -66,12 +66,19 @@ export function configureInitCommand(program: Command) {
66
66
"--pkg-args <args>" ,
67
67
"Additional arguments to pass to the package manager, accepts CSV for multiple args"
68
68
)
69
- ) . action ( async ( path , options ) => {
70
- await handleTelemetry ( async ( ) => {
71
- await printStandloneInitialBanner ( true ) ;
72
- await initCommand ( path , options ) ;
69
+ )
70
+ . addOption (
71
+ new CommandOption (
72
+ "--git-ref <git ref>" ,
73
+ "The git ref to use when fetching templates from GitHub"
74
+ ) . hideHelp ( )
75
+ )
76
+ . action ( async ( path , options ) => {
77
+ await handleTelemetry ( async ( ) => {
78
+ await printStandloneInitialBanner ( true ) ;
79
+ await initCommand ( path , options ) ;
80
+ } ) ;
73
81
} ) ;
74
- } ) ;
75
82
}
76
83
77
84
export async function initCommand ( dir : string , options : unknown ) {
@@ -227,6 +234,7 @@ async function createTriggerDir(dir: string, options: InitCommandOptions) {
227
234
message : `Choose an example to create in the ${ location } directory` ,
228
235
options : [
229
236
{ value : "simple" , label : "Simple (Hello World)" } ,
237
+ { value : "schedule" , label : "Scheduled Task" } ,
230
238
{
231
239
value : "none" ,
232
240
label : "None" ,
@@ -255,7 +263,7 @@ async function createTriggerDir(dir: string, options: InitCommandOptions) {
255
263
return { location, isCustomValue : location !== defaultValue } ;
256
264
}
257
265
258
- const templateUrl = generateTemplateUrl ( `examples/${ example } .ts` ) ;
266
+ const templateUrl = generateTemplateUrl ( `examples/${ example } .ts` , options . gitRef ) ;
259
267
const outputPath = join ( triggerDir , "example.ts" ) ;
260
268
261
269
await createFileFromTemplate ( {
@@ -449,7 +457,7 @@ async function writeConfigFile(
449
457
450
458
const projectDir = resolve ( process . cwd ( ) , dir ) ;
451
459
const outputPath = join ( projectDir , "trigger.config.ts" ) ;
452
- const templateUrl = generateTemplateUrl ( "trigger.config.ts" ) ;
460
+ const templateUrl = generateTemplateUrl ( "trigger.config.ts" , options . gitRef ) ;
453
461
454
462
span . setAttributes ( {
455
463
"cli.projectDir" : projectDir ,
0 commit comments