const saveConfiguration = (version) => { const config = { version: version, mode: cli['--mode'], user: cli['--user'], } return fs.writeFileAsync(configFile, yaml.safeDump(config)) }
async function replaceRegexInFile(file, search, replace){ let contents = await fs.readFileAsync(file, 'utf8') let replaced_contents = contents.replace(search, () => { return "`<style>" + replace + "</style>`"; }); let tmpfile = `${file}.jstmpreplace`; await fs.writeFileAsync(tmpfile, replaced_contents, 'utf8') await fs.renameAsync(tmpfile, file) return true }
// Write profile in file async writeProfile() { if (this.output === 'yaml') { return writeYamlAsync(`${this.input}.yml`, this.dataProfile); } return writeFileAsync( `${this.input}.json`, JSON.stringify(this.dataProfile, null, 2) ); }
function exportSchema(tableName, file, region, endpoint) { const dynamoDb = new AWS.DynamoDB({ region }); if (endpoint) dynamoDb.endpoint = endpoint; return dynamoDb.describeTable({ TableName: tableName }).promise() .then(data => { const table = data.Table; const file2 = file || sanitizeFilename(tableName + '.dynamoschema'); return fs.writeFileAsync(file2, JSON.stringify(table, null, 2)) }); }
const getServerId = async function () { const idFile = path.join(__dirname, '..', 'id.txt') try { const id = await fs.readFileAsync(idFile) return id } catch (e) { const newId = uuid() await fs.writeFileAsync(idFile, newId) return newId } }
const writeTestAndExternalData = async ({ testObj, packagedArguments }) => { console.log('Writing test for: ', testObj.filePath); mkdirp.sync(path.dirname(testObj.filePath)); const testFileName = getTestFileNameForFile(testObj.filePath, packagedArguments); const testFilePromise = writeFileAsync(testFileName, testObj.fileString); const externalDataPromises = testObj.externalData.map((ed) => { console.log('Creating dir:', path.dirname(ed.filePath)); console.log('Dumping: ', ed.filePath); mkdirp.sync(path.dirname(ed.filePath)); // TODO: Make async return writeFileAsync(ed.filePath, ed.fileString); }); return Promise.all([testFilePromise, ...externalDataPromises]); }
/** * It writes the keystore into a file. * * @param {String} keyStoreFilePath The keystore file path destination. */ async writeKeyStoreToFileAsync(keyStore, keyStoreFilePath) { const parsedkeyStoreFilePath = keyStoreFilePath.split(/[\r\n]+/).shift() const fileName = `${parsedkeyStoreFilePath}/UTC--${new Date().toISOString()}--${keyStore.address}` await writeFileAsync(fileName, JSON.stringify(keyStore)) this.log.info({ fn: 'generateKeyStore', fileName }, 'Generate keyStore file.') return fileName }
test('rm.all deletes content and index dirs', t => { const fixture = new Tacks(CacheContent({ [INTEGRITY]: CONTENT })) fixture.create(CACHE) return index.insert(CACHE, KEY, INTEGRITY, { metadata: METADATA }).then(() => { return fs.mkdirAsync(path.join(CACHE, 'tmp')) }).then(() => { return fs.writeFileAsync(path.join(CACHE, 'other.js'), 'hi') }).then(() => { return rm.all(CACHE) }).then(() => { return fs.readdirAsync(CACHE) }).then(files => { t.deepEqual(files.sort(), [ 'other.js', 'tmp' ], 'removes content and index directories without touching other stuff') }) })
async function captureSnapshots (ow) { await writeFileAsync('./tests/snapshots/profile.json', JSON.stringify(await ow.player(account))) await writeFileAsync('./tests/snapshots/stats.json', JSON.stringify(await ow.playerStats(account, 'pc'))) }
fs.readFileAsync(path.resolve(__dirname, '../' + sourceFile), 'utf8') .then(function(data) { if (modelName) { data = fillTemplatePlaceholders(data, modelName); } return fs.writeFileAsync(novemberDir() + targetFile, data, 'utf8'); }) .then(function() { console.log(('Generated ' + targetFile).data); resolver.resolve(); }) .catch(function(err) { resolver.reject(err); });
suite.add('content.read.copy() small data', { defer: true, setup () { const fixture = new Tacks(CacheContent({ [INTEGRITY]: CONTENT })) fixture.create(CACHE) }, fn (deferred) { if (read.copy) { read.copy(CACHE, INTEGRITY, path.join(CACHE, 'data')) .then( () => deferred.resolve(), err => deferred.reject(err) ) } else { read(CACHE, INTEGRITY) .then(data => fs.writeFileAsync(path.join(CACHE, 'data'), data)) .then( () => deferred.resolve(), err => deferred.reject(err) ) } } })
// Get current contents of router.js file and remove last part fs.readFileAsync(nov.novemberDir() + 'app/router.js', 'utf8') .then(function(fileContents) { routerContents = fileContents.substr(0, fileContents.lastIndexOf('}')); return fs.readFileAsync(nov.templateDir('router-action.js'), 'utf8'); }) // Inject the code for a new route and save the new router.js file .then(function(actionCode) { actionCode = nov.fillTemplatePlaceholders(actionCode, actionName); routerContents = routerContents + actionCode + routerFileEnding; return fs.writeFileAsync(nov.novemberDir() + 'app/router.js', routerContents, 'utf8'); }) // Add action file .then(function() { var templateFile = 'template-files/action.js'; var targetPath = 'app/actions/' + inflect.dasherize(actionName) + '.js'; return nov.generateFile(templateFile, targetPath, actionName); }) .then(function() { finalResolver.resolve(); }) .catch(function(err) { finalResolver.reject(err); });
async function writeResource (config, resources) { const list = { apiVersion: 'v1', kind: 'List', items: resources }; try { // Create the directory await helpers.createDir(`${config.projectLocation}/${DEFAULT_NODESHIFT_RESOURCE_DIR}`); // Now write the json to a file await writeFileAsync(`${config.projectLocation}/${DEFAULT_NODESHIFT_RESOURCE_DIR}/openshift.json`, JSON.stringify(list, null, 2), { encoding: 'utf8' }); // Then write the yaml to a file await writeFileAsync(`${config.projectLocation}/${DEFAULT_NODESHIFT_RESOURCE_DIR}/openshift.yaml`, jsyaml.safeDump(list, { skipInvalid: true }), { encoding: 'utf8' }); logger.info(`openshift.yaml and openshift.json written to ${config.projectLocation}/${DEFAULT_NODESHIFT_RESOURCE_DIR}/`); } catch (err) { logger.error(`error writing files: ${err}`); return Promise.reject(err); } return list; }
// Build Documentation documentation .build(['index.js'], { shallow: true, hljs: { highlightAuto: true, languages: ['js', 'json'] } }) .then(res => { return documentation.formats.md(res, { paths, hljs: { highlightAuto: true, languages: ['js', 'json'] } }); }) .then(output => { output = output.replace(/\n(#+)\s/g, '___\n$1 '); return fs.writeFileAsync(`${__dirname}/API.md`, output); }) .catch(function(err) { console.warn('error when parsing file'); console.error(err); return; });
suite.add('content.read.copy() big data', { defer: true, setup () { const fixture = new Tacks(CacheContent({ [BIGINTEGRITY]: BIGCONTENT })) fixture.create(CACHE) }, fn (deferred) { if (read.copy) { read.copy(CACHE, BIGINTEGRITY, path.join(CACHE, 'bigdata')) .then( () => deferred.resolve(), err => deferred.reject(err) ) } else { read(CACHE, BIGINTEGRITY) .then(data => fs.writeFileAsync(path.join(CACHE, 'bigdata'), data)) .then( () => deferred.resolve(), err => deferred.reject(err) ) } } })