@cjser/jsftp-mkdirp 5.0.0-cjser.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/@cjser/jsftp-mkdirp.tmp-26-1778153100080/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ default: () => jsFtpMkdirp
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+ var import_node_util = require("node:util");
36
+ var import_parent_dirs_v2_0_0 = __toESM(require("@cjser/parent-dirs__v2_0_0"), 1);
37
+ var import_slash_v4_0_0 = __toESM(require("@cjser/slash__v4_0_0"), 1);
38
+ async function mkdirp(directory) {
39
+ if (typeof directory !== "string") {
40
+ throw new TypeError("`path` is required");
41
+ }
42
+ const directories = (0, import_parent_dirs_v2_0_0.default)(directory);
43
+ if (directories[directories.length - 1] === "/") {
44
+ directories.pop();
45
+ }
46
+ if (directories.length === 0) {
47
+ return;
48
+ }
49
+ const mkdir = async (directory2) => {
50
+ directory2 = (0, import_slash_v4_0_0.default)(directory2);
51
+ try {
52
+ await (0, import_node_util.promisify)(this.raw.bind(this))("mkd", directory2);
53
+ } catch (error) {
54
+ if (error.code === 550 && directories.length > 0) {
55
+ await mkdir(directories.pop());
56
+ return;
57
+ }
58
+ error.message += ` - mkd: ${directory2}`;
59
+ throw error;
60
+ }
61
+ if (directories.length > 0) {
62
+ await mkdir(directories.pop());
63
+ }
64
+ };
65
+ const checkIfDirectoryExists = async (directory2) => {
66
+ directory2 = (0, import_slash_v4_0_0.default)(directory2);
67
+ try {
68
+ await (0, import_node_util.promisify)(this.raw.bind(this))("mlst", directory2);
69
+ } catch (error) {
70
+ if (error.code === 550) {
71
+ await mkdir(directory2);
72
+ return;
73
+ }
74
+ error.message += ` - mlst: ${directory2}`;
75
+ throw error;
76
+ }
77
+ if (directories.length > 0) {
78
+ await checkIfDirectoryExists(directories.pop());
79
+ }
80
+ };
81
+ await checkIfDirectoryExists(directories.pop());
82
+ }
83
+ function jsFtpMkdirp(JsFtp) {
84
+ JsFtp.prototype = Object.create(JsFtp.prototype, {
85
+ mkdirp: {
86
+ value: mkdirp
87
+ }
88
+ });
89
+ }
package/index.js ADDED
@@ -0,0 +1,70 @@
1
+ import {promisify} from 'node:util';
2
+ import parentDirs from '@cjser/parent-dirs__v2_0_0';
3
+ import slash from '@cjser/slash__v4_0_0';
4
+
5
+ async function mkdirp(directory) {
6
+ if (typeof directory !== 'string') {
7
+ throw new TypeError('`path` is required');
8
+ }
9
+
10
+ const directories = parentDirs(directory);
11
+
12
+ // Skip root as it's always there.
13
+ if (directories[directories.length - 1] === '/') {
14
+ directories.pop();
15
+ }
16
+
17
+ if (directories.length === 0) {
18
+ return;
19
+ }
20
+
21
+ const mkdir = async directory => {
22
+ directory = slash(directory);
23
+
24
+ try {
25
+ await promisify(this.raw.bind(this))('mkd', directory);
26
+ } catch (error) {
27
+ if (error.code === 550 && directories.length > 0) {
28
+ await mkdir(directories.pop());
29
+ return;
30
+ }
31
+
32
+ error.message += ` - mkd: ${directory}`;
33
+ throw error;
34
+ }
35
+
36
+ if (directories.length > 0) {
37
+ await mkdir(directories.pop());
38
+ }
39
+ };
40
+
41
+ const checkIfDirectoryExists = async directory => {
42
+ directory = slash(directory);
43
+
44
+ try {
45
+ await promisify(this.raw.bind(this))('mlst', directory);
46
+ } catch (error) {
47
+ if (error.code === 550) {
48
+ await mkdir(directory);
49
+ return;
50
+ }
51
+
52
+ error.message += ` - mlst: ${directory}`;
53
+ throw error;
54
+ }
55
+
56
+ if (directories.length > 0) {
57
+ await checkIfDirectoryExists(directories.pop());
58
+ }
59
+ };
60
+
61
+ await checkIfDirectoryExists(directories.pop());
62
+ }
63
+
64
+ export default function jsFtpMkdirp(JsFtp) {
65
+ JsFtp.prototype = Object.create(JsFtp.prototype, {
66
+ mkdirp: {
67
+ value: mkdirp,
68
+ },
69
+ });
70
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@cjser/jsftp-mkdirp",
3
+ "version": "5.0.0-cjser.2",
4
+ "description": "Recursively create nested directories with jsftp, like mkdirp",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "require": "./dist-cjser/index.cjs",
19
+ "default": "./index.js"
20
+ },
21
+ "engines": {
22
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
23
+ },
24
+ "scripts": {
25
+ "test": "xo && ava"
26
+ },
27
+ "files": [
28
+ "index.js",
29
+ "dist-cjser"
30
+ ],
31
+ "keywords": [
32
+ "ftp",
33
+ "jsftp",
34
+ "file",
35
+ "transfer",
36
+ "protocol",
37
+ "server",
38
+ "client",
39
+ "upload",
40
+ "deploy",
41
+ "deployment",
42
+ "mkdirp",
43
+ "directory",
44
+ "directories",
45
+ "folder"
46
+ ],
47
+ "dependencies": {
48
+ "@cjser/parent-dirs__v2_0_0": "2.0.0-cjser.2",
49
+ "@cjser/slash__v4_0_0": "4.0.0-cjser.2"
50
+ },
51
+ "devDependencies": {
52
+ "ava": "^3.15.0",
53
+ "del": "^6.0.0",
54
+ "delay": "^5.0.0",
55
+ "ftp-test-server": "0.0.2",
56
+ "jsftp": "^2.1.3",
57
+ "path-exists": "^4.0.0",
58
+ "xo": "^0.44.0"
59
+ },
60
+ "peerDependencies": {
61
+ "jsftp": "^2.1.3"
62
+ },
63
+ "main": "./dist-cjser/index.cjs",
64
+ "cjser": {
65
+ "sourceVersion": "5.0.0",
66
+ "cjserVersion": 2,
67
+ "original": {
68
+ "name": "jsftp-mkdirp",
69
+ "version": "5.0.0",
70
+ "exports": "./index.js",
71
+ "repository": "sindresorhus/jsftp-mkdirp",
72
+ "dependencies": {
73
+ "parent-dirs": "^2.0.0",
74
+ "slash": "^4.0.0"
75
+ },
76
+ "files": [
77
+ "index.js"
78
+ ],
79
+ "scripts": {
80
+ "test": "xo && ava"
81
+ }
82
+ }
83
+ }
84
+ }
package/readme.md ADDED
@@ -0,0 +1,49 @@
1
+ # jsftp-mkdirp
2
+
3
+ > Recursively create nested directories with [jsftp](https://github.com/sergi/jsftp), like [mkdirp](https://github.com/substack/node-mkdirp)
4
+
5
+ FTP can natively create only one directory at the time.
6
+
7
+ Useful for being able to upload files to deep paths without knowing if the directories exists beforehand.
8
+
9
+ ## Install
10
+
11
+ ```
12
+ $ npm install jsftp-mkdirp
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import JsFtp from 'jsftp';
19
+ import JsFtpMkdirp from 'jsftp-mkdirp';
20
+
21
+ // Decorate `JSFtp` with a new method `mkdirp`
22
+ JsFtpMkdirp(JSFtp);
23
+
24
+ const ftp = new JsFtp({
25
+ host: 'myserver.com'
26
+ });
27
+
28
+ const path = 'public_html/deploy/foo/bar';
29
+
30
+ await ftp.mkdirp(path);
31
+ console.log('Created path:', path);
32
+ ```
33
+
34
+ ## API
35
+
36
+ ### JsFtp.mkdirp(path)
37
+
38
+ Returns a `Promise`.
39
+
40
+ #### path
41
+
42
+ Type: `string`
43
+
44
+ The path of the nested directories you want to create.
45
+
46
+ ## cjser
47
+
48
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
49
+ Original repository: https://github.com/sindresorhus/jsftp-mkdirp