From ce0357d9bde5de343359d2e14de56d189f2c3ef2 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 16 Sep 2020 23:05:08 +0800 Subject: [PATCH] auto generate tsconfig --- .gitignore | 36 ++++++++------- build/prebuild.js | 57 ++++++++++++++++++++++++ package.json | 4 +- packages/better-search/tsconfig.json | 19 -------- packages/fps-importer/tsconfig.json | 19 -------- packages/geoip/tsconfig.json | 19 -------- packages/hydrojudge/tsconfig.json | 19 -------- packages/hydrooj/tsconfig.json | 23 ---------- packages/login-with-github/tsconfig.json | 19 -------- packages/login-with-google/tsconfig.json | 19 -------- packages/login-with-osu/tsconfig.json | 19 -------- packages/login-with-qq/tsconfig.json | 19 -------- packages/migrate-vijos/tsconfig.json | 19 -------- tsconfig.json | 27 ----------- 14 files changed, 80 insertions(+), 238 deletions(-) create mode 100644 build/prebuild.js delete mode 100644 packages/better-search/tsconfig.json delete mode 100644 packages/fps-importer/tsconfig.json delete mode 100644 packages/geoip/tsconfig.json delete mode 100644 packages/hydrojudge/tsconfig.json delete mode 100644 packages/hydrooj/tsconfig.json delete mode 100644 packages/login-with-github/tsconfig.json delete mode 100644 packages/login-with-google/tsconfig.json delete mode 100644 packages/login-with-osu/tsconfig.json delete mode 100644 packages/login-with-qq/tsconfig.json delete mode 100644 packages/migrate-vijos/tsconfig.json delete mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 243c85c34..ae4197abd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,36 @@ +# Base node_modules/ -config.yaml -config.json +!.gitkeep +!__mocks__ +__* + +# Built Files & Log .build/ dist/ -.cache/ *.cache -__* -ui/misc/.iconfont -ui/static/locale +/build/*.js +.cache/ *.log *.d.ts -build/*.js *.js.map -*.hydro -!.gitkeep *.tsbuildinfo -yarn.lock +*.hydro +.coverage +globalConfig.json +# Config Files +config.yaml +config.json +yarn.lock +tsconfig.json + +# Project Rules +!/build/prebuild.js +!**/bin/*.js packages/**/*.js !packages/hydrojudge/service.js -!**/bin/*.js packages/**/*.js.map packages/**/*.d.ts +# Data files *.mmdb - -.coverage -!__mocks__ -globalConfig.json \ No newline at end of file diff --git a/build/prebuild.js b/build/prebuild.js new file mode 100644 index 000000000..9a4d8e449 --- /dev/null +++ b/build/prebuild.js @@ -0,0 +1,57 @@ +const fs = require('fs'); +const path = require('path'); + +const compilerOptionsBase = { + target: 'es2019', + module: 'commonjs', + esModuleInterop: true, + moduleResolution: 'node', + declaration: true, + sourceMap: true, + composite: true, + strictBindCallApply: true, + experimentalDecorators: true, +}; +const config = { + compilerOptions: compilerOptionsBase, + references: [{ path: 'tsconfig.build.json' }], + files: [], +}; +const configSrc = { + compilerOptions: { + ...compilerOptionsBase, + outDir: 'dist', + rootDir: 'src', + }, + include: [ + 'src', + ], + exclude: [ + '**/__mocks__', + 'bin', + 'dist', + ], +}; +const configFlat = { + compilerOptions: { + ...compilerOptionsBase, + outDir: '.', + rootDir: '.', + }, + include: [ + '*.ts', + ], + exclude: [], +}; + +const packages = fs.readdirSync(path.resolve(process.cwd(), 'packages')); +console.log(packages); +for (const package of packages) { + config.references.push({ path: `packages/${package}` }); + const files = fs.readdirSync(path.resolve(process.cwd(), 'packages', package)); + fs.writeFileSync( + path.resolve(process.cwd(), 'packages', package, 'tsconfig.json'), + files.includes('src') ? JSON.stringify(configSrc) : JSON.stringify(configFlat), + ); +} +fs.writeFileSync(path.resolve(process.cwd(), 'tsconfig.json'), JSON.stringify(config)); diff --git a/package.json b/package.json index beb1ab94a..183ae2c1b 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "packages/*" ], "scripts": { - "build": "tsc -b", - "build:watch": "tsc -b --watch", + "build": "node build/prebuild.js && tsc -b", + "build:watch": "node build/prebuild.js && tsc -b --watch", "lint": "eslint packages --ext ts --fix", "pub": "node build/publish", "jest": "node build/jest", diff --git a/packages/better-search/tsconfig.json b/packages/better-search/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/better-search/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/fps-importer/tsconfig.json b/packages/fps-importer/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/fps-importer/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/geoip/tsconfig.json b/packages/geoip/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/geoip/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/hydrojudge/tsconfig.json b/packages/hydrojudge/tsconfig.json deleted file mode 100644 index bfb418460..000000000 --- a/packages/hydrojudge/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2018", - "module": "commonjs", - "outDir": "dist", - "rootDir": "src", - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "esModuleInterop": true, - "allowJs": false, - "resolveJsonModule": true - }, - "include": [ - "src" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/hydrooj/tsconfig.json b/packages/hydrooj/tsconfig.json deleted file mode 100644 index e37a34498..000000000 --- a/packages/hydrooj/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "composite": true, - "declaration": true, - "sourceMap": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": "dist", - "rootDir": "src" - }, - "include": [ - "src" - ], - "exclude": [ - "**/__mocks__", - "bin", - "dist" - ] -} \ No newline at end of file diff --git a/packages/login-with-github/tsconfig.json b/packages/login-with-github/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/login-with-github/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/login-with-google/tsconfig.json b/packages/login-with-google/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/login-with-google/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/login-with-osu/tsconfig.json b/packages/login-with-osu/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/login-with-osu/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/login-with-qq/tsconfig.json b/packages/login-with-qq/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/login-with-qq/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/packages/migrate-vijos/tsconfig.json b/packages/migrate-vijos/tsconfig.json deleted file mode 100644 index aa7d73857..000000000 --- a/packages/migrate-vijos/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - "outDir": ".", - "rootDir": "." - }, - "include": [ - "*.ts" - ], - "exclude": [] -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 2b60c7dc7..000000000 --- a/tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "compilerOptions": { - "target": "es2019", - "module": "commonjs", - "esModuleInterop": true, - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "composite": true, - "strictBindCallApply": true, - "experimentalDecorators": true, - }, - "references": [ - { "path": "packages/hydrooj" }, - { "path": "packages/hydrojudge" }, - { "path": "packages/geoip" }, - { "path": "packages/better-search" }, - { "path": "packages/fps-importer" }, - { "path": "packages/login-with-github" }, - { "path": "packages/login-with-google" }, - { "path": "packages/login-with-osu" }, - { "path": "packages/login-with-qq" }, - { "path": "packages/migrate-vijos" }, - { "path": "tsconfig.build.json" }, - ], - "files": [], -} \ No newline at end of file