Skip to content

Commit

Permalink
feat(setup): Add basic setup : .gitignore, .eslintrc, Dockerfile and …
Browse files Browse the repository at this point in the history
…sample app
  • Loading branch information
thomashermine committed Oct 18, 2023
1 parent 643a97f commit 4eb84e1
Show file tree
Hide file tree
Showing 7 changed files with 3,660 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
root: true,
ignorePatterns: [],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', 'd.ts'],
},
},
},
env: {
node: true,
},
extends: [
'airbnb-base',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
plugins: [
'@typescript-eslint',
'extra-rules',
],
rules: {
// Following are rules we added to the airbnb-base ruleset.
'extra-rules/no-commented-out-code': 'warn',

// Following are rules we explicitly don't want to follow.
'no-console': 'off', // Logging is a good practice.
'import/extensions': ['error', 'always', { // Never allow .js .ts in imports. Make transition from .js to .ts easier.
js: 'never',
ts: 'never',
}],
'no-restricted-imports': ['error', {
name: 'pg',
importNames: ['Pool'],
message: 'Use Pool from src/utils/db instead.',
}],
},
overrides: [
{
files: ['./src/**/*.test.js'],
globals: {
jest: true,
it: true,
fit: true,
describe: true,
afterAll: true,
beforeAll: true,
afterEach: true,
expect: true,
fail: true,
},
},
],
};

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ==================================================================================================
# Build Container
# ==================================================================================================
FROM node:18.15.0

WORKDIR /app

COPY ./package.json /app/package.json
COPY ./yarn.lock /app/yarn.lock

RUN mkdir /app/src
RUN yarn --frozen-lockfile

ENV NODE_ENV="production"

# Copy code
COPY src /app/src

# Build
RUN npx esbuild src/index.ts --bundle --platform=node --packages=external --outfile=build.js

# ==================================================================================================
# Server Container
# ==================================================================================================
FROM node:18.15.0
WORKDIR /app

# Copy code & node_modules from Build Container
# ==================================================================================================
COPY --from=0 /app/build.js /app/build.js
COPY --from=0 /app/node_modules /app/node_modules

# 2. Copy non-source code files needed for some modules
# ==================================================================================================
# Package.json to get version number
COPY package.json /app/package.json

# Prepare container for execution
ENV PORT=80
ENV NODE_ENV="production"
EXPOSE 80

CMD ["node", "build.js"],
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "assistant",
"version": "1.0.0",
"author": "Thomas Hermine",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon --exec node --loader @esbuild-kit/esm-loader -r @esbuild-kit/cjs-loader src/index.ts",
"d": "yarn dev",
"start": "node --loader @esbuild-kit/esm-loader -r @esbuild-kit/cjs-loader src/index.ts",
"lint": "eslint src --max-warnings=0",
"test": "jest"
},
"devDependencies": {
"@esbuild-kit/esm-loader": "^2.6.5",
"@types/jest": "^29.5.6",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.51.0",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
},
"dependencies": {
"@esbuild-kit/cjs-loader": "^2.4.4",
"dotenv": "^16.3.1",
"homeassistant": "^0.2.0",
"openai": "^4.12.4"
}
}
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'dotenv/config';

async function main() {
console.log("Hello, world!");
}

main();
Loading

0 comments on commit 4eb84e1

Please sign in to comment.