Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ runs:
shell: bash
run: pnpx nx affected:build --base=last-release --exclude="add-nx-to-qwik"

# - name: Test
# shell: bash
# run: npx nx affected --target=test --base=last-release
- name: Test
shell: bash
run: npx nx affected --target=test --base=last-release

# - name: E2E Tests
# shell: bash
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ nx generate qwik-nx:lib
nx generate qwik-nx:component
```

### Generating a route

```
nx generate qwik-nx:route
```

### Setting up Tailwind CSS

```
Expand Down
11 changes: 0 additions & 11 deletions packages/qwik-nx/README.md

This file was deleted.

7 changes: 6 additions & 1 deletion packages/qwik-nx/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
"main": "packages/qwik-nx/src/index.ts",
"tsConfig": "packages/qwik-nx/tsconfig.lib.json",
"assets": [
"packages/qwik-nx/*.md",
"README.md",
{
"input": "./assets",
"glob": "qwik-nx.png",
"output": "./assets"
},
{
"input": "./packages/qwik-nx/src",
"glob": "**/!(*.ts)",
Expand Down
7 changes: 6 additions & 1 deletion packages/qwik-nx/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function addFiles(tree: Tree, options: NormalizedSchema) {
);
}

export default async function (tree: Tree, options: QwikAppGeneratorSchema) {
export async function appGenerator(
tree: Tree,
options: QwikAppGeneratorSchema
) {
const normalizedOptions = normalizeOptions(tree, options);
const tasks: GeneratorCallback[] = [];

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

return runTasksInSerial(...tasks);
}

export default appGenerator;
13 changes: 6 additions & 7 deletions packages/qwik-nx/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ export interface QwikAppGeneratorSchema {
name: string;
tags?: string;
directory?: string;

style: 'css' | 'scss' | 'styl' | 'less' | 'none';
linter: Linter;
skipFormat: boolean;
style?: 'css' | 'scss' | 'styl' | 'less' | 'none';
linter?: Linter;
skipFormat?: boolean;
tailwind?: boolean;
unitTestRunner: 'vitest' | 'none';
strict: boolean;
e2eTestRunner: 'playwright' | 'cypress' | 'none';
unitTestRunner?: 'vitest' | 'none';
strict?: boolean;
e2eTestRunner?: 'playwright' | 'cypress' | 'none';
// router: 'qwik-city' | 'none'; // TODO: add setup w/o qwik-city
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { component$ } from '@builder.io/qwik';

export default component$(() => {
return (
<>

<Slot />

</>
);
});


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { component$ } from '@builder.io/qwik';

export default component$(() => {
return (
<div>
This is the <%= routeName %>
</div>
);
});


This file was deleted.

40 changes: 30 additions & 10 deletions packages/qwik-nx/src/generators/route/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Tree, readProjectConfiguration } from '@nrwl/devkit';
import { Tree } from '@nrwl/devkit';

import generator from './generator';
import { routeGenerator } from './generator';
import { RouteGeneratorSchema } from './schema';
import appGenerator from '../application/generator';

describe('route generator', () => {
let appTree: Tree;
const options: RouteGeneratorSchema = { name: 'test' };
function setup() {
const appTree = createTreeWithEmptyWorkspace();
appGenerator(appTree, { name: 'testApp' });

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace();
const routeOptions: RouteGeneratorSchema = {
name: 'fake-route',
project: 'test-app',
};

return {
appTree,
routeOptions,
};
}

it('should generate the route index.tsx in the right location', async () => {
const { appTree, routeOptions } = setup();
await routeGenerator(appTree, routeOptions);
expect(
appTree.exists('test-app/src/routes/fake-route/index.tsx')
).toBeTruthy();
});

it('should run successfully', async () => {
await generator(appTree, options);
const config = readProjectConfiguration(appTree, 'test');
expect(config).toBeDefined();
it('should generate layout.tsx if selected', async () => {
const { appTree, routeOptions } = setup();
routeOptions.addLayout = true;
await routeGenerator(appTree, routeOptions);
expect(
appTree.exists('test-app/src/routes/fake-route/layout.tsx')
).toBeTruthy();
});
});
89 changes: 50 additions & 39 deletions packages/qwik-nx/src/generators/route/generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
addProjectConfiguration,
formatFiles,
generateFiles,
getWorkspaceLayout,
getProjects,
logger,
names,
offsetFromRoot,
Tree,
Expand All @@ -11,63 +11,74 @@ import * as path from 'path';
import { RouteGeneratorSchema } from './schema';

interface NormalizedSchema extends RouteGeneratorSchema {
projectName: string;
projectRoot: string;
projectDirectory: string;
parsedTags: string[];
routeName: string;
projectSourceRoot: string;
routeDirectory: string;
}

export default routeGenerator;

export async function routeGenerator(
tree: Tree,
options: RouteGeneratorSchema
) {
const normalizedOptions = normalizeOptions(tree, options);

addFiles(tree, normalizedOptions);
await formatFiles(tree);
}

function normalizeOptions(
tree: Tree,
options: RouteGeneratorSchema
): NormalizedSchema {
const name = names(options.name).fileName;
const projectDirectory = options.directory
const project = getProjects(tree).get(options.project);
const projectSourceRoot = project.sourceRoot;

if (!project) {
logger.error(
`Cannot find the ${options.project} project. Please double check the project name.`
);
throw new Error();
}

const routeDirectory = options.directory
? `${names(options.directory).fileName}/${name}`
: name;
const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
const projectRoot = `${getWorkspaceLayout(tree).libsDir}/${projectDirectory}`;
const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
: [];
const routeName = name;

return {
...options,
projectName,
projectRoot,
projectDirectory,
parsedTags,
routeName,
projectSourceRoot,
routeDirectory,
};
}

function addFiles(tree: Tree, options: NormalizedSchema) {
const templateOptions = {
...options,
...names(options.name),
offsetFromRoot: offsetFromRoot(options.projectRoot),
routeName: names(options.name).fileName,
offsetFromRoot: offsetFromRoot(options.projectSourceRoot),
template: '',
};
generateFiles(
tree,
path.join(__dirname, 'files'),
options.projectRoot,
templateOptions
);
}

export default async function (tree: Tree, options: RouteGeneratorSchema) {
const normalizedOptions = normalizeOptions(tree, options);
addProjectConfiguration(tree, normalizedOptions.projectName, {
root: normalizedOptions.projectRoot,
projectType: 'library',
sourceRoot: `${normalizedOptions.projectRoot}/src`,
targets: {
build: {
executor: 'qwik-nx:build',
},
},
tags: normalizedOptions.parsedTags,
});
addFiles(tree, normalizedOptions);
await formatFiles(tree);
const routesFolder = `${options.projectSourceRoot}/routes`;

generateFilesByType('route');

if (options.addLayout) {
generateFilesByType('layout');
}

function generateFilesByType(fileType: 'route' | 'layout') {
generateFiles(
tree,
path.join(__dirname, `files/${fileType}`),
routesFolder,
templateOptions
);
}
}
3 changes: 2 additions & 1 deletion packages/qwik-nx/src/generators/route/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface RouteGeneratorSchema {
name: string;
tags?: string;
project: string;
addLayout?: boolean;
directory?: string;
}
24 changes: 17 additions & 7 deletions packages/qwik-nx/src/generators/route/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@
"title": "",
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "The name of the project.",
"alias": "p",
"$default": {
"$source": "projectName"
},
"x-prompt": "What is the name of the project for this route?",
"x-priority": "important"
},
"name": {
"type": "string",
"description": "",
"description": "The name of the route",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use?"
"x-prompt": "What name would you like to use?",
"x-priority": "important"
},
"tags": {
"type": "string",
"description": "Add tags to the project (used for linting)",
"alias": "t"
"addLayout": {
"type": "boolean",
"default": false
},
"directory": {
"type": "string",
"description": "A directory where the project is placed"
}
},
"required": ["name"]
"required": ["name", "project"]
}