fix(core): update

This commit is contained in:
Philipp Kunz 2022-03-15 13:01:18 +01:00
parent 687b83bafd
commit cf9ca73cd8
4 changed files with 61 additions and 22 deletions

View File

@ -6,7 +6,8 @@ export class TsBundle {
cwdArg: string, cwdArg: string,
fromArg: string, fromArg: string,
toArg: string, toArg: string,
bundlerArg: 'rollup' | 'parcel' bundlerArg: 'rollup' | 'parcel',
argvArg: any
) { ) {
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
const threadsimple = new plugins.smartspawn.ThreadSimple( const threadsimple = new plugins.smartspawn.ThreadSimple(
@ -20,6 +21,7 @@ export class TsBundle {
tsbundleFrom: fromArg, tsbundleFrom: fromArg,
tsbundleTo: toArg, tsbundleTo: toArg,
tsbundleBundler: bundlerArg, tsbundleBundler: bundlerArg,
tsbundleArgv: argvArg,
}, },
} }
); );
@ -30,7 +32,13 @@ export class TsBundle {
await done.promise; await done.promise;
} }
public async buildProduction(cwdArg: string, fromArg: string, toArg: string) { public async buildProduction (
cwdArg: string,
fromArg: string,
toArg: string,
bundlerArg: 'rollup' | 'parcel',
argvArg: any
) {
const done = plugins.smartpromise.defer(); const done = plugins.smartpromise.defer();
const threadsimple = new plugins.smartspawn.ThreadSimple( const threadsimple = new plugins.smartspawn.ThreadSimple(
plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'), plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'),
@ -42,6 +50,8 @@ export class TsBundle {
tsbundleCwd: cwdArg, tsbundleCwd: cwdArg,
tsbundleFrom: fromArg, tsbundleFrom: fromArg,
tsbundleTo: toArg, tsbundleTo: toArg,
tsbundleBundler: bundlerArg,
tsbundleArgv: argvArg,
}, },
} }
); );

View File

@ -7,7 +7,8 @@ export class TsBundleProcess {
*/ */
public getBaseOptions( public getBaseOptions(
fromArg: string = `ts_web/index.ts`, fromArg: string = `ts_web/index.ts`,
toArg: string = 'dist_bundle/bundle.js' toArg: string = 'dist_bundle/bundle.js',
argvArg: any
) { ) {
logger.log('info', `from: ${fromArg}`); logger.log('info', `from: ${fromArg}`);
logger.log('info', `to: ${toArg}`); logger.log('info', `to: ${toArg}`);
@ -39,8 +40,20 @@ export class TsBundleProcess {
lib: ['dom'], lib: ['dom'],
noImplicitAny: false, noImplicitAny: false,
target: 'es2020', target: 'es2020',
module: 'es2020',
moduleResolution: 'node12',
allowSyntheticDefaultImports: true, allowSyntheticDefaultImports: true,
importsNotUsedAsValues: 'preserve', importsNotUsedAsValues: 'preserve',
...argvArg && argvArg.skiplibcheck ? {
skipLibCheck: true
} : {},
...argvArg && argvArg.allowimplicitany ? {
noImplicitAny: false
} : {},
...argvArg && argvArg.commonjs ? {
module: 'commonjs',
moduleResolution: 'node',
} : {},
}), }),
(plugins.rollupJson as any)(), (plugins.rollupJson as any)(),
// Allow node_modules resolution, so you can use 'external' to control // Allow node_modules resolution, so you can use 'external' to control
@ -56,12 +69,12 @@ export class TsBundleProcess {
return baseOptions; return baseOptions;
} }
public getOptionsTest(fromArg: string, toArg: string): plugins.rollup.RollupOptions { public getOptionsTest(fromArg: string, toArg: string, argvArg: any): plugins.rollup.RollupOptions {
return this.getBaseOptions(fromArg, toArg); return this.getBaseOptions(fromArg, toArg, argvArg);
} }
public getOptionsProduction(fromArg: string, toArg: string): plugins.rollup.RollupOptions { public getOptionsProduction(fromArg: string, toArg: string, argvArg: any): plugins.rollup.RollupOptions {
const productionOptions = this.getBaseOptions(fromArg, toArg); const productionOptions = this.getBaseOptions(fromArg, toArg, argvArg);
productionOptions.plugins.push( productionOptions.plugins.push(
plugins.rollupTerser({ plugins.rollupTerser({
compress: true, compress: true,
@ -81,13 +94,14 @@ export class TsBundleProcess {
public async buildTest( public async buildTest(
fromArg: string, fromArg: string,
toArg: string, toArg: string,
bundlerArg: 'rollup' | 'parcel' = 'rollup' bundlerArg: 'rollup' | 'parcel' = 'rollup',
argvArg: any
) { ) {
// create a bundle // create a bundle
switch (bundlerArg) { switch (bundlerArg) {
case 'rollup': case 'rollup':
logger.log('info', `bundling for TEST!`); logger.log('info', `bundling for TEST!`);
const buildOptions = this.getOptionsTest(fromArg, toArg); const buildOptions = this.getOptionsTest(fromArg, toArg, argvArg);
const bundle = await plugins.rollup.rollup(buildOptions); const bundle = await plugins.rollup.rollup(buildOptions);
bundle.generate(buildOptions.output as plugins.rollup.OutputOptions); bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
await bundle.write(buildOptions.output as plugins.rollup.OutputOptions); await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
@ -107,10 +121,10 @@ export class TsBundleProcess {
/** /**
* creates a bundle for the production environment * creates a bundle for the production environment
*/ */
public async buildProduction(fromArg: string, toArg: string) { public async buildProduction(fromArg: string, toArg: string, argvArg: any) {
// create a bundle // create a bundle
logger.log('info', `bundling for PRODUCTION!`); logger.log('info', `bundling for PRODUCTION!`);
const buildOptions = this.getOptionsProduction(fromArg, toArg); const buildOptions = this.getOptionsProduction(fromArg, toArg, argvArg);
const bundle = await plugins.rollup.rollup(buildOptions); const bundle = await plugins.rollup.rollup(buildOptions);
bundle.generate(buildOptions.output as plugins.rollup.OutputOptions); bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
await bundle.write(buildOptions.output as plugins.rollup.OutputOptions); await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
@ -132,10 +146,11 @@ const run = async () => {
tsbundleProcessInstance.buildTest( tsbundleProcessInstance.buildTest(
process.env.tsbundleFrom, process.env.tsbundleFrom,
process.env.tsbundleTo, process.env.tsbundleTo,
process.env.tsbundleBundler as 'rollup' | 'parcel' process.env.tsbundleBundler as 'rollup' | 'parcel',
process.env.tsbundleArgv
); );
} else { } else {
tsbundleProcessInstance.buildProduction(process.env.tsbundleFrom, process.env.tsbundleTo); tsbundleProcessInstance.buildProduction(process.env.tsbundleFrom, process.env.tsbundleTo, process.env.tsbundleArgv);
} }
}; };

View File

@ -10,12 +10,12 @@ export const runCli = async () => {
// const htmlHandler = new HtmlHandler(); // const htmlHandler = new HtmlHandler();
switch (true) { switch (true) {
case argvArg.production || process.env.CI: case argvArg.production || process.env.CI:
await tsbundle.buildProduction(process.cwd(), argvArg.from, argvArg.to); await tsbundle.buildProduction(process.cwd(), argvArg.from, argvArg.to, 'rollup', argvArg);
// await htmlHandler.minifyHtml(); // await htmlHandler.minifyHtml();
break; break;
case argvArg.test: case argvArg.test:
default: default:
await tsbundle.buildTest(process.cwd(), argvArg.from, argvArg.to, 'rollup'); await tsbundle.buildTest(process.cwd(), argvArg.from, argvArg.to, 'rollup', argvArg);
// await htmlHandler.copyHtml(); // await htmlHandler.copyHtml();
return; return;
} }
@ -29,7 +29,9 @@ export const runCli = async () => {
await tsbundle.buildProduction( await tsbundle.buildProduction(
process.cwd(), process.cwd(),
'./ts_web/index.ts', './ts_web/index.ts',
'./dist_bundle/bundle.js' './dist_bundle/bundle.js',
'rollup',
argvArg
); );
// await htmlHandler.minifyHtml(); // await htmlHandler.minifyHtml();
break; break;
@ -39,7 +41,8 @@ export const runCli = async () => {
process.cwd(), process.cwd(),
'./ts_web/index.ts', './ts_web/index.ts',
'./dist_bundle/bundle.js', './dist_bundle/bundle.js',
'rollup' 'rollup',
argvArg
); );
// await htmlHandler.copyHtml(); // await htmlHandler.copyHtml();
return; return;
@ -51,7 +54,13 @@ export const runCli = async () => {
// const htmlHandler = new HtmlHandler(); // const htmlHandler = new HtmlHandler();
switch (true) { switch (true) {
case argvArg.production || process.env.CI: case argvArg.production || process.env.CI:
await tsbundle.buildProduction(process.cwd(), './ts/index.ts', './dist_bundle/bundle.js'); await tsbundle.buildProduction(
process.cwd(),
'./ts/index.ts',
'./dist_bundle/bundle.js',
'rollup',
argvArg
);
// await htmlHandler.minifyHtml(); // await htmlHandler.minifyHtml();
break; break;
case argvArg.test: case argvArg.test:
@ -60,7 +69,8 @@ export const runCli = async () => {
process.cwd(), process.cwd(),
'./ts/index.ts', './ts/index.ts',
'./dist_bundle/bundle.js', './dist_bundle/bundle.js',
'rollup' 'rollup',
argvArg
); );
// await htmlHandler.copyHtml(); // await htmlHandler.copyHtml();
return; return;
@ -75,7 +85,9 @@ export const runCli = async () => {
await tsbundle.buildProduction( await tsbundle.buildProduction(
process.cwd(), process.cwd(),
'./ts_web/index.ts', './ts_web/index.ts',
'./dist_serve/bundle.js' './dist_serve/bundle.js',
'rollup',
argvArg
); );
await htmlHandler.minifyHtml(); await htmlHandler.minifyHtml();
break; break;
@ -85,7 +97,8 @@ export const runCli = async () => {
process.cwd(), process.cwd(),
'./ts_web/index.ts', './ts_web/index.ts',
'./dist_serve/bundle.js', './dist_serve/bundle.js',
'rollup' 'rollup',
argvArg
); );
await htmlHandler.copyHtml(); await htmlHandler.copyHtml();
return; return;

View File

@ -4,5 +4,6 @@
"target": "ES2020", "target": "ES2020",
"module": "ES2020", "module": "ES2020",
"moduleResolution": "node12", "moduleResolution": "node12",
"esModuleInterop": true
} }
} }