refactor(server)*: tsconfigs (#2689)

* refactor(server): tsconfigs

* chore: dummy commit

* fix: start.sh

* chore: restore original entry scripts
This commit is contained in:
Jason Rasmussen 2023-06-08 11:01:07 -04:00 committed by GitHub
parent a2130aa6c5
commit 8ebac41318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
465 changed files with 209 additions and 332 deletions

View file

@ -167,13 +167,13 @@ jobs:
run: npm --prefix server run typeorm:migrations:run
- name: Generate new migrations
continue-on-error: true
run: npm --prefix server run typeorm:migrations:generate ./libs/infra/src/migrations/TestMigration
run: npm --prefix server run typeorm:migrations:generate ./src/infra/migrations/TestMigration
- name: Find file changes
uses: tj-actions/verify-changed-files@v13.1
id: verify-changed-files
with:
files: |
server/libs/infra/src/migrations/
server/src/infra/migrations/
- name: Verify files have not changed
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |

View file

@ -4,7 +4,7 @@ services:
immich-server:
container_name: immich_server
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
command: ["start-server.sh"]
command: [ "start.sh", "immich" ]
volumes:
- ${UPLOAD_LOCATION}:/usr/src/app/upload
env_file:
@ -18,7 +18,7 @@ services:
immich-microservices:
container_name: immich_microservices
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
command: ["start-microservices.sh"]
command: [ "start.sh", "microservices" ]
volumes:
- ${UPLOAD_LOCATION}:/usr/src/app/upload
env_file:

View file

@ -1,14 +1,14 @@
# Database Migrations
After making any changes in the `server/libs/database/src/entities`, a database migration need to run in order to register the changes in the database. Follow the steps below to create a new migration.
After making any changes in the `server/src/infra/database/entities`, a database migration need to run in order to register the changes in the database. Follow the steps below to create a new migration.
1. Run the command
```bash
npm run typeorm:migrations:generate ./libs/infra/src/<migration-name>
npm run typeorm:migrations:generate ./src/infra/<migration-name>
```
2. Check if the migration file makes sense.
3. Move the migration file to folder `server/libs/database/src/migrations` in your code editor.
3. Move the migration file to folder `./src/infra/database/migrations` in your code editor.
The server will automatically detect `*.ts` file changes and restart. Part of the server start-up process includes running any new migrations, so it will be applied immediately.

View file

@ -30,4 +30,4 @@ The Open API client libraries need to be regenerated whenever there are changes
## Database Migrations
A database migration needs to be generated whenever there are changes to `server/libs/infra/src/entities`. See [Database Migration](/docs/developer/database-migrations.md) for more details.
A database migration needs to be generated whenever there are changes to `server/src/infra/src/entities`. See [Database Migration](/docs/developer/database-migrations.md) for more details.

View file

@ -10,9 +10,9 @@ sidebar_position: 2
This environment includes the following services:
- Core server - `/server/apps/immich`
- Core server - `/server/src/immich`
- Machine learning - `/machine-learning`
- Microservices - `/server/apps/microservicess`
- Microservices - `/server/src/microservicess`
- Web app - `/web`
- Redis
- PostgreSQL development database with exposed port `5432` so you can use any database client to acess it

2
server/.gitignore vendored
View file

@ -40,3 +40,5 @@ upload/
tmp/
core
.reverse-geocoding-dump/
**/node_modules/**

View file

@ -32,7 +32,7 @@ COPY --from=prod /usr/src/app/bin ./bin
COPY LICENSE /licenses/LICENSE.txt
COPY LICENSE /LICENSE
COPY package.json package-lock.json ./
COPY start-server.sh start-microservices.sh ./
COPY start*.sh ./
RUN npm link && npm cache clean --force

View file

@ -1,6 +0,0 @@
## How to run migration
1. Attached to the container shell
2. Run `npm run typeorm -- migration:generate ./libs/database/src/<migration-name> -d libs/database/src/config/database.config.ts`
3. Check if the migration file makes sense
4. Move the migration file to folder `server/libs/database/src/migrations` in your code editor.

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": false,
"outDir": "../../dist/apps/cli"
},
"include": ["src/**/*", "../../libs/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}

View file

@ -1,6 +0,0 @@
import { ValidateUUID } from '../../../../../../apps/immich/src/decorators/validate-uuid.decorator';
export class AddUsersDto {
@ValidateUUID({ each: true })
sharedUserIds!: string[];
}

View file

@ -1,14 +0,0 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"modulePaths": ["<rootDir>", "<rootDir>../../../"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"^@app/infra(|/.*)$": "<rootDir>../../../libs/infra/src/$1",
"^@app/domain(|/.*)$": "<rootDir>../../../libs/domain/src/$1"
}
}

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": false,
"outDir": "../../dist/apps/immich"
},
"include": ["src/**/*", "../../libs/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}

View file

@ -1,21 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { MicroservicesModule } from './../src/microservices.module';
describe('MicroservicesController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [MicroservicesModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!');
});
});

View file

@ -1,9 +0,0 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": false,
"outDir": "../../dist/apps/microservices"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}

View file

@ -1 +1 @@
node ./dist/apps/cli/apps/cli/src/immich "$@"
node ./dist/main cli "$@"

View file

@ -1,13 +1,13 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { clearDb, getAuthUser, authCustom } from './test-utils';
import { clearDb, getAuthUser, authCustom } from '../test/test-utils';
import { CreateAlbumDto } from '@app/domain';
import { CreateAlbumShareLinkDto } from '../src/api-v1/album/dto/create-album-shared-link.dto';
import { AuthUserDto } from '../src/decorators/auth-user.decorator';
import { CreateAlbumShareLinkDto } from '@app/immich/api-v1/album/dto/create-album-shared-link.dto';
import { AuthUserDto } from '@app/immich/decorators/auth-user.decorator';
import { AlbumResponseDto, AuthService, SharedLinkResponseDto, UserService } from '@app/domain';
import { DataSource } from 'typeorm';
import { AppModule } from '../src/app.module';
import { AppModule } from '@app/immich/app.module';
async function _createAlbum(app: INestApplication, data: CreateAlbumDto) {
const res = await request(app.getHttpServer()).post('/album').send(data);

View file

@ -1,11 +1,11 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { clearDb, authCustom } from './test-utils';
import { clearDb, authCustom } from '../test/test-utils';
import { CreateUserDto, UserService, AuthUserDto, UserResponseDto } from '@app/domain';
import { DataSource } from 'typeorm';
import { AuthService } from '@app/domain';
import { AppModule } from '../src/app.module';
import { AppModule } from '@app/immich/app.module';
function _createUser(userService: UserService, data: CreateUserDto) {
return userService.createUser(data);

16
server/jest-e2e.json Normal file
View file

@ -0,0 +1,16 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"modulePaths": ["<rootDir>"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"^@test(|/.*)$": "<rootDir>/test/$1",
"^@app/immich(|/.*)$": "<rootDir>/src/immich/$1",
"^@app/infra(|/.*)$": "<rootDir>/src/infra/$1",
"^@app/domain(|/.*)$": "<rootDir>/src/domain/$1"
}
}

View file

@ -1,6 +0,0 @@
import { ValidateUUID } from '../../../../../apps/immich/src/decorators/validate-uuid.decorator';
export class AssetIdsDto {
@ValidateUUID({ each: true })
assetIds!: string[];
}

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "../../dist/libs/domain"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "../../dist/libs/infra"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}

View file

@ -1,11 +1,10 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "apps/immich/src",
"monorepo": true,
"root": "apps/immich",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"webpack": false,
"tsConfigPath": "apps/immich/tsconfig.app.json",
"plugins": [
{
"name": "@nestjs/swagger",
@ -15,52 +14,5 @@
}
}
]
},
"projects": {
"immich": {
"type": "application",
"root": "apps/immich",
"entryFile": "main",
"sourceRoot": "apps/immich/src",
"compilerOptions": {
"tsConfigPath": "apps/immich/tsconfig.app.json"
}
},
"microservices": {
"type": "application",
"root": "apps/microservices",
"entryFile": "main",
"sourceRoot": "apps/microservices/src",
"compilerOptions": {
"tsConfigPath": "apps/microservices/tsconfig.app.json"
}
},
"cli": {
"type": "application",
"root": "apps/cli",
"entryFile": "immich",
"sourceRoot": "apps/cli/src",
"compilerOptions": {
"tsConfigPath": "apps/cli/tsconfig.app.json"
}
},
"infra": {
"type": "library",
"root": "libs/infra",
"entryFile": "index",
"sourceRoot": "libs/infra/src",
"compilerOptions": {
"tsConfigPath": "libs/infra/tsconfig.lib.json"
}
},
"domain": {
"type": "library",
"root": "libs/domain",
"entryFile": "index",
"sourceRoot": "libs/domain/src",
"compilerOptions": {
"tsConfigPath": "libs/domain/tsconfig.lib.json"
}
}
}
}

View file

@ -9,16 +9,14 @@
"immich": "./bin/cli.sh"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build immich && nest build microservices && nest build cli",
"build": "nest build",
"format": "prettier --check .",
"format:fix": "prettier --write .",
"start": "nest start",
"start": "npm run start:dev",
"nest": "nest",
"start:dev": "nest start --watch",
"start:debug": "rimraf dist && nest start --debug 0.0.0.0:9230 --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{apps,libs}/**/*.ts\" --max-warnings 0",
"start:dev": "nest start --watch --",
"start:debug": "nest start --debug 0.0.0.0:9230 --watch --",
"lint": "eslint \"src/**/*.ts\" --max-warnings 0",
"lint:fix": "npm run lint -- --fix",
"check": "tsc --noEmit",
"check:code": "npm run format && npm run lint && npm run check",
@ -27,13 +25,13 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./apps/immich/test/jest-e2e.json --runInBand",
"test:e2e": "jest --config jest-e2e.json --runInBand",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
"typeorm:migrations:create": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:create",
"typeorm:migrations:generate": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate -d ./libs/infra/src/database.config.ts",
"typeorm:migrations:run": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:run -d ./libs/infra/src/database.config.ts",
"typeorm:migrations:revert": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:revert -d ./libs/infra/src/database.config.ts",
"typeorm:schema:drop": "node --require ts-node/register ./node_modules/typeorm/cli.js schema:drop -d ./libs/infra/src/database.config.ts",
"typeorm:migrations:generate": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate -d ./src/infra/database.config.ts",
"typeorm:migrations:run": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:run -d ./src/infra/database.config.ts",
"typeorm:migrations:revert": "node --require ts-node/register ./node_modules/typeorm/cli.js migration:revert -d ./src/infra/database.config.ts",
"typeorm:schema:drop": "node --require ts-node/register ./node_modules/typeorm/cli.js schema:drop -d ./src/infra/database.config.ts",
"typeorm:schema:reset": "npm run typeorm:schema:drop && npm run typeorm:migrations:run",
"api:typescript": "bash ./bin/generate-open-api.sh web",
"api:dart": "bash ./bin/generate-open-api.sh mobile",
@ -134,11 +132,11 @@
},
"collectCoverageFrom": [
"**/*.(t|j)s",
"!<rootDir>/libs/infra/**/*"
"!<rootDir>/infra/**/*"
],
"coverageDirectory": "./coverage",
"coverageThreshold": {
"./libs/domain/": {
"./src/domain/": {
"branches": 80,
"functions": 80,
"lines": 90,
@ -146,17 +144,15 @@
}
},
"setupFilesAfterEnv": [
"<rootDir>/libs/domain/test/setup.ts"
"<rootDir>/test/setup.ts"
],
"testEnvironment": "node",
"roots": [
"<rootDir>/apps/",
"<rootDir>/libs/"
],
"moduleNameMapper": {
"^@app/infra(|/.*)$": "<rootDir>/libs/infra/src/$1",
"^@app/domain(|/.*)$": "<rootDir>/libs/domain/src/$1"
"^@test(|/.*)$": "<rootDir>/test/$1",
"^@app/immich(|/.*)$": "<rootDir>/src/immich/$1",
"^@app/infra(|/.*)$": "<rootDir>/src/infra/$1",
"^@app/domain(|/.*)$": "<rootDir>/src/domain/$1"
},
"globalSetup": "<rootDir>/libs/domain/test/global-setup.js"
"globalSetup": "<rootDir>/test/global-setup.js"
}
}

View file

@ -13,7 +13,7 @@ export class ResetAdminPasswordCommand extends CommandRunner {
async run(): Promise<void> {
const ask = (admin: UserResponseDto) => {
const { id, oauthId, email, firstName, lastName } = admin;
console.log(`Found Admin:
console.log(`Found Admin:
- ID=${id}
- OAuth ID=${oauthId}
- Email=${email}

View file

@ -1,7 +1,6 @@
import { CommandFactory } from 'nest-commander';
import { AppModule } from './app.module';
async function bootstrap() {
export async function bootstrap() {
await CommandFactory.run(AppModule, ['warn', 'error']);
}
bootstrap();

View file

@ -8,7 +8,7 @@ import {
newJobRepositoryMock,
newUserRepositoryMock,
userEntityStub,
} from '../../test';
} from '@test';
import { IAssetRepository } from '../asset';
import { IJobRepository, JobName } from '../job';
import { IUserRepository } from '../user';

View file

@ -1,5 +1,5 @@
import { ArrayNotEmpty } from 'class-validator';
import { ValidateUUID } from '../../../../../apps/immich/src/decorators/validate-uuid.decorator';
import { ValidateUUID } from '@app/immich/decorators/validate-uuid.decorator';
export class AddUsersDto {
@ValidateUUID({ each: true })

View file

@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { ValidateUUID } from '../../../../../apps/immich/src/decorators/validate-uuid.decorator';
import { ValidateUUID } from '@app/immich/decorators/validate-uuid.decorator';
import { IsNotEmpty, IsString } from 'class-validator';
export class CreateAlbumDto {

View file

@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsOptional } from 'class-validator';
import { ValidateUUID } from '../../../../../apps/immich/src/decorators/validate-uuid.decorator';
import { ValidateUUID } from '@app/immich/decorators/validate-uuid.decorator';
export class UpdateAlbumDto {
@IsOptional()

View file

@ -1,8 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsBoolean, IsOptional } from 'class-validator';
import { ValidateUUID } from '../../../../../apps/immich/src/decorators/validate-uuid.decorator';
import { toBoolean } from '../../../../../apps/immich/src/utils/transform.util';
import { ValidateUUID } from '@app/immich/decorators/validate-uuid.decorator';
import { toBoolean } from '@app/immich/utils/transform.util';
export class GetAlbumsDto {
@IsOptional()

View file

@ -1,5 +1,5 @@
import { BadRequestException } from '@nestjs/common';
import { authStub, keyStub, newCryptoRepositoryMock, newKeyRepositoryMock } from '../../test';
import { authStub, keyStub, newCryptoRepositoryMock, newKeyRepositoryMock } from '@test';
import { ICryptoRepository } from '../crypto';
import { IKeyRepository } from './api-key.repository';
import { APIKeyService } from './api-key.service';

View file

@ -1,5 +1,5 @@
import { assetEntityStub, authStub, newAssetRepositoryMock } from '../../test';
import { AssetService, IAssetRepository } from '../asset';
import { assetEntityStub, authStub, newAssetRepositoryMock } from '@test';
import { AssetService, IAssetRepository } from '.';
describe(AssetService.name, () => {
let sut: AssetService;

View file

@ -0,0 +1,6 @@
import { ValidateUUID } from '@app/immich/decorators/validate-uuid.decorator';
export class AssetIdsDto {
@ValidateUUID({ each: true })
assetIds!: string[];
}

View file

@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsBoolean, IsDate, IsOptional } from 'class-validator';
import { toBoolean } from '../../../../../apps/immich/src/utils/transform.util';
import { toBoolean } from '@app/immich/utils/transform.util';
export class MapMarkerDto {
@ApiProperty()

View file

@ -17,7 +17,7 @@ import {
systemConfigStub,
userEntityStub,
userTokenEntityStub,
} from '../../test';
} from '@test';
import { IKeyRepository } from '../api-key';
import { ICryptoRepository } from '../crypto/crypto.repository';
import { ISharedLinkRepository } from '../shared-link';

View file

@ -1,5 +1,5 @@
import { BadRequestException } from '@nestjs/common';
import pkg from '../../../package.json';
import pkg from 'src/../../package.json';
const [major, minor, patch] = pkg.version.split('.');

View file

@ -10,7 +10,7 @@ import {
newSearchRepositoryMock,
newStorageRepositoryMock,
personStub,
} from '../../test';
} from '@test';
import { IAssetRepository, WithoutProperty } from '../asset';
import { IJobRepository, JobName } from '../job';
import { IMediaRepository } from '../media';

Some files were not shown because too many files have changed in this diff Show more