function cacheOnDisk(registry) { return mkdirp(CACHE_HOME) .then(() => fs.writeFile(CACHE_FILE, JSON.stringify(registry), "utf8")) .then(() => registry); }
function set(entries) { if (typeof entries !== "object" || !Object.keys(entries).length) { return Promise.reject( new Error( "config.set() requires an object with configuration key/value pairs" ) ); } return get() .catch(error => { // ENOENT errors (file absence) will be ignored if (error.code === "ENOENT") return {}; throw error; }) .then(prevConfig => ({ ...prevConfig, ...entries })) .then(config => JSON.stringify(config, null, " ")) .then(json => { return mkdirp(CONFIG_HOME).then(fs.writeFile(CONFIG_FILE, json, "utf8")); }); }
function fetchInDisk(keys, options) { return mkdirp(DSAFIO_DATA_HOME) .then(fetch(keys)) .then(challenges => { return Promise.all( challenges.map(challenge => { return mkdirp(`${DSAFIO_DATA_HOME}/${challenge.title}`).then(() => { return Promise.all( challenge.files.map(function(file) { const filepath = `${DSAFIO_DATA_HOME}/${challenge.title}/${file.name}`; return fs.writeFile(filepath, file.content, "utf8"); }) ); }); }) ).then(() => undefined); // noop }); }
ensureAssetCacheDirectory(path) { return exists(path).then(exists => exists || mkdirp(path)); }