(dir: string, options: InitCommandOptions)
| 181 | } |
| 182 | |
| 183 | async function createTriggerDir(dir: string, options: InitCommandOptions) { |
| 184 | return await tracer.startActiveSpan("createTriggerDir", async (span) => { |
| 185 | try { |
| 186 | const defaultValue = join(dir, "src", "trigger"); |
| 187 | |
| 188 | const location = await text({ |
| 189 | message: "Where would you like to create the Trigger.dev directory?", |
| 190 | defaultValue: defaultValue, |
| 191 | placeholder: defaultValue, |
| 192 | }); |
| 193 | |
| 194 | if (isCancel(location)) { |
| 195 | throw new OutroCommandError(); |
| 196 | } |
| 197 | |
| 198 | const triggerDir = resolve(process.cwd(), location); |
| 199 | |
| 200 | logger.debug({ triggerDir }); |
| 201 | |
| 202 | span.setAttributes({ |
| 203 | "cli.triggerDir": triggerDir, |
| 204 | }); |
| 205 | |
| 206 | if (await pathExists(triggerDir)) { |
| 207 | throw new Error(`Directory already exists at ${triggerDir}`); |
| 208 | } |
| 209 | |
| 210 | const exampleSelection = await select({ |
| 211 | message: `Choose an example to create in the ${location} directory`, |
| 212 | options: [ |
| 213 | { value: "simple", label: "Simple (Hello World)" }, |
| 214 | { |
| 215 | value: "none", |
| 216 | label: "None", |
| 217 | hint: "skip creating an example", |
| 218 | }, |
| 219 | ], |
| 220 | }); |
| 221 | |
| 222 | if (isCancel(exampleSelection)) { |
| 223 | throw new OutroCommandError(); |
| 224 | } |
| 225 | |
| 226 | const example = exampleSelection as string; |
| 227 | |
| 228 | span.setAttributes({ |
| 229 | "cli.example": example, |
| 230 | }); |
| 231 | |
| 232 | if (example === "none") { |
| 233 | // Create a .gitkeep file in the trigger dir |
| 234 | await createFile(join(triggerDir, ".gitkeep"), ""); |
| 235 | |
| 236 | log.step(`Created directory at ${location}`); |
| 237 | |
| 238 | span.end(); |
| 239 | return { location, isCustomValue: location !== defaultValue }; |
| 240 | } |
no test coverage detected
searching dependent graphs…