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Root":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@apexearth/copy@1.4.5/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const fs          = require('fs')\nconst path        = require('path')\nconst {promisify} = require('util')\nconst readFile    = promisify(fs.readFile)\nconst writeFile   = promisify(fs.writeFile)\nconst mkdir       = promisify(fs.mkdir)\nconst mkdirp      = require('mkdirp')\nconst pretty      = require('prettysize')\nconst sleep       = require('sleep-promise')\nconst assert      = require('assert')\n\n/**\n * @param {string} from - Source copy path.\n * @param {string} to - Destination copy path.\n * @param {boolean} recursive - Copy recursively.\n * @param {boolean} overwrite - Overwrite existing files.\n * @param {boolean} overwriteMismatches - Overwrite if size mismatch or from modified date is more recent.\n * @param {boolean} verbose - Verbose output.\n * @param {boolean} json - JSON output. (options: true, pretty)\n * @param {boolean} ignoreErrors - Continue on errors.\n * @param {boolean} parallelJobs - Number of possible concurrent jobs.\n * @param {string} state - Save state for resume ability.\n * @param {string} stateFrequency - Save state frequency.\n * @param {string} copyFile - Supply your own copyFile function. (from, to, cb)\n * @param {string} readdir - Supply your own readdir function. (path, cb)\n * @param {string} stat - Supply your own stat function. (path, cb)\n */\nclass Copy {\n    constructor(options = {}) {\n        this.from                = path.normalize(options.from)\n        this.to                  = path.normalize(options.to)\n        this.recursive           = options.recursive || false\n        this.overwrite           = options.overwrite || false\n        this.overwriteMismatches = options.overwriteMismatches || false\n        this.verbose             = options.verbose || false\n        this.json                = options.json || false\n        this.ignoreErrors        = options.ignoreErrors || false\n        this.parallelJobs        = options.parallelJobs || 1\n        this.stateFile           = options.state\n        this.stateFrequency      = options.stateFrequency || 100\n        this.fns                 = {\n            stat    : promisify(options.stat || fs.stat),\n            readdir : promisify(options.readdir || fs.readdir),\n            copyFile: promisify(options.copyFile || fs.copyFile),\n        }\n        this.stateCatchUp        = 0 // Set true when we need to catch up to our saved state.\n        this.state               = {\n            wip   : [],\n            counts: {\n                directories: 0,\n                files      : 0,\n                copies     : 0,\n            },\n        }\n\n        this.pending = []\n        this.errors  = []\n\n        assert.equal(typeof this.from, 'string', 'from should be a string')\n        assert.equal(typeof this.to, 'string', 'to should be a string')\n        assert.equal(typeof this.parallelJobs, 'number', 'parallelJobs should be a number')\n        assert.equal(typeof this.stateFrequency, 'number', 'stateFrequency should be a number')\n        assert.equal(typeof this.fns.stat, 'function', 'stat should be a function')\n        assert.equal(typeof this.fns.readdir, 'function', 'readdir should be a function')\n        assert.equal(typeof this.fns.copyFile, 'function', 'copyFile should be a function')\n    }\n\n    async start() {\n        try {\n            await this.loadState()\n            if ((await this.fns.stat(this.from)).isDirectory()) {\n                await mkdirp(this.to)\n            } else {\n                const basedir = path.dirname(this.to)\n                await mkdirp(basedir)\n            }\n            await this.copy(this.from, this.to)\n\n            // Wait for all jobs to complete.\n            while (this.pending.length > 0) {\n                await sleep(10)\n            }\n            await this.processJobErrors()\n            await this.saveState()\n            if (this.state.wip.length) {\n                throw new Error('Incomplete `wip` found. Copy likely incomplete.')\n            }\n            return this.state\n        } catch (err) {\n            err.state = this.state\n            throw err\n        }\n    }\n\n    async loadState() {\n        if (!this.stateFile) return\n        try {\n            await this.fns.stat(this.stateFile)\n            this.state        = JSON.parse(await readFile(this.stateFile))\n            this.stateCatchUp = this.state.wip.length\n        } catch (err) {\n            if (err.code !== 'ENOENT') {\n                throw err\n            }\n        }\n    }\n\n    async saveState() {\n        if (!this.stateFile) return\n        await writeFile(this.stateFile, JSON.stringify(this.state, null, 2))\n    }\n\n    async processJobErrors() {\n        let err = this.errors.shift()\n        while (err) {\n            this.handleError(err)\n            err = this.errors.shift()\n        }\n    }\n\n    async copy(from, to) {\n        let catchingUp = this.stateCatchUp > 0\n        if (catchingUp) {\n            if (this.state.wip.includes(from)) {\n                this.stateCatchUp -= 1 // Found one, decrease our catch up count.\n            } else if (!this.state.wip.some(wipFile => wipFile.startsWith(from))) {\n                return\n            }\n        }\n        try {\n            await this.processJobErrors()\n            const fromStat    = await this.fns.stat(from)\n            const isDirectory = fromStat.isDirectory()\n            if (isDirectory && this.recursive) {\n                await this.copyDirectory(from, to)\n            } else if (!isDirectory) {\n                if (!catchingUp) {\n                    this.state.wip.push(from)\n                }\n                await this.queueAction(() => this.copyFile(from, to, fromStat))\n                if (this.state.counts.files % this.stateFrequency === 0) {\n                    await this.saveState()\n                }\n            }\n        } catch (err) {\n            this.handleError(err)\n        }\n    }\n\n    async copyDirectory(from, to) {\n        try {\n            try {\n                await this.fns.stat(to)\n            } catch (err) {\n                if (err.code === 'ENOENT') {\n                    await mkdir(to)\n                } else {\n                    throw err\n                }\n            }\n            const files = await this.fns.readdir(from)\n            for (let file of files) {\n                await this.copy(path.join(from, file), path.join(to, file))\n            }\n        } catch (err) {\n            this.handleError(err)\n        } finally {\n            this.state.counts.directories++\n        }\n    }\n\n    async queueAction(asyncFunction) {\n        while (this.pending.length >= this.parallelJobs) {\n            await sleep(10)\n        }\n        const action = async () => {\n            try {\n                await asyncFunction()\n            } finally {\n                this.pending.splice(this.pending.indexOf(asyncFunction), 1)\n            }\n        }\n        this.pending.push(action)\n        action().catch(err => this.errors.push(err))\n    }\n\n    async copyFile(from, to, fromStat) {\n        this.logCopyAction(to, 'start')\n        try {\n            const toStat = await this.fns.stat(to)\n            if (this.overwrite) {\n                await this.doCopy(from, to, fromStat)\n            } else if (this.overwriteMismatches) {\n                if (fromStat.size !== toStat.size ||\n                    fromStat.mtimeMs > toStat.mtimeMs) {\n                    this.logCopyAction(to, 'stats mismatch', {\n                        fromStat: {\n                            size   : fromStat.size,\n                            mtimeMs: fromStat.mtimeMs,\n                        },\n                        toStat  : {\n                            size   : toStat.size,\n                            mtimeMs: toStat.mtimeMs,\n                        },\n                    })\n                    await this.doCopy(from, to, fromStat)\n                } else {\n                    this.logCopyAction(to, 'skipped, stats match')\n                }\n            } else {\n                this.logCopyAction(to, 'skipped')\n            }\n            this.removeWip(from)\n        } catch (err) {\n            if (err.code === 'ENOENT') {\n                await this.doCopy(from, to, fromStat)\n                this.removeWip(from)\n            } else {\n                throw err\n            }\n        }\n        this.state.counts.files++\n    }\n\n    async doCopy(from, to, fromStat) {\n        try {\n            if (this.verbose || this.json) {\n                const start = Date.now()\n                await this.fns.copyFile(from, to)\n                const speed = fromStat.size / ((Date.now() - start) / 1000)\n                this.logCopyAction(to, 'complete', {speed})\n            } else {\n                await this.fns.copyFile(from, to)\n            }\n            this.state.counts.copies++\n        } catch (err) {\n            this.logCopyAction(to, 'error')\n            this.handleError(err)\n        }\n    }\n\n    removeWip(from) {\n        let wipIndex = this.state.wip.indexOf(from)\n        if (wipIndex >= 0) {\n            this.state.wip.splice(wipIndex, 1)\n        }\n    }\n\n    log(message) {\n        if (this.verbose || this.json) {\n            if (this.json === 'pretty') {\n                console.log(JSON.stringify({message, state: this.state}, null, 2) + '\\n') // Double our line endings for some clear delimitation.\n            } else if (this.json) {\n                console.log(JSON.stringify({message, state: this.state}))\n            } else {\n                console.log(`Count: ${this.state.counts.directories}d ${this.state.counts.files}f Jobs: ${this.pending.length} ${message}`)\n            }\n        }\n    }\n\n    logCopyAction(file, action, extra) {\n        if (this.json) {\n            let message = {file, action}\n            if (extra) {\n                Object.assign(message, extra)\n            }\n            this.log(message)\n        } else {\n            let message = `Copying: '${file}' (${action})`\n            if (extra && extra.speed !== undefined) {\n                message += ` (${pretty(extra.speed)}/s)`\n            }\n            this.log(message)\n        }\n    }\n\n    handleError(err) {\n        if (this.ignoreErrors) {\n            console.error(err)\n        } else {\n            throw err\n        }\n    }\n}\n\nmodule.exports      = options => {\n    const copy = new Copy(options)\n    return copy.start()\n}\nmodule.exports.Copy = Copy\n"]}