This commit is contained in:
azw 2023-09-03 10:31:10 +08:00
parent 37a0b58d53
commit 31dc304525

View File

@ -1,6 +1,9 @@
const parseArgs = require('minimist'); const parseArgs = require('minimist');
const fs = require('fs'); const fs = require('fs');
const assert = require('assert'); const assert = require('assert');
const { resolve } = require('path');
const IDENT = ' ';
class MyDoc { class MyDoc {
@ -14,25 +17,49 @@ class MyDoc {
async convert() { async convert() {
this.env = fs.readFileSync(`${this.workDir}env.json`, 'utf8'); this.env = fs.readFileSync(`${this.workDir}env.json`, 'utf8');
let data = ` this.data = `
<?php5 <?php5
class Doc class Doc
{ {
`; `;
if (fs.existsSync(`${this.workDir}README.php`)) { if (fs.existsSync(`${this.workDir}README.php`)) {
data += fs.readFileSync(`${this.workDir}README.php`, 'utf8'); this.data += fs.readFileSync(`${this.workDir}README.php`, 'utf8');
} }
const files = fs.readdirSync('./', {encoding:'utf8', withFileTypes:true}); const files = fs.readdirSync('./', {encoding:'utf8', withFileTypes:true});
files.forEach((item) => { files.forEach((item) => {
if (item.name.slice(-3) == '.js' && if (item.name.slice(-3) == '.js' &&
item.name != 'common.js') { item.name != 'common.js') {
//console.log(require('./' + item.name.slice(0, -3))); const c = require(resolve('./') + '/' + item.name.slice(0, -3));
console.log(require('/home/azw/pub/game2006go/doc/admin/User')); 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(); (new MyDoc).init();