function initLogs( timestamp ) { const dir = path.join( E2E_DIR, 'logs', `${ timestamp }` ); mkdirSync( dir, { recursive: true } ); const appLogPath = path.join( dir, `app-${ timestamp }.log` ); const driverLogPath = path.join( dir, `chromedriver-${ timestamp }.log` ); const appLogFd = openSync( appLogPath, 'a' ); const driverLogFd = openSync( driverLogPath, 'a' ); if ( ! appLogFd || ! driverLogFd ) { throw 'failed to initialize logs'; } const appLog = { path: appLogPath, fd: appLogFd }; const driverLog = { path: driverLogPath, fd: driverLogFd }; return { appLog, driverLog }; }
function createDatabase(file){ var db = new sqlite3.Database(file); if(!fs.existsSync(file)){ console.log("creating database file"); fs.openSync(file, "w"); db.run("CREATE TABLE users (username TEXT, password TEXT, email TEXT)", function(createResult){ if(createResult) throw createResult; }); console.log("database initialized"); } return db; }
function overwriteFile (path, onInputRead) { try { fs.closeSync(fs.openSync(path, 'a+')) // if the file doesn't exist, create it const encoding = 'utf-8' fs.writeFileSync(path, onInputRead(fs.readFileSync(path, encoding)), encoding) } catch (error) { console.error(`error writing ${path}, error: ${error}`) } }
function saveToFile (data, outFile, callback) { var writeFile; try { writeFile = fs.openSync(outFile, 'w'); fs.writeSync(writeFile, data); fs.close(writeFile); callback(null, outFile); } catch (err) { console.log('\n[' + chalk.gray('mochawesome') + '] Error: Unable to save ' + outFile + '\n' + err + '\n'); callback(err); } }
/** * Clears the data.json file and starts to aggregate the data on the FHIR server */ function aggregate() { if (!fs.existsSync(APP.outputFile)) { fs.closeSync(fs.openSync(APP.outputFile, 'w')); } fs.writeFileSync(APP.outputFile, '{"tags": []}'); lib.getAllResources(lib.buildFhirURL(APP.server, 'Patient', ['_count=50']), handlePatientData); getDataForResourceTable(config.TAGS); }
gulp.task('deploy', () => { fs.openSync('public/.nojekyll', 'w') return gulp.src(['public/.nojekyll', 'public/**/*']) .pipe($.ghPages({ remoteUrl: `git@github.com:${pkg.repository}.git`, message: `Deploy ${gitRevSync.short()} from v${pkg.version}` })) })
getRunningPid((err, pid) => { if (!err) { process.kill(pid, 'SIGTERM'); console.log('\nRestarting musiqpad'); daemon.daemon(`${__dirname}/start.js`, '--daemon', { stdout: fs.openSync(path.join(process.cwd(), 'log.txt'), 'a'), stderr: fs.openSync(path.join(process.cwd(), 'log.txt'), 'a'), }); } else { console.log('musiqpad could not be restarted, as a running instance could not be found.'); } });
//----------------------------------------------------------------------------- function append_newstr() { if (newstr.length>0) { console.log('Writing '+newstr.length+' entries'); entry_str = ''; for (var i in newstr) { entry_str += newstr[i]+'\n'; } dlh_fh = fs.openSync(dlh_locn,'a'); fs.appendFileSync(dlh_locn, entry_str, 'utf8'); fs.closeSync(dlh_fh); } }
// section: fs function handleFileError(delegate, retry, error) { if (error.code === 'ENOENT') { fs.openSync(delegate.file, 'a'); retry(delegate); } else { throw error; } }
fs.openSync('./config/server.js', 'r', function(err, fd){ if (err && err.code=='ENOENT') { return console.log('Server.js does not exist') } resolve(); });
open() { // Sanity check const parent = path.join(this.filename, '..') fs.mkdirSync(parent, { recursive: true }) this.handle = fs.openSync(this.filename, 'w') return this }
process.on('exit',function(code){ if (entries.length>0) { console.log('Writing '+entries.length+' new entries'); entry_str = ''; for (var i in entries) { entry_str += entries[i]+'\n'; } dlh_fh = fs.openSync(dlh_locn,'a'); fs.appendFileSync(dlh_locn, entry_str, 'utf8'); fs.closeSync(dlh_fh); } });
function touchSync(filename) { console.log('create file: ' + filename); fs.openSync(filename, 'w'); return filename; }
function Led(ledPath) { if (!(this instanceof Led)) { return new Led(ledPath); } this.brightnessFd = fs.openSync(ledPath + '/brightness', 'r+'); fs.writeFileSync(ledPath + '/trigger', 'none'); }
// number of tests currently running var touch = function(fileName) { fs.closeSync(fs.openSync(fileName, 'w')); }