( tasks: CronTask[], dir?: string, )
| 181 | * deleting) so the file watcher sees a change event on last-task-removed. |
| 182 | */ |
| 183 | export async function writeCronTasks( |
| 184 | tasks: CronTask[], |
| 185 | dir?: string, |
| 186 | ): Promise<void> { |
| 187 | const root = dir ?? getProjectRoot() |
| 188 | await mkdir(join(root, '.ncode'), { recursive: true }) |
| 189 | // Strip the runtime-only `durable` flag — everything on disk is durable |
| 190 | // by definition, and keeping the flag out means readCronTasks() naturally |
| 191 | // yields durable: undefined without having to set it explicitly. |
| 192 | const body: CronFile = { |
| 193 | tasks: tasks.map(({ durable: _durable, ...rest }) => rest), |
| 194 | } |
| 195 | await writeFile( |
| 196 | getCronFilePath(root), |
| 197 | jsonStringify(body, null, 2) + '\n', |
| 198 | 'utf-8', |
| 199 | ) |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Append a task. Returns the generated id. Caller is responsible for having |
no test coverage detected