forked from streetsidesoftware/cspell-dicts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
50 lines (39 loc) · 1 KB
/
util.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
'use strict';
// Cspell:word configstore
var Configstore = require('configstore');
var Path = require('path');
var packageName = 'cspell';
var importPath = 'import';
var configLocation = Path.join(__dirname, 'cspell-ext.json');
function getImports(conf) {
var imports = conf.get(importPath);
imports = imports || [];
if (typeof imports === 'string') {
imports = [imports];
}
return imports;
}
function install() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */
var imports = getImports(conf);
if (imports.indexOf(configLocation) < 0) {
imports.push(configLocation);
conf.set(importPath, imports);
}
}
function uninstall() {
var conf = new Configstore(packageName);
/** @type {string[]|string|undefined} */
var imports = getImports(conf);
var index = imports.indexOf(configLocation);
if (index >= 0) {
imports.splice(index, 1);
conf.set(importPath, imports);
}
}
module.exports = {
install,
uninstall,
configLocation,
};