fix(core): update

This commit is contained in:
2019-06-16 17:02:38 +02:00
parent 834934f10e
commit 508bb44348
10 changed files with 309 additions and 200 deletions

View File

@ -1,86 +1,12 @@
import * as early from '@pushrocks/early';
early.start('tsbundle');
import * as plugins from './tsbundle.plugins';
// lets import all plugins beforehand
import './tsbundle.plugins';
import { logger } from './tsbundle.logging';
import { runCli } from './tsbundle.cli';
early.stop();
const rollupOptions: plugins.rollup.RollupOptions = {
input: `ts_web/index.ts`,
output: {
name: 'tsbundle',
// file: 'dist_web/bundle.js',
file: 'dist_web/bundle.js',
format: 'iife',
sourcemap: true
},
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: [],
watch: {
include: ['src/**']
},
plugins: [
// Compile TypeScript files
plugins.rollupTypescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declaration: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
inlineSourceMap: true,
noEmitOnError: true,
lib: ['es2017', 'dom'],
target: 'es2017',
noImplicitAny: false
}
}
}),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
plugins.rollupResolve(),
plugins.rollupCommonjs({
namedExports: {
'node_modules/@pushrocks/smartstate/dist/index.js': ['Smartstate']
}
}),
// Resolve source maps to the original source
plugins.rollupSourceMaps(),
plugins.rollupBabel({
runtimeHelpers: true,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelrc: false,
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
chrome: '41'
}
}
]
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true
}
]
]
})
]
};
async function build() {
// create a bundle
logger.log('info', `starting bundling now!`);
const bundle = await plugins.rollup.rollup(rollupOptions);
bundle.generate(rollupOptions.output);
bundle.write(rollupOptions.output);
logger.log('ok', `Successfully bundled files!`);
if (process.env.CLI_CALL) {
runCli();
}
build();

View File

@ -0,0 +1,113 @@
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', `starting bundling for TEST now!`);
const bundle = await plugins.rollup.rollup(this.optionsTest);
bundle.generate(this.optionsTest.output);
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', `starting for PRODUCTION now!`);
const bundle = await plugins.rollup.rollup(this.optionsProduction);
bundle.generate(this.optionsProduction.output);
bundle.write(this.optionsProduction.output);
logger.log('ok', `Successfully bundled files!`);
}
/**
* the basic default options for rollup
*/
public getBaseOptions() {
const baseOptions: plugins.rollup.RollupOptions = {
input: `ts_web/index.ts`,
output: {
name: 'tsbundle',
// file: 'dist_web/bundle.js',
file: 'dist_web/bundle.js',
format: 'iife',
sourcemap: true
},
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: [],
watch: {
include: ['src/**']
},
plugins: [
// Compile TypeScript files
plugins.rollupTypescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declaration: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
inlineSourceMap: true,
noEmitOnError: true,
lib: ['es2017', 'dom'],
target: 'es2017',
noImplicitAny: false
}
}
}),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
plugins.rollupResolve(),
plugins.rollupCommonjs({
namedExports: {
'node_modules/@pushrocks/smartstate/dist/index.js': ['Smartstate']
}
}),
// Resolve source maps to the original source
plugins.rollupSourceMaps(),
plugins.rollupBabel({
runtimeHelpers: true,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelrc: false,
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
chrome: '41'
}
}
]
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true
}
]
]
})
]
};
return baseOptions;
}
}

23
ts/tsbundle.cli.ts Normal file
View File

@ -0,0 +1,23 @@
import * as plugins from './tsbundle.plugins';
import { TsBundle } from './tsbundle.class.tsbundle';
import { logger } from './tsbundle.logging';
export const runCli = async () => {
const tsBundleCli = new plugins.smartcli.Smartcli();
tsBundleCli.standardTask().subscribe(async argvArg => {
const tsbundle = new TsBundle();
switch (true) {
case argvArg.production:
await tsbundle.buildProduction();
break;
case argvArg.test:
await tsbundle.buildTest();
break;
default:
logger.log('error', `Can not determine build target environement. Please specify via --production or --test`)
return;
}
});
tsBundleCli.startParse();
};

View File

@ -5,7 +5,7 @@ export const logger = new plugins.smartlog.Smartlog({
company: 'Some Company',
companyunit: 'Some CompanyUnit',
containerName: 'Some Containername',
environment: "local",
environment: 'local',
runtime: 'node',
zone: 'gitzone'
},

View File

@ -1,11 +1,9 @@
// pushrocks scope
import * as smartcli from '@pushrocks/smartcli';
import * as smartlog from '@pushrocks/smartlog';
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
export {
smartlog,
smartlogDestinationLocal
}
export { smartcli, smartlog, smartlogDestinationLocal };
// third party scope
import * as rollup from 'rollup';
@ -13,6 +11,7 @@ import rollupBabel from 'rollup-plugin-babel';
import rollupCommonjs from 'rollup-plugin-commonjs';
import rollupResolve from 'rollup-plugin-node-resolve';
import rollupSourceMaps from 'rollup-plugin-sourcemaps';
import { terser as rollupTerser } from 'rollup-plugin-terser';
import rollupTypescript from 'rollup-plugin-typescript2';
export {
@ -21,5 +20,6 @@ export {
rollupCommonjs,
rollupResolve,
rollupSourceMaps,
rollupTypescript,
};
rollupTerser,
rollupTypescript
};

View File

@ -1 +0,0 @@
import * as plugins from './tsbundle.plugins';