Skip to content

Commit

Permalink
Add nx server+client apps and shared lib
Browse files Browse the repository at this point in the history
  • Loading branch information
lrdiv committed Jan 9, 2025
1 parent 437640d commit 8afce10
Show file tree
Hide file tree
Showing 88 changed files with 22,018 additions and 9,475 deletions.
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export OAUTH_CALLBACK_URL="http://localhost:3000/auth/callback"
export POST_AUTH_REDIRECT="http://localhost:4200/auth"

export DB_HOST="127.0.0.1"
export DB_PORT=54321
export DB_USERNAME="spincycle"
export DB_PASSWORD="spincycle"
export DB_DATABASE="spincycle"
export REDIS_URL="redis://localhost:63791"
export DISCOGS_KEY="WnLGBmVhAiSqeOklehdG"
export DISCOGS_SECRET="GsxNVzKifRhjpqnMIBRenYRfmTMMYDko"
export DISCOGS_USER_AGENT="SpinCycle/0.1"

export JWT_SECRET="a1f373cfe890e284a9027b56763b0d7898c1fdf84cbf41f1788d8824409472a6"
export SESSION_SECRET="791e1bd6315a06038d0c3fa3b82c5f9555162619d82373293234d4484d42da78"
15 changes: 15 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export OAUTH_CALLBACK_URL="where the discogs oauth flow should redirect to"
export POST_AUTH_REDIRECT="the client URL that the API should redirect to after oauth"

export DB_HOST="database host"
export DB_PORT=5432
export DB_USERNAME="spincycle"
export DB_PASSWORD="spincycle"
export DB_DATABASE="spincycle"
export REDIS_URL="redis URL"
export DISCOGS_KEY="discogs consumer key"
export DISCOGS_SECRET="discogs consumer secret"
export DISCOGS_USER_AGENT="SpinCycle/0.1"

export JWT_SECRET="secure secret"
export SESSION_SECRET="another secure secret"
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ Thumbs.db

.nx/cache
.nx/workspace-data

.angular

vite.config.*.timestamp*
vitest.config.*.timestamp*
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/dist
/coverage
/.nx/cache
/.nx/workspace-data
/.nx/workspace-data
.angular
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"singleQuote": true
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"singleQuote": true,
"printWidth": 120,
"semi": true,
"importOrderParserPlugins": ["typescript", "decorators-legacy"],
"importOrder": ["^@$", "<THIRD_PARTY_MODULES>", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"trailingComma": "all"
}
90 changes: 14 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,20 @@
# SpinCycleMono
# Spin Cycle

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>
![](https://media3.giphy.com/media/xT9IgpTy4UVnddmso0/200.gif?cid=6c09b9527ad4ac5y9ktmurnmi8ck9dv91qmvj7pszr7ah37j&ep=v1_internal_gif_by_id&rid=200.gif&ct=g)

✨ Your new, shiny [Nx workspace](https://nx.dev) is almost ready ✨.
So, you spent all your money on records, and now you can't decide which one to listen to next...

[Learn more about this workspace setup and its capabilities](https://nx.dev/nx-api/nest?utm_source=nx_project&amp;utm_medium=readme&amp;utm_campaign=nx_projects) or run `npx nx graph` to visually explore what was created. Now, let's get you up to speed!
Spin Cycle sends you a randomly selected record (or CD! or cassette! or whatever!) from your collection on Discogs every morning.

## Finish your CI setup
- We make sure to cycle through your entire collection before we send a duplicate
- You can select a specific sub-collection in Discogs for recommendations
- Tell us you didn't listen to something and we'll put it back in the mix

[Click here to finish setting up your workspace!](https://cloud.nx.app/connect/kQxZUV0S1Q)
### TODO:


## Run tasks

To run the dev server for your app, use:

```sh
npx nx serve spin-cycle
```

To create a production bundle:

```sh
npx nx build spin-cycle
```

To see all available targets to run for a project, run:

```sh
npx nx show project spin-cycle
```

These targets are either [inferred automatically](https://nx.dev/concepts/inferred-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) or defined in the `project.json` or `package.json` files.

[More about running tasks in the docs &raquo;](https://nx.dev/features/run-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Add new projects

While you could add new projects to your workspace manually, you might want to leverage [Nx plugins](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) and their [code generation](https://nx.dev/features/generate-code?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) feature.

Use the plugin's generator to create new projects.

To generate a new application, use:

```sh
npx nx g @nx/nest:app demo
```

To generate a new library, use:

```sh
npx nx g @nx/node:lib mylib
```

You can use `npx nx list` to get a list of installed plugins. Then, run `npx nx list <plugin-name>` to learn about more specific capabilities of a particular plugin. Alternatively, [install Nx Console](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) to browse plugins and generators in your IDE.

[Learn more about Nx plugins &raquo;](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) | [Browse the plugin registry &raquo;](https://nx.dev/plugin-registry?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)


[Learn more about Nx on CI](https://nx.dev/ci/intro/ci-with-nx#ready-get-started-with-your-provider?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Install Nx Console

Nx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ.

[Install Nx Console &raquo;](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Useful links

Learn more:

- [Learn more about this workspace setup](https://nx.dev/nx-api/nest?utm_source=nx_project&amp;utm_medium=readme&amp;utm_campaign=nx_projects)
- [Learn about Nx on CI](https://nx.dev/ci/intro/ci-with-nx?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Releasing Packages with Nx release](https://nx.dev/features/manage-releases?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [What are Nx plugins?](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

And join the Nx community:
- [Discord](https://go.nx.dev/community)
- [Follow us on X](https://twitter.com/nxdevtools) or [LinkedIn](https://www.linkedin.com/company/nrwl)
- [Our Youtube channel](https://www.youtube.com/@nxdevtools)
- [Our blog](https://nx.dev/blog?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [x] Authentication with Discogs
- [ ] Messaging (SMTP)
- [ ] Scheduling
- [ ] History UI
- [ ] Settings UI (custom time, collection)
- [ ] Donation-based SMS option (?)
34 changes: 34 additions & 0 deletions apps/spin-cycle-client/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const nx = require('@nx/eslint-plugin');
const baseConfig = require('../../eslint.config.cjs');

module.exports = [
...baseConfig,
...nx.configs['flat/angular'],
...nx.configs['flat/angular-template'],
{
files: ['**/*.ts'],
rules: {
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'sc',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'sc',
style: 'kebab-case',
},
],
},
},
{
files: ['**/*.html'],
// Override or add rules here
rules: {},
},
];
95 changes: 95 additions & 0 deletions apps/spin-cycle-client/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"name": "spin-cycle-client",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"prefix": "app",
"sourceRoot": "apps/spin-cycle-client/src",
"tags": [],
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/spin-cycle-client",
"index": "apps/spin-cycle-client/src/index.html",
"browser": "apps/spin-cycle-client/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/spin-cycle-client/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"glob": "**/*",
"input": "apps/spin-cycle-client/public"
}
],
"styles": ["apps/spin-cycle-client/src/styles.scss"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "4kb",
"maximumError": "8kb"
}
],
"fileReplacements": [
{
"replace": "environments/environment.ts",
"with": "environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "spin-cycle-client:build:production"
},
"development": {
"buildTarget": "spin-cycle-client:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "spin-cycle-client:build"
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
"options": {
"reportsDirectory": "../../coverage/apps/spin-cycle-client"
}
},
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "spin-cycle-client:build",
"staticFilePath": "dist/apps/spin-cycle-client/browser",
"spa": true
}
}
}
}
Binary file added apps/spin-cycle-client/public/favicon.ico
Binary file not shown.
9 changes: 9 additions & 0 deletions apps/spin-cycle-client/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<main class="main">
<div class="content">
@if (!authenticated()) {
<a [href]="authUrl">Login</a>
}
</div>
</main>

<router-outlet />
Empty file.
30 changes: 30 additions & 0 deletions apps/spin-cycle-client/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { TestBed } from '@angular/core/testing';

import { AppComponent } from './app.component';

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

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it(`should have the 'spin-cycle' title`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('spin-cycle');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, spin-cycle');
});
});
22 changes: 22 additions & 0 deletions apps/spin-cycle-client/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, OnInit, Signal, inject } from '@angular/core';
import { RouterOutlet } from '@angular/router';

import { AuthService } from './auth/auth.service';

@Component({
selector: 'sc-root',
standalone: true,
imports: [RouterOutlet],
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
})
export class AppComponent implements OnInit {
private readonly authService: AuthService = inject(AuthService);

public readonly authUrl: string = this.authService.authUrl;
public readonly authenticated: Signal<boolean> = this.authService.authenticated;

ngOnInit(): void {
this.authService.restoreToken();
}
}
14 changes: 14 additions & 0 deletions apps/spin-cycle-client/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { authInterceptor } from './auth/auth.interceptor';

export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
provideHttpClient(withInterceptors([authInterceptor])),
],
};
25 changes: 25 additions & 0 deletions apps/spin-cycle-client/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Routes } from '@angular/router';

import { AuthComponent } from './auth/auth.component';
import { AuthGuard } from './auth/auth.guard';
import { UnauthGuard } from './auth/unauth.guard';
import { HistoryComponent } from './history/history.component';
import { SettingsComponent } from './settings/settings.component';

export const routes: Routes = [
{
path: 'auth',
component: AuthComponent,
canActivate: [UnauthGuard],
},
{
path: 'settings',
component: SettingsComponent,
canActivate: [AuthGuard],
},
{
path: 'history',
component: HistoryComponent,
canActivate: [AuthGuard],
},
];
Empty file.
Empty file.
Loading

0 comments on commit 8afce10

Please sign in to comment.