Open History to see the last commit
1import { CONFIG_FILE } from './constants.js'
2import { joinPaths } from './edge-path.js'
3
4import type { Environment, Options } from './types.js'
5
6export type PersistedOptions = Omit<
7 Partial<Options>,
8 'addOns' | 'chosenAddOns' | 'framework' | 'starter' | 'targetDir'
9> & {
10 framework: string
11 version: number
12 chosenAddOns: Array<string>
13 starter?: string
14}
15
16function createPersistedOptions(options: Options): PersistedOptions {
17 const { chosenAddOns, framework, targetDir: _targetDir, ...rest } = options
18 return {
19 ...rest,
20 version: 1,
21 framework: framework.id,
22 chosenAddOns: chosenAddOns.map((addOn) => addOn.id),
23 starter: options.starter?.id ?? undefined,
24 }
25}
26
27export async function writeConfigFileToEnvironment(
28 environment: Environment,
29 options: Options,
30) {
31 await environment.writeFile(
32 joinPaths(options.targetDir, CONFIG_FILE),
33 JSON.stringify(createPersistedOptions(options), null, 2),
34 )
35}