"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/fs-extra/lib/ensure/file.js" (7 Feb 2017, 924 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var path = require('path')
    2 var fs = require('graceful-fs')
    3 var mkdir = require('../mkdirs')
    4 
    5 function createFile (file, callback) {
    6   function makeFile () {
    7     fs.writeFile(file, '', function (err) {
    8       if (err) return callback(err)
    9       callback()
   10     })
   11   }
   12 
   13   fs.exists(file, function (fileExists) {
   14     if (fileExists) return callback()
   15     var dir = path.dirname(file)
   16     fs.exists(dir, function (dirExists) {
   17       if (dirExists) return makeFile()
   18       mkdir.mkdirs(dir, function (err) {
   19         if (err) return callback(err)
   20         makeFile()
   21       })
   22     })
   23   })
   24 }
   25 
   26 function createFileSync (file) {
   27   if (fs.existsSync(file)) return
   28 
   29   var dir = path.dirname(file)
   30   if (!fs.existsSync(dir)) {
   31     mkdir.mkdirsSync(dir)
   32   }
   33 
   34   fs.writeFileSync(file, '')
   35 }
   36 
   37 module.exports = {
   38   createFile: createFile,
   39   createFileSync: createFileSync,
   40   // alias
   41   ensureFile: createFile,
   42   ensureFileSync: createFileSync
   43 }