38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
|
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);
|
||
|
}
|
||
|
}
|