( environment: Environment, targetDir: string, )
| 39 | } |
| 40 | |
| 41 | export async function readConfigFileFromEnvironment( |
| 42 | environment: Environment, |
| 43 | targetDir: string, |
| 44 | ): Promise<PersistedOptions | null> { |
| 45 | try { |
| 46 | const configFile = resolve(targetDir, CONFIG_FILE) |
| 47 | const config = await environment.readFile(configFile) |
| 48 | |
| 49 | const originalJSON = JSON.parse(config) |
| 50 | |
| 51 | // Look for markers out outdated config files and upgrade the format on the fly (it will be written in the updated version after we add add-ons) |
| 52 | if (originalJSON.existingAddOns) { |
| 53 | if (originalJSON.framework === 'react-cra') { |
| 54 | originalJSON.framework = 'react' |
| 55 | } |
| 56 | originalJSON.chosenAddOns = originalJSON.existingAddOns |
| 57 | delete originalJSON.existingAddOns |
| 58 | delete originalJSON.addOns |
| 59 | if (originalJSON.toolchain && originalJSON.toolchain !== 'none') { |
| 60 | originalJSON.chosenAddOns.push(originalJSON.toolchain) |
| 61 | } |
| 62 | delete originalJSON.toolchain |
| 63 | delete originalJSON.variableValues |
| 64 | } |
| 65 | |
| 66 | if (originalJSON.framework === 'react-cra') { |
| 67 | originalJSON.framework = 'react' |
| 68 | } |
| 69 | |
| 70 | return originalJSON |
| 71 | } catch { |
| 72 | return null |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | export async function readConfigFile( |
| 77 | targetDir: string, |
no outgoing calls
no test coverage detected