/* eslint no-console: 0 */

/**
 * This script is made to copy the content of the public folder
 * into the same destination in the client projects
 *
 * Note:
 *   npm install copies only the listed files to the package folder,
 *   therefore only those files can be copied to the client's public folder
 *   example listing:
 *   "files": [
 *     ...
 *     "public/translations",
 *     "public/favicon.ico"
 *   ],
 *
 * Runs only when installing this package as a dependency in client projects
 *
 * usage: node ./scripts/cpPublic.js
 *
 * @author boda@redhotmagma.de
 */

const path = require('path');

const { cpDirDeep, testMatchers } = require('@configuratorware/scripts/utils/fileSystem');
const { isDependency } = require('@configuratorware/scripts/utils/process');

// keep existing files listed below
const test = testMatchers.keepIfExists(/favicon\.ico$/);

if (isDependency()) {
    console.log(
        '\x1b[37m\x1b[42m%s\x1b[0m',
        'Copying public content into the public directory of the client project'
    );

    const src = path.resolve(__dirname, '../public');
    const dst = path.resolve(__dirname, '../../../../public');

    cpDirDeep(src, dst, { testFn: test });
}
