| 22 | * then we load that settings module and return all uppercase attributes. |
| 23 | */ |
| 24 | export async function getDjangoSettings( |
| 25 | projectDir: string, |
| 26 | env: NodeJS.ProcessEnv |
| 27 | ): Promise<DjangoSettingsResult> { |
| 28 | const { stdout } = await execa('python', ['-c', script], { |
| 29 | env, |
| 30 | cwd: projectDir, |
| 31 | }); |
| 32 | const parsed = JSON.parse(stdout) as { |
| 33 | settings_module: string; |
| 34 | django_settings: Record<string, unknown>; |
| 35 | django_version?: DjangoVersion; |
| 36 | } | null; |
| 37 | if (!parsed) { |
| 38 | throw new Error('manage.py did not return any settings'); |
| 39 | } |
| 40 | return { |
| 41 | settingsModule: parsed.settings_module, |
| 42 | djangoSettings: parsed.django_settings, |
| 43 | djangoVersion: parsed.django_version ?? null, |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | export interface DjangoCollectStaticResult { |
| 48 | /** Absolute paths of source static dirs to exclude from the Lambda bundle. */ |