From 31967ab8460b817d021b04ad1ba4eb358f315a54 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 18 Jul 2019 18:15:24 +0200 Subject: [PATCH] fix(core): update --- ts/tsbundle.class.tsbundle.ts | 80 ++++++++++++++++++----------------- ts/tsbundle.cli.ts | 6 ++- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/ts/tsbundle.class.tsbundle.ts b/ts/tsbundle.class.tsbundle.ts index 99ddac7..4d958d4 100644 --- a/ts/tsbundle.class.tsbundle.ts +++ b/ts/tsbundle.class.tsbundle.ts @@ -2,49 +2,15 @@ import * as plugins from './tsbundle.plugins'; import { logger } from './tsbundle.logging'; export class TsBundle { - public optionsTest: plugins.rollup.RollupOptions = this.getBaseOptions(); - public optionsProduction: plugins.rollup.RollupOptions = (() => { - const productionOptions = this.getBaseOptions(); - productionOptions.plugins.push(plugins.rollupTerser()); - return productionOptions; - })(); - - constructor() {} - - /** - * creates a bundle for the test enviroment - */ - public async buildTest() { - // create a bundle - logger.log('info', `bundling for TEST!`); - const bundle = await plugins.rollup.rollup(this.optionsTest); - bundle.generate(this.optionsTest.output); - await bundle.write(this.optionsTest.output); - logger.log('ok', `Successfully bundled files!`); - } - - /** - * creates a bundle for the production environment - */ - public async buildProduction() { - // create a bundle - logger.log('info', `bundling for PRODUCTION!`); - const bundle = await plugins.rollup.rollup(this.optionsProduction); - bundle.generate(this.optionsProduction.output); - await bundle.write(this.optionsProduction.output); - logger.log('ok', `Successfully bundled files!`); - } - /** * the basic default options for rollup */ - public getBaseOptions() { + public getBaseOptions(fromArg: string = `ts_web/index.ts`, toArg: string = 'dist_web/bundle.js') { const baseOptions: plugins.rollup.RollupOptions = { - input: `ts_web/index.ts`, + input: fromArg, output: { name: 'tsbundle', - // file: 'dist_web/bundle.js', - file: 'dist_web/bundle.js', + file: toArg, format: 'iife', sourcemap: true }, @@ -82,7 +48,7 @@ export class TsBundle { // Resolve source maps to the original source plugins.rollupSourceMaps(), - plugins.rollupBabel({ + /*plugins.rollupBabel({ runtimeHelpers: true, extensions: ['.js', '.jsx', '.ts', '.tsx'], babelrc: false, @@ -105,9 +71,45 @@ export class TsBundle { } ] ] - }) + })*/ ] }; return baseOptions; } + + public getOptionsTest(fromArg: string, toArg: string): plugins.rollup.RollupOptions { + return this.getBaseOptions(); + } + + public getOptionsProduction(fromArg: string, toArg: string): plugins.rollup.RollupOptions { + const productionOptions = this.getBaseOptions(); + productionOptions.plugins.push(plugins.rollupTerser()); + return productionOptions; + } + + constructor() {} + + /** + * creates a bundle for the test enviroment + */ + public async buildTest(fromArg: string, toArg: string) { + // create a bundle + logger.log('info', `bundling for TEST!`); + const bundle = await plugins.rollup.rollup(this.getOptionsTest(fromArg, toArg)); + bundle.generate(this.getOptionsTest(fromArg, toArg).output); + await bundle.write(this.getOptionsTest(fromArg, toArg).output); + logger.log('ok', `Successfully bundled files!`); + } + + /** + * creates a bundle for the production environment + */ + public async buildProduction(fromArg: string, toArg: string) { + // create a bundle + logger.log('info', `bundling for PRODUCTION!`); + const bundle = await plugins.rollup.rollup(this.getOptionsProduction(fromArg, toArg)); + bundle.generate(this.getOptionsProduction(fromArg, toArg).output); + await bundle.write(this.getOptionsProduction(fromArg, toArg).output); + logger.log('ok', `Successfully bundled files!`); + } } diff --git a/ts/tsbundle.cli.ts b/ts/tsbundle.cli.ts index acee9d9..8f141ed 100644 --- a/ts/tsbundle.cli.ts +++ b/ts/tsbundle.cli.ts @@ -10,16 +10,18 @@ export const runCli = async () => { const htmlHandler = new HtmlHandler(); switch (true) { case argvArg.production || process.env.CI: - await tsbundle.buildProduction(); + await tsbundle.buildProduction(null, null); await htmlHandler.minifyHtml(); break; case argvArg.test: default: - await tsbundle.buildTest(); + await tsbundle.buildTest(null, null); await htmlHandler.copyHtml(); return; } }); + + tsBundleCli.startParse(); };