Skip to content

Commit

Permalink
build: migrate to newest nx
Browse files Browse the repository at this point in the history
  • Loading branch information
yharaskrik committed Dec 26, 2023
1 parent a9a4473 commit a5fdba6
Show file tree
Hide file tree
Showing 46 changed files with 1,538 additions and 2,092 deletions.
6 changes: 3 additions & 3 deletions apps/api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"assets": ["apps/api/src/assets"],
"maxWorkers": 2,
"target": "node",
"compiler": "tsc"
"compiler": "tsc",
"isolatedConfig": false
},
"configurations": {
"production": {
Expand Down Expand Up @@ -47,8 +48,7 @@
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/api/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/api/jest.config.ts"
},
"outputs": ["{workspaceRoot}/coverage/apps/api"]
}
Expand Down
9 changes: 4 additions & 5 deletions apps/conways-game-of-life/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "conways-game-of-life:build:production"
"buildTarget": "conways-game-of-life:build:production"
},
"development": {
"browserTarget": "conways-game-of-life:build:development"
"buildTarget": "conways-game-of-life:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "conways-game-of-life:build"
"buildTarget": "conways-game-of-life:build"
}
},
"lint": {
Expand All @@ -80,8 +80,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/conways-game-of-life"],
"options": {
"jestConfig": "apps/conways-game-of-life/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/conways-game-of-life/jest.config.ts"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions apps/conways-game-of-life/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { GAME_STATE, gameReducer } from './state/game.state';
EffectsModule.forRoot([GameEffects]),
StoreDevtoolsModule.instrument({
logOnly: false,
connectInZone: true,
}),
LetDirective,
PushPipe,
Expand Down
9 changes: 4 additions & 5 deletions apps/dns-validator-demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "dns-validator-demo:build:production"
"buildTarget": "dns-validator-demo:build:production"
},
"development": {
"browserTarget": "dns-validator-demo:build:development"
"buildTarget": "dns-validator-demo:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "dns-validator-demo:build"
"buildTarget": "dns-validator-demo:build"
}
},
"lint": {
Expand All @@ -80,8 +80,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/dns-validator-demo"],
"options": {
"jestConfig": "apps/dns-validator-demo/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/dns-validator-demo/jest.config.ts"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion apps/nest-worker-threads-demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
}
],
"target": "node",
"compiler": "tsc"
"compiler": "tsc",
"isolatedConfig": false
}
},
"serve": {
Expand Down
9 changes: 4 additions & 5 deletions apps/ngrx-data-websocket-demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "ngrx-data-websocket-demo:build"
"buildTarget": "ngrx-data-websocket-demo:build"
},
"configurations": {
"production": {
"browserTarget": "ngrx-data-websocket-demo:build:production"
"buildTarget": "ngrx-data-websocket-demo:build:production"
}
}
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "ngrx-data-websocket-demo:build"
"buildTarget": "ngrx-data-websocket-demo:build"
}
},
"lint": {
Expand All @@ -89,8 +89,7 @@
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "apps/ngrx-data-websocket-demo/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/ngrx-data-websocket-demo/jest.config.ts"
},
"outputs": ["{workspaceRoot}/coverage/apps/ngrx-data-websocket-demo"]
}
Expand Down
2 changes: 1 addition & 1 deletion apps/ngrx-data-websocket-demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { AppComponent } from './app.component';
},
},
}),
StoreDevtoolsModule.instrument({}),
StoreDevtoolsModule.instrument({ connectInZone: true }),
HttpClientModule,
HttpClientJsonpModule,
NgrxDataWebsocketClientModule.forRoot({
Expand Down
6 changes: 3 additions & 3 deletions apps/ngrx-universal-rehydrate-demo-api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"assets": ["apps/ngrx-universal-rehydrate-demo-api/src/assets"],
"maxWorkers": 2,
"target": "node",
"compiler": "tsc"
"compiler": "tsc",
"isolatedConfig": false
},
"configurations": {
"production": {
Expand Down Expand Up @@ -47,8 +48,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/ngrx-universal-rehydrate-demo-api"],
"options": {
"jestConfig": "apps/ngrx-universal-rehydrate-demo-api/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/ngrx-universal-rehydrate-demo-api/jest.config.ts"
}
}
},
Expand Down
11 changes: 5 additions & 6 deletions apps/ngrx-universal-rehydrate-demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "ngrx-universal-rehydrate-demo:build"
"buildTarget": "ngrx-universal-rehydrate-demo:build"
},
"configurations": {
"production": {
"browserTarget": "ngrx-universal-rehydrate-demo:build:production"
"buildTarget": "ngrx-universal-rehydrate-demo:build:production"
}
}
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "ngrx-universal-rehydrate-demo:build"
"buildTarget": "ngrx-universal-rehydrate-demo:build"
}
},
"lint": {
Expand All @@ -87,8 +87,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/apps/ngrx-universal-rehydrate-demo"],
"options": {
"jestConfig": "apps/ngrx-universal-rehydrate-demo/jest.config.ts",
"passWithNoTests": true
"jestConfig": "apps/ngrx-universal-rehydrate-demo/jest.config.ts"
}
},
"server": {
Expand Down Expand Up @@ -129,7 +128,7 @@
}
},
"serve-ssr": {
"executor": "@nguniversal/builders:ssr-dev-server",
"executor": "@angular-devkit/build-angular:ssr-dev-server",
"options": {
"browserTarget": "ngrx-universal-rehydrate-demo:build",
"serverTarget": "ngrx-universal-rehydrate-demo:server"
Expand Down
56 changes: 27 additions & 29 deletions apps/ngrx-universal-rehydrate-demo/server.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import 'zone.js/node';

import { APP_BASE_HREF } from '@angular/common';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { CommonEngine } from '@angular/ssr';
import * as express from 'express';
import { existsSync } from 'fs';
import { join } from 'path';
import 'zone.js/node';
import { AppServerModule } from './src/main.server';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import bootstrap from './src/main.server';

// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
const server = express();
const distFolder = join(
process.cwd(),
'dist/apps/ngrx-universal-rehydrate-demo/browser'
);
const distFolder = join(process.cwd(), 'dist/apps/ngrx-universal-rehydrate-demo/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? 'index.original.html'
: 'index';
? join(distFolder, 'index.original.html')
: join(distFolder, 'index.html');

// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine(
'html',
ngExpressEngine({
bootstrap: AppServerModule,
})
);
const commonEngine = new CommonEngine();

server.set('view engine', 'html');
server.set('views', distFolder);
Expand All @@ -38,26 +30,32 @@ export function app(): express.Express {
})
);

// All regular routes use the Universal engine
server.get('*', (req, res) => {
res.render(indexHtml, {
req,
providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
});
// All regular routes use the Angular engine
server.get('*', (req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;

commonEngine
.render({
bootstrap,
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: distFolder,
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
})
.then((html) => res.send(html))
.catch((err) => next(err));
});

return server;
}

function run(): void {
const port = process.env.PORT || 4000;
const port = process.env['PORT'] || 4000;

// Start up the Node server
const server = app();
server.listen(port, () => {
console.log(
`Node Express server listening on http://localhost:${port}`
);
console.log(`Node Express server listening on http://localhost:${port}`);
});
}

Expand All @@ -71,4 +69,4 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}

export * from './src/main.server';
export default bootstrap;
74 changes: 74 additions & 0 deletions apps/ngrx-universal-rehydrate-demo/server.ts.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { APP_BASE_HREF } from '@angular/common';
import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import { existsSync } from 'fs';
import { join } from 'path';
import 'zone.js/node';
import { AppServerModule } from './src/main.server';

// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
const server = express();
const distFolder = join(
process.cwd(),
'dist/apps/ngrx-universal-rehydrate-demo/browser'
);
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? 'index.original.html'
: 'index';

// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine(
'html',
ngExpressEngine({
bootstrap: AppServerModule,
})
);

server.set('view engine', 'html');
server.set('views', distFolder);

// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get(
'*.*',
express.static(distFolder, {
maxAge: '1y',
})
);

// All regular routes use the Universal engine
server.get('*', (req, res) => {
res.render(indexHtml, {
req,
providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
});
});

return server;
}

function run(): void {
const port = process.env.PORT || 4000;

// Start up the Node server
const server = app();
server.listen(port, () => {
console.log(
`Node Express server listening on http://localhost:${port}`
);
});
}

// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}

export * from './src/main.server';
2 changes: 1 addition & 1 deletion apps/ngrx-universal-rehydrate-demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { loadData, titleReducer } from './store';
stores: ['root'],
disableWarnings: false,
}),
StoreDevtoolsModule.instrument({}),
StoreDevtoolsModule.instrument({ connectInZone: true }),
HttpClientModule,
HttpClientJsonpModule,
RouterModule.forRoot([
Expand Down
6 changes: 3 additions & 3 deletions apps/preload-chunk-demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "preload-chunk-demo:build:production"
"buildTarget": "preload-chunk-demo:build:production"
},
"development": {
"browserTarget": "preload-chunk-demo:build:development"
"buildTarget": "preload-chunk-demo:build:development"
}
},
"defaultConfiguration": "development"
Expand Down Expand Up @@ -131,7 +131,7 @@
}
},
"serve-ssr": {
"executor": "@nguniversal/builders:ssr-dev-server",
"executor": "@angular-devkit/build-angular:ssr-dev-server",
"options": {
"browserTarget": "preload-chunk-demo:build:development",
"serverTarget": "preload-chunk-demo:server:development"
Expand Down
Loading

0 comments on commit a5fdba6

Please sign in to comment.