-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add addon:config & update addon:create command
- Loading branch information
1 parent
aa7c6ac
commit 8adfa6f
Showing
12 changed files
with
492 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const fetch = require('node-fetch') | ||
|
||
async function getAddonManifest(addonName, netlifyApiToken) { | ||
const url = `https://api.netlify.com/api/v1/services/${addonName}/manifest` | ||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${netlifyApiToken}` | ||
} | ||
}) | ||
|
||
const data = await response.json() | ||
|
||
if (response.status === 422) { | ||
throw new Error(`Error ${JSON.stringify(data)}`) | ||
} | ||
|
||
return data | ||
} | ||
|
||
module.exports = getAddonManifest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const isEqual = require('lodash.isequal') | ||
|
||
module.exports = function compare(oldValues, newValues) { | ||
const initialData = { | ||
// default everything is equal | ||
isEqual: true, | ||
// Keys that are different | ||
keys: [], | ||
// Values of the keys that are different | ||
diffs: {} | ||
} | ||
|
||
const oldKeys = Object.keys(oldValues) | ||
const newKeys = Object.keys(newValues) | ||
const set = new Set(newKeys.concat(oldKeys)) | ||
|
||
return Array.from(set).reduce((acc, current) => { | ||
// if values not deep equal. There are changes | ||
if (!isEqual(newValues[current], oldValues[current])) { | ||
return { | ||
isEqual: false, | ||
keys: acc.keys.concat(current), | ||
diffs: Object.assign({}, acc.diffs, { | ||
[`${current}`]: { | ||
newValue: newValues[current], | ||
oldValue: oldValues[current] | ||
} | ||
}) | ||
} | ||
} | ||
return acc | ||
}, initialData) | ||
} | ||
|
||
// const newValues = { | ||
// lol: 'byelol', | ||
// } | ||
// const oldValues = { | ||
// lol: 'bye', | ||
// cool: 'dddd' | ||
// } | ||
|
||
// const diffs = compareNewToOld(newValues, oldValues) | ||
// console.log('diffs', diffs) | ||
|
||
// const diff = diffValues(oldValues, newValues) | ||
// if (diff) { | ||
// console.log(`Config updates\n`) | ||
// console.log(`${diff}\n`) | ||
// // from '${currentState}' to '${newInput}' | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const concordance = require('concordance') | ||
const { concordanceOptions, concordanceDiffOptions } = require('./options') | ||
|
||
function formatDescriptorDiff(actualDescriptor, expectedDescriptor, options) { | ||
const diffOptions = Object.assign({}, options, concordanceDiffOptions) | ||
return concordance.diffDescriptors(actualDescriptor, expectedDescriptor, diffOptions) | ||
} | ||
|
||
module.exports = function diffValues(actual, expected) { | ||
const result = concordance.compare(actual, expected, concordanceOptions) | ||
if (result.pass) { | ||
return null | ||
} | ||
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions) | ||
const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions) | ||
|
||
return formatDescriptorDiff(actualDescriptor, expectedDescriptor) | ||
} |
Oops, something went wrong.