packages/strapi-plugin-content-type-builder/services/schema-builder/component-builder.js
/**
     * create a component in the tmpComponent map
     */
create a component in the tmpComponent map
create a component in the tmpComponent map
createComponent(infos) {
      const uid = this.createComponentUID(infos);
      if (this.components.has(uid)) {
        throw new Error('component.alreadyExists');
      }
      const handler = createSchemaHandler({
        dir: path.join(strapi.dir, 'components', nameToSlug(infos.category)),
        filename: `${nameToSlug(infos.name)}.json`,
      });
      const defaultConnection = _.get(
        strapi,
        ['config', 'currentEnvironment', 'database', 'defaultConnection'],
        'default'
      );
      const defaultCollectionName = `components_${nameToCollectionName(
        infos.category
      )}_${nameToCollectionName(pluralize(infos.name))}`;
      handler
        .setUID(uid)
        .set('connection', infos.connection || defaultConnection)
        .set('collectionName', infos.collectionName || defaultCollectionName)
        .set(['info', 'name'], infos.name)
        .set(['info', 'icon'], infos.icon)
        .set(['info', 'description'], infos.description)
        .setAttributes(this.convertAttributes(infos.attributes));
      if (this.components.size === 0) {
        strapi.emit('didCreateFirstComponent');
      } else {
        strapi.emit('didCreateComponent');
      }
      this.components.set(uid, handler);
      return handler;
    }
createComponent ( infos ) { const uid = this . createComponentUID ( infos ) ; if ( this . components . has ( uid ) ) { throw new Error ( 'component.alreadyExists' ) ; } const handler = createSchemaHandler ( { dir : path . join ( strapi . dir , 'components' , nameToSlug ( infos . category ) ) , filename : ` ${ nameToSlug ( infos . name ) } ` , } ) ; const defaultConnection = _ . get ( strapi , [ 'config' , 'currentEnvironment' , 'database' , 'defaultConnection' ] , 'default' ) ; const defaultCollectionName = ` ${ nameToCollectionName ( infos . category ) } ${ nameToCollectionName ( pluralize ( infos . name ) ) } ` ; handler . setUID ( uid ) . set ( 'connection' , infos . connection || defaultConnection ) . set ( 'collectionName' , infos . collectionName || defaultCollectionName ) . set ( [ 'info' , 'name' ] , infos . name ) . set ( [ 'info' , 'icon' ] , infos . icon ) . set ( [ 'info' , 'description' ] , infos . description ) . setAttributes ( this . convertAttributes ( infos . attributes ) ) ; if ( this . components . size === 0 ) { strapi . emit ( 'didCreateFirstComponent' ) ; } else { strapi . emit ( 'didCreateComponent' ) ; } this . components . set ( uid , handler ) ; return handler ; }
create a component in the tmpComponent map
create a component in the tmpComponent map