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

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