forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension-json.js
92 lines (76 loc) · 1.94 KB
/
extension-json.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const fs = require('fs')
const { log, fatal } = require('../helpers/logger')
const chalk = require('chalk')
const appPaths = require('../app-paths')
const extensionPath = appPaths.resolve.app('quasar.extensions.json')
class ExtensionJson {
constructor () {
if (!fs.existsSync(extensionPath)) {
this.extensions = {}
return
}
try {
this.extensions = require(extensionPath)
}
catch (e) {
console.log(e)
fatal(`[FAIL] quasar.extensions.json is malformed`)
}
}
list () {
if (Object.keys(this.extensions).length === 0) {
log(' No App Extensions are installed')
log(' You can look for "quasar-app-extension-*" in npm registry.')
return
}
log('Listing installed App Extensions')
log()
for (let ext in this.extensions) {
console.log('Extension name: ' + chalk.green(ext))
console.log('Extension prompts: ' + JSON.stringify(this.extensions[ext], null, 2))
console.log()
}
}
getList () {
return this.extensions
}
set (extId, opts) {
log(`Updating /quasar.extensions.json for "${extId}" extension ...`)
this.extensions[extId] = opts
this.__save()
}
setInternal (extId, opts) {
const cfg = this.get(extId)
cfg.__internal = opts
this.set(extId, cfg)
}
remove (extId) {
if (this.has(extId)) {
log(`Removing "${extId}" extension from /quasar.extensions.json ...`)
delete this.extensions[extId]
this.__save()
}
}
get (extId) {
return this.extensions[extId] || {}
}
getPrompts (extId) {
const { __internal, ...prompts } = this.get(extId)
return prompts
}
getInternal (extId) {
const cfg = this.get(extId)
return cfg.__internal || {}
}
has (extId) {
return this.extensions[extId] !== void 0
}
__save () {
fs.writeFileSync(
extensionPath,
JSON.stringify(this.extensions, null, 2),
'utf-8'
)
}
}
module.exports = new ExtensionJson()