configorama 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/main.js +4 -4
- package/lib/resolvers/valueFromGit.js +141 -123
- package/package.json +9 -9
package/lib/main.js
CHANGED
|
@@ -13,7 +13,7 @@ const getValueFromString = require('./resolvers/valueFromString')
|
|
|
13
13
|
const getValueFromNumber = require('./resolvers/valueFromNumber')
|
|
14
14
|
const getValueFromEnv = require('./resolvers/valueFromEnv')
|
|
15
15
|
const getValueFromOptions = require('./resolvers/valueFromOptions')
|
|
16
|
-
const
|
|
16
|
+
const createGitResolver = require('./resolvers/valueFromGit')
|
|
17
17
|
/* Default File Parsers */
|
|
18
18
|
const YAML = require('./parsers/yaml')
|
|
19
19
|
const TOML = require('./parsers/toml')
|
|
@@ -88,7 +88,7 @@ class Configorama {
|
|
|
88
88
|
} else if (typeof fileOrObject === 'string') {
|
|
89
89
|
// read and parse file
|
|
90
90
|
const fileContents = fs.readFileSync(fileOrObject, 'utf-8')
|
|
91
|
-
const fileDirectory = path.dirname(fileOrObject)
|
|
91
|
+
const fileDirectory = path.dirname(path.resolve(fileOrObject))
|
|
92
92
|
const fileType = path.extname(fileOrObject)
|
|
93
93
|
|
|
94
94
|
let configObject
|
|
@@ -194,7 +194,7 @@ class Configorama {
|
|
|
194
194
|
},
|
|
195
195
|
|
|
196
196
|
// Git refs
|
|
197
|
-
|
|
197
|
+
createGitResolver(this.configPath),
|
|
198
198
|
/* Internal Resolvers */
|
|
199
199
|
// {
|
|
200
200
|
// match: funcRegex,
|
|
@@ -1671,7 +1671,7 @@ Please use ":" to reference sub properties`
|
|
|
1671
1671
|
|
|
1672
1672
|
function findNestedVariable(split, originalSource) {
|
|
1673
1673
|
return split.find((thing) => {
|
|
1674
|
-
if (originalSource) {
|
|
1674
|
+
if (originalSource && typeof originalSource === 'string') {
|
|
1675
1675
|
return originalSource.indexOf(`\${${thing}}`) > -1
|
|
1676
1676
|
}
|
|
1677
1677
|
return false
|
|
@@ -18,129 +18,145 @@ async function _exec(cmd, options = { timeout: 1000 }) {
|
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
function createResolver(cwd) {
|
|
22
|
+
async function _getValueFromGit(variableString) {
|
|
23
|
+
const variable = variableString.split(`${GIT_PREFIX}:`)[1]
|
|
24
|
+
let value = null
|
|
25
|
+
// console.log('variableStringvariableString', variableString)
|
|
26
|
+
if (variable.match(/^remote/i)) {
|
|
27
|
+
const hasParams = functionRegex.exec(variableString)
|
|
28
|
+
const remoteName = (hasParams && hasParams[2]) ? formatFunctionArgs(hasParams[2]) : 'origin'
|
|
29
|
+
value = await getGitRemote(remoteName)
|
|
30
|
+
return value
|
|
31
|
+
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
const verifyMsg = `Verify the cwd has a .git directory\n`
|
|
34
|
+
const normalizedVar = (variable || '').toLowerCase()
|
|
34
35
|
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
36
|
+
switch (normalizedVar) {
|
|
37
|
+
// Repo owner/name
|
|
38
|
+
case 'repo':
|
|
39
|
+
case 'repository':
|
|
40
|
+
case 'reposlug':
|
|
41
|
+
case 'repo-slug':
|
|
42
|
+
const urla = await getGitRemote()
|
|
43
|
+
const parseda = GitUrlParse(urla)
|
|
44
|
+
value = parseda.full_name
|
|
45
|
+
break;
|
|
46
|
+
// Repo name
|
|
47
|
+
case 'name':
|
|
48
|
+
case 'reponame': // repoName
|
|
49
|
+
case 'repo-name':
|
|
50
|
+
value = await _exec('basename `git rev-parse --show-toplevel`')
|
|
51
|
+
break;
|
|
52
|
+
// Repo org or owner
|
|
53
|
+
case 'org':
|
|
54
|
+
case 'owner':
|
|
55
|
+
case 'organization':
|
|
56
|
+
case 'repoowner': // repoOwner
|
|
57
|
+
case 'repo-owner':
|
|
58
|
+
const url = await getGitRemote()
|
|
59
|
+
const parsed = GitUrlParse(url)
|
|
60
|
+
value = parsed.organization || parsed.owner
|
|
61
|
+
break;
|
|
62
|
+
// Repo name
|
|
63
|
+
case 'dir':
|
|
64
|
+
case 'dirpath': // dirPath
|
|
65
|
+
case 'dir-path':
|
|
66
|
+
case 'dir_path':
|
|
67
|
+
const gitBasePath = await _exec('git rev-parse --show-toplevel')
|
|
68
|
+
if (cwd) {
|
|
69
|
+
const subPath = cwd.replace(gitBasePath, '')
|
|
70
|
+
const branch = await _exec('git rev-parse --abbrev-ref HEAD')
|
|
71
|
+
const url = await getGitRemote()
|
|
72
|
+
value = (subPath) ? `${url}/tree/${branch}${subPath}` : url
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
// Repo url
|
|
76
|
+
case 'url':
|
|
77
|
+
case 'repourl': // repoUrl
|
|
78
|
+
case 'repo-url':
|
|
79
|
+
value = await getGitRemote()
|
|
80
|
+
break;
|
|
81
|
+
// Current commit sha
|
|
82
|
+
case 'sha':
|
|
83
|
+
case 'sha1':
|
|
84
|
+
try {
|
|
85
|
+
value = await _exec('git rev-parse --short HEAD')
|
|
86
|
+
} catch (err) {
|
|
87
|
+
throw new Error(`\${git:sha1} error ${verifyMsg}`)
|
|
88
|
+
}
|
|
89
|
+
break
|
|
90
|
+
// Current commit full sha
|
|
91
|
+
case 'commit':
|
|
92
|
+
case 'commitsha':
|
|
93
|
+
case 'commit-sha':
|
|
94
|
+
case 'commithash':
|
|
95
|
+
case 'commit-hash':
|
|
96
|
+
try {
|
|
97
|
+
value = await _exec('git rev-parse HEAD')
|
|
98
|
+
} catch (err) {
|
|
99
|
+
throw new Error(`\${git:commit} error. ${verifyMsg}`)
|
|
100
|
+
}
|
|
101
|
+
break
|
|
102
|
+
// Branches
|
|
103
|
+
case 'branch':
|
|
104
|
+
case 'branchname':
|
|
105
|
+
case 'branch-name':
|
|
106
|
+
case 'currentbranch': // currentBranch
|
|
107
|
+
case 'current-branch':
|
|
108
|
+
try {
|
|
109
|
+
value = await _exec('git rev-parse --abbrev-ref HEAD')
|
|
110
|
+
} catch (err) {
|
|
111
|
+
throw new Error(`\${git:branch} error. ${verifyMsg}`)
|
|
112
|
+
}
|
|
113
|
+
break
|
|
114
|
+
// Commit msg
|
|
115
|
+
case 'msg':
|
|
116
|
+
case 'message':
|
|
117
|
+
case 'commitmessage': // commitMessage
|
|
118
|
+
case 'commit-message':
|
|
119
|
+
case 'commitmsg': // commitMsg
|
|
120
|
+
case 'commit-msg':
|
|
121
|
+
try {
|
|
122
|
+
value = await _exec('git log -1 --pretty=%B')
|
|
123
|
+
} catch (err) {
|
|
124
|
+
throw new Error(`\${git:message} error. ${verifyMsg}`)
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
// Git tags
|
|
128
|
+
case 'tag':
|
|
129
|
+
case 'describe':
|
|
130
|
+
try {
|
|
131
|
+
value = await _exec('git describe --always')
|
|
132
|
+
} catch (err) {
|
|
133
|
+
throw new Error(`\${git:describeLight} error. ${verifyMsg}`)
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
// Git tags
|
|
137
|
+
case 'describeLight':
|
|
138
|
+
case 'describelight':
|
|
139
|
+
case 'describe-light':
|
|
140
|
+
try {
|
|
141
|
+
value = await _exec('git describe --always --tags')
|
|
142
|
+
} catch (err) {
|
|
143
|
+
throw new Error(`\${git:describeLight} error. ${verifyMsg}`)
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
// Is branch dirty
|
|
147
|
+
case 'isDirty':
|
|
148
|
+
case 'isdirty':
|
|
149
|
+
case 'is-dirty':
|
|
150
|
+
const writeTree = await _exec('git write-tree')
|
|
151
|
+
const changes = await _exec(`git diff-index ${writeTree} --`)
|
|
152
|
+
value = `${changes.length > 0}`
|
|
153
|
+
break
|
|
154
|
+
default:
|
|
155
|
+
throw new Error(`Git variable ${variable} is unknown. Candidates are 'describe', 'describeLight', 'sha1', 'commit', 'branch', 'message', 'repository'`)
|
|
156
|
+
}
|
|
157
|
+
return value
|
|
142
158
|
}
|
|
143
|
-
return
|
|
159
|
+
return _getValueFromGit
|
|
144
160
|
}
|
|
145
161
|
|
|
146
162
|
async function getGitRemote(name = 'origin') {
|
|
@@ -182,7 +198,9 @@ async function getGitRemote(name = 'origin') {
|
|
|
182
198
|
}
|
|
183
199
|
}
|
|
184
200
|
|
|
185
|
-
module.exports = {
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
module.exports = function createGitResolver(cwd) {
|
|
202
|
+
return {
|
|
203
|
+
match: gitVariableSyntax,
|
|
204
|
+
resolver: createResolver(cwd)
|
|
205
|
+
}
|
|
188
206
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "configorama",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"description": "Variable support for configuration files",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"dot-prop": "^5.3.0",
|
|
32
32
|
"find-up": "^3.0.0",
|
|
33
33
|
"git-url-parse": "^14.0.0",
|
|
34
|
-
"js-yaml": "^3.14.
|
|
35
|
-
"json5": "^2.
|
|
36
|
-
"lodash": "^4.17.
|
|
37
|
-
"promise.prototype.finally": "^3.1.
|
|
34
|
+
"js-yaml": "^3.14.1",
|
|
35
|
+
"json5": "^2.2.3",
|
|
36
|
+
"lodash": "^4.17.21",
|
|
37
|
+
"promise.prototype.finally": "^3.1.8",
|
|
38
38
|
"replaceall": "^0.1.6",
|
|
39
39
|
"sync-rpc": "^1.3.6",
|
|
40
|
-
"traverse": "^0.6.
|
|
40
|
+
"traverse": "^0.6.8"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"ava": "^2.
|
|
44
|
-
"markdown-magic": "^
|
|
45
|
-
"minimist": "^1.2.
|
|
43
|
+
"ava": "^2.4.0",
|
|
44
|
+
"markdown-magic": "^2.6.1",
|
|
45
|
+
"minimist": "^1.2.8"
|
|
46
46
|
},
|
|
47
47
|
"ava": {
|
|
48
48
|
"files": [
|