Skip to content

Commit 8ab1d5e

Browse files
authored
fix(qwik-nx): got route generator to work (#45)
1 parent ed0eb18 commit 8ab1d5e

File tree

13 files changed

+150
-81
lines changed

13 files changed

+150
-81
lines changed

.github/actions/test/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ runs:
1818
shell: bash
1919
run: pnpx nx affected:build --base=last-release --exclude="add-nx-to-qwik"
2020

21-
# - name: Test
22-
# shell: bash
23-
# run: npx nx affected --target=test --base=last-release
21+
- name: Test
22+
shell: bash
23+
run: npx nx affected --target=test --base=last-release
2424

2525
# - name: E2E Tests
2626
# shell: bash

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ nx generate qwik-nx:lib
5555
nx generate qwik-nx:component
5656
```
5757

58+
### Generating a route
59+
60+
```
61+
nx generate qwik-nx:route
62+
```
63+
5864
### Setting up Tailwind CSS
5965

6066
```

packages/qwik-nx/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/qwik-nx/project.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
"main": "packages/qwik-nx/src/index.ts",
1313
"tsConfig": "packages/qwik-nx/tsconfig.lib.json",
1414
"assets": [
15-
"packages/qwik-nx/*.md",
15+
"README.md",
16+
{
17+
"input": "./assets",
18+
"glob": "qwik-nx.png",
19+
"output": "./assets"
20+
},
1621
{
1722
"input": "./packages/qwik-nx/src",
1823
"glob": "**/!(*.ts)",

packages/qwik-nx/src/generators/application/generator.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ function addFiles(tree: Tree, options: NormalizedSchema) {
3434
);
3535
}
3636

37-
export default async function (tree: Tree, options: QwikAppGeneratorSchema) {
37+
export async function appGenerator(
38+
tree: Tree,
39+
options: QwikAppGeneratorSchema
40+
) {
3841
const normalizedOptions = normalizeOptions(tree, options);
3942
const tasks: GeneratorCallback[] = [];
4043

@@ -90,3 +93,5 @@ export default async function (tree: Tree, options: QwikAppGeneratorSchema) {
9093

9194
return runTasksInSerial(...tasks);
9295
}
96+
97+
export default appGenerator;

packages/qwik-nx/src/generators/application/schema.d.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ export interface QwikAppGeneratorSchema {
44
name: string;
55
tags?: string;
66
directory?: string;
7-
8-
style: 'css' | 'scss' | 'styl' | 'less' | 'none';
9-
linter: Linter;
10-
skipFormat: boolean;
7+
style?: 'css' | 'scss' | 'styl' | 'less' | 'none';
8+
linter?: Linter;
9+
skipFormat?: boolean;
1110
tailwind?: boolean;
12-
unitTestRunner: 'vitest' | 'none';
13-
strict: boolean;
14-
e2eTestRunner: 'playwright' | 'cypress' | 'none';
11+
unitTestRunner?: 'vitest' | 'none';
12+
strict?: boolean;
13+
e2eTestRunner?: 'playwright' | 'cypress' | 'none';
1514
// router: 'qwik-city' | 'none'; // TODO: add setup w/o qwik-city
1615
}
1716

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { component$ } from '@builder.io/qwik';
2+
3+
export default component$(() => {
4+
return (
5+
<>
6+
7+
<Slot />
8+
9+
</>
10+
);
11+
});
12+
13+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { component$ } from '@builder.io/qwik';
2+
3+
export default component$(() => {
4+
return (
5+
<div>
6+
This is the <%= routeName %>
7+
</div>
8+
);
9+
});
10+
11+

packages/qwik-nx/src/generators/route/files/src/index.ts__template__

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
2-
import { Tree, readProjectConfiguration } from '@nrwl/devkit';
2+
import { Tree } from '@nrwl/devkit';
33

4-
import generator from './generator';
4+
import { routeGenerator } from './generator';
55
import { RouteGeneratorSchema } from './schema';
6+
import appGenerator from '../application/generator';
67

78
describe('route generator', () => {
8-
let appTree: Tree;
9-
const options: RouteGeneratorSchema = { name: 'test' };
9+
function setup() {
10+
const appTree = createTreeWithEmptyWorkspace();
11+
appGenerator(appTree, { name: 'testApp' });
1012

11-
beforeEach(() => {
12-
appTree = createTreeWithEmptyWorkspace();
13+
const routeOptions: RouteGeneratorSchema = {
14+
name: 'fake-route',
15+
project: 'test-app',
16+
};
17+
18+
return {
19+
appTree,
20+
routeOptions,
21+
};
22+
}
23+
24+
it('should generate the route index.tsx in the right location', async () => {
25+
const { appTree, routeOptions } = setup();
26+
await routeGenerator(appTree, routeOptions);
27+
expect(
28+
appTree.exists('test-app/src/routes/fake-route/index.tsx')
29+
).toBeTruthy();
1330
});
1431

15-
it('should run successfully', async () => {
16-
await generator(appTree, options);
17-
const config = readProjectConfiguration(appTree, 'test');
18-
expect(config).toBeDefined();
32+
it('should generate layout.tsx if selected', async () => {
33+
const { appTree, routeOptions } = setup();
34+
routeOptions.addLayout = true;
35+
await routeGenerator(appTree, routeOptions);
36+
expect(
37+
appTree.exists('test-app/src/routes/fake-route/layout.tsx')
38+
).toBeTruthy();
1939
});
2040
});

0 commit comments

Comments
 (0)