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

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

View File

@ -1,5 +1,11 @@
# Changelog
## 2025-01-29 - 2.2.0 - feat(AssetsHandler)
Add asset handling to the CLI workflow
- Introduced AssetsHandler class for managing asset directories and files.
- Updated tsbundle.cli.ts to include asset processing in the 'website' command.
## 2025-01-28 - 2.1.1 - fix(core)
Update dependencies and remove GitLab CI configuration.

View File

@ -26,7 +26,7 @@
"@push.rocks/early": "^4.0.4",
"@push.rocks/smartcli": "^4.0.11",
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartfile": "^11.1.5",
"@push.rocks/smartfile": "^11.1.6",
"@push.rocks/smartlog": "^3.0.7",
"@push.rocks/smartlog-destination-local": "^9.0.2",
"@push.rocks/smartpath": "^5.0.18",

32
pnpm-lock.yaml generated
View File

@ -18,8 +18,8 @@ importers:
specifier: ^3.0.5
version: 3.0.5
'@push.rocks/smartfile':
specifier: ^11.1.5
version: 11.1.5
specifier: ^11.1.6
version: 11.1.6
'@push.rocks/smartlog':
specifier: ^3.0.7
version: 3.0.7
@ -777,8 +777,8 @@ packages:
'@push.rocks/smartfile@10.0.41':
resolution: {integrity: sha512-xOOy0duI34M2qrJZggpk51EHGXmg9+mBL1Q55tNiQKXzfx89P3coY1EAZG8tvmep3qB712QEKe7T+u04t42Kjg==}
'@push.rocks/smartfile@11.1.5':
resolution: {integrity: sha512-N+f7P4MqgkDiPR5CrvzMJF9JVtXQK1Di24cYAd8roFkDVpnILlLQOQql558FPm2QE+HtDLuPLPBu2uaSZRLReA==}
'@push.rocks/smartfile@11.1.6':
resolution: {integrity: sha512-xKcynSrP7JmG1BKQsO+UskF0/fNyUFeDF3FGxoTgHsMqZgEgKDJqlHv657LcM6x6CV2VJcZdNOfIBr2zbkyitQ==}
'@push.rocks/smartguard@3.1.0':
resolution: {integrity: sha512-J23q84f1O+TwFGmd4lrO9XLHUh2DaLXo9PN/9VmTWYzTkQDv5JehmifXVI0esophXcCIfbdIu6hbt7/aHlDF4A==}
@ -4236,7 +4236,7 @@ snapshots:
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartenv': 5.0.12
'@push.rocks/smartfeed': 1.0.11
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartjson': 5.0.20
'@push.rocks/smartlog': 3.0.7
'@push.rocks/smartlog-destination-devtools': 1.0.12
@ -5041,7 +5041,7 @@ snapshots:
'@push.rocks/early': 4.0.4
'@push.rocks/smartcli': 4.0.11
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartlog': 3.0.7
'@push.rocks/smartpath': 5.0.18
'@push.rocks/smartpromise': 4.2.2
@ -5054,7 +5054,7 @@ snapshots:
'@push.rocks/early': 4.0.4
'@push.rocks/smartcli': 4.0.11
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartlog': 3.0.7
'@push.rocks/smartlog-destination-local': 9.0.2
'@push.rocks/smartpath': 5.0.18
@ -5071,7 +5071,7 @@ snapshots:
dependencies:
'@push.rocks/smartcli': 4.0.11
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartlog': 3.0.7
'@push.rocks/smartnpm': 2.0.4
'@push.rocks/smartpath': 5.0.18
@ -5082,7 +5082,7 @@ snapshots:
'@git.zone/tsrun@1.3.3':
dependencies:
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartshell': 3.2.2
tsx: 4.19.2
@ -5094,7 +5094,7 @@ snapshots:
'@push.rocks/consolecolor': 2.0.2
'@push.rocks/smartbrowser': 2.0.8
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartlog': 3.0.7
'@push.rocks/smartpromise': 4.2.2
'@push.rocks/smartshell': 3.2.2
@ -5286,7 +5286,7 @@ snapshots:
'@push.rocks/smartcache': 1.0.16
'@push.rocks/smartenv': 5.0.12
'@push.rocks/smartexit': 1.0.23
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartjson': 5.0.20
'@push.rocks/smartpath': 5.0.18
'@push.rocks/smartpromise': 4.2.2
@ -5324,7 +5324,7 @@ snapshots:
dependencies:
'@api.global/typedrequest': 3.1.10
'@configvault.io/interfaces': 1.0.17
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartlog': 3.0.7
'@push.rocks/smartpath': 5.0.18
@ -5476,7 +5476,7 @@ snapshots:
glob: 10.4.5
js-yaml: 4.1.0
'@push.rocks/smartfile@11.1.5':
'@push.rocks/smartfile@11.1.6':
dependencies:
'@push.rocks/lik': 6.1.0
'@push.rocks/smartdelay': 3.0.5
@ -5633,7 +5633,7 @@ snapshots:
dependencies:
'@push.rocks/smartbuffer': 3.0.4
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartnetwork': 3.0.2
'@push.rocks/smartpath': 5.0.18
'@push.rocks/smartpromise': 4.2.2
@ -5686,7 +5686,7 @@ snapshots:
'@push.rocks/smarts3@2.2.5':
dependencies:
'@push.rocks/smartbucket': 3.3.7
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartpath': 5.0.18
'@tsclass/tsclass': 4.4.0
'@types/s3rver': 3.7.4
@ -5833,7 +5833,7 @@ snapshots:
'@push.rocks/smartdelay': 3.0.5
'@push.rocks/smartenv': 5.0.12
'@push.rocks/smartexpect': 1.4.0
'@push.rocks/smartfile': 11.1.5
'@push.rocks/smartfile': 11.1.6
'@push.rocks/smartjson': 5.0.20
'@push.rocks/smartmongo': 2.0.10(@aws-sdk/credential-providers@3.734.0)(socks@2.8.3)
'@push.rocks/smartpath': 5.0.18

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();