2023-09-03 10:31:10 +08:00

66 lines
1.3 KiB
JavaScript

const parseArgs = require('minimist');
const fs = require('fs');
const assert = require('assert');
const { resolve } = require('path');
const IDENT = ' ';
class MyDoc {
constructor() {
this.workDir = './';
}
async init() {
await this.convert();
}
async convert() {
this.env = fs.readFileSync(`${this.workDir}env.json`, 'utf8');
this.data = `
<?php5
class Doc
{
`;
if (fs.existsSync(`${this.workDir}README.php`)) {
this.data += fs.readFileSync(`${this.workDir}README.php`, 'utf8');
}
const files = fs.readdirSync('./', {encoding:'utf8', withFileTypes:true});
files.forEach((item) => {
if (item.name.slice(-3) == '.js' &&
item.name != 'common.js') {
const c = require(resolve('./') + '/' + item.name.slice(0, -3));
this.convertClass(new c());
}
});
}
async convertClass(c) {
c.apis.forEach(
(item) => {
const method = item.method ? 'GET' : item.method;
this.data += `
/**
* @api ${method} ${item.url}
* @apiPermission
* @apiGroup ${item.group}
* @apiVersion 1.0
* @apiDescription ${item.desc}
`;
if (item.is_json_params) {
} else {
}
this.data += ` */
`;
}
);
console.log(this.data);
}
}
(new MyDoc).init();