-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigurationManager.js
73 lines (63 loc) · 1.84 KB
/
configurationManager.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
'use babel'
'use strict'
const path = require('path')
const fsp = require('fs-promise')
const PROJECT_ROOT = /\${workspaceRoot}/g
const ATTACH_RESOURCE = /\${attachPackage}/g
const MAIN_NODE_MODULES_PATH = /\${mainNodeModulesPath}/g
class ConfigurationManager {
getWatchFilePath () {
const _this = this
return this._getConfigObject()
.then((configObject) => {
return _this._parse(configObject.main)
})
}
getConfig () {
const _this = this
return this._getConfigObject()
.then((configObject) => {
let configString = JSON.stringify(configObject)
return JSON.parse(_this._parse(configString))
})
}
getLaunchConfig () {
const _this = this
return this._getConfigObject()
.then((configObject) => {
if (!configObject) {
throw new Error('configuration not found')
} else {
return {
appid: configObject.launch.appid,
path: _this._parse(configObject.launch.path)
}
}
})
}
_getConfigObject () {
if (!this.lanuchConfigPath) {
let projectPath = this._projectPath()
if (projectPath) {
this.lanuchConfigPath = path.join(projectPath, '.thera', 'launch.json')
} else {
return Promise.resolve(undefined)
}
}
return fsp.readJson(this.lanuchConfigPath)
}
_parse (value) {
let projectPath = this._projectPath()
return value.replace(PROJECT_ROOT, projectPath)
.replace(ATTACH_RESOURCE, path.join(atom.config.resourcePath, 'node_modules'))
.replace(MAIN_NODE_MODULES_PATH, path.join(atom.config.resourcePath, 'node_modules'))
}
_projectPath () {
let projectPath
if (atom.project.getDirectories()[0]) {
projectPath = atom.project.getDirectories()[0].path
}
return projectPath
}
}
module.exports = new ConfigurationManager()