diff --git a/.eslintrc.js b/.eslintrc.js index c3e5e957..0894c864 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,6 +21,7 @@ module.exports = { 'guard-for-in': 'off', 'implicit-arrow-linebreak': 'off', 'import/extensions': 'off', + 'import/no-cycle': 'off', 'import/no-extraneous-dependencies': 'off', 'import/no-named-as-default-member': 'off', 'import/prefer-default-export': 'off', diff --git a/.gitignore b/.gitignore index 048ca6ce..c1e81077 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,3 @@ -# Base -node_modules/ -!.gitkeep -!__mocks__ -__* - # Built Files & Log .build/ dist/ @@ -25,12 +19,16 @@ yarn.lock tsconfig.json # Project Rules -!/build/prebuild.js -!**/bin/*.js packages/**/*.js +!/build/build.js +!**/bin/*.js !packages/hydrojudge/service.js -packages/**/*.js.map -packages/**/*.d.ts # Data files *.mmdb + +# Base +node_modules/ +__* +!__mocks__ +!.gitkeep diff --git a/build/prebuild.js b/build/build.js similarity index 67% rename from build/prebuild.js rename to build/build.js index 9a4d8e44..eaad3fc2 100644 --- a/build/prebuild.js +++ b/build/build.js @@ -1,5 +1,7 @@ const fs = require('fs'); const path = require('path'); +const child = require('child_process'); +const { argv } = require('yargs'); const compilerOptionsBase = { target: 'es2019', @@ -14,7 +16,10 @@ const compilerOptionsBase = { }; const config = { compilerOptions: compilerOptionsBase, - references: [{ path: 'tsconfig.build.json' }], + references: [ + { path: 'tsconfig.build.json' }, + { path: 'packages/hydrooj' }, + ], files: [], }; const configSrc = { @@ -47,7 +52,7 @@ const configFlat = { const packages = fs.readdirSync(path.resolve(process.cwd(), 'packages')); console.log(packages); for (const package of packages) { - config.references.push({ path: `packages/${package}` }); + if (package !== 'hydrooj') 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'), @@ -55,3 +60,14 @@ for (const package of packages) { ); } fs.writeFileSync(path.resolve(process.cwd(), 'tsconfig.json'), JSON.stringify(config)); + +if (argv.watch) { + child.spawnSync('../node_modules/.bin/tsc -b --watch', { stdio: 'inherit' }); +} else { + let result = child.spawnSync('../node_modules/.bin/tsc -b', { stdio: 'inherit' }); + if (result.status != 0) { + result = child.spawnSync('../node_modules/.bin/tsc -b', { stdio: 'inherit' }); + } + console.log(result); + process.exit(result.status); +} \ No newline at end of file diff --git a/package.json b/package.json index 183ae2c1..a4b287c5 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,13 @@ "packages/*" ], "scripts": { - "build": "node build/prebuild.js && tsc -b", - "build:watch": "node build/prebuild.js && tsc -b --watch", + "build": "node build/build.js", + "build:watch": "node build/build.js --watch", "lint": "eslint packages --ext ts --fix", "pub": "node build/publish", "jest": "node build/jest", - "start": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start", + "debug": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start", + "start": "node build/start", "clean": "zsh -c \"rm -r tsconfig.build.tsbuildinfo ./packages/*/tsconfig.tsbuildinfo ./packages/*/dist ./.coverage\"" }, "version": "1.0.0", diff --git a/packages/hydrooj/src/logger.ts b/packages/hydrooj/src/logger.ts index 063f8118..f5d16631 100644 --- a/packages/hydrooj/src/logger.ts +++ b/packages/hydrooj/src/logger.ts @@ -1,6 +1,7 @@ import { inspect, InspectOptions, format } from 'util'; import { argv } from 'yargs'; import { stderr } from 'supports-color'; +import { } from './loader'; namespace Time { export const second = 1000;