forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-api.js
72 lines (62 loc) · 1.82 KB
/
get-api.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const appPaths = require('../app-paths')
const { fatal } = require('./logger')
module.exports = async function getApi(item) {
try {
const api = require(
require.resolve(`quasar/dist/api/${item}.json`, {
paths: [appPaths.appDir]
})
)
return {
api
}
}
catch (e) {}
const extensionJson = require('../app-extension/extension-json')
const extensions = Object.keys(extensionJson.getList())
if (extensions.length > 0) {
const Extension = require('../app-extension/Extension.js')
for (let ext of extensions) {
const instance = new Extension(ext)
const hooks = await instance.run({})
if (hooks.describeApi !== void 0 && hooks.describeApi[item]) {
const fs = require('fs')
const path = require('path')
let file
const {
callerPath,
relativePath
} = hooks.describeApi[item]
if (relativePath.charAt(0) === '~') {
try {
file = relativePath.slice(1)
file = require.resolve(
file, {
paths: [callerPath, appPaths.appDir]
}
)
}
catch (e) {
fatal(`Extension(${instance.extId}): registerDescribeApi - there is no package "${file}" installed`)
}
}
else {
file = path.resolve(callerPath, relativePath)
if (!fs.existsSync(file)) {
fatal(`Extension(${instance.extId}): registerDescribeApi - there is no file at ${file}`)
}
}
try {
return {
api: require(file),
supplier: instance.extId
}
}
catch (e) {
fatal(`Extension(${instance.extId}): Malformed API file at ${file}`)
}
}
}
}
fatal(`No API found for requested "${item}"\n`)
}