From 10af586f282483579ac221dca4054d9668ef0dc2 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 29 Jan 2025 13:12:01 +0100 Subject: [PATCH] feat(AssetsHandler): Add asset handling to the CLI workflow --- changelog.md | 6 ++++++ package.json | 2 +- pnpm-lock.yaml | 32 ++++++++++++++++---------------- ts/00_commitinfo_data.ts | 2 +- ts/mod_assets/index.ts | 38 ++++++++++++++++++++++++++++++++++++++ ts/mod_assets/plugins.ts | 1 + ts/tsbundle.cli.ts | 7 +++++++ 7 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 ts/mod_assets/index.ts create mode 100644 ts/mod_assets/plugins.ts diff --git a/changelog.md b/changelog.md index b6b45e7..691522e 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/package.json b/package.json index eeeca84..ea3b491 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9055835..0e9d105 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index ac8f669..c7fddb2 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -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' } diff --git a/ts/mod_assets/index.ts b/ts/mod_assets/index.ts new file mode 100644 index 0000000..e94878a --- /dev/null +++ b/ts/mod_assets/index.ts @@ -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); + } +} \ No newline at end of file diff --git a/ts/mod_assets/plugins.ts b/ts/mod_assets/plugins.ts new file mode 100644 index 0000000..0bafc30 --- /dev/null +++ b/ts/mod_assets/plugins.ts @@ -0,0 +1 @@ +export * from '../plugins.js'; diff --git a/ts/tsbundle.cli.ts b/ts/tsbundle.cli.ts index 4d989ea..61e1e7d 100644 --- a/ts/tsbundle.cli.ts +++ b/ts/tsbundle.cli.ts @@ -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();