Skip to content

Commit

Permalink
Refactor inline variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ProchaLu committed Jan 24, 2025
1 parent 3ee4cbc commit de6c878
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions bin/expo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,33 @@ await promisify(exec)('pnpm add --save-dev prettier');

const { format } = await import('prettier');

const appFilePath = 'app.json';
const appJson = JSON.parse(await readFile(appFilePath, 'utf8'));
const appJsonFilePath = 'app.json';
const appJson = JSON.parse(await readFile(appJsonFilePath, 'utf8'));

if (!isPlainObject(appJson) || !isPlainObject(appJson.expo)) {
throw new Error(
'app.json either contains non-object or contains object without .expo property',
);
}

const expoConfig = `import { type ExpoConfig } from 'expo/config';
await writeFile(
'app.config.ts',
await format(
`import { type ExpoConfig } from 'expo/config';
const config: ExpoConfig = ${JSON.stringify(appJson.expo, null, 2)};
export default config;`.trim();

const formattedConfig = await format(expoConfig, {
parser: 'typescript',
singleQuote: true,
});

await writeFile('app.config.ts', formattedConfig, 'utf8');
export default config;`.trim(),
{
parser: 'typescript',
singleQuote: true,
},
),
'utf8',
);
console.log('✅ Converted and formatted app.json to app.config.ts');

await unlink(appFilePath);
await unlink(appJsonFilePath);
console.log('✅ Deleted app.json');

await writeFile('.env.development', 'EXPO_USE_FAST_RESOLVER=1', 'utf8');
Expand Down

0 comments on commit de6c878

Please sign in to comment.