Skip to content

Commit 3a84ced

Browse files
authored
feat(platform): add initial Nx plugin support (#308)
Fixes #293
1 parent 5e4b898 commit 3a84ced

File tree

71 files changed

+2194
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2194
-34
lines changed

.eslintrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"files": ["*.js", "*.jsx"],
3131
"extends": ["plugin:@nrwl/nx/javascript"],
3232
"rules": {}
33+
},
34+
{
35+
"files": "*.json",
36+
"parser": "jsonc-eslint-parser",
37+
"rules": {}
3338
}
3439
]
3540
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"eslint.validate": ["json"]
3+
}

apps/nx-plugin-e2e/jest.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'nx-plugin-e2e',
4+
preset: '../../jest.preset.js',
5+
transform: {
6+
'^.+\\.[tj]s$': 'ts-jest',
7+
},
8+
moduleFileExtensions: ['ts', 'js', 'html'],
9+
};

apps/nx-plugin-e2e/project.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "nx-plugin-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"projectType": "application",
5+
"sourceRoot": "apps/nx-plugin-e2e/src",
6+
"targets": {
7+
"e2e": {
8+
"executor": "@nrwl/nx-plugin:e2e",
9+
"options": {
10+
"target": "nx-plugin:build",
11+
"jestConfig": "apps/nx-plugin-e2e/jest.config.ts",
12+
"coverageDirectory": "../../coverage/apps/nx-plugin-e2e"
13+
}
14+
}
15+
},
16+
"tags": [],
17+
"implicitDependencies": ["nx-plugin"]
18+
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
checkFilesExist,
3+
ensureNxProject,
4+
readJson,
5+
runNxCommandAsync,
6+
uniq,
7+
} from '@nrwl/nx-plugin/testing';
8+
9+
describe('nx-plugin e2e', () => {
10+
// Setting up individual workspaces per
11+
// test can cause e2e runs to take a long time.
12+
// For this reason, we recommend each suite only
13+
// consumes 1 workspace. The tests should each operate
14+
// on a unique project in the workspace, such that they
15+
// are not dependent on one another.
16+
beforeAll(() => {
17+
ensureNxProject('@analogjs/nx', 'dist/packages/nx-plugin');
18+
});
19+
20+
afterAll(() => {
21+
// `nx reset` kills the daemon, and performs
22+
// some work which can help clean up e2e leftovers
23+
runNxCommandAsync('reset');
24+
});
25+
26+
it('should create hello-world', async () => {
27+
const project = uniq('hello-world');
28+
await runNxCommandAsync(`generate @analogjs/nx:app ${project}`);
29+
const result = await runNxCommandAsync(`build ${project}`);
30+
expect(result.stdout).toContain(
31+
'Successfully ran target build for project'
32+
);
33+
}, 120000);
34+
35+
describe('--directory', () => {
36+
it('should create src in the specified directory', async () => {
37+
const project = uniq('hello-world');
38+
await runNxCommandAsync(
39+
`generate @analogjs/nx:app ${project} --directory subdir`
40+
);
41+
expect(() =>
42+
checkFilesExist(`apps/subdir/${project}/index.html`)
43+
).not.toThrow();
44+
}, 120000);
45+
});
46+
47+
describe('--tags', () => {
48+
it('should add tags to the project', async () => {
49+
const projectName = uniq('hello-world');
50+
await runNxCommandAsync(
51+
`generate @analogjs/nx:app ${projectName} --tags e2etag,e2ePackage`
52+
);
53+
const project = readJson(`apps/${projectName}/project.json`);
54+
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
55+
}, 120000);
56+
});
57+
});

apps/nx-plugin-e2e/tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"files": [],
4+
"include": [],
5+
"references": [
6+
{
7+
"path": "./tsconfig.spec.json"
8+
}
9+
]
10+
}

apps/nx-plugin-e2e/tsconfig.spec.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"include": [
9+
"jest.config.ts",
10+
"src/**/*.test.ts",
11+
"src/**/*.spec.ts",
12+
"src/**/*.d.ts"
13+
]
14+
}

commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
'router',
1414
'platform',
1515
'content',
16+
'nx-plugin',
1617
],
1718
],
1819
},

package.json

+8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,20 @@
7474
"@ngtools/webpack": "~15.1.3",
7575
"@nrwl/cli": "15.7.0",
7676
"@nrwl/cypress": "15.7.0",
77+
"@nrwl/devkit": "15.7.0",
7778
"@nrwl/eslint-plugin-nx": "15.7.0",
7879
"@nrwl/jest": "15.7.0",
80+
"@nrwl/js": "15.7.0",
7981
"@nrwl/linter": "15.7.0",
82+
"@nrwl/nx-plugin": "15.7.0",
8083
"@nrwl/vite": "15.7.0",
8184
"@nrwl/web": "15.7.0",
8285
"@nrwl/workspace": "15.7.0",
8386
"@nx-plus/docusaurus": "15.0.0-rc.0",
8487
"@schematics/angular": "~15.1.3",
88+
"@swc-node/register": "^1.4.2",
89+
"@swc/cli": "~0.1.55",
90+
"@swc/core": "^1.2.173",
8591
"@swc/helpers": "^0.4.14",
8692
"@types/jest": "29.4.0",
8793
"@types/marked": "^4.0.8",
@@ -99,7 +105,9 @@
99105
"eslint-config-prettier": "8.6.0",
100106
"eslint-plugin-cypress": "^2.12.1",
101107
"jest": "29.4.1",
108+
"jest-environment-jsdom": "28.1.1",
102109
"jsdom": "^21.1.0",
110+
"jsonc-eslint-parser": "^2.1.0",
103111
"kolorist": "^1.6.0",
104112
"lint-staged": "^13.1.0",
105113
"minimist": "^1.2.7",

packages/nx-plugin/.babelrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
[
4+
"@nrwl/js/babel",
5+
{
6+
"useBuiltIns": "usage"
7+
}
8+
]
9+
]
10+
}

packages/nx-plugin/.eslintrc.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
},
17+
{
18+
"files": ["./package.json", "./generators.json", "./executors.json"],
19+
"parser": "jsonc-eslint-parser",
20+
"rules": {
21+
"@nrwl/nx/nx-plugin-checks": "error"
22+
}
23+
}
24+
]
25+
}

packages/nx-plugin/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# @analogjs/nx
2+
3+
Official plugin to add AnalogJs to your Nx monorepo.
4+
5+
## Supported Generators
6+
7+
### app
8+
9+
Creates a preconfigured Analog application.
10+
11+
```sh
12+
nx g @analogjs/nx:app analog-app
13+
```
14+
15+
## Development
16+
17+
### Building
18+
19+
Run `nx build nx-plugin` to build the library.
20+
21+
### Running unit tests
22+
23+
Run `nx test nx-plugin` to execute the unit tests via [Jest](https://jestjs.io).

packages/nx-plugin/generators.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"name": "nx-plugin",
4+
"version": "0.0.1",
5+
"generators": {
6+
"app": {
7+
"factory": "./src/generators/app/generator",
8+
"schema": "./src/generators/app/schema.json",
9+
"description": "Generates an AnalogJs application"
10+
}
11+
},
12+
"schematics": {
13+
"app": {
14+
"factory": "./src/generators/app/generator",
15+
"schema": "./src/generators/app/schema.json",
16+
"description": "Add Angular Three with proper packages and config"
17+
}
18+
}
19+
}

packages/nx-plugin/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@analogjs/nx",
3+
"version": "0.0.1-alpha.0",
4+
"main": "src/index.js",
5+
"generators": "./generators.json",
6+
"schematics": "./generators.json"
7+
}

packages/nx-plugin/project.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "nx-plugin",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "packages/nx-plugin/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "@nrwl/js:tsc",
9+
"outputs": ["{options.outputPath}"],
10+
"options": {
11+
"outputPath": "dist/packages/nx-plugin",
12+
"main": "packages/nx-plugin/src/index.ts",
13+
"tsConfig": "packages/nx-plugin/tsconfig.lib.json",
14+
"assets": [
15+
"packages/nx-plugin/*.md",
16+
{
17+
"input": "./packages/nx-plugin/src",
18+
"glob": "**/!(*.ts)",
19+
"output": "./src"
20+
},
21+
{
22+
"input": "./packages/nx-plugin/src",
23+
"glob": "**/*.d.ts",
24+
"output": "./src"
25+
},
26+
{
27+
"input": "./packages/nx-plugin",
28+
"glob": "generators.json",
29+
"output": "."
30+
}
31+
]
32+
}
33+
},
34+
"lint": {
35+
"executor": "@nrwl/linter:eslint",
36+
"outputs": ["{options.outputFile}"],
37+
"options": {
38+
"lintFilePatterns": [
39+
"packages/nx-plugin/**/*.ts",
40+
"packages/nx-plugin/generators.json",
41+
"packages/nx-plugin/package.json"
42+
]
43+
}
44+
},
45+
"test": {
46+
"executor": "@nrwl/vite:test"
47+
}
48+
},
49+
"tags": []
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": [
8+
"plugin:@nrwl/nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "<%= className %>",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "<%= fileName %>",
25+
"style": "kebab-case"
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nrwl/nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>MyApp</title>
6+
<base href="/">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="icon" type="image/x-icon" href="/src/favicon.ico">
9+
<link rel="stylesheet" href="/src/styles.css" />
10+
</head>
11+
<body>
12+
<<%= fileName %>-root></<%= fileName %>-root>
13+
<script type="module" src="/src/main.ts"></script>
14+
</body>
15+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
3+
import { AppComponent } from './app.component';
4+
5+
describe('AppComponent', () => {
6+
beforeEach(async () => {
7+
await TestBed.configureTestingModule({
8+
imports: [RouterTestingModule, AppComponent],
9+
}).compileComponents();
10+
});
11+
12+
it('should create the app', () => {
13+
const fixture = TestBed.createComponent(AppComponent);
14+
const app = fixture.componentInstance;
15+
expect(app).toBeTruthy();
16+
});
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component } from '@angular/core';
2+
import { RouterOutlet } from '@angular/router';
3+
4+
@Component({
5+
selector: '<%= fileName %>-root',
6+
standalone: true,
7+
imports: [RouterOutlet],
8+
template: ` <router-outlet></router-outlet> `,
9+
styles: [
10+
`
11+
:host {
12+
max-width: 1280px;
13+
margin: 0 auto;
14+
padding: 2rem;
15+
text-align: center;
16+
}
17+
`,
18+
],
19+
})
20+
export class AppComponent {}

0 commit comments

Comments
 (0)