index.js
function configureComponent(configPath, component, componentPath) {
    let config;
    try {
        config = require(configPath);

        // If this is the default variant
        if (!component.variant) {
            config.title = component.name;
            config.status = component.status;
            config.context = config.context || {};
            config.context.type = component.type;
        }

        config.variants = config.variants || [];
    } catch (e) {
        config = {
            title: component.name,
            status: component.status,
            context: {
                type: component.type,
            },
            variants: [],
        };
    }

    // Register the preview component
    if (component.preview) {
        config.preview = `@${[...componentPath, dashify(component.name), 'preview'].join('-')}`;
    }

    // Remove the variant if already present
    const variant = component.variant || 'default';
    config.variants = config.variants.filter(vt => vt.name !== variant);

    // Register the variant
    config.variants.push({
        name: variant,
        label: component.label || ((variant === 'default') ? component.name : variant),
        context: {
            config: component.config,
            parameters: component.parameters || {},
            request: component.request,
            component: component.class,
        },
    });

    config.variants = config.variants.sort((a, b) => {
        const aName = a.label.toLowerCase();
        const bName = b.label.toLowerCase();
        if (aName > bName) {
            return 1;
        }
        return (aName < bName) ? -1 : 0;
    });
    config.variants.forEach((v, i) => {
        config.variants[i].order = i;
    });

    // Write the configuration file
    writeFile(configPath, JSON.stringify(config, null, 4));

    // If there's a component note
    if ((variant === 'default') && component.notice) {
        const readme = path.join(path.dirname(configPath), 'README.md');
        writeFile(readme, component.notice);
    }
}
function configureComponent(configPath, component, componentPath) {
    let config;
    try {
        config = require(configPath);

        // If this is the default variant
        if (!component.variant) {
            config.title = component.name;
            config.status = component.status;
            config.context = config.context || {};
            config.context.type = component.type;
        }

        config.variants = config.variants || [];
    } catch (e) {
        config = {
            title: component.name,
            status: component.status,
            context: {
                type: component.type,
            },
            variants: [],
        };
    }

    // Register the preview component
    if (component.preview) {
        config.preview = `@${[...componentPath, dashify(component.name), 'preview'].join('-')}`;
    }

    // Remove the variant if already present
    const variant = component.variant || 'default';
    config.variants = config.variants.filter(vt => vt.name !== variant);

    // Register the variant
    config.variants.push({
        name: variant,
        label: component.label || ((variant === 'default') ? component.name : variant),
        context: {
            config: component.config,
            parameters: component.parameters || {},
            request: component.request,
            component: component.class,
        },
    });

    config.variants = config.variants.sort((a, b) => {
        const aName = a.label.toLowerCase();
        const bName = b.label.toLowerCase();
        if (aName > bName) {
            return 1;
        }
        return (aName < bName) ? -1 : 0;
    });
    config.variants.forEach((v, i) => {
        config.variants[i].order = i;
    });

    // Write the configuration file
    writeFile(configPath, JSON.stringify(config, null, 4));

    // If there's a component note
    if ((variant === 'default') && component.notice) {
        const readme = path.join(path.dirname(configPath), 'README.md');
        writeFile(readme, component.notice);
    }
}
function configureComponent ( configPath , component , componentPath ) { let config ; try { config = require ( configPath ) ; // If this is the default variant if ( ! component . variant ) { config . title = component . name ; config . status = component . status ; config . context = config . context || { } ; config . context . type = component . type ; } config . variants = config . variants || [ ] ; } catch ( e ) { config = { title : component . name , status : component . status , context : { type : component . type , } , variants : [ ] , } ; } // Register the preview component if ( component . preview ) { config . preview = ` ${ [ ... componentPath , dashify ( component . name ) , 'preview' ] . join ( '-' ) } ` ; } // Remove the variant if already present const variant = component . variant || 'default' ; config . variants = config . variants . filter ( vt => vt . name !== variant ) ; // Register the variant config . variants . push ( { name : variant , label : component . label || ( ( variant === 'default' ) ? component . name : variant ) , context : { config : component . config , parameters : component . parameters || { } , request : component . request , component : component . class , } , } ) ; config . variants = config . variants . sort ( ( a , b ) => { const aName = a . label . toLowerCase ( ) ; const bName = b . label . toLowerCase ( ) ; if ( aName > bName ) { return 1 ; } return ( aName < bName ) ? - 1 : 0 ; } ) ; config . variants . forEach ( ( v , i ) => { config . variants [ i ] . order = i ; } ) ; // Write the configuration file writeFile ( configPath , JSON . stringify ( config , null , 4 ) ) ; // If there's a component note if ( ( variant === 'default' ) && component . notice ) { const readme = path . join ( path . dirname ( configPath ) , 'README.md' ) ; writeFile ( readme , component . notice ) ; } }
Configure a component

@param {String} configPath Component configuration path
@param {Object} component Component properties
@param {String} componentPath Component path
Configure a component