Skip to content

Commit d6a95d7

Browse files
authored
Deploy to Github Pages (#70)
* Deploy to Github Pages * trigger build * add back homepage * add hash * add base url for monaco * update base href * add deploy url * hard code url * configure base herf with env vairables * update build for pages * add build for github page deployment * remove base href * remove href from build * fix build env * fix test * revert to main * keep original layout for netlify
1 parent 4556442 commit d6a95d7

22 files changed

+161
-31
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '22.x'
20+
21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Build Angular app
25+
run: npm run build:pages2
26+
27+
- name: Deploy to GitHub Pages
28+
uses: JamesIves/github-pages-deploy-action@v4
29+
with:
30+
branch: gh-pages
31+
folder: dist/browser
32+
clean: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ npm-debug.log
3535
yarn-error.log
3636
testem.log
3737
/typings
38+
/cypress/screenshots/
3839
/cypress/videos/
3940
/cypress/downloads/
4041

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Three available demos:
2525
* `Live Demo on Netlify:` <a href="https://text-compare.netlify.app/" target="\_blank">https://text-compare.netlify.app/</a>
2626
* `Live Demo on Render:` <a href="https://text-compare.onrender.com/" target="\_blank">https://text-compare.onrender.com/</a>
2727
* `Live Demo on Azure:` <a href="https://text-compare.azurewebsites.net/" target="\_blank">https://text-compare.azurewebsites.net/</a>
28+
* `Live Demo on GitHub Page:` <a href="https://bit-developer.github.io/text-compare-angular/" target="\_blank">https://bit-developer.github.io/text-compare-angular/</a>
2829

2930
*Note: The demo websites may be slow when you access them for the first time. Be patient!*
3031

angular.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@
9999
}
100100
]
101101
},
102+
"pages": {
103+
"budgets": [
104+
{
105+
"type": "anyComponentStyle",
106+
"maximumWarning": "6kb"
107+
}
108+
],
109+
"optimization": true,
110+
"outputHashing": "all",
111+
"sourceMap": false,
112+
"namedChunks": false,
113+
"extractLicenses": true,
114+
"fileReplacements": [
115+
{
116+
"replace": "src/environments/environment.ts",
117+
"with": "src/environments/environment.pages.ts"
118+
}
119+
]
120+
},
121+
"pages2": {
122+
"budgets": [
123+
{
124+
"type": "anyComponentStyle",
125+
"maximumWarning": "6kb"
126+
}
127+
],
128+
"optimization": true,
129+
"outputHashing": "all",
130+
"sourceMap": false,
131+
"namedChunks": false,
132+
"extractLicenses": true,
133+
"fileReplacements": [
134+
{
135+
"replace": "src/environments/environment.ts",
136+
"with": "src/environments/environment.pages2.ts"
137+
}
138+
]
139+
},
102140
"nas": {
103141
"budgets": [
104142
{
@@ -156,6 +194,12 @@
156194
"render": {
157195
"buildTarget": "text-compare-angular:build:render"
158196
},
197+
"pages": {
198+
"buildTarget": "text-compare-angular:build:pages"
199+
},
200+
"pages2": {
201+
"buildTarget": "text-compare-angular:build:pages2"
202+
},
159203
"nas": {
160204
"buildTarget": "text-compare-angular:build:nas"
161205
},

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
"scripts": {
1010
"start": "ng serve",
1111
"start:prod": "ng serve --configuration production",
12+
"start:azure": "ng serve --configuration azure",
13+
"start:netlify": "ng serve --configuration netlify",
14+
"start:render": "ng serve --configuration render",
15+
"start:pages": "ng serve --configuration pages",
1216
"start:nas": "ng serve --configuration nas",
13-
"start:mock": "node server.js",
17+
"start:server": "node server.js",
1418
"build": "ng build --configuration production",
1519
"build:azure": "ng build --configuration azure",
1620
"build:netlify": "ng build --configuration netlify",
1721
"build:render": "ng build --configuration render",
22+
"build:pages": "ng build --configuration pages",
23+
"build:pages2": "ng build --configuration pages2 --base-href /text-compare-angular/",
1824
"build:nas": "ng build --configuration nas",
1925
"build:cross:env": "rimraf dist compiled && cross-env SOURCE_MAP=0 ng build --configuration production",
2026
"test": "ng test",

src/app/app-routing.module.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { NgModule } from '@angular/core';
2+
import { RouterModule, Routes } from '@angular/router';
3+
4+
import { HomeComponent } from './home/home.component';
5+
import { CompareEditorComponent } from './compare-editor/compare-editor.component';
6+
import { environment } from '../environments/environment';
7+
8+
const defaultComponent = environment.envName === 'Netlify'
9+
? CompareEditorComponent
10+
: HomeComponent;
11+
12+
const routes: Routes = [
13+
{ path: '', component: defaultComponent },
14+
{ path: 'home', component: HomeComponent },
15+
{ path: 'textcompare', component: CompareEditorComponent },
16+
// otherwise redirect to home
17+
{ path: '**', redirectTo: '' },
18+
];
19+
20+
@NgModule({
21+
imports: [RouterModule.forRoot(routes, { useHash: true })],
22+
exports: [RouterModule],
23+
})
24+
export class AppRoutingModule {}

src/app/app.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ describe('AppComponent', () => {
1717
it('should have as title app', waitForAsync(async () => {
1818
const fixture = TestBed.createComponent(AppComponent);
1919
const app = fixture.debugElement.componentInstance as AppComponent;
20-
await expect(app.title).toEqual('app');
20+
await expect(app.title).toEqual('Text Compare');
2121
}));
2222
});

src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import { Component } from '@angular/core';
77
standalone: false
88
})
99
export class AppComponent {
10-
title = 'app';
10+
title = 'Text Compare';
1111
}

src/app/app.module.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
3-
import { RouterModule } from '@angular/router';
3+
import { APP_BASE_HREF } from '@angular/common';
44

55
import { AppComponent } from './app.component';
66
import { HomeComponent } from './home/home.component';
@@ -12,7 +12,8 @@ import { FormsModule } from '@angular/forms';
1212
import { MonacoEditorModule } from 'ngx-monaco-editor-v2';
1313

1414
// routes
15-
import { appRoutes } from './app.route';
15+
import { AppRoutingModule } from './app-routing.module';
16+
import { environment } from '../environments/environment';
1617

1718
@NgModule({
1819
declarations: [
@@ -25,10 +26,12 @@ import { appRoutes } from './app.route';
2526
imports: [
2627
BrowserModule,
2728
FormsModule,
28-
MonacoEditorModule.forRoot(),
29-
RouterModule.forRoot(appRoutes, {})
29+
AppRoutingModule,
30+
MonacoEditorModule.forRoot({
31+
baseUrl: environment.monacoBaseUrl
32+
})
3033
],
31-
providers: [],
34+
providers: [{ provide: APP_BASE_HREF, useValue: environment.baseHref }],
3235
bootstrap: [AppComponent]
3336
})
3437
export class AppModule {}

src/app/app.route.ts

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

0 commit comments

Comments
 (0)