feat(AssetsHandler): Add asset handling to the CLI workflow

This commit is contained in:
2025-01-29 13:12:01 +01:00
parent 230e217368
commit 10af586f28
7 changed files with 70 additions and 18 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@git.zone/tsbundle',
version: '2.1.1',
version: '2.2.0',
description: 'a bundler using rollup for painless bundling of web projects'
}

38
ts/mod_assets/index.ts Normal file
View File

@@ -0,0 +1,38 @@
import * as plugins from './plugins.js';
import * as paths from '../paths.js';
export class AssetsHandler {
public defaultFromDirPath: string = plugins.path.join(paths.cwd, './assets');
public defaultToDirPath: string = plugins.path.join(paths.cwd, './dist_serve/assets');
public async ensureAssetsDir() {
const assetsDirExists = await plugins.smartfile.fs.isDirectory(this.defaultFromDirPath);
if (!assetsDirExists) {
console.log(`creating assets directory at ${this.defaultFromDirPath}`);
await plugins.smartfile.fs.ensureDir(this.defaultFromDirPath);
}
}
// copies the html
public async processAssets(optionsArg?: {
from?: string;
to?: string;
}) {
// lets assemble the options
optionsArg = {
... {
from: this.defaultFromDirPath,
to: this.defaultToDirPath,
},
...(optionsArg || {})
}
await this.ensureAssetsDir()
optionsArg.from = plugins.smartpath.transform.toAbsolute(optionsArg.from, paths.cwd) as string;
optionsArg.to = plugins.smartpath.transform.toAbsolute(optionsArg.to, paths.cwd) as string;
// lets clean theh target directory
plugins.smartfile.fs.ensureEmptyDir(optionsArg.to);
plugins.smartfile.fs.copySync(optionsArg.from, optionsArg.to);
}
}

1
ts/mod_assets/plugins.ts Normal file
View File

@@ -0,0 +1 @@
export * from '../plugins.js';

View File

@@ -2,6 +2,7 @@ import * as plugins from './plugins.js';
import { TsBundle } from './tsbundle.class.tsbundle.js';
import { HtmlHandler } from './mod_html/index.js';
import { logger } from './tsbundle.logging.js';
import { AssetsHandler } from './mod_assets/index.js';
export const runCli = async () => {
const tsBundleCli = new plugins.smartcli.Smartcli();
@@ -34,6 +35,8 @@ export const runCli = async () => {
tsBundleCli.addCommand('website').subscribe(async (argvArg) => {
const tsbundle = new TsBundle();
// lets deal with the html
const htmlHandler = new HtmlHandler();
await tsbundle.build(
process.cwd(),
@@ -49,6 +52,10 @@ export const runCli = async () => {
minify: true,
});
}
// lets deal with the assets
const assetsHandler = new AssetsHandler();
await assetsHandler.processAssets();
});
tsBundleCli.startParse();