//#region imports
import { UtilsFilesFoldersSync } from 'tnp-core/lib';
import { Helpers } from 'tnp-core/lib';
import { HelpersTaon } from 'tnp-helpers/lib';
import { srcMainProject, } from '../../../../constants';
import { RenameRule } from 'magic-renamer/lib';
//#endregion
/**
 * Global helper for artifacts
 */
export class ArtifactsGlobalHelper {
    project;
    branding;
    constructor(project) {
        this.project = project;
        //#region @backend
        this.branding = new (require('./branding').Branding)(project);
        //#endregion
        // this.docker = new DockerHelper(project); /// TODO @UNCOMMENT when docker is ready
    }
    //#region add sources from core
    addSrcFolderFromCoreProject() {
        //#region @backend
        const corePath = this.project.framework.coreProject.pathFor(srcMainProject);
        const dest = this.project.pathFor(srcMainProject);
        HelpersTaon.copy(corePath, dest, {
            recursive: true,
            overwrite: true,
            // filter: src => {
            //   return [appTsFromSrc, appVscodeTsFromSrc].includes(path.basename(src));
            // },
        });
        UtilsFilesFoldersSync.getFilesFrom(dest, {
            recursive: true,
            followSymlinks: false,
        }).forEach(f => {
            let content = Helpers.readFile(f);
            const rules = RenameRule.from(`${this.project.framework.coreProject.name} => ${this.project.name}`);
            for (const rule of rules) {
                content = rule.replaceInString(content);
            }
            // content = content.replace(/from 'tnp-core\/src/g, `from '${config.npmScope}/core/source`);
            // content = content.replace(/from "tnp-core\/src/g, `from "${config.npmScope}/core/source`);
            Helpers.writeFile(f, content);
        });
        //#endregion
    }
    //#endregion
    //#region getters & methods / remove (m)js.map files from release
    /**
     * because of that
     * In vscode there is a mess..
     * TODO
     */
    __removeJsMapsFrom(absPathReleaseDistFolder) {
        //#region @backendFunc
        return; // TODO not a good idea
        Helpers.filesFrom(absPathReleaseDistFolder, true)
            .filter(f => f.endsWith('.js.map') || f.endsWith('.mjs.map'))
            .forEach(f => Helpers.removeFileIfExists(f));
        //#endregion
    }
}
//# sourceMappingURL=artifacts-helpers.js.map