import fs from 'fs';
import path from 'path';
import FileUtils from '../utils/FileUtils';
import { PackageScript } from './PackageScript';



export default function PackageWeb(projectDir: string, key: string, isolate: boolean = false): void {
    console.log(`-----------------------------------------------------Handle package [${key}] start-----------------------------------------------------`);

    const outputDir = path.join(projectDir, 'build', 'subgame', 'web-mobile', key);
    FileUtils.rm(outputDir);
    FileUtils.mkdir(path.dirname(outputDir));
    console.log(`Make package [${key}] output dir: ${outputDir}`);

    const buildDir = path.join(projectDir, 'build', 'web-mobile');
    const bundleDir = path.join(buildDir, 'assets', key);

    PackageScript(key, buildDir, isolate);


    fs.renameSync(bundleDir, outputDir)
    console.log(`-----------------------------------------------------Handle package [${key}] end-------------------------------------------------------\n\n`);
}
