diff --git a/package.json b/package.json index 142a38db..589848a3 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "private": true, "devDependencies": { - "@builder.io/qwik": "0.17.4", + "@builder.io/qwik": "0.17.5", "@commitlint/cli": "^17.3.0", "@commitlint/config-angular": "^17.3.0", "@commitlint/config-conventional": "^17.3.0", diff --git a/packages/qwik-nx/generators.json b/packages/qwik-nx/generators.json index bd5c8092..8e7945fd 100644 --- a/packages/qwik-nx/generators.json +++ b/packages/qwik-nx/generators.json @@ -54,6 +54,11 @@ "factory": "./src/generators/integrations/cloudflare-pages-integration/generator", "schema": "./src/generators/integrations/cloudflare-pages-integration/schema.json", "description": "Qwik City Cloudflare Pages adaptor allows you to connect Qwik City to Cloudflare Pages" + }, + "setup-ssg": { + "factory": "./src/generators/setup-ssg/generator", + "schema": "./src/generators/setup-ssg/schema.json", + "description": "Add Static Site Generation (SSG) to a Qwik app" } } } diff --git a/packages/qwik-nx/src/generators/setup-ssg/files/adapters/static/vite.config.ts__template__ b/packages/qwik-nx/src/generators/setup-ssg/files/adapters/static/vite.config.ts__template__ new file mode 100644 index 00000000..cec5d6da --- /dev/null +++ b/packages/qwik-nx/src/generators/setup-ssg/files/adapters/static/vite.config.ts__template__ @@ -0,0 +1,19 @@ +import { staticAdapter } from '@builder.io/qwik-city/adapters/static/vite'; +import { extendConfig } from '@builder.io/qwik-city/vite'; +import baseConfig from '../../vite.config'; + +export default extendConfig(baseConfig, () => { + return { + build: { + ssr: true, + rollupOptions: { + input: ['@qwik-city-plan'], + }, + }, + plugins: [ + staticAdapter({ + origin: 'https://yoursite.qwik.dev', + }), + ], + }; +}); diff --git a/packages/qwik-nx/src/generators/setup-ssg/generator.spec.ts b/packages/qwik-nx/src/generators/setup-ssg/generator.spec.ts new file mode 100644 index 00000000..8c766947 --- /dev/null +++ b/packages/qwik-nx/src/generators/setup-ssg/generator.spec.ts @@ -0,0 +1,20 @@ +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import { Tree, readProjectConfiguration } from '@nrwl/devkit'; + +import generator from './generator'; +import { SetupSsgGeneratorSchema } from './schema'; + +describe('setup-ssg generator', () => { + let appTree: Tree; + const options: SetupSsgGeneratorSchema = { name: 'test' }; + + beforeEach(() => { + appTree = createTreeWithEmptyWorkspace(); + }); + + it('should run successfully', async () => { + await generator(appTree, options); + const config = readProjectConfiguration(appTree, 'test'); + expect(config).toBeDefined(); + }); +}); diff --git a/packages/qwik-nx/src/generators/setup-ssg/generator.ts b/packages/qwik-nx/src/generators/setup-ssg/generator.ts new file mode 100644 index 00000000..2bf74d07 --- /dev/null +++ b/packages/qwik-nx/src/generators/setup-ssg/generator.ts @@ -0,0 +1,68 @@ +import { + formatFiles, + joinPathFragments, + logger, + readProjectConfiguration, + Tree, + updateProjectConfiguration, +} from '@nrwl/devkit'; +import { addSsgFiles } from './lib/add-ssg-files'; +import { NormalizedSchema, SetupSsgGeneratorSchema } from './schema'; + +function normalizeOptions( + tree: Tree, + options: SetupSsgGeneratorSchema +): NormalizedSchema { + const project = readProjectConfiguration(tree, options.project); + const projectRoot = project.root; + + return { + ...options, + projectRoot, + }; +} + +export async function setupSsgGenerator( + tree: Tree, + options: SetupSsgGeneratorSchema +) { + const normalizedOptions = normalizeOptions(tree, options); + + const { projectRoot } = normalizedOptions; + + const ssgConfigPath = joinPathFragments( + projectRoot, + 'adapters', + 'static', + 'vite.config.ts' + ); + + if (tree.exists(ssgConfigPath)) { + logger.info( + `Skipping setup since there is an existing static adapter configuration. For more configuration, see https://qwik.builder.io/qwikcity/guides/static-site-generation/.` + ); + return; + } + + const projectConfig = readProjectConfiguration(tree, options.project); + + addSsgFiles(tree, normalizedOptions); + + updateProjectConfiguration(tree, options.project, { + ...projectConfig, + targets: { + ...projectConfig.targets, + 'build-server': { + executor: '@nrwl/vite:build', + options: { + outputPath: 'dist/docs', + configFile: ssgConfigPath, + }, + }, + }, + }); + + await formatFiles(tree); +} + +export default setupSsgGenerator; diff --git a/packages/qwik-nx/src/generators/setup-ssg/lib/add-ssg-files.ts b/packages/qwik-nx/src/generators/setup-ssg/lib/add-ssg-files.ts new file mode 100644 index 00000000..b90c58bd --- /dev/null +++ b/packages/qwik-nx/src/generators/setup-ssg/lib/add-ssg-files.ts @@ -0,0 +1,17 @@ +import { generateFiles, offsetFromRoot, Tree } from '@nrwl/devkit'; +import * as path from 'path'; +import { NormalizedSchema } from '../schema'; + +export function addSsgFiles(tree: Tree, options: NormalizedSchema) { + const templateOptions = { + ...options, + offsetFromRoot: offsetFromRoot(options.projectRoot), + template: '', + }; + generateFiles( + tree, + path.join(__dirname, '..', 'files'), + options.projectRoot, + templateOptions + ); +} diff --git a/packages/qwik-nx/src/generators/setup-ssg/schema.d.ts b/packages/qwik-nx/src/generators/setup-ssg/schema.d.ts new file mode 100644 index 00000000..624dcc48 --- /dev/null +++ b/packages/qwik-nx/src/generators/setup-ssg/schema.d.ts @@ -0,0 +1,7 @@ +export interface SetupSsgGeneratorSchema { + project: string; +} + +interface NormalizedSchema extends SetupSsgGeneratorSchema { + projectRoot: string; +} diff --git a/packages/qwik-nx/src/generators/setup-ssg/schema.json b/packages/qwik-nx/src/generators/setup-ssg/schema.json new file mode 100644 index 00000000..2c75d743 --- /dev/null +++ b/packages/qwik-nx/src/generators/setup-ssg/schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "http://json-schema.org/schema", + "cli": "nx", + "$id": "SetupSsg", + "title": "", + "type": "object", + "properties": { + "project": { + "type": "string", + "description": "The name of the project to add the SSG setup for.", + "alias": "p", + "$default": { + "$source": "argv", + "index": 0 + }, + "x-dropdown": "projects", + "x-prompt": "What project would you like to add the SSG setup?" + } + }, + "additionalProperties": false, + "required": ["project"] +} diff --git a/packages/qwik-nx/src/utils/add-common-qwik-dependencies.ts b/packages/qwik-nx/src/utils/add-common-qwik-dependencies.ts index ce8d6c4c..3c8dfd7f 100644 --- a/packages/qwik-nx/src/utils/add-common-qwik-dependencies.ts +++ b/packages/qwik-nx/src/utils/add-common-qwik-dependencies.ts @@ -7,6 +7,7 @@ import { nodeFetchVersion, qwikCityVersion, qwikVersion, + undiciVersion, viteTsconfigPathsVersion, viteVersion, } from './versions'; @@ -21,6 +22,7 @@ export function addCommonQwikDependencies(host: Tree): GeneratorCallback { vite: viteVersion, 'vite-tsconfig-paths': viteTsconfigPathsVersion, 'node-fetch': nodeFetchVersion, + undici: undiciVersion, // TODO: dependencies below should be setup correctly by Nx's generator, so not needed to provide them here? // "@types/eslint": typesEslint, // '@types/node': 'latest', diff --git a/packages/qwik-nx/src/utils/versions.ts b/packages/qwik-nx/src/utils/versions.ts index 2919262a..c66336c2 100644 --- a/packages/qwik-nx/src/utils/versions.ts +++ b/packages/qwik-nx/src/utils/versions.ts @@ -1,8 +1,11 @@ // qwik packages -export const qwikVersion = '0.16.2'; -export const qwikCityVersion = '0.0.128'; +export const qwikVersion = '0.17.5'; +export const qwikCityVersion = '0.1.0'; export const qwikEslintPluginVersion = '0.16.2'; +// qwik dependencies +export const undiciVersion = '5.18.0'; + // css preprocessors export const sassVersion = '1.56.1'; export const lessVersion = '4.1.3'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 837bbf08..6e8beac8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3,7 +3,7 @@ lockfileVersion: 5.4 importers: .: specifiers: - '@builder.io/qwik': 0.17.4 + '@builder.io/qwik': 0.17.5 '@commitlint/cli': ^17.3.0 '@commitlint/config-angular': ^17.3.0 '@commitlint/config-conventional': ^17.3.0 @@ -55,7 +55,7 @@ importers: '@swc/helpers': 0.4.14 tslib: 2.4.1 devDependencies: - '@builder.io/qwik': 0.17.4_undici@5.18.0 + '@builder.io/qwik': 0.17.5_undici@5.18.0 '@commitlint/cli': 17.3.0_@swc+core@1.3.19 '@commitlint/config-angular': 17.3.0 '@commitlint/config-conventional': 17.3.0 @@ -1689,10 +1689,10 @@ packages: } dev: true - /@builder.io/qwik/0.17.4_undici@5.18.0: + /@builder.io/qwik/0.17.5_undici@5.18.0: resolution: { - integrity: sha512-f/qYBczshaDabtjlcpyupIpiyxi8PS/YCMSs+pIBoKlqbpVRsTZBdE5MP2hJ1HO5YAPu2+0T8qmB5IFucmXX7g==, + integrity: sha512-eckU4GHo98hVgGfFIh72LZo2e3aj4eIvM2zDvJ+7gW1sQheiUGX70zUrKYTC4/+k6wsYp82ItwoyhJhL3SqpbQ==, } engines: { node: '>=16.8.0' } hasBin: true