async function storeToken(token) { try { fs.mkdirSync(TOKEN_DIR); } catch (err) { if (err.code !== 'EEXIST') { throw err; } } await fs.promises.writeFile(TOKEN_PATH, JSON.stringify(token)); }
const guardarObjeto = async (ruta, totales) => { const datos = JSON.stringify(totales) await fs.writeFile(ruta, datos) console.log( `Los totales acumulados de seguros quedaron guardados en ${archivoOut}.` ) }
fetch("https://www.sony.net/united/clock/assets/js/heritage_data.js") .then(async function (res) { let data = new Function(await res.text() + " return a_clock_heritage_data;")(); let pid = Math.floor(Math.random() * data.length); let number = Math.ceil(new Date().getHours() / 2); if (number === 0) number = 1; let image = await fetch(`https://www.sony.net/united/clock/share/img/photo/${data[pid].id}/fp_hd/${(number < 10 ? "0" : "") + number}.jpg`).catch(self.close); fs.writeFile(process.env.HOME + "/.config/wallpaper.jpg", Buffer.from(await image.arrayBuffer())) .then(e => self.close()).catch(console.error); }).catch(self.close);
const main = async () => { for (let i = 0; i < tables.length; i++) { const data = await db.select().from(tables[i]); const yaml = YAML.stringify(data); await fs.writeFile(path.join(__dirname, 'seeds', 'data', `${tables[i]}.yml`), yaml); } db.destroy(); }
/** * Guardado de resultados en salida. * * @param {*} ruta * @param {*} datos */ const guardarResultado = (ruta, datos) => { fsp.writeFile(ruta, datos) activarLogs && console.log(`Guardando datos en ${ruta} ->`, datos) }
/** * Update a file using a dictionary * @method updateFile * @param {Object} dictionary A key-value dictionary * @param {String} [filePath=''] The path for the file * @return {Promise} */ async function updateFile(dictionary, filePath = '') { const resolvedFilePath = utils.files.resolvePath(filePath); const originalFile = await fs.readFile(resolvedFilePath, 'utf8'); const generatedFile = utils.string.replaceByDictionary(originalFile, dictionary); await fs.writeFile(resolvedFilePath, generatedFile); console.log(`File ${resolvedFilePath} updated`); }
confirmButton.addEventListener("click", () => { modal.addEventListener("hidden.bs.modal", () => { modal.remove(); }); modal.controller.hide(); if (file.classList.contains("active")) { let newFile = path.join(baseDir, file.tab.input.value); fsp.writeFile(newFile, "", "utf-8").catch(reject).then(() => resolve(newFile)); } else { let newFolder = path.join(baseDir, folder.tab.input.value); fsp.mkdir(newFolder).catch(reject).then(() => resolve(newFolder)); } });
const save = async sitemap => { // Build the XML const urlset = builder.create('urlset'); urlset.att('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); urlset.att('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); urlset.att('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'); sitemap.forEach(item => { const url = urlset.ele('url'); url.ele('loc', config.baseURL + item.loc); url.ele('priority', item.priority); }); // Save the XML const xml = urlset.end({ pretty: true }); await fs.writeFile(path.join(__dirname, '..', 'Public', 'sitemap.xml'), xml); }
/** * Saves the current session object as session_user_id.session */ async save() { if (this.sessionUserId) { const str = JSON.stringify(this, function(key, value) { if (typeof value === 'bigint') { return value.toString() + 'n' } else { return value } }) await fs.writeFile(`${this.sessionUserId}.session`, str) } }
click() { if (currentFile) fs.writeFile(currentFile, el.textarea.value, "utf-8") .then(() => new Snackbar("File was saved")) .catch(() => new Snackbar('There was a problem saving the file')); else nav.saveDrop.menu.getMenuItemById("saveAs").click(); }
async updateMainChangelog() { const { versionComponents, newVersion } = this; // Remove the leading 'v'. const lastRef = this.getLastRef().substring(1); const mainChangelogPath = path.resolve('CHANGELOG.md'); const data = await fs.readFile(mainChangelogPath, 'utf8'); const arr = data.split('\n'); const hrefLink = `doc/changelogs/CHANGELOG_V${versionComponents.major}.md`; const newRefLink = `<a href="${hrefLink}#${newVersion}">${newVersion}</a>`; const lastRefLink = `<a href="${hrefLink}#${lastRef}">${lastRef}</a>`; for (let idx = 0; idx < arr.length; idx++) { if (arr[idx].includes(`<b>${lastRefLink}</b><br/>`)) { arr.splice(idx, 1, `<b>${newRefLink}</b><br/>`, `${lastRefLink}<br/>`); break; } }; await fs.writeFile(mainChangelogPath, arr.join('\n')); }
function save() { currentFile = currentFile || (Shell.uniqueId() + ".md"); fs.promises.writeFile(path.join(notesLocation, currentFile), "# " + noteName.value + "\n" + noteArea.value, "utf-8").then(console.log); }
const escribirArchivo = async (filePath, data) => { return fs.promises.writeFile(filePath, data) }
/** * Write the auth data json in the file * @method update * @param {String} [property='all'] The property to be updated * @param {String|Array|Object} [data=''] The value to be updated * @param {String} filePath The path of the file * @return {Promise} */ update(property = 'all', value = '', filePath = this.settingsPath) { if (property !== 'all') { this[property] = value; } const json = JSON.stringify(this, null, 2); return fs.writeFile(filePath, json); }
const escribirArchivo = async (filePath, data) => { return fs.promises.writeFile(filePath, data) }