@app-config/git
Advanced tools
Comparing version 2.1.5 to 2.1.6
import simpleGit from 'simple-git'; | ||
import { AppConfigError } from '@app-config/core'; | ||
import { forKey, validateOptions } from '@app-config/extension-utils'; | ||
/** Access to the git branch and commit ref */ | ||
export default function gitRefDirectives(getStatus = gitStatus) { | ||
return (value, [_, key]) => { | ||
if (key === '$git') { | ||
return async (parse) => { | ||
if (typeof value !== 'string') { | ||
throw new AppConfigError('$git directive should be passed a string'); | ||
} | ||
switch (value) { | ||
case 'commit': | ||
return getStatus().then(({ commitRef }) => parse(commitRef, { shouldFlatten: true })); | ||
case 'commitShort': | ||
return getStatus().then(({ commitRef }) => parse(commitRef.slice(0, 7), { shouldFlatten: true })); | ||
case 'branch': | ||
case 'branchName': | ||
return getStatus().then(({ branchName }) => { | ||
if (!branchName) { | ||
throw new AppConfigError('The $git directive tried to retrieve branchname, but it appears no branch is checked out'); | ||
} | ||
return parse(branchName, { shouldFlatten: true }); | ||
}); | ||
case 'tag': | ||
return getStatus().then(({ tag }) => { | ||
return parse(tag ?? null, { shouldFlatten: true }); | ||
}); | ||
default: | ||
throw new AppConfigError('$git directive was not passed a valid option'); | ||
} | ||
}; | ||
return forKey('$git', validateOptions((SchemaBuilder) => SchemaBuilder.stringSchema(), (value) => async (parse) => { | ||
switch (value) { | ||
case 'commit': | ||
return getStatus().then(({ commitRef }) => parse(commitRef, { shouldFlatten: true })); | ||
case 'commitShort': | ||
return getStatus().then(({ commitRef }) => parse(commitRef.slice(0, 7), { shouldFlatten: true })); | ||
case 'branch': | ||
case 'branchName': | ||
return getStatus().then(({ branchName }) => { | ||
if (!branchName) { | ||
throw new AppConfigError('The $git directive tried to retrieve branchname, but it appears no branch is checked out'); | ||
} | ||
return parse(branchName, { shouldFlatten: true }); | ||
}); | ||
case 'tag': | ||
return getStatus().then(({ tag }) => { | ||
return parse(tag ?? null, { shouldFlatten: true }); | ||
}); | ||
default: | ||
throw new AppConfigError('$git directive was not passed a valid option'); | ||
} | ||
return false; | ||
}; | ||
})); | ||
} | ||
@@ -36,0 +29,0 @@ async function gitStatus() { |
@@ -8,34 +8,27 @@ "use strict"; | ||
const core_1 = require("@app-config/core"); | ||
const extension_utils_1 = require("@app-config/extension-utils"); | ||
/** Access to the git branch and commit ref */ | ||
function gitRefDirectives(getStatus = gitStatus) { | ||
return (value, [_, key]) => { | ||
if (key === '$git') { | ||
return async (parse) => { | ||
if (typeof value !== 'string') { | ||
throw new core_1.AppConfigError('$git directive should be passed a string'); | ||
} | ||
switch (value) { | ||
case 'commit': | ||
return getStatus().then(({ commitRef }) => parse(commitRef, { shouldFlatten: true })); | ||
case 'commitShort': | ||
return getStatus().then(({ commitRef }) => parse(commitRef.slice(0, 7), { shouldFlatten: true })); | ||
case 'branch': | ||
case 'branchName': | ||
return getStatus().then(({ branchName }) => { | ||
if (!branchName) { | ||
throw new core_1.AppConfigError('The $git directive tried to retrieve branchname, but it appears no branch is checked out'); | ||
} | ||
return parse(branchName, { shouldFlatten: true }); | ||
}); | ||
case 'tag': | ||
return getStatus().then(({ tag }) => { | ||
return parse(tag !== null && tag !== void 0 ? tag : null, { shouldFlatten: true }); | ||
}); | ||
default: | ||
throw new core_1.AppConfigError('$git directive was not passed a valid option'); | ||
} | ||
}; | ||
return extension_utils_1.forKey('$git', extension_utils_1.validateOptions((SchemaBuilder) => SchemaBuilder.stringSchema(), (value) => async (parse) => { | ||
switch (value) { | ||
case 'commit': | ||
return getStatus().then(({ commitRef }) => parse(commitRef, { shouldFlatten: true })); | ||
case 'commitShort': | ||
return getStatus().then(({ commitRef }) => parse(commitRef.slice(0, 7), { shouldFlatten: true })); | ||
case 'branch': | ||
case 'branchName': | ||
return getStatus().then(({ branchName }) => { | ||
if (!branchName) { | ||
throw new core_1.AppConfigError('The $git directive tried to retrieve branchname, but it appears no branch is checked out'); | ||
} | ||
return parse(branchName, { shouldFlatten: true }); | ||
}); | ||
case 'tag': | ||
return getStatus().then(({ tag }) => { | ||
return parse(tag !== null && tag !== void 0 ? tag : null, { shouldFlatten: true }); | ||
}); | ||
default: | ||
throw new core_1.AppConfigError('$git directive was not passed a valid option'); | ||
} | ||
return false; | ||
}; | ||
})); | ||
} | ||
@@ -42,0 +35,0 @@ exports.default = gitRefDirectives; |
{ | ||
"name": "@app-config/git", | ||
"description": "$git directive parsing extension for @app-config", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"license": "MPL-2.0", | ||
@@ -33,7 +33,8 @@ "author": { | ||
"dependencies": { | ||
"@app-config/core": "^2.1.5", | ||
"@app-config/core": "^2.1.6", | ||
"@app-config/extension-utils": "^2.1.6", | ||
"simple-git": "2" | ||
}, | ||
"devDependencies": { | ||
"@app-config/test-utils": "^2.1.5" | ||
"@app-config/test-utils": "^2.1.6" | ||
}, | ||
@@ -40,0 +41,0 @@ "prettier": "@lcdev/prettier", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9654
3
105
+ Added@app-config/extension-utils@2.8.7(transitive)
+ Added@serafin/schema-builder@0.14.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedextsprintf@1.4.1(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedverror@1.10.1(transitive)
Updated@app-config/core@^2.1.6