overlays-cli
Advanced tools
Comparing version 0.1.0 to 0.2.0
54
index.js
@@ -1,31 +0,33 @@ | ||
const Nimma = require('nimma').default | ||
const axios = require('axios') | ||
const getStdin = require('./get-stdin') | ||
const applyOverlay = require('./apply-overlay') | ||
const unset = require('lodash/unset') | ||
const set = require('lodash/set') | ||
const get = require('lodash/get') | ||
const overlaysSchema = require('./overlays.schema.json') | ||
const jsYaml = require('js-yaml') | ||
const Ajv = require('ajv') | ||
const ajv = new Ajv({allErrors: true}) // options can be passed, e.g. {allErrors: true} | ||
const validateOverlays = ajv.compile(overlaysSchema) | ||
module.exports = { | ||
applyOverlay | ||
} | ||
run().then(console.log, (err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) | ||
async function applyOverlay(overlay, resolver) { | ||
const source = await resolver(overlay.extends) | ||
const {actions} = overlay | ||
actions.forEach(action => { | ||
const n = new Nimma([action.target]); | ||
n.query(source, { | ||
[action.target]({ path }) { | ||
if(action.remove === true) { | ||
unset(source, path) | ||
} else if(action.update && typeof action.update === 'object') { | ||
let merged = Object.assign({}, get(source, path), action.update) | ||
set(source, path, merged) | ||
} else if(typeof action.update !== 'undefined') { | ||
set(source, path, action.update) | ||
} | ||
}, | ||
}); | ||
// Functions | ||
async function run() { | ||
const overlay = jsYaml.load(await getStdin()) | ||
const valid = validateOverlays(overlay) | ||
if(!valid) { | ||
throw validateOverlays.errors | ||
} | ||
}) | ||
return source | ||
const applied = await applyOverlay(overlay, extendsResolver) | ||
return jsYaml.dump(applied) | ||
} | ||
async function extendsResolver(url) { | ||
const {data} = await axios.get(url) | ||
if(typeof data === 'string') | ||
return jsYaml.load(data) | ||
return data | ||
} |
{ | ||
"name": "overlays-cli", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A cli tool to execute an Overlays document. See https://github.com/OAI/Overlay-Specification/", | ||
@@ -17,2 +17,3 @@ "bin": { | ||
"dependencies": { | ||
"axios": "^0.27.2", | ||
"js-yaml": "^4.1.0", | ||
@@ -19,0 +20,0 @@ "lodash": "^4.17.21", |
const fs = require('fs'); | ||
const path = require('path') | ||
const jsYaml = require('js-yaml') | ||
const {applyOverlay} = require('./index') | ||
const applyOverlay = require('./apply-overlay') | ||
@@ -6,0 +6,0 @@ describe('Test Suite', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8344
16
145
4
+ Addedaxios@^0.27.2
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@0.27.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)