fix(core): update

This commit is contained in:
2022-03-14 16:32:12 +01:00
parent 5f92b58353
commit 3c9b178c09
21 changed files with 660 additions and 389 deletions

View File

@ -1,13 +1,13 @@
import * as early from '@pushrocks/early';
early.start('tsbundle');
// lets import all plugins beforehand
import './tsbundle.plugins';
import './tsbundle.plugins.js';
import { logger } from './tsbundle.logging';
import { runCli } from './tsbundle.cli';
import { logger } from './tsbundle.logging.js';
import { runCli } from './tsbundle.cli.js';
early.stop();
// lets make this usable programmatically
export * from './tsbundle.class.tsbundle';
export * from './tsbundle.htmlhandler';
export * from './tsbundle.class.tsbundle.js';
export * from './tsbundle.htmlhandler.js';
export { runCli };

View File

@ -1,41 +1,54 @@
import * as plugins from './tsbundle.plugins';
import { logger } from './tsbundle.logging';
import * as plugins from './tsbundle.plugins.js';
import { logger } from './tsbundle.logging.js';
export class TsBundle {
public async buildTest(cwdArg: string, fromArg: string, toArg: string, bundlerArg: 'rollup' | 'parcel') {
public async buildTest(
cwdArg: string,
fromArg: string,
toArg: string,
bundlerArg: 'rollup' | 'parcel'
) {
const done = plugins.smartpromise.defer();
const threadsimple = new plugins.smartspawn.ThreadSimple(plugins.path.join(__dirname, './tsbundle.class.tsbundleprocess.js'), [], {
env: {
...process.env,
tsbundleMode: 'test',
tsbundleCwd: cwdArg,
tsbundleFrom: fromArg,
tsbundleTo: toArg,
tsbundleBundler: bundlerArg
const threadsimple = new plugins.smartspawn.ThreadSimple(
plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'),
[],
{
env: {
...process.env,
tsbundleMode: 'test',
tsbundleCwd: cwdArg,
tsbundleFrom: fromArg,
tsbundleTo: toArg,
tsbundleBundler: bundlerArg,
},
}
})
);
const childProcess = await threadsimple.start();
childProcess.on('exit', (status) => {
done.resolve();
})
});
await done.promise;
};
}
public async buildProduction(cwdArg: string, fromArg: string, toArg: string) {
const done = plugins.smartpromise.defer();
const threadsimple = new plugins.smartspawn.ThreadSimple(plugins.path.join(__dirname, './tsbundle.class.tsbundleprocess.js'), [], {
env: {
...process.env,
tsbundleMode: 'production',
tsbundleCwd: cwdArg,
tsbundleFrom: fromArg,
tsbundleTo: toArg
const threadsimple = new plugins.smartspawn.ThreadSimple(
plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'),
[],
{
env: {
...process.env,
tsbundleMode: 'production',
tsbundleCwd: cwdArg,
tsbundleFrom: fromArg,
tsbundleTo: toArg,
},
}
})
);
const childProcess = await threadsimple.start();
childProcess.on('exit', (status) => {
done.resolve();
})
});
await done.promise;
};
}
}

View File

@ -1,5 +1,5 @@
import * as plugins from './tsbundle.plugins';
import { logger } from './tsbundle.logging';
import * as plugins from './tsbundle.plugins.js';
import { logger } from './tsbundle.logging.js';
export class TsBundleProcess {
/**
@ -27,7 +27,7 @@ export class TsBundleProcess {
},
plugins: [
// Compile TypeScript files
plugins.rollupTypescript({
(plugins.rollupTypescript as any)({
include: plugins.path.parse(fromArg).dir
? plugins.path.parse(fromArg).dir + '/**/*.ts'
: '**/*.ts',
@ -36,21 +36,21 @@ export class TsBundleProcess {
experimentalDecorators: true,
inlineSourceMap: true,
noEmitOnError: true,
lib: ['esnext', 'dom', 'es2017.object'],
lib: ['dom'],
noImplicitAny: false,
target: 'es2018',
target: 'es2020',
allowSyntheticDefaultImports: true,
importsNotUsedAsValues: 'preserve',
}),
plugins.rollupJson(),
(plugins.rollupJson as any)(),
// 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({}),
(plugins.rollupCommonjs as any)({}),
// Resolve source maps to the original source
plugins.rollupSourceMaps()
plugins.rollupSourceMaps(),
],
};
return baseOptions;
@ -65,7 +65,7 @@ export class TsBundleProcess {
productionOptions.plugins.push(
plugins.rollupTerser({
compress: true,
mangle: true
mangle: true,
})
);
return productionOptions;
@ -95,7 +95,11 @@ export class TsBundleProcess {
process.exit(0);
case 'parcel':
const parsedPath = plugins.path.parse(toArg);
const parcelInstance = new plugins.smartparcel.Parcel(fromArg, parsedPath.dir, parsedPath.base);
const parcelInstance = new plugins.smartparcel.Parcel(
fromArg,
parsedPath.dir,
parsedPath.base
);
await parcelInstance.build();
}
}
@ -122,13 +126,17 @@ const run = async () => {
console.log(`to: ${process.env.tsbundleTo}`);
console.log(`mode: ${process.env.tsbundleMode}`);
process.chdir(process.env.tsbundleCwd);
console.log(`switched to ${process.cwd()}`)
console.log(`switched to ${process.cwd()}`);
const tsbundleProcessInstance = new TsBundleProcess();
if (process.env.tsbundleMode === 'test') {
tsbundleProcessInstance.buildTest(process.env.tsbundleFrom, process.env.tsbundleTo, process.env.tsbundleBundler as 'rollup' | 'parcel');
tsbundleProcessInstance.buildTest(
process.env.tsbundleFrom,
process.env.tsbundleTo,
process.env.tsbundleBundler as 'rollup' | 'parcel'
);
} else {
tsbundleProcessInstance.buildProduction(process.env.tsbundleFrom, process.env.tsbundleTo);
}
}
};
run();

View File

@ -1,11 +1,11 @@
import * as plugins from './tsbundle.plugins';
import { TsBundle } from './tsbundle.class.tsbundle';
import { HtmlHandler } from './tsbundle.htmlhandler';
import { logger } from './tsbundle.logging';
import * as plugins from './tsbundle.plugins.js';
import { TsBundle } from './tsbundle.class.tsbundle.js';
import { HtmlHandler } from './tsbundle.htmlhandler.js';
import { logger } from './tsbundle.logging.js';
export const runCli = async () => {
const tsBundleCli = new plugins.smartcli.Smartcli();
tsBundleCli.standardTask().subscribe(async argvArg => {
tsBundleCli.standardTask().subscribe(async (argvArg) => {
const tsbundle = new TsBundle();
// const htmlHandler = new HtmlHandler();
switch (true) {
@ -21,23 +21,32 @@ export const runCli = async () => {
}
});
tsBundleCli.addCommand('element').subscribe(async argvArg => {
tsBundleCli.addCommand('element').subscribe(async (argvArg) => {
const tsbundle = new TsBundle();
// const htmlHandler = new HtmlHandler();
switch (true) {
case argvArg.production || process.env.CI:
await tsbundle.buildProduction(process.cwd(), './ts_web/index.ts', './dist_bundle/bundle.js');
await tsbundle.buildProduction(
process.cwd(),
'./ts_web/index.ts',
'./dist_bundle/bundle.js'
);
// await htmlHandler.minifyHtml();
break;
case argvArg.test:
default:
await tsbundle.buildTest(process.cwd(), './ts_web/index.ts', './dist_bundle/bundle.js', 'rollup');
await tsbundle.buildTest(
process.cwd(),
'./ts_web/index.ts',
'./dist_bundle/bundle.js',
'rollup'
);
// await htmlHandler.copyHtml();
return;
}
});
tsBundleCli.addCommand('npm').subscribe(async argvArg => {
tsBundleCli.addCommand('npm').subscribe(async (argvArg) => {
const tsbundle = new TsBundle();
// const htmlHandler = new HtmlHandler();
switch (true) {
@ -47,23 +56,37 @@ export const runCli = async () => {
break;
case argvArg.test:
default:
await tsbundle.buildTest(process.cwd(), './ts/index.ts', './dist_bundle/bundle.js', 'rollup');
await tsbundle.buildTest(
process.cwd(),
'./ts/index.ts',
'./dist_bundle/bundle.js',
'rollup'
);
// await htmlHandler.copyHtml();
return;
}
});
tsBundleCli.addCommand('website').subscribe(async argvArg => {
tsBundleCli.addCommand('website').subscribe(async (argvArg) => {
const tsbundle = new TsBundle();
const htmlHandler = new HtmlHandler();
switch (true) {
case argvArg.production || process.env.CI:
await tsbundle.buildProduction(process.cwd(), './ts_web/index.ts', './dist_serve/bundle.js');
await tsbundle.buildProduction(
process.cwd(),
'./ts_web/index.ts',
'./dist_serve/bundle.js'
);
await htmlHandler.minifyHtml();
break;
case argvArg.test:
default:
await tsbundle.buildTest(process.cwd(), './ts_web/index.ts', './dist_serve/bundle.js', 'rollup');
await tsbundle.buildTest(
process.cwd(),
'./ts_web/index.ts',
'./dist_serve/bundle.js',
'rollup'
);
await htmlHandler.copyHtml();
return;
}

View File

@ -1,5 +1,5 @@
import * as plugins from './tsbundle.plugins';
import * as paths from './tsbundle.paths';
import * as plugins from './tsbundle.plugins.js';
import * as paths from './tsbundle.paths.js';
export class HtmlHandler {
public sourceFilePath: string = plugins.path.join(paths.htmlDir, 'index.html');
@ -31,7 +31,7 @@ export class HtmlHandler {
removeAttributeQuotes: true,
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true
removeComments: true,
});
plugins.smartfile.memory.toFsSync(minifiedHtml, targetPathArg);
}

View File

@ -1,4 +1,4 @@
import * as plugins from './tsbundle.plugins';
import * as plugins from './tsbundle.plugins.js';
export const logger = new plugins.smartlog.Smartlog({
logContext: {
@ -7,9 +7,9 @@ export const logger = new plugins.smartlog.Smartlog({
containerName: 'Some Containername',
environment: 'local',
runtime: 'node',
zone: 'gitzone'
zone: 'gitzone',
},
minimumLogLevel: 'silly'
minimumLogLevel: 'silly',
});
logger.addLogDestination(new plugins.smartlogDestinationLocal.DestinationLocal());

View File

@ -1,7 +1,10 @@
import * as plugins from './tsbundle.plugins';
import * as plugins from './tsbundle.plugins.js';
export const cwd = process.cwd();
export const packageDir = plugins.path.join(__dirname, '../');
export const packageDir = plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
'../'
);
export const htmlDir = plugins.path.join(cwd, './html');
export const distServeDir = plugins.path.join(cwd, './dist_serve');
export const assetsDir = plugins.path.join(packageDir, 'assets');

View File

@ -8,11 +8,21 @@ 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';
import * as smartpath from '@pushrocks/smartpath';
import * as smartparcel from '@pushrocks/smartparcel';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartspawn from '@pushrocks/smartspawn';
export { smartcli, smartfile, smartlog, smartlogDestinationLocal, smartparcel, smartpromise, smartspawn };
export {
smartcli,
smartfile,
smartlog,
smartlogDestinationLocal,
smartpath,
smartparcel,
smartpromise,
smartspawn,
};
// third party scope
import * as rollup from 'rollup';
@ -35,5 +45,5 @@ export {
rollupSourceMaps,
rollupTerser,
rollupTypescript,
htmlMinifier
htmlMinifier,
};