You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/build/build.js

70 lines
1.9 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const child = require('child_process');
const { argv } = require('yargs');
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' },
{ path: 'packages/hydrooj' },
],
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) {
const files = fs.readdirSync(path.resolve(process.cwd(), 'packages', package));
if (!files.includes('src') && !files.map(n => n.split('.')[1]).includes('ts')) continue;
if (package !== 'hydrooj') config.references.push({ path: `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));
if (argv.watch) {
child.execSync('./node_modules/.bin/tsc -b --watch', { stdio: 'inherit' });
} else {
child.execSync('cd packages/hydrooj && yarn build', { stdio: 'inherit' });
child.execSync('./node_modules/.bin/tsc -b', { stdio: 'inherit' });
}