diff --git a/apps/openchallenges/app-tailwind/.eslintrc.json b/apps/openchallenges/app-tailwind/.eslintrc.json new file mode 100644 index 0000000000..36040daaee --- /dev/null +++ b/apps/openchallenges/app-tailwind/.eslintrc.json @@ -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": {} + } + ] +} diff --git a/apps/openchallenges/app-tailwind/jest.config.ts b/apps/openchallenges/app-tailwind/jest.config.ts new file mode 100644 index 0000000000..cc73902e16 --- /dev/null +++ b/apps/openchallenges/app-tailwind/jest.config.ts @@ -0,0 +1,21 @@ +export default { + displayName: 'openchallenges-app-tailwind', + preset: '../../../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + coverageDirectory: '../../../coverage/apps/openchallenges/app-tailwind', + transform: { + '^.+\\.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/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', + ], +}; diff --git a/apps/openchallenges/app-tailwind/project.json b/apps/openchallenges/app-tailwind/project.json new file mode 100644 index 0000000000..eb817c797c --- /dev/null +++ b/apps/openchallenges/app-tailwind/project.json @@ -0,0 +1,94 @@ +{ + "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": "@angular-devkit/build-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": [ + { + "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": "@angular-devkit/build-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 + } + } + } +} diff --git a/apps/openchallenges/app-tailwind/public/favicon.ico b/apps/openchallenges/app-tailwind/public/favicon.ico new file mode 100644 index 0000000000..317ebcb233 Binary files /dev/null and b/apps/openchallenges/app-tailwind/public/favicon.ico differ diff --git a/apps/openchallenges/app-tailwind/server.ts b/apps/openchallenges/app-tailwind/server.ts new file mode 100644 index 0000000000..9c65f56d29 --- /dev/null +++ b/apps/openchallenges/app-tailwind/server.ts @@ -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(); diff --git a/apps/openchallenges/app-tailwind/src/app/app.component.html b/apps/openchallenges/app-tailwind/src/app/app.component.html new file mode 100644 index 0000000000..0f4018b6d7 --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/app/app.component.html @@ -0,0 +1 @@ + diff --git a/apps/openchallenges/app-tailwind/src/app/app.component.scss b/apps/openchallenges/app-tailwind/src/app/app.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/openchallenges/app-tailwind/src/app/app.component.spec.ts b/apps/openchallenges/app-tailwind/src/app/app.component.spec.ts new file mode 100644 index 0000000000..f1584ffc3c --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/app/app.component.spec.ts @@ -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'); + }); +}); diff --git a/apps/openchallenges/app-tailwind/src/app/app.component.ts b/apps/openchallenges/app-tailwind/src/app/app.component.ts new file mode 100644 index 0000000000..05974888b6 --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/app/app.component.ts @@ -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'; +} diff --git a/apps/openchallenges/app-tailwind/src/app/app.config.server.ts b/apps/openchallenges/app-tailwind/src/app/app.config.server.ts new file mode 100644 index 0000000000..1980cfe118 --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/app/app.config.server.ts @@ -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); diff --git a/apps/openchallenges/app-tailwind/src/app/app.config.ts b/apps/openchallenges/app-tailwind/src/app/app.config.ts new file mode 100644 index 0000000000..8f91ae956c --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/app/app.config.ts @@ -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), + ], +}; diff --git a/apps/openchallenges/app-tailwind/src/app/app.routes.ts b/apps/openchallenges/app-tailwind/src/app/app.routes.ts new file mode 100644 index 0000000000..8762dfe2c6 --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/app/app.routes.ts @@ -0,0 +1,3 @@ +import { Route } from '@angular/router'; + +export const appRoutes: Route[] = []; diff --git a/apps/openchallenges/app-tailwind/src/app/nx-welcome.component.ts b/apps/openchallenges/app-tailwind/src/app/nx-welcome.component.ts new file mode 100644 index 0000000000..1bd71a85b1 --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/app/nx-welcome.component.ts @@ -0,0 +1,935 @@ +import { Component, ViewEncapsulation } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@Component({ + selector: 'app-nx-welcome', + standalone: true, + imports: [CommonModule], + template: ` + + +
+
+ +
+

+ Hello there, + Welcome openchallenges-app-tailwind 👋 +

+
+ +
+
+

+ + + + You're up and running +

+ What's next? +
+
+ + + +
+
+ + + +
+

Next steps

+

Here are some things you can do with Nx:

+
+ + + + + Build, test and lint your app + +
# Build
+nx build 
+# Test
+nx test 
+# Lint
+nx lint 
+# Run them together!
+nx run-many -t build test lint
+
+
+ + + + + View project details + +
nx show project openchallenges-app-tailwind
+
+ +
+ + + + + View interactive project graph + +
nx graph
+
+ +
+ + + + + Add UI library + +
# Generate UI lib
+nx g @nx/angular:lib ui
+# Add a component
+nx g @nx/angular:component ui/src/lib/button
+
+
+

+ Carefully crafted with + + + +

+
+
+ `, + styles: [], + encapsulation: ViewEncapsulation.None, +}) +export class NxWelcomeComponent {} diff --git a/apps/openchallenges/app-tailwind/src/index.html b/apps/openchallenges/app-tailwind/src/index.html new file mode 100644 index 0000000000..a643a399cb --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/index.html @@ -0,0 +1,13 @@ + + + + + openchallenges-app-tailwind + + + + + + + + diff --git a/apps/openchallenges/app-tailwind/src/main.server.ts b/apps/openchallenges/app-tailwind/src/main.server.ts new file mode 100644 index 0000000000..4b9d4d1545 --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/main.server.ts @@ -0,0 +1,7 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; +import { config } from './app/app.config.server'; + +const bootstrap = () => bootstrapApplication(AppComponent, config); + +export default bootstrap; diff --git a/apps/openchallenges/app-tailwind/src/main.ts b/apps/openchallenges/app-tailwind/src/main.ts new file mode 100644 index 0000000000..17447a5dce --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/main.ts @@ -0,0 +1,5 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { appConfig } from './app/app.config'; +import { AppComponent } from './app/app.component'; + +bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err)); diff --git a/apps/openchallenges/app-tailwind/src/styles.scss b/apps/openchallenges/app-tailwind/src/styles.scss new file mode 100644 index 0000000000..77e408aa8b --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/styles.scss @@ -0,0 +1,5 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/openchallenges/app-tailwind/src/test-setup.ts b/apps/openchallenges/app-tailwind/src/test-setup.ts new file mode 100644 index 0000000000..ab1eeeb335 --- /dev/null +++ b/apps/openchallenges/app-tailwind/src/test-setup.ts @@ -0,0 +1,8 @@ +// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment +globalThis.ngJest = { + testEnvironmentOptions: { + errorOnUnknownElements: true, + errorOnUnknownProperties: true, + }, +}; +import 'jest-preset-angular/setup-jest'; diff --git a/apps/openchallenges/app-tailwind/tailwind.config.js b/apps/openchallenges/app-tailwind/tailwind.config.js new file mode 100644 index 0000000000..38183db2c8 --- /dev/null +++ b/apps/openchallenges/app-tailwind/tailwind.config.js @@ -0,0 +1,14 @@ +const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); +const { join } = require('path'); + +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: [ + join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), + ...createGlobPatternsForDependencies(__dirname), + ], + theme: { + extend: {}, + }, + plugins: [], +}; diff --git a/apps/openchallenges/app-tailwind/tsconfig.app.json b/apps/openchallenges/app-tailwind/tsconfig.app.json new file mode 100644 index 0000000000..2afe01ea4a --- /dev/null +++ b/apps/openchallenges/app-tailwind/tsconfig.app.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": ["node"] + }, + "files": ["src/main.ts", "src/main.server.ts", "server.ts"], + "include": ["src/**/*.d.ts"], + "exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"] +} diff --git a/apps/openchallenges/app-tailwind/tsconfig.editor.json b/apps/openchallenges/app-tailwind/tsconfig.editor.json new file mode 100644 index 0000000000..a8ac182c08 --- /dev/null +++ b/apps/openchallenges/app-tailwind/tsconfig.editor.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": {}, + "exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"] +} diff --git a/apps/openchallenges/app-tailwind/tsconfig.json b/apps/openchallenges/app-tailwind/tsconfig.json new file mode 100644 index 0000000000..ddb3050218 --- /dev/null +++ b/apps/openchallenges/app-tailwind/tsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "target": "es2022", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.editor.json" + }, + { + "path": "./tsconfig.app.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/apps/openchallenges/app-tailwind/tsconfig.spec.json b/apps/openchallenges/app-tailwind/tsconfig.spec.json new file mode 100644 index 0000000000..e637bf83b5 --- /dev/null +++ b/apps/openchallenges/app-tailwind/tsconfig.spec.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "target": "es2016", + "types": ["jest", "node"] + }, + "files": ["src/test-setup.ts"], + "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] +}