@hubspot/cms-lib
Advanced tools
Comparing version 0.0.10 to 0.0.11
const { ALLOWED_EXTENSIONS } = require('./lib/constants'); | ||
const { | ||
loadConfig, | ||
getConfig, | ||
getPortalId, | ||
getPortalConfig, | ||
@@ -14,3 +16,5 @@ updatePortalConfig, | ||
getConfig, | ||
loadConfig, | ||
getPortalConfig, | ||
getPortalId, | ||
updatePortalConfig, | ||
@@ -17,0 +21,0 @@ sync, |
@@ -5,23 +5,46 @@ const yaml = require('js-yaml'); | ||
// TODO make the config overrideable via CLI `--config` param | ||
const configPath = findup('hubspot.config.yml'); | ||
let config; | ||
let configPath; | ||
if (!configPath) { | ||
throw new Error('A hubspot.config.yml file could not be found'); | ||
} | ||
const configFile = yaml.safeLoad(fs.readFileSync(configPath)); | ||
const writeConfig = () => { | ||
fs.writeFileSync( | ||
configPath, | ||
yaml.safeDump(JSON.parse(JSON.stringify(configFile, null, 2))) | ||
yaml.safeDump(JSON.parse(JSON.stringify(config, null, 2))) | ||
); | ||
}; | ||
const getConfig = () => configFile; | ||
const loadConfig = path => { | ||
configPath = path || findup('hubspot.config.yml'); | ||
if (!configPath) { | ||
throw new Error('A hubspot.config.yml file could not be found'); | ||
} | ||
config = yaml.safeLoad(fs.readFileSync(configPath)); | ||
}; | ||
const getConfig = () => { | ||
if (!config) { | ||
loadConfig(); | ||
} | ||
return config; | ||
}; | ||
const setConfig = updatedConfig => { | ||
config = updatedConfig; | ||
return config; | ||
}; | ||
const getPortalConfig = portalId => | ||
configFile.portals.find(portal => portal.portalId === portalId); | ||
config.portals.find(portal => portal.portalId === portalId); | ||
const getPortalId = name => { | ||
const portal = config.portals.find(p => p.name === name); | ||
if (portal) { | ||
return portal.portalId; | ||
} | ||
return null; | ||
}; | ||
const updatePortalConfig = configOptions => { | ||
@@ -58,6 +81,6 @@ const { | ||
if (portalConfig) { | ||
const index = configFile.portals.indexOf(portalConfig); | ||
configFile.portals[index] = nextPortalConfig; | ||
const index = config.portals.indexOf(portalConfig); | ||
config.portals[index] = nextPortalConfig; | ||
} else { | ||
configFile.portals.push(nextPortalConfig); | ||
config.portals.push(nextPortalConfig); | ||
} | ||
@@ -69,4 +92,7 @@ writeConfig(); | ||
getConfig, | ||
setConfig, | ||
loadConfig, | ||
getPortalConfig, | ||
getPortalId, | ||
updatePortalConfig, | ||
}; |
{ | ||
"name": "@hubspot/cms-lib", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Library for working with the HubSpot CMS", | ||
"main": "index.js", | ||
"dependencies": { | ||
"chokidar": "^2.1.5", | ||
"chokidar": "^3.0.1", | ||
"findup-sync": "^3.0.0", | ||
@@ -15,6 +15,9 @@ "fs-extra": "^7.0.1", | ||
}, | ||
"engines": { | ||
"node": ">=8.9.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "ab46a9bbb64fe2070cbb6cd7fb9dc52e5c918275" | ||
"gitHead": "6615c512ed462ade7b7744633931f6ef98057882" | ||
} |
21426
15
560
+ Addedanymatch@3.1.3(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedto-regex-range@5.0.1(transitive)
- Removedanymatch@2.0.0(transitive)
- Removedasync-each@1.0.6(transitive)
- Removedbinary-extensions@1.13.1(transitive)
- Removedbindings@1.5.0(transitive)
- Removedchokidar@2.1.8(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedfsevents@1.2.13(transitive)
- Removedglob-parent@3.1.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-binary-path@1.0.1(transitive)
- Removedis-glob@3.1.0(transitive)
- Removednan@2.20.0(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removedpath-dirname@1.0.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedreaddirp@2.2.1(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedupath@1.2.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedchokidar@^3.0.1