tsbundle/ts/tsbundle.class.tsbundle.ts

50 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

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