|
| 1 | +import { |
| 2 | + addProjectConfiguration, |
| 3 | + formatFiles, |
| 4 | + generateFiles, |
| 5 | + GeneratorCallback, |
| 6 | + joinPathFragments, |
| 7 | + names, |
| 8 | + TargetConfiguration, |
| 9 | + Tree, |
| 10 | + runTasksInSerial, |
| 11 | +} from '@nx/devkit'; |
| 12 | +import { Linter } from '@nx/eslint'; |
| 13 | +import { initGenerator } from '@nx/vite'; |
| 14 | +import { initGenerator as jsInitGenerator } from '@nx/js'; |
| 15 | +import { addCommonQwikDependencies } from '../../utils/add-common-qwik-dependencies'; |
| 16 | +import { addStyledModuleDependencies } from '../../utils/add-styled-dependencies'; |
| 17 | +import { configureEslint } from '../../utils/configure-eslint'; |
| 18 | +import setupTailwindGenerator from '../setup-tailwind/setup-tailwind'; |
| 19 | +import { SetupTailwindOptions } from './../setup-tailwind/schema.d'; |
| 20 | +import { NormalizedSchema, QwikAppGeneratorSchema } from './schema'; |
| 21 | +import { getQwikApplicationProjectTargets } from './utils/get-qwik-application-project-params'; |
| 22 | +import { normalizeOptions } from './utils/normalize-options'; |
| 23 | +import { addE2eProject } from './utils/add-e2e'; |
| 24 | + |
| 25 | +function addFiles(tree: Tree, options: NormalizedSchema) { |
| 26 | + const templateOptions = { |
| 27 | + ...options, |
| 28 | + ...names(options.name), |
| 29 | + template: '', |
| 30 | + }; |
| 31 | + generateFiles( |
| 32 | + tree, |
| 33 | + joinPathFragments(__dirname, 'files'), |
| 34 | + options.projectRoot, |
| 35 | + templateOptions |
| 36 | + ); |
| 37 | +} |
| 38 | + |
| 39 | +export async function appGeneratorInternal( |
| 40 | + tree: Tree, |
| 41 | + options: QwikAppGeneratorSchema |
| 42 | +) { |
| 43 | + const tasks: GeneratorCallback[] = []; |
| 44 | + |
| 45 | + const normalizedOptions = await normalizeOptions(tree, options); |
| 46 | + |
| 47 | + const targets: Record<string, TargetConfiguration> = |
| 48 | + getQwikApplicationProjectTargets(normalizedOptions); |
| 49 | + |
| 50 | + if (!normalizedOptions.setupVitest) { |
| 51 | + delete targets['test']; |
| 52 | + } |
| 53 | + |
| 54 | + await jsInitGenerator(tree, { |
| 55 | + skipFormat: true, |
| 56 | + }); |
| 57 | + |
| 58 | + addProjectConfiguration(tree, normalizedOptions.projectName, { |
| 59 | + root: normalizedOptions.projectRoot, |
| 60 | + name: normalizedOptions.projectName, |
| 61 | + projectType: 'application', |
| 62 | + sourceRoot: `${normalizedOptions.projectRoot}/src`, |
| 63 | + targets, |
| 64 | + tags: normalizedOptions.parsedTags, |
| 65 | + }); |
| 66 | + |
| 67 | + addFiles(tree, normalizedOptions); |
| 68 | + |
| 69 | + tasks.push( |
| 70 | + await initGenerator(tree, { |
| 71 | + includeLib: false, |
| 72 | + uiFramework: 'none', |
| 73 | + testEnvironment: 'node', |
| 74 | + }) |
| 75 | + ); |
| 76 | + |
| 77 | + if (normalizedOptions.linter === Linter.EsLint) { |
| 78 | + tasks.push(configureEslint(tree, normalizedOptions.projectName, true)); |
| 79 | + } |
| 80 | + |
| 81 | + if (normalizedOptions.styleExtension) { |
| 82 | + tasks.push( |
| 83 | + addStyledModuleDependencies(tree, normalizedOptions.styleExtension) |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + tasks.push(addCommonQwikDependencies(tree)); |
| 88 | + |
| 89 | + if ( |
| 90 | + normalizedOptions.e2eTestRunner && |
| 91 | + normalizedOptions.e2eTestRunner !== 'none' |
| 92 | + ) { |
| 93 | + const e2eProjectTask = await addE2eProject(tree, normalizedOptions); |
| 94 | + tasks.push(e2eProjectTask); |
| 95 | + } |
| 96 | + |
| 97 | + if (!options.skipFormat) { |
| 98 | + await formatFiles(tree); |
| 99 | + } |
| 100 | + |
| 101 | + if (options.tailwind) { |
| 102 | + const twOptions: SetupTailwindOptions = { |
| 103 | + project: normalizedOptions.name, |
| 104 | + }; |
| 105 | + tasks.push(await setupTailwindGenerator(tree, twOptions)); |
| 106 | + } |
| 107 | + |
| 108 | + return runTasksInSerial(...tasks); |
| 109 | +} |
0 commit comments