forked from analogjs/analog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(astro-integration-angular): move astro integration to analog mon…
…orepo (analogjs#28) Closes analogjs#24
- Loading branch information
1 parent
d049508
commit dfbd57b
Showing
22 changed files
with
2,337 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { getJestProjects } from '@nrwl/jest'; | ||
|
||
export default { | ||
projects: getJestProjects(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const nxPreset = require('@nrwl/jest/preset').default; | ||
|
||
module.exports = { ...nxPreset }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# @analogjs/astro-integration-angular | ||
|
||
An Angular integration for Astro | ||
|
||
## Setup | ||
|
||
Install dependencies | ||
|
||
```sh | ||
yarn add @analogjs/astro-integration-angular --dev | ||
``` | ||
|
||
Add Angular to `integrations` array and enable `experimental.integrations` | ||
|
||
```js | ||
import { defineConfig } from 'astro/config'; | ||
import angular from '@analogjs/astro-integration-angular'; | ||
|
||
export default defineConfig({ | ||
integrations: [angular()], | ||
experimental: { | ||
integrations: true, | ||
}, | ||
}); | ||
``` | ||
|
||
## Defining A Component | ||
|
||
The Astro Angular integration **only** supports bootstrapping standalone components: | ||
|
||
```ts | ||
import { CommonModule } from '@angular/common'; | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-hello', | ||
standalone: true, | ||
imports: [CommonModule], | ||
template: ` | ||
<p>Hello from Angular!!</p> | ||
<p *ngIf="show">help</p> | ||
<button (click)="toggle()">Toggle</button> | ||
`, | ||
}) | ||
export class HelloComponent { | ||
show = false; | ||
|
||
toggle() { | ||
this.show = !this.show; | ||
} | ||
} | ||
``` | ||
|
||
And add the Angular component to the Astro component: | ||
|
||
```ts | ||
--- | ||
import { HelloComponent } from '../components/hello.component.ts'; | ||
--- | ||
|
||
<HelloComponent client:visible /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"displayName": "astro-integration-angular", | ||
"preset": "../../jest.preset.js", | ||
"globals": { | ||
"ts-jest": { | ||
"tsconfig": "<rootDir>/tsconfig.spec.json" | ||
} | ||
}, | ||
"transform": { | ||
"^.+\\.[tj]s$": "ts-jest" | ||
}, | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js", | ||
"html", | ||
"json" | ||
], | ||
"coverageDirectory": "../../coverage/packages/astro-integration-angular" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@analogjs/astro-integration-angular", | ||
"version": "0.0.1", | ||
"description": "An Angular integration for Astro", | ||
"type": "module", | ||
"author": "Brandon Roberts <robertsbt@gmail.com>", | ||
"exports": { | ||
".": "./src/index.js", | ||
"./client.js": "./src/client.js", | ||
"./server.js": "./src/server.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"client.js", | ||
"server.js" | ||
], | ||
"keywords": [ | ||
"angular", | ||
"astro", | ||
"astro-integration", | ||
"astro-component", | ||
"renderer" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/analogjs/analog/issues" | ||
}, | ||
"homepage": "https://github.com/analogjs/analog#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/analogjs/analog.git" | ||
}, | ||
"dependencies": { | ||
"@analogjs/vite-plugin-angular": "latest" | ||
}, | ||
"peerDependencies": { | ||
"@angular-devkit/build-angular": "^14.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/astro-integration-angular/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/js:tsc", | ||
"outputs": [ | ||
"{options.outputPath}" | ||
], | ||
"options": { | ||
"outputPath": "dist/packages/astro-integration-angular", | ||
"main": "packages/astro-integration-angular/src/index.ts", | ||
"tsConfig": "packages/astro-integration-angular/tsconfig.lib.json", | ||
"assets": [ | ||
"packages/astro-integration-angular/*.md" | ||
] | ||
} | ||
}, | ||
"publish": { | ||
"executor": "@nrwl/workspace:run-commands", | ||
"options": { | ||
"command": "node tools/scripts/publish.mjs astro-integration-angular {args.ver} {args.tag}" | ||
}, | ||
"dependsOn": [ | ||
{ | ||
"projects": "self", | ||
"target": "build" | ||
} | ||
] | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/astro-integration-angular/**/*.ts" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": [ | ||
"coverage/packages/astro-integration-angular" | ||
], | ||
"options": { | ||
"jestConfig": "packages/astro-integration-angular/jest.config.json", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'zone.js/dist/zone.js'; | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { ɵComponentType } from '@angular/core'; | ||
|
||
export default (_element?: HTMLElement) => { | ||
return ( | ||
Component: ɵComponentType<unknown>, | ||
_props?: unknown, | ||
_childHTML?: unknown | ||
) => { | ||
bootstrapApplication(Component); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import astroPlugin from './index'; | ||
|
||
describe('angularVitePlugin', () => { | ||
it('should return astro configurations', () => { | ||
expect(astroPlugin().name).toEqual('@analogjs/astro-integration-angular'); | ||
expect(astroPlugin().hooks).toStrictEqual({ | ||
'astro:config:setup': expect.anything(), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import viteAngular from '@analogjs/vite-plugin-angular'; | ||
import { AstroIntegration, AstroRenderer } from 'astro'; | ||
|
||
function getRenderer(): AstroRenderer { | ||
return { | ||
name: '@analogjs/astro-integration-angular', | ||
clientEntrypoint: '@analogjs/astro-integration-angular/client.js', | ||
serverEntrypoint: '@analogjs/astro-integration-angular/server.js', | ||
}; | ||
} | ||
|
||
function getViteConfiguration() { | ||
return { | ||
optimizeDeps: { | ||
include: ['@analogjs/astro-integration-angular/client.js'], | ||
exclude: ['@analogjs/astro-integration-angular/server.js'], | ||
}, | ||
/** | ||
* | ||
* Why I am casting viteAngular as any | ||
* | ||
* The vite angular plugins is shipped as commonjs, while this astro | ||
* integration is shipped using ESM and if you call the the default | ||
* function, you get the following error: viteAngular is not a function. | ||
* Attempt to use ESM for the angular vite plugin broke something, hence | ||
* this workaround for now. | ||
* | ||
*/ | ||
plugins: [(viteAngular as any).default()], | ||
}; | ||
} | ||
|
||
export default function (): AstroIntegration { | ||
return { | ||
name: '@analogjs/astro-integration-angular', | ||
hooks: { | ||
'astro:config:setup': ({ addRenderer, updateConfig }) => { | ||
addRenderer(getRenderer()); | ||
updateConfig({ vite: getViteConfiguration() }); | ||
}, | ||
}, | ||
}; | ||
} |
Oops, something went wrong.