tsbundle/ts/mod_esbuild/index.child.ts

83 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-03-16 00:21:05 +01:00
import * as plugins from './plugins.js';
2022-05-04 17:13:52 +02:00
import * as paths from '../paths.js';
2022-03-16 00:21:05 +01:00
import * as interfaces from '../interfaces/index.js';
import { logger } from '../tsbundle.logging.js';
export class TsBundleProcess {
constructor() {
// Nothing here
}
/**
* creates a bundle for the test enviroment
*/
public async buildTest(
fromArg: string,
toArg: string,
argvArg: any
) {
// create a bundle
const esbuild = await plugins.esbuild.build({
entryPoints: [fromArg],
bundle: true,
2022-03-17 08:28:11 +01:00
sourcemap: true,
format: 'esm',
2022-03-25 19:48:58 +01:00
target: 'es2020',
2022-05-04 17:13:52 +02:00
outfile: toArg,
tsconfig: paths.tsconfigPath
2022-03-16 00:21:05 +01:00
});
}
/**
* creates a bundle for the production environment
*/
public async buildProduction(
fromArg: string,
toArg: string,
argvArg: any
) {
// create a bundle
2022-03-16 11:08:52 +01:00
console.log('esbuild specific:');
console.log(`from: ${fromArg}`);
console.log((`to: ${toArg}`));
2022-03-16 00:21:05 +01:00
const esbuild = await plugins.esbuild.build({
entryPoints: [fromArg],
bundle: true,
2022-03-17 08:28:11 +01:00
sourcemap: true,
format: 'esm',
2022-03-25 19:48:58 +01:00
target: 'es2020',
2022-03-17 08:28:11 +01:00
minify: true,
2022-05-04 17:20:28 +02:00
outfile: toArg,
tsconfig: paths.tsconfigPath
2022-03-16 00:21:05 +01:00
});
}
}
const run = async () => {
console.log('running spawned compilation process');
const transportOptions: interfaces.IEnvTransportOptions = JSON.parse(process.env.transportOptions);
2022-03-16 13:25:08 +01:00
console.log('=======> ESBUILD');
2022-03-16 00:21:05 +01:00
console.log(transportOptions);
process.chdir(transportOptions.cwd);
console.log(`switched to ${process.cwd()}`);
const tsbundleProcessInstance = new TsBundleProcess();
if (transportOptions.mode === 'test') {
console.log('building for test:')
tsbundleProcessInstance.buildTest(
2022-03-16 11:52:59 +01:00
plugins.smartpath.transform.makeAbsolute(transportOptions.from, process.cwd()),
plugins.smartpath.transform.makeAbsolute(transportOptions.to, process.cwd()),
2022-03-16 00:21:05 +01:00
transportOptions.argv
);
} else {
console.log('building for production:')
tsbundleProcessInstance.buildProduction(
2022-03-16 11:52:59 +01:00
plugins.smartpath.transform.makeAbsolute(transportOptions.from, process.cwd()),
plugins.smartpath.transform.makeAbsolute(transportOptions.to, process.cwd()),
2022-03-16 00:21:05 +01:00
transportOptions.argv
);
}
};
run();