Skip to content

Commit 3f48e3a

Browse files
committed
feat(qwik-nx): setup ssg generator
1 parent a6e725a commit 3f48e3a

File tree

12 files changed

+107
-75
lines changed

12 files changed

+107
-75
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"eslint.validate": ["json"],
3-
"git.pullTags": false
3+
"git.pullTags": false,
4+
"liveServer.settings.port": 5501
45
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"private": true,
1414
"devDependencies": {
15-
"@builder.io/qwik": "0.17.4",
15+
"@builder.io/qwik": "0.17.5",
1616
"@commitlint/cli": "^17.3.0",
1717
"@commitlint/config-angular": "^17.3.0",
1818
"@commitlint/config-conventional": "^17.3.0",

packages/qwik-nx/generators.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"setup-ssg": {
5959
"factory": "./src/generators/setup-ssg/generator",
6060
"schema": "./src/generators/setup-ssg/schema.json",
61-
"description": "setup-ssg generator"
61+
"description": "Add Static Site Generation (SSG) to a Qwik app"
6262
}
6363
}
6464
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { staticAdapter } from '@builder.io/qwik-city/adapters/static/vite';
2+
import { extendConfig } from '@builder.io/qwik-city/vite';
3+
import baseConfig from '../../vite.config';
4+
5+
export default extendConfig(baseConfig, () => {
6+
return {
7+
build: {
8+
ssr: true,
9+
rollupOptions: {
10+
input: ['@qwik-city-plan'],
11+
},
12+
},
13+
plugins: [
14+
staticAdapter({
15+
origin: 'https://yoursite.qwik.dev',
16+
}),
17+
],
18+
};
19+
});

packages/qwik-nx/src/generators/setup-ssg/files/src/index.ts__template__

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,68 @@
11
import {
2-
addProjectConfiguration,
32
formatFiles,
4-
generateFiles,
5-
getWorkspaceLayout,
6-
names,
7-
offsetFromRoot,
3+
joinPathFragments,
4+
logger,
5+
readProjectConfiguration,
86
Tree,
7+
updateProjectConfiguration,
98
} from '@nrwl/devkit';
10-
import * as path from 'path';
11-
import { SetupSsgGeneratorSchema } from './schema';
12-
13-
interface NormalizedSchema extends SetupSsgGeneratorSchema {
14-
projectName: string;
15-
projectRoot: string;
16-
projectDirectory: string;
17-
parsedTags: string[];
18-
}
9+
import { addSsgFiles } from './lib/add-ssg-files';
10+
import { NormalizedSchema, SetupSsgGeneratorSchema } from './schema';
1911

2012
function normalizeOptions(
2113
tree: Tree,
2214
options: SetupSsgGeneratorSchema
2315
): NormalizedSchema {
24-
const name = names(options.name).fileName;
25-
const projectDirectory = options.directory
26-
? `${names(options.directory).fileName}/${name}`
27-
: name;
28-
const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
29-
const projectRoot = `${getWorkspaceLayout(tree).libsDir}/${projectDirectory}`;
30-
const parsedTags = options.tags
31-
? options.tags.split(',').map((s) => s.trim())
32-
: [];
16+
const project = readProjectConfiguration(tree, options.project);
17+
const projectRoot = project.root;
3318

3419
return {
3520
...options,
36-
projectName,
3721
projectRoot,
38-
projectDirectory,
39-
parsedTags,
4022
};
4123
}
4224

43-
function addFiles(tree: Tree, options: NormalizedSchema) {
44-
const templateOptions = {
45-
...options,
46-
...names(options.name),
47-
offsetFromRoot: offsetFromRoot(options.projectRoot),
48-
template: '',
49-
};
50-
generateFiles(
51-
tree,
52-
path.join(__dirname, 'files'),
53-
options.projectRoot,
54-
templateOptions
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'
5538
);
56-
}
5739

58-
export default async function (tree: Tree, options: SetupSsgGeneratorSchema) {
59-
const normalizedOptions = normalizeOptions(tree, options);
60-
addProjectConfiguration(tree, normalizedOptions.projectName, {
61-
root: normalizedOptions.projectRoot,
62-
projectType: 'library',
63-
sourceRoot: `${normalizedOptions.projectRoot}/src`,
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,
6453
targets: {
65-
build: {
66-
executor: 'qwik-nx:build',
54+
...projectConfig.targets,
55+
'build-server': {
56+
executor: '@nrwl/vite:build',
57+
options: {
58+
outputPath: 'dist/docs',
59+
configFile: ssgConfigPath,
60+
},
6761
},
6862
},
69-
tags: normalizedOptions.parsedTags,
7063
});
71-
addFiles(tree, normalizedOptions);
64+
7265
await formatFiles(tree);
7366
}
67+
68+
export default setupSsgGenerator;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { generateFiles, offsetFromRoot, Tree } from '@nrwl/devkit';
2+
import * as path from 'path';
3+
import { NormalizedSchema } from '../schema';
4+
5+
export function addSsgFiles(tree: Tree, options: NormalizedSchema) {
6+
const templateOptions = {
7+
...options,
8+
offsetFromRoot: offsetFromRoot(options.projectRoot),
9+
template: '',
10+
};
11+
generateFiles(
12+
tree,
13+
path.join(__dirname, '..', 'files'),
14+
options.projectRoot,
15+
templateOptions
16+
);
17+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export interface SetupSsgGeneratorSchema {
2-
name: string;
3-
tags?: string;
4-
directory?: string;
2+
project: string;
3+
}
4+
5+
interface NormalizedSchema extends SetupSsgGeneratorSchema {
6+
projectRoot: string;
57
}

packages/qwik-nx/src/generators/setup-ssg/schema.json

+7-13
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@
55
"title": "",
66
"type": "object",
77
"properties": {
8-
"name": {
8+
"project": {
99
"type": "string",
10-
"description": "",
10+
"description": "The name of the project to add the SSG setup for.",
11+
"alias": "p",
1112
"$default": {
1213
"$source": "argv",
1314
"index": 0
1415
},
15-
"x-prompt": "What name would you like to use?"
16-
},
17-
"tags": {
18-
"type": "string",
19-
"description": "Add tags to the project (used for linting)",
20-
"alias": "t"
21-
},
22-
"directory": {
23-
"type": "string",
24-
"description": "A directory where the project is placed"
16+
"x-dropdown": "projects",
17+
"x-prompt": "What project would you like to add the SSG setup?"
2518
}
2619
},
27-
"required": ["name"]
20+
"additionalProperties": false,
21+
"required": ["project"]
2822
}

packages/qwik-nx/src/utils/add-common-qwik-dependencies.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
nodeFetchVersion,
88
qwikCityVersion,
99
qwikVersion,
10+
undiciVersion,
1011
viteTsconfigPathsVersion,
1112
viteVersion,
1213
} from './versions';
@@ -21,6 +22,7 @@ export function addCommonQwikDependencies(host: Tree): GeneratorCallback {
2122
vite: viteVersion,
2223
'vite-tsconfig-paths': viteTsconfigPathsVersion,
2324
'node-fetch': nodeFetchVersion,
25+
undici: undiciVersion,
2426
// TODO: dependencies below should be setup correctly by Nx's generator, so not needed to provide them here?
2527
// "@types/eslint": typesEslint,
2628
// '@types/node': 'latest',

packages/qwik-nx/src/utils/versions.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// qwik packages
2-
export const qwikVersion = '0.16.2';
3-
export const qwikCityVersion = '0.0.128';
2+
export const qwikVersion = '0.17.5';
3+
export const qwikCityVersion = '0.1.0';
44
export const qwikEslintPluginVersion = '0.16.2';
55

6+
// qwik dependencies
7+
export const undiciVersion = '5.18.0';
8+
69
// css preprocessors
710
export const sassVersion = '1.56.1';
811
export const lessVersion = '4.1.3';

pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)