react/node_modules/@webpack-cli/utils/lib/scaffold.js
/**
 *
 * Runs the transformations from an object we get from yeoman
 *
 * @param	{Object} transformConfig 	- Configuration to transform
 * @param	{String} action 			- Action to be done on the given ast
 * @returns {Promise} - A promise that writes each transform, runs prettier
 * and writes the file
 */
Runs the transformations from an object we get from yeoman
@param       {Object} transformConfig        - Configuration to transform
@param       {String} action                         - Action to be done on the given ast
@returns {Promise} - A promise that writes each transform, runs prettier
and writes the file
Runs the transformations from an object we get from yeoman @param { Object } transformConfig - Configuration to transform @param { String } action - Action to be done on the given ast @returns { Promise } - A promise that writes each transform runs prettier and writes the file
function runTransform(transformConfig, action, generateConfig) {
    const webpackConfig = Object.keys(transformConfig).filter((p) => {
        if (p == 'usingDefaults') {
            return generateConfig;
        }
        return p !== 'configFile' && p !== 'configPath';
    });
    const initActionNotDefined = action && action !== 'init' ? true : false;
    webpackConfig.forEach((scaffoldPiece) => {
        const config = transformConfig[scaffoldPiece];
        const transformations = mapOptionsToTransform(config);
        if (config.topScope && !transformations.includes('topScope')) {
            transformations.push('topScope');
        }
        if (config.merge && !transformations.includes('merge')) {
            transformations.push('merge');
        }
        const ast = jscodeshift_1.default(initActionNotDefined ? transformConfig.configFile : 'module.exports = {}');
        const transformAction = action || null;
        return pEachSeries(transformations, (f) => {
            if (f === 'merge' || f === 'topScope') {
                return recursive_parser_1.recursiveTransform(jscodeshift_1.default, ast, f, config[f], transformAction);
            }
            return recursive_parser_1.recursiveTransform(jscodeshift_1.default, ast, f, config.webpackOptions[f], transformAction);
        })
            .then(() => {
            let configurationName;
            if (!config.configName) {
                configurationName = 'webpack.config.js';
            }
            else {
                configurationName = 'webpack.' + config.configName + '.js';
            }
            const projectRoot = path_utils_1.findProjectRoot();
            const outputPath = initActionNotDefined
                ? transformConfig.configPath
                : path_1.default.join(projectRoot || process.cwd(), configurationName);
            const source = ast.toSource({
                quote: 'single',
            });
            run_prettier_1.runPrettier(outputPath, source);
        })
            .catch((err) => {
            logger_1.default.error(err);
        });
    });
    const runCommand = get_package_manager_1.getPackageManager() === 'yarn' ? 'yarn build' : 'npm run build';
    let successMessage = colorette_1.green('Congratulations! Your new webpack configuration file has been created!\n\n') +
        `You can now run ${colorette_1.green(runCommand)} to bundle your application!\n\n`;
    if (initActionNotDefined && transformConfig.config.item) {
        successMessage = colorette_1.green(`Congratulations! ${transformConfig.config.item} has been ${action}ed!\n`);
    }
    logger_1.default.log(`\n${successMessage}`);
}
function runTransform ( transformConfig , action , generateConfig ) { const webpackConfig = Object . keys ( transformConfig ) . filter ( ( p ) => { if ( p == 'usingDefaults' ) { return generateConfig ; } return p !== 'configFile' && p !== 'configPath' ; } ) ; const initActionNotDefined = action && action !== 'init' ? true : false ; webpackConfig . forEach ( ( scaffoldPiece ) => { const config = transformConfig [ scaffoldPiece ] ; const transformations = mapOptionsToTransform ( config ) ; if ( config . topScope && ! transformations . includes ( 'topScope' ) ) { transformations . push ( 'topScope' ) ; } if ( config . merge && ! transformations . includes ( 'merge' ) ) { transformations . push ( 'merge' ) ; } const ast = jscodeshift_1 . default ( initActionNotDefined ? transformConfig . configFile : 'module.exports = {}' ) ; const transformAction = action || null ; return pEachSeries ( transformations , ( f ) => { if ( f === 'merge' || f === 'topScope' ) { return recursive_parser_1 . recursiveTransform ( jscodeshift_1 . default , ast , f , config [ f ] , transformAction ) ; } return recursive_parser_1 . recursiveTransform ( jscodeshift_1 . default , ast , f , config . webpackOptions [ f ] , transformAction ) ; } ) . then ( ( ) => { let configurationName ; if ( ! config . configName ) { configurationName = 'webpack.config.js' ; } else { configurationName = 'webpack.' + config . configName + '.js' ; } const projectRoot = path_utils_1 . findProjectRoot ( ) ; const outputPath = initActionNotDefined ? transformConfig . configPath : path_1 . default . join ( projectRoot || process . cwd ( ) , configurationName ) ; const source = ast . toSource ( { quote : 'single' , } ) ; run_prettier_1 . runPrettier ( outputPath , source ) ; } ) . catch ( ( err ) => { logger_1 . default . error ( err ) ; } ) ; } ) ; const runCommand = get_package_manager_1 . getPackageManager ( ) === 'yarn' ? 'yarn build' : 'npm run build' ; let successMessage = colorette_1 . green ( 'Congratulations! Your new webpack configuration file has been created!\n\n' ) + ` ${ colorette_1 . green ( runCommand ) } \n \n ` ; if ( initActionNotDefined && transformConfig . config . item ) { successMessage = colorette_1 . green ( ` ${ transformConfig . config . item } ${ action } \n ` ) ; } logger_1 . default . log ( ` \n ${ successMessage } ` ) ; }
Runs the transformations from an object we get from yeoman
 @param       {Object} transformConfig        - Configuration to transform
 @param       {String} action                         - Action to be done on the given ast
 @returns {Promise} - A promise that writes each transform, runs prettier
 and writes the file
Runs the transformations from an object we get from yeoman @param { Object } transformConfig - Configuration to transform @param { String } action - Action to be done on the given ast @returns { Promise } - A promise that writes each transform runs prettier and writes the file
// webpackOptions.name sent to nameTransform if match // TODO: typing here is difficult to understand // eslint-disable-next-line @typescript-eslint/no-explicit-any