aboutsummaryrefslogtreecommitdiff
path: root/node_modules/move-concurrently/move.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/move-concurrently/move.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/move-concurrently/move.js')
-rw-r--r--node_modules/move-concurrently/move.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/node_modules/move-concurrently/move.js b/node_modules/move-concurrently/move.js
new file mode 100644
index 00000000..6a2a7332
--- /dev/null
+++ b/node_modules/move-concurrently/move.js
@@ -0,0 +1,84 @@
+'use strict'
+module.exports = move
+
+var nodeFs = require('fs')
+var rimraf = require('rimraf')
+var validate = require('aproba')
+var copy = require('copy-concurrently')
+var RunQueue = require('run-queue')
+var extend = Object.assign || require('util')._extend
+
+function promisify (Promise, fn) {
+ return function () {
+ var args = [].slice.call(arguments)
+ return new Promise(function (resolve, reject) {
+ return fn.apply(null, args.concat(function (err, value) {
+ if (err) {
+ reject(err)
+ } else {
+ resolve(value)
+ }
+ }))
+ })
+ }
+}
+
+function move (from, to, opts) {
+ validate('SSO|SS', arguments)
+ opts = extend({}, opts || {})
+
+ var Promise = opts.Promise || global.Promise
+ var fs = opts.fs || nodeFs
+ var rimrafAsync = promisify(Promise, rimraf)
+ var renameAsync = promisify(Promise, fs.rename)
+
+ opts.top = from
+
+ var queue = new RunQueue({
+ maxConcurrency: opts.maxConcurrency,
+ Promise: Promise
+ })
+ opts.queue = queue
+ opts.recurseWith = rename
+
+ queue.add(0, rename, [from, to, opts])
+
+ return queue.run().then(function () {
+ return remove(from)
+ }, function (err) {
+ // if the target already exists don't clobber it
+ if (err.code === 'EEXIST' || err.code === 'EPERM') {
+ return passThroughError()
+ } else {
+ return remove(to).then(passThroughError, passThroughError)
+ }
+ function passThroughError () {
+ return Promise.reject(err)
+ }
+ })
+
+ function remove (target) {
+ var opts = {
+ unlink: fs.unlink,
+ chmod: fs.chmod,
+ stat: fs.stat,
+ lstat: fs.lstat,
+ rmdir: fs.rmdir,
+ readdir: fs.readdir,
+ glob: false
+ }
+ return rimrafAsync(target, opts)
+ }
+
+ function rename (from, to, opts, done) {
+ return renameAsync(from, to).catch(function (err) {
+ if (err.code !== 'EXDEV') {
+ return Promise.reject(err)
+ } else {
+ return remove(to).then(function () {
+ return copy.item(from, to, opts)
+ })
+ }
+ })
+ }
+}