UNPKG

1.57 kBJavaScriptView Raw
1const
2 { removeSync } = require('fs-extra')
3
4const
5 appPaths = require('../app-paths'),
6 extensionJson = require('./extension-json')
7
8/**
9 * API for extension's /uninstall.js script
10 */
11module.exports = class UninstallAPI {
12 constructor ({ extId, prompts }) {
13 this.extId = extId
14 this.prompts = prompts
15 this.resolve = appPaths.resolve
16 this.appDir = appPaths.appDir
17
18 this.__hooks = {
19 exitLog: []
20 }
21 }
22
23 /**
24 * Get the internal persistent config of this extension.
25 * Returns empty object if it has none.
26 *
27 * @return {object} internal persistent config of this extension
28 */
29 getPersistentConf () {
30 return extensionJson.getInternal(this.extId)
31 }
32
33 /**
34 * Check if another app extension is installed.
35 *
36 * @param {string} extId
37 * @return {boolean} has the extension installed.
38 */
39 hasExtension (extId) {
40 return extensionJson.has(extId)
41 }
42
43 /**
44 * Remove a file or folder from devland which the
45 * extension has installed and is no longer needed.
46 *
47 * Be careful about it and do not delete the files
48 * that would break developer's app.
49 *
50 * The __path (file or folder) needs to be relative
51 * to project's root folder.
52 *
53 * @param {string} __path
54 */
55 removePath (__path) {
56 removeSync(appPaths.resolve.app(__path))
57 }
58
59 /**
60 * Add a message to be printed after App CLI finishes up install.
61 *
62 * @param {string} msg
63 */
64 onExitLog (msg) {
65 this.__hooks.exitLog.push(msg)
66 }
67
68 /**
69 * Private methods
70 */
71
72 __getHooks () {
73 return this.__hooks
74 }
75}