tsbundle/ts/tsbundle.class.tsbundle.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-03-16 00:21:05 +01:00
import * as plugins from './plugins.js';
import * as interfaces from './interfaces/index.js';
2022-03-14 16:32:12 +01:00
import { logger } from './tsbundle.logging.js';
2019-06-16 17:02:38 +02:00
export class TsBundle {
2022-03-14 16:32:12 +01:00
2022-03-16 00:21:05 +01:00
public async build(
2022-03-15 13:01:18 +01:00
cwdArg: string,
2022-03-16 00:21:05 +01:00
fromArg: string = './ts_web/index.ts',
toArg: string = './dist_bundle/bundle.js',
argvArg: interfaces.ICliOptions
2022-03-15 13:01:18 +01:00
) {
2021-07-23 15:45:23 +02:00
const done = plugins.smartpromise.defer();
2022-03-16 00:21:05 +01:00
const getBundlerPath = () => {
if (argvArg.bundler === 'esbuild') {
return './mod_esbuild/index.child.js'
}
return './mod_esbuild/index.child.js'
}
const transportOptions: interfaces.IEnvTransportOptions = {
cwd: cwdArg,
from: fromArg,
to: toArg,
mode: argvArg && argvArg.production ? 'production' : 'test',
2022-03-18 15:46:11 +01:00
argv: {
bundler: 'esbuild',
...argvArg
2022-03-16 00:21:05 +01:00
}
}
2022-03-14 16:32:12 +01:00
const threadsimple = new plugins.smartspawn.ThreadSimple(
2022-03-15 13:45:03 +01:00
plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
2022-03-16 00:21:05 +01:00
getBundlerPath()
2022-03-15 13:45:03 +01:00
),
2022-03-14 16:32:12 +01:00
[],
{
env: {
...process.env,
2022-03-16 00:21:05 +01:00
transportOptions: JSON.stringify(transportOptions),
2022-03-14 16:32:12 +01:00
},
2021-07-23 15:45:23 +02:00
}
2022-03-14 16:32:12 +01:00
);
2021-07-23 15:45:23 +02:00
const childProcess = await threadsimple.start();
childProcess.on('exit', (status) => {
done.resolve();
2022-03-14 16:32:12 +01:00
});
2021-07-23 15:45:23 +02:00
await done.promise;
2022-03-14 16:32:12 +01:00
}
2019-06-16 17:02:38 +02:00
}