{"ast":null,"code":"\"use strict\";\n\nconst pathUtil = require(\"path\");\n\nconst fs = require(\"./utils/fs\");\n\nconst validate = require(\"./utils/validate\");\n\nconst copy = require(\"./copy\");\n\nconst dir = require(\"./dir\");\n\nconst exists = require(\"./exists\");\n\nconst remove = require(\"./remove\");\n\nconst validateInput = (methodName, from, to, options) => {\n  const methodSignature = `${methodName}(from, to, [options])`;\n  validate.argument(methodSignature, \"from\", from, [\"string\"]);\n  validate.argument(methodSignature, \"to\", to, [\"string\"]);\n  validate.options(methodSignature, \"options\", options, {\n    overwrite: [\"boolean\"]\n  });\n};\n\nconst parseOptions = options => {\n  const opts = options || {};\n  return opts;\n};\n\nconst generateDestinationExistsError = path => {\n  const err = new Error(`Destination path already exists ${path}`);\n  err.code = \"EEXIST\";\n  return err;\n};\n\nconst generateSourceDoesntExistError = path => {\n  const err = new Error(`Path to move doesn't exist ${path}`);\n  err.code = \"ENOENT\";\n  return err;\n}; // ---------------------------------------------------------\n// Sync\n// ---------------------------------------------------------\n\n\nconst moveSync = (from, to, options) => {\n  const opts = parseOptions(options);\n\n  if (exists.sync(to) !== false && opts.overwrite !== true) {\n    throw generateDestinationExistsError(to);\n  } // We now have permission to overwrite, since either `opts.overwrite` is true\n  // or the destination does not exist (in which overwriting is irrelevant).\n\n\n  try {\n    // If destination is a file, `fs.renameSync` will overwrite it.\n    fs.renameSync(from, to);\n  } catch (err) {\n    if (err.code === \"EISDIR\" || err.code === \"EPERM\") {\n      // Looks like the destination path is a directory in the same device,\n      // so we can remove it and call `fs.renameSync` again.\n      remove.sync(to);\n      fs.renameSync(from, to);\n    } else if (err.code === \"EXDEV\") {\n      // The destination path is in another device.\n      copy.sync(from, to, {\n        overwrite: true\n      });\n      remove.sync(from);\n    } else if (err.code === \"ENOENT\") {\n      // This can be caused by either the source not existing or one or more folders\n      // in the destination path not existing.\n      if (!exists.sync(from)) {\n        throw generateSourceDoesntExistError(from);\n      } // One or more directories in the destination path don't exist.\n\n\n      dir.createSync(pathUtil.dirname(to)); // Retry the attempt\n\n      fs.renameSync(from, to);\n    } else {\n      // We can't make sense of this error. Rethrow it.\n      throw err;\n    }\n  }\n}; // ---------------------------------------------------------\n// Async\n// ---------------------------------------------------------\n\n\nconst ensureDestinationPathExistsAsync = to => {\n  return new Promise((resolve, reject) => {\n    const destDir = pathUtil.dirname(to);\n    exists.async(destDir).then(dstExists => {\n      if (!dstExists) {\n        dir.createAsync(destDir).then(resolve, reject);\n      } else {\n        // Hah, no idea.\n        reject();\n      }\n    }).catch(reject);\n  });\n};\n\nconst moveAsync = (from, to, options) => {\n  const opts = parseOptions(options);\n  return new Promise((resolve, reject) => {\n    exists.async(to).then(destinationExists => {\n      if (destinationExists !== false && opts.overwrite !== true) {\n        reject(generateDestinationExistsError(to));\n      } else {\n        // We now have permission to overwrite, since either `opts.overwrite` is true\n        // or the destination does not exist (in which overwriting is irrelevant).\n        // If destination is a file, `fs.rename` will overwrite it.\n        fs.rename(from, to).then(resolve).catch(err => {\n          if (err.code === \"EISDIR\" || err.code === \"EPERM\") {\n            // Looks like the destination path is a directory in the same device,\n            // so we can remove it and call `fs.rename` again.\n            remove.async(to).then(() => fs.rename(from, to)).then(resolve, reject);\n          } else if (err.code === \"EXDEV\") {\n            // The destination path is in another device.\n            copy.async(from, to, {\n              overwrite: true\n            }).then(() => remove.async(from)).then(resolve, reject);\n          } else if (err.code === \"ENOENT\") {\n            // This can be caused by either the source not existing or one or more folders\n            // in the destination path not existing.\n            exists.async(from).then(srcExists => {\n              if (!srcExists) {\n                reject(generateSourceDoesntExistError(from));\n              } else {\n                // One or more directories in the destination path don't exist.\n                ensureDestinationPathExistsAsync(to).then(() => {\n                  // Retry the attempt\n                  return fs.rename(from, to);\n                }).then(resolve, reject);\n              }\n            }).catch(reject);\n          } else {\n            // Something unknown. Rethrow original error.\n            reject(err);\n          }\n        });\n      }\n    });\n  });\n}; // ---------------------------------------------------------\n// API\n// ---------------------------------------------------------\n\n\nexports.validateInput = validateInput;\nexports.sync = moveSync;\nexports.async = moveAsync;","map":{"version":3,"sources":["D:/Development/Work/CENOS/cenos-ui/node_modules/fs-jetpack/lib/move.js"],"names":["pathUtil","require","fs","validate","copy","dir","exists","remove","validateInput","methodName","from","to","options","methodSignature","argument","overwrite","parseOptions","opts","generateDestinationExistsError","path","err","Error","code","generateSourceDoesntExistError","moveSync","sync","renameSync","createSync","dirname","ensureDestinationPathExistsAsync","Promise","resolve","reject","destDir","async","then","dstExists","createAsync","catch","moveAsync","destinationExists","rename","srcExists","exports"],"mappings":"AAAA;;AAEA,MAAMA,QAAQ,GAAGC,OAAO,CAAC,MAAD,CAAxB;;AACA,MAAMC,EAAE,GAAGD,OAAO,CAAC,YAAD,CAAlB;;AACA,MAAME,QAAQ,GAAGF,OAAO,CAAC,kBAAD,CAAxB;;AACA,MAAMG,IAAI,GAAGH,OAAO,CAAC,QAAD,CAApB;;AACA,MAAMI,GAAG,GAAGJ,OAAO,CAAC,OAAD,CAAnB;;AACA,MAAMK,MAAM,GAAGL,OAAO,CAAC,UAAD,CAAtB;;AACA,MAAMM,MAAM,GAAGN,OAAO,CAAC,UAAD,CAAtB;;AAEA,MAAMO,aAAa,GAAG,CAACC,UAAD,EAAaC,IAAb,EAAmBC,EAAnB,EAAuBC,OAAvB,KAAmC;AACvD,QAAMC,eAAe,GAAI,GAAEJ,UAAW,uBAAtC;AACAN,EAAAA,QAAQ,CAACW,QAAT,CAAkBD,eAAlB,EAAmC,MAAnC,EAA2CH,IAA3C,EAAiD,CAAC,QAAD,CAAjD;AACAP,EAAAA,QAAQ,CAACW,QAAT,CAAkBD,eAAlB,EAAmC,IAAnC,EAAyCF,EAAzC,EAA6C,CAAC,QAAD,CAA7C;AACAR,EAAAA,QAAQ,CAACS,OAAT,CAAiBC,eAAjB,EAAkC,SAAlC,EAA6CD,OAA7C,EAAsD;AACpDG,IAAAA,SAAS,EAAE,CAAC,SAAD;AADyC,GAAtD;AAGD,CAPD;;AASA,MAAMC,YAAY,GAAGJ,OAAO,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B,gBAAAA,gCAAgC,CAAClB,EAAD,CAAhC,CACGwB,IADH,CACQ,MAAM;AACV;AACA,yBAAOjC,EAAE,CAACuC,MAAH,CAAU/B,IAAV,EAAgBC,EAAhB,CAAP;AACD,iBAJH,EAKGwB,IALH,CAKQJ,OALR,EAKiBC,MALjB;AAMD;AACF,aAdH,EAeGM,KAfH,CAeSN,MAfT;AAgBD,WAnBM,MAmBA;AACL;AACAA,YAAAA,MAAM,CAACZ,GAAD,CAAN;AACD;AACF,SAvCH;AAwCD;AACF,KAhDD;AAiDD,GAlDM,CAAP;AAmDD,CAtDD,C,CAwDA;AACA;AACA;;;AAEAuB,OAAO,CAACnC,aAAR,GAAwBA,aAAxB;AACAmC,OAAO,CAAClB,IAAR,GAAeD,QAAf;AACAmB,OAAO,CAACT,KAAR,GAAgBK,SAAhB","sourcesContent":["\"use strict\";\n\nconst pathUtil = require(\"path\");\nconst fs = require(\"./utils/fs\");\nconst validate = require(\"./utils/validate\");\nconst copy = require(\"./copy\");\nconst dir = require(\"./dir\");\nconst exists = require(\"./exists\");\nconst remove = require(\"./remove\");\n\nconst validateInput = (methodName, from, to, options) => {\n  const methodSignature = `${methodName}(from, to, [options])`;\n  validate.argument(methodSignature, \"from\", from, [\"string\"]);\n  validate.argument(methodSignature, \"to\", to, [\"string\"]);\n  validate.options(methodSignature, \"options\", options, {\n    overwrite: [\"boolean\"]\n  });\n};\n\nconst parseOptions = options => {\n  const opts = options || {};\n  return opts;\n};\n\nconst generateDestinationExistsError = path => {\n  const err = new Error(`Destination path already exists ${path}`);\n  err.code = \"EEXIST\";\n  return err;\n};\n\nconst generateSourceDoesntExistError = path => {\n  const err = new Error(`Path to move doesn't exist ${path}`);\n  err.code = \"ENOENT\";\n  return err;\n};\n\n// ---------------------------------------------------------\n// Sync\n// ---------------------------------------------------------\n\nconst moveSync = (from, to, options) => {\n  const opts = parseOptions(options);\n\n  if (exists.sync(to) !== false && opts.overwrite !== true) {\n    throw generateDestinationExistsError(to);\n  }\n\n  // We now have permission to overwrite, since either `opts.overwrite` is true\n  // or the destination does not exist (in which overwriting is irrelevant).\n\n  try {\n    // If destination is a file, `fs.renameSync` will overwrite it.\n    fs.renameSync(from, to);\n  } catch (err) {\n    if (err.code === \"EISDIR\" || err.code === \"EPERM\") {\n      // Looks like the destination path is a directory in the same device,\n      // so we can remove it and call `fs.renameSync` again.\n      remove.sync(to);\n      fs.renameSync(from, to);\n    } else if (err.code === \"EXDEV\") {\n      // The destination path is in another device.\n      copy.sync(from, to, { overwrite: true });\n      remove.sync(from);\n    } else if (err.code === \"ENOENT\") {\n      // This can be caused by either the source not existing or one or more folders\n      // in the destination path not existing.\n      if (!exists.sync(from)) {\n        throw generateSourceDoesntExistError(from);\n      }\n\n      // One or more directories in the destination path don't exist.\n      dir.createSync(pathUtil.dirname(to));\n      // Retry the attempt\n      fs.renameSync(from, to);\n    } else {\n      // We can't make sense of this error. Rethrow it.\n      throw err;\n    }\n  }\n};\n\n// ---------------------------------------------------------\n// Async\n// ---------------------------------------------------------\n\nconst ensureDestinationPathExistsAsync = to => {\n  return new Promise((resolve, reject) => {\n    const destDir = pathUtil.dirname(to);\n    exists\n      .async(destDir)\n      .then(dstExists => {\n        if (!dstExists) {\n          dir.createAsync(destDir).then(resolve, reject);\n        } else {\n          // Hah, no idea.\n          reject();\n        }\n      })\n      .catch(reject);\n  });\n};\n\nconst moveAsync = (from, to, options) => {\n  const opts = parseOptions(options);\n\n  return new Promise((resolve, reject) => {\n    exists.async(to).then(destinationExists => {\n      if (destinationExists !== false && opts.overwrite !== true) {\n        reject(generateDestinationExistsError(to));\n      } else {\n        // We now have permission to overwrite, since either `opts.overwrite` is true\n        // or the destination does not exist (in which overwriting is irrelevant).\n        // If destination is a file, `fs.rename` will overwrite it.\n        fs.rename(from, to)\n          .then(resolve)\n          .catch(err => {\n            if (err.code === \"EISDIR\" || err.code === \"EPERM\") {\n              // Looks like the destination path is a directory in the same device,\n              // so we can remove it and call `fs.rename` again.\n              remove\n                .async(to)\n                .then(() => fs.rename(from, to))\n                .then(resolve, reject);\n            } else if (err.code === \"EXDEV\") {\n              // The destination path is in another device.\n              copy\n                .async(from, to, { overwrite: true })\n                .then(() => remove.async(from))\n                .then(resolve, reject);\n            } else if (err.code === \"ENOENT\") {\n              // This can be caused by either the source not existing or one or more folders\n              // in the destination path not existing.\n              exists\n                .async(from)\n                .then(srcExists => {\n                  if (!srcExists) {\n                    reject(generateSourceDoesntExistError(from));\n                  } else {\n                    // One or more directories in the destination path don't exist.\n                    ensureDestinationPathExistsAsync(to)\n                      .then(() => {\n                        // Retry the attempt\n                        return fs.rename(from, to);\n                      })\n                      .then(resolve, reject);\n                  }\n                })\n                .catch(reject);\n            } else {\n              // Something unknown. Rethrow original error.\n              reject(err);\n            }\n          });\n      }\n    });\n  });\n};\n\n// ---------------------------------------------------------\n// API\n// ---------------------------------------------------------\n\nexports.validateInput = validateInput;\nexports.sync = moveSync;\nexports.async = moveAsync;\n"]},"metadata":{},"sourceType":"script"}