-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·27 lines (24 loc) · 860 Bytes
/
app.js
File metadata and controls
executable file
·27 lines (24 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';
const fs = require('fs');
const path = require('path');
const { getAbsoluteFSPath } = require('./index');
module.exports = app => {
// sync api to the same path of plugin
syncApiToPlugin(app.baseDir);
};
async function syncApiToPlugin(rootDir) {
// Get document, or throw exception on error
try {
const destFile = path.join(getAbsoluteFSPath(), '/swagger.yml');
// copy api file
if (fs.existsSync(path.join(rootDir, '/api.yml'))) {
fs.copyFileSync(path.join(rootDir, '/api.yml'), destFile);
} else if (fs.existsSync(path.join(rootDir, '/api.json'))) {
fs.copyFileSync(path.join(rootDir, '/api.json'), destFile);
} else {
console.info('!!!Use default swagger.yml,please add your own api.yml/api.json in the root dir.');
}
} catch (e) {
console.error('syncApiToPlugin error:', e);
}
}