Просмотр исходного кода

initial commit for growi-bot-proxy

Yuki Takei 5 лет назад
Родитель
Сommit
579ba6ff7b

+ 1 - 1
.gitignore

@@ -1,7 +1,7 @@
 # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
 
 # dependencies
-/node_modules
+node_modules
 /.pnp
 .pnp.js
 

+ 1 - 0
packages/growi-bot-proxy/.dockerignore

@@ -0,0 +1 @@
+node_modules

+ 31 - 0
packages/growi-bot-proxy/.eslintrc.js

@@ -0,0 +1,31 @@
+module.exports = {
+  parser: '@typescript-eslint/parser',
+  extends: [
+    'weseek',
+    'weseek/typescript',
+    'plugin:jest/recommended',
+  ],
+  env: {
+    jquery: true,
+    'jest/globals': true,
+  },
+  globals: {
+  },
+  plugins: [
+    'jest',
+  ],
+  rules: {
+    'import/prefer-default-export': 'off',
+    '@typescript-eslint/no-explicit-any': 'off',
+    indent: [
+      'error',
+      2,
+      {
+        SwitchCase: 1,
+        ArrayExpression: 'first',
+        FunctionDeclaration: { body: 1, parameters: 2 },
+        FunctionExpression: { body: 1, parameters: 2 },
+      },
+    ],
+  },
+};

+ 34 - 3
packages/growi-bot-proxy/package.json

@@ -2,8 +2,39 @@
   "name": "growi-bot-proxy",
   "version": "0.9.0-RC",
   "scripts": {
-
+    "build": "yarn tsc",
+    "tsc": "tsc --project tsconfig.compile.json",
+    "tsc:w": "tsc --project tsconfig.json -w",
+    "dev": "ts-node-dev src/index.ts",
+    "start:prod": "cross-env NODE_ENV=production node dist/index.js",
+    "test": "yarn test:lint && yarn test:coverage",
+    "test:unit": "cross-env NODE_ENV=test jest",
+    "test:coverage": "yarn test:unit",
+    "test:lint": "eslint src --ext .ts",
+    "test:lint:fix": "eslint src --ext .ts --fix"
   },
-  "dependencies": {},
-  "devDependencies": {}
+  "dependencies": {
+    "compression": "^1.7.4"
+  },
+  "devDependencies": {
+    "@tsed/common": "^6.34.3",
+    "@tsed/core": "^6.34.3",
+    "@tsed/di": "^6.34.3",
+    "@tsed/exceptions": "^6.34.3",
+    "@tsed/json-mapper": "^6.34.3",
+    "@tsed/platform-express": "^6.34.3",
+    "@tsed/schema": "^6.34.3",
+    "@tsed/swagger": "^6.34.3",
+    "@types/compression": "^1.7.0",
+    "@types/express": "^4.17.11",
+    "@types/multer": "^1.4.5",
+    "@types/node": "^14.14.35",
+    "@typescript-eslint/eslint-plugin": "^4.18.0",
+    "@typescript-eslint/parser": "^4.18.0",
+    "eslint-import-resolver-typescript": "^2.4.0",
+    "ts-jest": "^26.5.4",
+    "ts-node": "^9.1.1",
+    "ts-node-dev": "^1.1.6",
+    "typescript": "^4.2.3"
+  }
 }

+ 64 - 0
packages/growi-bot-proxy/src/Server.ts

@@ -0,0 +1,64 @@
+import { Configuration, Inject } from '@tsed/di';
+import { PlatformApplication } from '@tsed/common';
+import '@tsed/platform-express'; // /!\ keep this import
+import session from 'express-session';
+import bodyParser from 'body-parser';
+import compress from 'compression';
+import cookieParser from 'cookie-parser';
+import methodOverride from 'method-override';
+import '@tsed/swagger';
+
+export const rootDir = __dirname;
+
+@Configuration({
+  rootDir,
+  acceptMimes: ['application/json'],
+  httpPort: process.env.PORT || 8080,
+  httpsPort: false, // CHANGE
+  mount: {
+    '/': [
+      `${rootDir}/controllers/*.ts`,
+      `${rootDir}/middlewares/*.ts`,
+    ],
+  },
+  swagger: [
+    {
+      path: '/docs',
+      specVersion: '3.0.1',
+    },
+  ],
+  exclude: [
+    '**/*.spec.ts',
+  ],
+})
+export class Server {
+
+  @Inject()
+  app: PlatformApplication;
+
+  @Configuration()
+  settings: Configuration;
+
+  $beforeRoutesInit(): void {
+    this.app
+      .use(cookieParser())
+      .use(compress({}))
+      .use(methodOverride())
+      .use(bodyParser.json())
+      .use(bodyParser.urlencoded({
+        extended: true
+      }))
+      // @ts-ignore
+      .use(session({
+        secret: "mysecretkey",
+        resave: true,
+        saveUninitialized: true,
+        cookie: {
+          path: "/",
+          httpOnly: true,
+          secure: false,
+        }
+      }));
+  }
+
+}

+ 18 - 0
packages/growi-bot-proxy/src/index.ts

@@ -0,0 +1,18 @@
+import { $log } from '@tsed/common';
+import { PlatformExpress } from '@tsed/platform-express';
+import { Server } from './Server';
+
+async function bootstrap() {
+  try {
+    $log.debug('Start server...');
+    const platform = await PlatformExpress.bootstrap(Server);
+
+    await platform.listen();
+    $log.debug('Server initialized');
+  }
+  catch (er) {
+    $log.error(er);
+  }
+}
+
+bootstrap();

+ 14 - 0
packages/growi-bot-proxy/tsconfig.compile.json

@@ -0,0 +1,14 @@
+{
+  "extends": "./tsconfig.json",
+  "compilerOptions": {
+    "baseUrl": ".",
+    "outDir": "./dist",
+    "moduleResolution": "node",
+    "declaration": true,
+    "noResolve": false,
+    "preserveConstEnums": true,
+    "sourceMap": true,
+    "noEmit": false,
+    "inlineSources": true
+  }
+}

+ 45 - 0
packages/growi-bot-proxy/tsconfig.json

@@ -0,0 +1,45 @@
+{
+  "compilerOptions": {
+    "target": "es2019",
+    "module": "commonjs",
+    "isolatedModules": false,
+    "importHelpers": true,
+    "sourceMap": true,
+    "removeComments": false,
+    "noEmit": true,
+    "lib": ["dom", "dom.iterable", "esnext"],
+
+    /* Strict Type-Checking Options */
+    // "strict": true,
+    "strictNullChecks": true,
+    "noImplicitAny": false,
+
+    /* Additional Checks */
+    "noUnusedLocals": false,
+    "noUnusedParameters": false,
+
+    /* Module Resolution Options */
+    "baseUrl": ".",
+    "paths": {
+      "~/*": ["src/*"],
+      "^/*": ["./*"],
+    },
+    "typeRoots": [
+      "../../node_modules/@types",
+      "./node_modules/@types"
+    ],
+    "allowSyntheticDefaultImports": true,
+    "esModuleInterop": true,
+
+    /* Misc */
+    "preserveConstEnums": true,
+    "forceConsistentCasingInFileNames": true,
+    "resolveJsonModule": true,
+
+    /* Experimental Options */
+    "experimentalDecorators": true,
+    "emitDecoratorMetadata": true
+  },
+  "exclude": ["node_modules", "./public", "dist", "test"],
+  "include": ["./src/**/*.ts"]
+}

Разница между файлами не показана из-за своего большого размера
+ 559 - 23
yarn.lock


Некоторые файлы не были показаны из-за большого количества измененных файлов