initComposer()

in lib/generator.js [88:163]


  initComposer() {
    this.composer.name = this.composer.packageName || (this.config.packageInfo && this.config.packageInfo.name);
    this.composer.type = 'library';
    this.composer.description = this.composer.description || (this.config.packageInfo && this.config.packageInfo.desc);
    this.composer.github = this.composer.github || (this.config.packageInfo && this.config.packageInfo.github);
    this.composer.main = this.composer.main || 'src/Client.php';
    this.composer.authors = this.composer.authors || [];
    if(this.config.maintainers) {
      let authors = [];
      this.composer.authors.forEach(author => {
        authors.push(`${author.name || ''}:${author.email || ''}`);
      });
      this.config.maintainers.forEach(maintainer => {
        let name = maintainer.name ? maintainer.name : '';
        let email = maintainer.email ? maintainer.email : '';
        if(!authors.includes(`${name}:${email}`)) {
          this.composer.authors.push({ name: name, email: email });
        }
      });
    }
    this.composer.license = this.composer.license || 'Apache-2.0';
    if (!this.composer.autoload) {
      this.composer.autoload = {
        'psr-4': {}
      };
      const namsespace = this.config.package.split('.').join('\\');
      this.composer.autoload['psr-4'][`${namsespace}\\`] = 'src';
    }

    if (!this.composer.scripts) {
      this.composer.scripts = {
        fixer: 'php-cs-fixer fix ./'
      };
    }

    if (!this.composer.config) {
      this.composer.config = {
        'sort-packages': true,
        'preferred-install': 'dist',
        'optimize-autoloader': true
      };
    }
    if (!this.composer.require) {
      this.composer.require = {
        'php': '>5.5',
        'alibabacloud/darabonba': '^1.0.0',
      };
    }
    
    Object.keys(this.requires).map(key => {
      this.composer.require[key] = this.requires[key];
    });
    if(this.typedef) {
      Object.keys(this.typedef).map(key => {
        if(!this.typedef[key].package) {
          return;
        }
        const [ name, version ] = this.typedef[key].package.split(':');
        this.composer.require[name] = version;
      });
    }
    


    if (!this.composer['prefer-stable']) {
      this.composer['prefer-stable'] = true;
    }

    if (!this.composer.config) {
      this.composer.config = {
        'sort-packages': true,
        'preferred-install': 'dist',
        'optimize-autoloader': true
      };
    }
  }