constructor()

in lib/generator.js [25:73]


  constructor(option = {}) {
    this.config = Object.assign({
      outputDir: '',
      indent: '    ',
      clientName: option.python.clientName || 'Client',
      className: option.className || 'Client',
    }, option);
    assert.ok(this.config.outputDir, '`option.outputDir` should not empty');
    assert.ok(this.config.package, `Darafile -> python -> package should not empty, please add python option into Darafile.
      example:
        "pthon": {
          "package": "darabonba.core",
          "className": "Client"
        }`);

    this.typedef = this.config.typedef || {};
    this.imports = [];
    this.outputDir = this.config.outputDir;
    this.setupPath = path.join(this.outputDir, 'setup.py');
    this.modelPath = path.join(this.outputDir, this.config.package, 'models');
    this.modelPackage = 'models';
    this.exceptionPath = path.join(this.outputDir, this.config.package, 'exceptions');
    this.exceptionPackage = 'exceptions';
    this.config.clientPath = path.join(this.outputDir, this.config.package, `${_snakeCase(this.config.clientName)}.py`);
    this.classNamespace = new Map();
    // 新增:用于存储已使用的类型
    this.isAsyncFunction = false; // 新增:用于标记是否为异步函数
    this.isStaticFunction = true; // 新增:用于标记是否为非静态函数
    // this.moduleDir = this.config.modelDirName || 'Models'; // 新增,用于存储models文件

    this.output = '';
    if (!fs.existsSync(this.outputDir)) {
      fs.mkdirSync(this.outputDir, {
        recursive: true
      });
    }

    if (!this.outputDir) {
      throw new Error('`option.outputDir` should not empty');
    }

    if (!fs.existsSync(this.outputDir)) {
      fs.mkdirSync(this.outputDir, {
        recursive: true
      });
    }
    this.package = {};
    this.initSetupPy();
  }