|
| 1 | +import { |
| 2 | + formatFiles, |
| 3 | + joinPathFragments, |
| 4 | + logger, |
| 5 | + readProjectConfiguration, |
| 6 | + Tree, |
| 7 | + updateProjectConfiguration, |
| 8 | +} from '@nrwl/devkit'; |
| 9 | +import { addSsgFiles } from './lib/add-ssg-files'; |
| 10 | +import { NormalizedSchema, SetupSsgGeneratorSchema } from './schema'; |
| 11 | + |
| 12 | +function normalizeOptions( |
| 13 | + tree: Tree, |
| 14 | + options: SetupSsgGeneratorSchema |
| 15 | +): NormalizedSchema { |
| 16 | + const project = readProjectConfiguration(tree, options.project); |
| 17 | + const projectRoot = project.root; |
| 18 | + |
| 19 | + return { |
| 20 | + ...options, |
| 21 | + projectRoot, |
| 22 | + }; |
| 23 | +} |
| 24 | + |
| 25 | +export async function setupSsgGenerator( |
| 26 | + tree: Tree, |
| 27 | + options: SetupSsgGeneratorSchema |
| 28 | +) { |
| 29 | + const normalizedOptions = normalizeOptions(tree, options); |
| 30 | + |
| 31 | + const { projectRoot } = normalizedOptions; |
| 32 | + |
| 33 | + const ssgConfigPath = joinPathFragments( |
| 34 | + projectRoot, |
| 35 | + 'adapters', |
| 36 | + 'static', |
| 37 | + 'vite.config.ts' |
| 38 | + ); |
| 39 | + |
| 40 | + if (tree.exists(ssgConfigPath)) { |
| 41 | + logger.info( |
| 42 | + `Skipping setup since there is an existing static adapter configuration. For more configuration, see https://qwik.builder.io/qwikcity/guides/static-site-generation/.` |
| 43 | + ); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + const projectConfig = readProjectConfiguration(tree, options.project); |
| 48 | + |
| 49 | + addSsgFiles(tree, normalizedOptions); |
| 50 | + |
| 51 | + updateProjectConfiguration(tree, options.project, { |
| 52 | + ...projectConfig, |
| 53 | + targets: { |
| 54 | + ...projectConfig.targets, |
| 55 | + 'build-server': { |
| 56 | + executor: '@nrwl/vite:build', |
| 57 | + options: { |
| 58 | + outputPath: 'dist/docs', |
| 59 | + configFile: ssgConfigPath, |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }); |
| 64 | + |
| 65 | + await formatFiles(tree); |
| 66 | +} |
| 67 | + |
| 68 | +export default setupSsgGenerator; |
0 commit comments