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

Project & API Setup #1

Merged
merged 2 commits into from
Sep 23, 2022
Merged
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
28 changes: 28 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": ["@commitlint/config-conventional"],
"rules": {
"subject-case": [
2,
"always",
["sentence-case", "start-case", "pascal-case", "upper-case", "lower-case"]
],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"style",
"test",
"sample"
]
]
}
}
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
12 changes: 12 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# OSX
.DS_Store
94 changes: 94 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
module.exports = {
root: true,
extends: [
'airbnb-typescript',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended',
'plugin:promise/recommended',
],
ignorePatterns: ['.eslintrc.js', '*.json', 'jest.config.js'],
plugins: ['import', 'promise', '@typescript-eslint', 'prettier'],
parser: '@typescript-eslint/parser',
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
parserOptions: {
project: './tsconfig.json',
ecmaVersion: 2020,
sourceType: 'module',
},
rules: {
'@typescript-eslint/space-before-blocks': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
'react/jsx-wrap-multilines': 'off',
'react/jsx-filename-extension': 'off',
'multiline-comment-style': ['error', 'starred-block'],
'promise/catch-or-return': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'react/jsx-closing-bracket-location': 'off',
'@typescript-eslint/no-var-requires': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['off'],
'mocha/no-mocha-arrows': 'off',
'@typescript-eslint/default-param-last': 'off',
'no-return-await': 'off',
'no-await-in-loop': 'off',
'no-continue': 'off',
'no-console': 'warn',
'no-prototype-builtins': 'off',
'import/no-cycle': 'off',
'class-methods-use-this': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-explicit-any': 1,
'no-restricted-syntax': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'no-underscore-dangle': 'off',
'import/prefer-default-export': 'off',
// A temporary hack related to IDE not resolving correct package.json
'import/no-extraneous-dependencies': 'off',
'react/jsx-one-expression-per-line': 'off',
'react/jsx-no-bind': 'off',
'lines-between-class-members': 'off',
'max-classes-per-file': 'off',
'react/react-in-jsx-scope': 'off',
'max-len': ['warn', { code: 140 }],
'@typescript-eslint/return-await': 'off',
'no-restricted-imports': [
'error',
{
patterns: ['@impler/shared/*', '@impler/dal/*', '!import2/good'],
},
],
'padding-line-between-statements': [
'error',
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['if', 'for'] },
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] },
{ blankLine: 'always', prev: '*', next: 'return' },
],
'id-length': ['error', { min: 2, exceptions: ['i', 'e', 'a', 'b', '_', 't'], properties: 'never' }],
'@typescript-eslint/naming-convention': [
'error',

{ selector: 'enumMember', format: ['UPPER_CASE'] },
{ selector: 'enum', format: ['PascalCase'], suffix: ['Enum'] },
{ selector: 'class', format: ['PascalCase'] },
{ selector: 'variableLike', format: ['camelCase', 'UPPER_CASE', 'PascalCase'], leadingUnderscore: 'allow' },
{
selector: 'interface',
format: ['PascalCase'],
prefix: ['I'],
},
{
selector: ['function'],
format: ['camelCase'],
leadingUnderscore: 'allow',
},
],
},
};
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
build

.env
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm lint-staged
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
auto-install-peers=true
strict-peer-dependencies=false
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package.json is formatted by package managers, so we ignore it here
package.json
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 120,
"trailingComma": "es5",
"singleQuote": true,
"semi": true,
"tabWidth": 2,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"arrowParens": "always",
"endOfLine": "lf"
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"npm.packageManager": "pnpm",
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true,
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
}

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# impler.io
4 changes: 4 additions & 0 deletions apps/api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: ['../../.eslintrc.js'],
ignorePatterns: '*.spec.ts',
};
49 changes: 49 additions & 0 deletions apps/api/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [
{
"include": ".env",
"outDir": "dist/src"
},
{
"include": ".env.development",
"outDir": "dist/src"
},
{
"include": ".env.test",
"outDir": "dist/src"
},
{
"include": ".env.production",
"outDir": "dist/src"
},
{
"include": "app/content-templates/usecases/compile-template/templates/basic.handlebars",
"outDir": "dist/src"
}
],
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"classValidatorShim": true,
"introspectComments": true
}
}
],
"webpack": true
},
"projects": {
"dal": {
"type": "library",
"root": "../../../libs/dal",
"entryFile": "index",
"sourceRoot": "../../../libs/dal/src",
"compilerOptions": {
"tsConfigPath": "../../../libs/dal/tsconfig.build.json"
}
}
}
}
8 changes: 8 additions & 0 deletions apps/api/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"watch": ["src", "../core/dist"],
"ext": "ts",
"delay": 2,
"ignoreRoot": [".git"],
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
}
47 changes: 47 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@impler/api",
"version": "1.0.0",
"main": "index.js",
"author": "knovator",
"license": "MIT",
"private": false,
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\"",
"start": "pnpm start:dev",
"start:dev": "cross-env TZ=UTC nest start --watch",
"start:test": "cross-env NODE_ENV=test PORT=1336 TZ=UTC nest start --watch",
"start:debug": "TZ=UTC nodemon --config nodemon-debug.json",
"start:prod": "TZ=UTC node dist/main.js",
"lint": "eslint src",
"lint:fix": "pnpm lint -- --fix"
},
"dependencies": {
"@impler/dal": "workspace:^1.0.0",
"@nestjs/common": "^9.1.2",
"@nestjs/core": "^9.1.2",
"@nestjs/platform-express": "^9.1.2",
"@nestjs/swagger": "^6.1.2",
"body-parser": "^1.20.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"compression": "^1.7.4",
"dotenv": "^16.0.2",
"rimraf": "^3.0.2"
},
"devDependencies": {
"@types/express": "^4.17.14",
"@types/node": "^18.7.18",
"nodemon": "^2.0.20",
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "^4.8.3"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
]
}
}
6 changes: 6 additions & 0 deletions apps/api/src/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NODE_ENV=local
PORT=3000
API_ROOT_URL=http://localhost:3000
FRONT_BASE_URL=http://localhost:4200

MONGO_URL=mongodb://localhost:27017/impler-db
6 changes: 6 additions & 0 deletions apps/api/src/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NODE_ENV=local
PORT=3000
API_ROOT_URL=http://localhost:3000
FRONT_BASE_URL=http://localhost:4200

MONGO_URL=mongodb://localhost:27017/impler-db
6 changes: 6 additions & 0 deletions apps/api/src/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NODE_ENV=local
PORT=3000
API_ROOT_URL=http://localhost:3000
FRONT_BASE_URL=http://localhost:4200

MONGO_URL=mongodb://localhost:27017/impler-db
16 changes: 16 additions & 0 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DynamicModule, Module } from '@nestjs/common';
import { Type } from '@nestjs/common/interfaces/type.interface';
import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
import { SharedModule } from './app/shared/shared.module';
import { ProjectModule } from './app/project/project.module';

const modules: Array<Type | DynamicModule | Promise<DynamicModule> | ForwardReference> = [ProjectModule, SharedModule];

const providers = [];

@Module({
imports: modules,
controllers: [],
providers,
})
export class AppModule {}
8 changes: 8 additions & 0 deletions apps/api/src/app/project/dtos/projects-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';

export class ProjectResponseDto {
@ApiProperty()
name: string;
@ApiProperty()
code: string;
}
18 changes: 18 additions & 0 deletions apps/api/src/app/project/project.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { ProjectResponseDto } from './dtos/projects-response.dto';
import { GetProjects } from './usecases/get-projects/get-projects.usecase';

@Controller('/project')
@ApiTags('Project')
export class ProjectController {
constructor(private getProjectsUsecase: GetProjects) {}

@Get('')
@ApiOperation({
summary: 'Get projects',
})
getProjects(): Promise<ProjectResponseDto[]> {
return this.getProjectsUsecase.execute();
}
}
11 changes: 11 additions & 0 deletions apps/api/src/app/project/project.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { USE_CASES } from './usecases';
import { ProjectController } from './project.controller';
import { SharedModule } from '../shared/shared.module';

@Module({
imports: [SharedModule],
providers: [...USE_CASES],
controllers: [ProjectController],
})
export class ProjectModule {}
Loading