fix(core): update
This commit is contained in:
@ -1,17 +1,21 @@
|
||||
import * as plugins from './tsbundle.plugins';
|
||||
import { TsBundle } from './tsbundle.class.tsbundle';
|
||||
import { HtmlHandler } from './tsbundle.htmlhandler';
|
||||
import { logger } from './tsbundle.logging';
|
||||
|
||||
export const runCli = async () => {
|
||||
const tsBundleCli = new plugins.smartcli.Smartcli();
|
||||
tsBundleCli.standardTask().subscribe(async argvArg => {
|
||||
const tsbundle = new TsBundle();
|
||||
const htmlHandler = new HtmlHandler();
|
||||
switch (true) {
|
||||
case argvArg.production:
|
||||
await tsbundle.buildProduction();
|
||||
await htmlHandler.minifyHtml();
|
||||
break;
|
||||
case argvArg.test:
|
||||
await tsbundle.buildTest();
|
||||
await htmlHandler.copyHtml();
|
||||
break;
|
||||
default:
|
||||
logger.log('error', `Can not determine build target environement. Please specify via --production or --test`)
|
||||
|
28
ts/tsbundle.htmlhandler.ts
Normal file
28
ts/tsbundle.htmlhandler.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import * as plugins from './tsbundle.plugins';
|
||||
import * as paths from './tsbundle.paths';
|
||||
|
||||
export class HtmlHandler {
|
||||
public sourceFilePath: string = plugins.path.join(paths.htmlDir, 'index.html');
|
||||
public targetFilePath: string = plugins.path.join(paths.distWebDir, 'index.html');
|
||||
|
||||
// copies the html
|
||||
public async copyHtml() {
|
||||
await plugins.smartfile.fs.copy(
|
||||
this.sourceFilePath,
|
||||
this.targetFilePath
|
||||
);
|
||||
}
|
||||
|
||||
// copies and minifies the html
|
||||
public async minifyHtml() {
|
||||
const fileString = plugins.smartfile.fs.toStringSync(this.sourceFilePath);
|
||||
const minifiedHtml = plugins.htmlMinifier.minify(fileString, {
|
||||
minifyCSS: true,
|
||||
minifyJS: true,
|
||||
sortAttributes: true,
|
||||
sortClassName: true,
|
||||
removeAttributeQuotes: true
|
||||
});
|
||||
plugins.smartfile.memory.toFsSync(minifiedHtml, this.targetFilePath);
|
||||
}
|
||||
}
|
6
ts/tsbundle.paths.ts
Normal file
6
ts/tsbundle.paths.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import * as plugins from './tsbundle.plugins';
|
||||
|
||||
export const cwd = process.cwd();
|
||||
export const packageDir = plugins.path.join(__dirname, '../');
|
||||
export const htmlDir = plugins.path.join(cwd, './html');
|
||||
export const distWebDir = plugins.path.join(cwd, './dist_web');
|
@ -1,9 +1,17 @@
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
path
|
||||
};
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartcli from '@pushrocks/smartcli';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
|
||||
|
||||
export { smartcli, smartlog, smartlogDestinationLocal };
|
||||
export { smartcli, smartfile, smartlog, smartlogDestinationLocal };
|
||||
|
||||
// third party scope
|
||||
import * as rollup from 'rollup';
|
||||
@ -14,6 +22,8 @@ import rollupSourceMaps from 'rollup-plugin-sourcemaps';
|
||||
import { terser as rollupTerser } from 'rollup-plugin-terser';
|
||||
import rollupTypescript from 'rollup-plugin-typescript2';
|
||||
|
||||
import * as htmlMinifier from 'html-minifier';
|
||||
|
||||
export {
|
||||
rollup,
|
||||
rollupBabel,
|
||||
@ -21,5 +31,6 @@ export {
|
||||
rollupResolve,
|
||||
rollupSourceMaps,
|
||||
rollupTerser,
|
||||
rollupTypescript
|
||||
rollupTypescript,
|
||||
htmlMinifier
|
||||
};
|
||||
|
Reference in New Issue
Block a user