in lib/generator.js [26:68]
constructor(option = {}) {
this.config = {
outputDir: '',
indent: ' ',
package: option.package,
clientName: option.clientName || 'Client',
...option
};
this.used = [];
this.output = '';
this.outputDir = option.outputDir;
if(!this.outputDir) {
throw Error('`option.outputDir` should not empty');
}
this.config.clientPath = path.join(this.outputDir, 'src', `${this.config.clientName}.php`);
this.modelDir = this.config.modelDirName || 'Models';
this.exceptionDir = this.config.exceptionDirName || 'Exceptions';
this.typedef = this.config.typedef;
this.__module = {};
this.innerModuleClassName = new Map();
this.__externModule = new Map();
this.classNamespace = new Map();
this.usedClass = new Map();
if (!this.outputDir) {
throw new Error('`option.outputDir` should not empty');
}
if (!fs.existsSync(this.outputDir)) {
fs.mkdirSync(this.outputDir, {
recursive: true
});
}
this.composer = {};
const composerPath = path.join(this.outputDir, 'composer.json');
if (fs.existsSync(composerPath)) {
try {
this.composer = JSON.parse(fs.readFileSync(composerPath));
} catch (err) {
throw new Error('invalid composer.json');
}
}
}