index.js
function registerComponent(component) {
    const componentName = dashify(component.name);
    const componentLocalConfig = (component.local instanceof Array) ? component.local : [];
    while (componentLocalConfig.length < component.path.length) {
        componentLocalConfig.push([]);
    }
    const componentPath = component.path.slice(0).map(p => dashify(p));
    const componentRealPath = componentPath.map((p, i) => {
        return componentLocalConfig[i].dirsort ?
            `${(new String(componentLocalConfig[i].dirsort)).padStart(2, '0')}-${p}` : p;
    });
    const componentParent = path.join(app.components.get('path'), ...componentRealPath);
    const componentDirectory = path.join(componentParent, componentName);

    // Create the component directory
    if (!createCollection(app.components.get('path'), [...componentRealPath, componentName], componentLocalConfig)) {
        throw new Error(`Could not create component directory ${componentDirectory}`);
    }

    // Write out the template file
    const componentVariantName = componentName + (component.variant ? `--${dashify(component.variant)}` : '');
    const componentTemplate = path.join(componentDirectory, `${componentVariantName}.${component.extension}`);
    writeFile(componentTemplate, component.template);

    // Write out the preview template
    if (component.preview) {
        writeFile(path.join(componentParent, `_${componentName}-preview.t3s`), component.preview);
    }

    // Configure the component
    configureComponent(path.join(componentDirectory, `${componentName}.config.json`), component, componentPath);
}
function registerComponent(component) {
    const componentName = dashify(component.name);
    const componentLocalConfig = (component.local instanceof Array) ? component.local : [];
    while (componentLocalConfig.length < component.path.length) {
        componentLocalConfig.push([]);
    }
    const componentPath = component.path.slice(0).map(p => dashify(p));
    const componentRealPath = componentPath.map((p, i) => {
        return componentLocalConfig[i].dirsort ?
            `${(new String(componentLocalConfig[i].dirsort)).padStart(2, '0')}-${p}` : p;
    });
    const componentParent = path.join(app.components.get('path'), ...componentRealPath);
    const componentDirectory = path.join(componentParent, componentName);

    // Create the component directory
    if (!createCollection(app.components.get('path'), [...componentRealPath, componentName], componentLocalConfig)) {
        throw new Error(`Could not create component directory ${componentDirectory}`);
    }

    // Write out the template file
    const componentVariantName = componentName + (component.variant ? `--${dashify(component.variant)}` : '');
    const componentTemplate = path.join(componentDirectory, `${componentVariantName}.${component.extension}`);
    writeFile(componentTemplate, component.template);

    // Write out the preview template
    if (component.preview) {
        writeFile(path.join(componentParent, `_${componentName}-preview.t3s`), component.preview);
    }

    // Configure the component
    configureComponent(path.join(componentDirectory, `${componentName}.config.json`), component, componentPath);
}
function registerComponent ( component ) { const componentName = dashify ( component . name ) ; const componentLocalConfig = ( component . local instanceof Array ) ? component . local : [ ] ; while ( componentLocalConfig . length < component . path . length ) { componentLocalConfig . push ( [ ] ) ; } const componentPath = component . path . slice ( 0 ) . map ( p => dashify ( p ) ) ; const componentRealPath = componentPath . map ( ( p , i ) => { return componentLocalConfig [ i ] . dirsort ? ` ${ ( new String ( componentLocalConfig [ i ] . dirsort ) ) . padStart ( 2 , '0' ) } ${ p } ` : p ; } ) ; const componentParent = path . join ( app . components . get ( 'path' ) , ... componentRealPath ) ; const componentDirectory = path . join ( componentParent , componentName ) ; // Create the component directory if ( ! createCollection ( app . components . get ( 'path' ) , [ ... componentRealPath , componentName ] , componentLocalConfig ) ) { throw new Error ( ` ${ componentDirectory } ` ) ; } // Write out the template file const componentVariantName = componentName + ( component . variant ? ` ${ dashify ( component . variant ) } ` : '' ) ; const componentTemplate = path . join ( componentDirectory , ` ${ componentVariantName } ${ component . extension } ` ) ; writeFile ( componentTemplate , component . template ) ; // Write out the preview template if ( component . preview ) { writeFile ( path . join ( componentParent , ` ${ componentName } ` ) , component . preview ) ; } // Configure the component configureComponent ( path . join ( componentDirectory , ` ${ componentName } ` ) , component , componentPath ) ; }
Register a component

@param {Object} component Component
Register a component