Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(openchallenges): create a fresh project for the app using tailwind css(ARCH-298) #2905

Closed
wants to merge 18 commits into from
Closed
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
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"extensions": [
"alefragnani.Bookmarks",
"Angular.ng-template",
"bradlc.vscode-tailwindcss",
"dbaeumer.vscode-eslint",
"donjayamanne.python-environment-manager",
"dorzey.vscode-sqlfluff",
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"password": "changeme"
}
],
"tailwindCSS.lint.invalidConfigPath": "ignore",
"terminal.integrated.showExitAlert": false,
"rewrap.wrappingColumn": 100,
"jest.runMode": "on-demand"
Expand Down
33 changes: 33 additions & 0 deletions apps/openchallenges/app-tailwind/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}
21 changes: 21 additions & 0 deletions apps/openchallenges/app-tailwind/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default {
displayName: 'openchallenges-app-tailwind',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../../coverage/apps/openchallenges/app-tailwind',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
109 changes: 109 additions & 0 deletions apps/openchallenges/app-tailwind/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"name": "openchallenges-app-tailwind",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"prefix": "app",
"sourceRoot": "apps/openchallenges/app-tailwind/src",
"tags": [],
"targets": {
"build": {
"executor": "@nx/angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/openchallenges/app-tailwind",
"index": "apps/openchallenges/app-tailwind/src/index.html",
"browser": "apps/openchallenges/app-tailwind/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/openchallenges/app-tailwind/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"input": "libs/shared/typescript/assets/src/assets",
"glob": "**/*",
"output": "assets"
},
{
"input": "libs/openchallenges/assets/src/assets",
"glob": "**/*",
"output": "openchallenges-assets"
},
{
"input": "libs/openchallenges/assets/src",
"glob": "favicon.ico",
"output": ""
},
{
"glob": "**/*",
"input": "apps/openchallenges/app-tailwind/public"
}
],
"styles": ["apps/openchallenges/app-tailwind/src/styles.scss"],
"scripts": [],
"server": "apps/openchallenges/app-tailwind/src/main.server.ts",
"prerender": true,
"ssr": {
"entry": "apps/openchallenges/app-tailwind/server.ts"
}
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"executor": "@nx/angular:dev-server",
"configurations": {
"production": {
"buildTarget": "openchallenges-app-tailwind:build:production"
},
"development": {
"buildTarget": "openchallenges-app-tailwind:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "openchallenges-app-tailwind:build"
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/openchallenges/app-tailwind/jest.config.ts"
}
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "openchallenges-app-tailwind:build",
"staticFilePath": "dist/apps/openchallenges/app-tailwind/browser",
"spa": true
}
}
}
}
Binary file not shown.
60 changes: 60 additions & 0 deletions apps/openchallenges/app-tailwind/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { APP_BASE_HREF } from '@angular/common';
import { CommonEngine } from '@angular/ssr';
import express from 'express';
import { fileURLToPath } from 'node:url';
import { dirname, join, resolve } 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 serverDistFolder = dirname(fileURLToPath(import.meta.url));
const browserDistFolder = resolve(serverDistFolder, '../browser');
const indexHtml = join(serverDistFolder, 'index.server.html');

const commonEngine = new CommonEngine();

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

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

// 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: browserDistFolder,
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;

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

run();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<router-outlet></router-outlet>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { NxWelcomeComponent } from './nx-welcome.component';
import { RouterModule } from '@angular/router';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent, NxWelcomeComponent, RouterModule.forRoot([])],
}).compileComponents();
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain(
'Welcome openchallenges-app-tailwind',
);
});

it(`should have as title 'openchallenges-app-tailwind'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('openchallenges-app-tailwind');
});
});
14 changes: 14 additions & 0 deletions apps/openchallenges/app-tailwind/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@angular/core';
import { RouterModule } from '@angular/router';
import { NxWelcomeComponent } from './nx-welcome.component';

@Component({
standalone: true,
imports: [NxWelcomeComponent, RouterModule],
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
})
export class AppComponent {
title = 'openchallenges-app-tailwind';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering } from '@angular/platform-server';
import { appConfig } from './app.config';

const serverConfig: ApplicationConfig = {
providers: [provideServerRendering()],
};

export const config = mergeApplicationConfig(appConfig, serverConfig);
12 changes: 12 additions & 0 deletions apps/openchallenges/app-tailwind/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { appRoutes } from './app.routes';
import { provideClientHydration } from '@angular/platform-browser';

export const appConfig: ApplicationConfig = {
providers: [
provideClientHydration(),
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(appRoutes),
],
};
14 changes: 14 additions & 0 deletions apps/openchallenges/app-tailwind/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Routes } from '@angular/router';

export const appRoutes: Routes = [
{ path: '', redirectTo: 'not-found', pathMatch: 'full' },
{
path: 'not-found',
loadChildren: () =>
import('@sagebionetworks/openchallenges/not-found-tailwind').then((routes) => routes.routes),
},
{
path: '**',
redirectTo: '/not-found',
},
];
Loading
Loading