@youcan/cli-kit 2.1.4 → 2.3.0
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.
- package/dist/common/string.d.ts +2 -2
- package/dist/common/string.js +11 -11
- package/dist/index.d.ts +19 -17
- package/dist/index.js +4 -0
- package/dist/internal/node/constants.d.ts +5 -5
- package/dist/internal/node/constants.js +10 -10
- package/dist/internal/node/ui.d.ts +11 -11
- package/dist/internal/node/ui.js +41 -40
- package/dist/node/callback.d.ts +5 -5
- package/dist/node/callback.js +53 -53
- package/dist/node/cli.d.ts +25 -21
- package/dist/node/cli.js +97 -62
- package/dist/node/config.d.ts +20 -20
- package/dist/node/config.js +20 -22
- package/dist/node/context/helpers.d.ts +1 -1
- package/dist/node/context/helpers.js +5 -5
- package/dist/node/context/local.d.ts +2 -2
- package/dist/node/context/local.js +2 -2
- package/dist/node/crypto.d.ts +12 -9
- package/dist/node/crypto.js +23 -23
- package/dist/node/env.d.ts +5 -6
- package/dist/node/env.js +36 -47
- package/dist/node/filesystem.d.ts +34 -29
- package/dist/node/filesystem.js +112 -82
- package/dist/node/form.d.ts +9 -9
- package/dist/node/form.js +39 -39
- package/dist/node/git.d.ts +10 -10
- package/dist/node/git.js +46 -46
- package/dist/node/github.d.ts +6 -6
- package/dist/node/github.js +8 -8
- package/dist/node/http.d.ts +4 -4
- package/dist/node/http.js +37 -34
- package/dist/node/path.d.ts +5 -5
- package/dist/node/path.js +14 -14
- package/dist/node/session.d.ts +8 -8
- package/dist/node/session.js +92 -78
- package/dist/node/system.d.ts +26 -21
- package/dist/node/system.js +87 -60
- package/dist/node/tasks.d.ts +8 -7
- package/dist/node/tasks.js +33 -25
- package/dist/node/worker.d.ts +16 -19
- package/dist/node/worker.js +43 -30
- package/dist/services/cloudflared.d.ts +12 -0
- package/dist/services/cloudflared.js +206 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/ui/components/DevOutput.d.ts +27 -0
- package/dist/ui/components/DevOutput.js +60 -0
- package/dist/ui/components/Error.d.ts +6 -0
- package/dist/ui/components/Error.js +18 -0
- package/dist/ui/components/HotKeys.d.ts +12 -0
- package/dist/ui/components/HotKeys.js +25 -0
- package/dist/ui/components/utils/symbols.d.ts +3 -0
- package/dist/ui/components/utils/symbols.js +7 -0
- package/dist/ui/index.d.ts +3 -0
- package/dist/ui/index.js +3 -0
- package/package.json +7 -2
package/dist/node/config.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import Conf from 'conf';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function manager(options) {
|
|
24
|
-
return new Manager(options);
|
|
3
|
+
class Manager {
|
|
4
|
+
store;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.store = new Conf(options);
|
|
7
|
+
}
|
|
8
|
+
get(key) {
|
|
9
|
+
return this.store.get(key);
|
|
10
|
+
}
|
|
11
|
+
set(key, value) {
|
|
12
|
+
this.store.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
delete(key) {
|
|
15
|
+
this.store.delete(key);
|
|
16
|
+
}
|
|
17
|
+
clear() {
|
|
18
|
+
this.store.clear();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function manager(options) {
|
|
22
|
+
return new Manager(options);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export { manager };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function truthy(val: string | undefined): boolean;
|
|
1
|
+
export declare function truthy(val: string | undefined): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
function truthy(val) {
|
|
2
|
-
if (!val) {
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
return ['1', 'true', 'TRUE', 'yes', 'YES', 'y', 'Y'].includes(val);
|
|
1
|
+
function truthy(val) {
|
|
2
|
+
if (!val) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
return ['1', 'true', 'TRUE', 'yes', 'YES', 'y', 'Y'].includes(val);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export { truthy };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export declare function isDevelopment(env?: NodeJS.ProcessEnv): boolean;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare function isDevelopment(env?: NodeJS.ProcessEnv): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ENV_VARS } from '../../internal/node/constants.js';
|
|
2
2
|
|
|
3
|
-
function isDevelopment(env = process.env) {
|
|
4
|
-
return env[ENV_VARS.ENV] === 'development';
|
|
3
|
+
function isDevelopment(env = process.env) {
|
|
4
|
+
return env[ENV_VARS.ENV] === 'development';
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export { isDevelopment };
|
package/dist/node/crypto.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { BinaryLike } from 'crypto';
|
|
5
|
+
export declare function randomHex(size: number): string;
|
|
6
|
+
export declare function base64URLEncode(str: Buffer): string;
|
|
7
|
+
export declare function sha256(str: BinaryLike): Buffer;
|
|
8
|
+
export declare function sha1(str: BinaryLike): string;
|
|
9
|
+
export declare function hashString(str: string): string;
|
|
10
|
+
export declare function fileHash(buff: BinaryLike): string;
|
|
11
|
+
export declare function randomBytes(size: number): Buffer;
|
|
12
|
+
export declare function randomUUID(): string;
|
package/dist/node/crypto.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
|
|
3
|
-
function randomHex(size) {
|
|
4
|
-
return crypto.randomBytes(size).toString('hex');
|
|
5
|
-
}
|
|
6
|
-
function base64URLEncode(str) {
|
|
7
|
-
return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/[=]/g, '');
|
|
8
|
-
}
|
|
9
|
-
function sha256(str) {
|
|
10
|
-
return crypto.createHash('sha256').update(str).digest();
|
|
11
|
-
}
|
|
12
|
-
function sha1(str) {
|
|
13
|
-
return crypto.createHash('sha1').update(str).digest('hex');
|
|
14
|
-
}
|
|
15
|
-
function hashString(str) {
|
|
16
|
-
return crypto.createHash('sha1').update(str).digest('hex');
|
|
17
|
-
}
|
|
18
|
-
function fileHash(buff) {
|
|
19
|
-
return crypto.createHash('md5').update(buff).digest('hex');
|
|
20
|
-
}
|
|
21
|
-
function randomBytes(size) {
|
|
22
|
-
return crypto.randomBytes(size);
|
|
23
|
-
}
|
|
24
|
-
function randomUUID() {
|
|
25
|
-
return crypto.randomUUID();
|
|
3
|
+
function randomHex(size) {
|
|
4
|
+
return crypto.randomBytes(size).toString('hex');
|
|
5
|
+
}
|
|
6
|
+
function base64URLEncode(str) {
|
|
7
|
+
return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/[=]/g, '');
|
|
8
|
+
}
|
|
9
|
+
function sha256(str) {
|
|
10
|
+
return crypto.createHash('sha256').update(str).digest();
|
|
11
|
+
}
|
|
12
|
+
function sha1(str) {
|
|
13
|
+
return crypto.createHash('sha1').update(str).digest('hex');
|
|
14
|
+
}
|
|
15
|
+
function hashString(str) {
|
|
16
|
+
return crypto.createHash('sha1').update(str).digest('hex');
|
|
17
|
+
}
|
|
18
|
+
function fileHash(buff) {
|
|
19
|
+
return crypto.createHash('md5').update(buff).digest('hex');
|
|
20
|
+
}
|
|
21
|
+
function randomBytes(size) {
|
|
22
|
+
return crypto.randomBytes(size);
|
|
23
|
+
}
|
|
24
|
+
function randomUUID() {
|
|
25
|
+
return crypto.randomUUID();
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export { base64URLEncode, fileHash, hashString, randomBytes, randomHex, randomUUID, sha1, sha256 };
|
package/dist/node/env.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ENV_VARS } from '@/internal/node/constants';
|
|
2
|
-
export declare function get(key: keyof typeof ENV_VARS): string;
|
|
3
|
-
export declare function oauthClientId(): string;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function apiHostname(): string;
|
|
1
|
+
import { ENV_VARS } from '@/internal/node/constants';
|
|
2
|
+
export declare function get(key: keyof typeof ENV_VARS): string;
|
|
3
|
+
export declare function oauthClientId(): string;
|
|
4
|
+
export declare function sellerAreaHostname(): string;
|
|
5
|
+
export declare function apiHostname(): string;
|
package/dist/node/env.js
CHANGED
|
@@ -1,51 +1,40 @@
|
|
|
1
1
|
import { ENV_VARS } from '../internal/node/constants.js';
|
|
2
2
|
|
|
3
|
-
function get(key) {
|
|
4
|
-
return process.env[ENV_VARS[key]];
|
|
5
|
-
}
|
|
6
|
-
function oauthClientId() {
|
|
7
|
-
switch (get('HOST_ENV')) {
|
|
8
|
-
case 'dev':
|
|
9
|
-
return '
|
|
10
|
-
case 'test':
|
|
11
|
-
return '11';
|
|
12
|
-
case 'prod':
|
|
13
|
-
default:
|
|
14
|
-
return '
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function
|
|
18
|
-
switch (get('HOST_ENV')) {
|
|
19
|
-
case 'dev':
|
|
20
|
-
return '
|
|
21
|
-
case 'test':
|
|
22
|
-
return '
|
|
23
|
-
case 'prod':
|
|
24
|
-
default:
|
|
25
|
-
return '
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function
|
|
29
|
-
switch (get('HOST_ENV')) {
|
|
30
|
-
case 'dev':
|
|
31
|
-
return '
|
|
32
|
-
case 'test':
|
|
33
|
-
return '
|
|
34
|
-
case 'prod':
|
|
35
|
-
default:
|
|
36
|
-
return '
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function apiHostname() {
|
|
40
|
-
switch (get('HOST_ENV')) {
|
|
41
|
-
case 'dev':
|
|
42
|
-
return 'api.dotshop.com';
|
|
43
|
-
case 'test':
|
|
44
|
-
return 'api.testyoucan.shop';
|
|
45
|
-
case 'prod':
|
|
46
|
-
default:
|
|
47
|
-
return 'api.youcan.shop';
|
|
48
|
-
}
|
|
3
|
+
function get(key) {
|
|
4
|
+
return process.env[ENV_VARS[key]];
|
|
5
|
+
}
|
|
6
|
+
function oauthClientId() {
|
|
7
|
+
switch (get('HOST_ENV')) {
|
|
8
|
+
case 'dev':
|
|
9
|
+
return '1';
|
|
10
|
+
case 'test':
|
|
11
|
+
return '11';
|
|
12
|
+
case 'prod':
|
|
13
|
+
default:
|
|
14
|
+
return '398';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function sellerAreaHostname() {
|
|
18
|
+
switch (get('HOST_ENV')) {
|
|
19
|
+
case 'dev':
|
|
20
|
+
return 'seller-area.dotshop.com';
|
|
21
|
+
case 'test':
|
|
22
|
+
return 'seller-area.testyoucan.shop';
|
|
23
|
+
case 'prod':
|
|
24
|
+
default:
|
|
25
|
+
return 'seller-area.youcan.shop';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function apiHostname() {
|
|
29
|
+
switch (get('HOST_ENV')) {
|
|
30
|
+
case 'dev':
|
|
31
|
+
return 'api.dotshop.com';
|
|
32
|
+
case 'test':
|
|
33
|
+
return 'api.testyoucan.shop';
|
|
34
|
+
case 'prod':
|
|
35
|
+
default:
|
|
36
|
+
return 'api.youcan.shop';
|
|
37
|
+
}
|
|
49
38
|
}
|
|
50
39
|
|
|
51
|
-
export { apiHostname, get, oauthClientId,
|
|
40
|
+
export { apiHostname, get, oauthClientId, sellerAreaHostname };
|
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function
|
|
28
|
-
export declare
|
|
29
|
-
export
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import type { Mode, OpenMode, PathLike, Stats } from 'fs';
|
|
5
|
+
import type { GlobOptions } from 'glob';
|
|
6
|
+
export declare function exists(path: string): Promise<boolean>;
|
|
7
|
+
export declare function isExecutable(path: string): Promise<boolean>;
|
|
8
|
+
export declare function isDirectory(path: string): Promise<boolean>;
|
|
9
|
+
export declare function tapIntoTmp<T>(callback: (tmp: string) => T | Promise<T>): Promise<T>;
|
|
10
|
+
export declare function mkdir(path: string): Promise<void>;
|
|
11
|
+
export declare function rm(path: string): Promise<void>;
|
|
12
|
+
interface MoveFileOptions {
|
|
13
|
+
overwrite?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function move(src: string, dest: string, options?: MoveFileOptions): Promise<void>;
|
|
16
|
+
export declare function readFile(path: PathLike, options?: {
|
|
17
|
+
encoding?: BufferEncoding;
|
|
18
|
+
flag?: OpenMode;
|
|
19
|
+
}): Promise<Buffer | string>;
|
|
20
|
+
export declare function writeFile(path: PathLike, data: string, options?: {
|
|
21
|
+
encoding: BufferEncoding;
|
|
22
|
+
flag: Mode;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
export declare function readJsonFile<T = Record<string, unknown>>(path: PathLike): Promise<T>;
|
|
25
|
+
export declare function writeJsonFile(path: PathLike, data: Record<string, unknown>): Promise<void>;
|
|
26
|
+
export declare function glob(pattern: string | string[], options?: GlobOptions): Promise<string[]>;
|
|
27
|
+
export declare function archived(path: string, name: string, glob?: string): Promise<string>;
|
|
28
|
+
export declare function unlink(path: string): Promise<void>;
|
|
29
|
+
export declare function readdir(path: string): Promise<string[]>;
|
|
30
|
+
export declare function stat(path: string): Promise<Stats>;
|
|
31
|
+
export declare const watch: typeof import("chokidar").watch;
|
|
32
|
+
export declare function decompressGzip(file: string, destination: string, mode?: number): Promise<void>;
|
|
33
|
+
export declare function extractTar(file: string, cwd: string, mode: number): Promise<void>;
|
|
34
|
+
export {};
|
package/dist/node/filesystem.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import FilesystemPromises from 'node:fs/promises';
|
|
2
|
-
import {
|
|
2
|
+
import { createGunzip } from 'node:zlib';
|
|
3
|
+
import { pipeline } from 'node:stream/promises';
|
|
4
|
+
import { createWriteStream, createReadStream } from 'node:fs';
|
|
3
5
|
import { temporaryDirectoryTask } from 'tempy';
|
|
4
6
|
import FsExtra from 'fs-extra';
|
|
5
7
|
import archiver from 'archiver';
|
|
6
8
|
import chokidar from 'chokidar';
|
|
7
9
|
import { glob as glob$1 } from 'glob';
|
|
10
|
+
import * as tar from 'tar';
|
|
8
11
|
import './cli.js';
|
|
9
12
|
import 'simple-git';
|
|
10
|
-
import 'execa';
|
|
11
|
-
import 'tcp-port-used';
|
|
12
13
|
import 'find-process';
|
|
14
|
+
import 'tcp-port-used';
|
|
15
|
+
import 'execa';
|
|
13
16
|
import 'env-paths';
|
|
14
17
|
import { resolve } from './path.js';
|
|
15
18
|
import 'node-fetch';
|
|
@@ -20,85 +23,112 @@ import 'formdata-node/file-from-path';
|
|
|
20
23
|
import 'kleur';
|
|
21
24
|
import 'conf';
|
|
22
25
|
import 'dayjs';
|
|
26
|
+
import '../ui/components/DevOutput.js';
|
|
27
|
+
import 'react';
|
|
28
|
+
import 'ink';
|
|
23
29
|
|
|
24
|
-
async function exists(path) {
|
|
25
|
-
try {
|
|
26
|
-
await FilesystemPromises.access(path);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
async function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
async function
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
async function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
30
|
+
async function exists(path) {
|
|
31
|
+
try {
|
|
32
|
+
await FilesystemPromises.access(path);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function isExecutable(path) {
|
|
40
|
+
if (!await exists(path)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await FilesystemPromises.access(path, FilesystemPromises.constants.X_OK);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function isDirectory(path) {
|
|
52
|
+
try {
|
|
53
|
+
const stats = await FilesystemPromises.stat(path);
|
|
54
|
+
return stats.isDirectory();
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function tapIntoTmp(callback) {
|
|
61
|
+
return temporaryDirectoryTask(callback);
|
|
62
|
+
}
|
|
63
|
+
async function mkdir(path) {
|
|
64
|
+
await FilesystemPromises.mkdir(path, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
async function rm(path) {
|
|
67
|
+
await FilesystemPromises.rm(path, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
async function move(src, dest, options = {}) {
|
|
70
|
+
await FsExtra.move(src, dest, options);
|
|
71
|
+
}
|
|
72
|
+
async function readFile(path, options = { encoding: 'utf-8', flag: 'r' }) {
|
|
73
|
+
return await FilesystemPromises.readFile(path, options);
|
|
74
|
+
}
|
|
75
|
+
async function writeFile(path, data, options = { encoding: 'utf-8', flag: 'w' }) {
|
|
76
|
+
return await FilesystemPromises.writeFile(path, data, options);
|
|
77
|
+
}
|
|
78
|
+
async function readJsonFile(path) {
|
|
79
|
+
const content = await readFile(path, { encoding: 'utf8' });
|
|
80
|
+
return JSON.parse(content);
|
|
81
|
+
}
|
|
82
|
+
async function writeJsonFile(path, data) {
|
|
83
|
+
return writeFile(path, JSON.stringify(data, null, 4));
|
|
84
|
+
}
|
|
85
|
+
async function glob(pattern, options) {
|
|
86
|
+
let _options = options;
|
|
87
|
+
if (options?.dot == null) {
|
|
88
|
+
_options = { ...options, dot: true };
|
|
89
|
+
}
|
|
90
|
+
return glob$1.glob(pattern, _options || {});
|
|
91
|
+
}
|
|
92
|
+
async function archived(path$1, name, glob = '**/*') {
|
|
93
|
+
return new Promise((resolve$1, reject) => {
|
|
94
|
+
try {
|
|
95
|
+
const archivePath = resolve(path$1, `${name}.zip`);
|
|
96
|
+
const output = createWriteStream(archivePath);
|
|
97
|
+
const _archiver = archiver('zip', { zlib: { level: 9 } });
|
|
98
|
+
output.on('close', () => resolve$1(archivePath));
|
|
99
|
+
_archiver.on('error', () => (err) => reject(err));
|
|
100
|
+
_archiver.pipe(output);
|
|
101
|
+
_archiver.glob(glob, {
|
|
102
|
+
ignore: [`${name}.zip`],
|
|
103
|
+
cwd: path$1,
|
|
104
|
+
});
|
|
105
|
+
_archiver.finalize();
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
reject(err);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async function unlink(path) {
|
|
113
|
+
if (await exists(path)) {
|
|
114
|
+
await FilesystemPromises.unlink(path);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function readdir(path) {
|
|
118
|
+
return await FilesystemPromises.readdir(path);
|
|
119
|
+
}
|
|
120
|
+
async function stat(path) {
|
|
121
|
+
return await FilesystemPromises.stat(path);
|
|
122
|
+
}
|
|
102
123
|
const watch = chokidar.watch;
|
|
124
|
+
async function decompressGzip(file, destination, mode = 0o755) {
|
|
125
|
+
const unzip = createGunzip();
|
|
126
|
+
const readStream = createReadStream(file);
|
|
127
|
+
const writeStream = createWriteStream(destination, { mode });
|
|
128
|
+
await pipeline(readStream, unzip, writeStream);
|
|
129
|
+
}
|
|
130
|
+
async function extractTar(file, cwd, mode) {
|
|
131
|
+
await tar.extract({ cwd, file, mode });
|
|
132
|
+
}
|
|
103
133
|
|
|
104
|
-
export { archived, exists, glob, isDirectory, mkdir, move, readFile, readJsonFile, readdir, stat, tapIntoTmp, unlink, watch, writeFile, writeJsonFile };
|
|
134
|
+
export { archived, decompressGzip, exists, extractTar, glob, isDirectory, isExecutable, mkdir, move, readFile, readJsonFile, readdir, rm, stat, tapIntoTmp, unlink, watch, writeFile, writeJsonFile };
|
package/dist/node/form.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { FormData } from 'formdata-node';
|
|
3
|
-
import type { FormDataEntryValue } from 'formdata-node';
|
|
4
|
-
import { fileFromPath } from 'formdata-node/file-from-path';
|
|
5
|
-
export type FormDataResolvable = Array<FormDataResolvable> | {
|
|
6
|
-
[key: string]: FormDataResolvable;
|
|
7
|
-
} | FormDataEntryValue | undefined | boolean | number | Blob | Date | null;
|
|
8
|
-
export declare const file: typeof fileFromPath;
|
|
9
|
-
export declare function convert(source: Record<string, FormDataResolvable>, form?: FormData, parentKey?: string | null): FormData;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FormData } from 'formdata-node';
|
|
3
|
+
import type { FormDataEntryValue } from 'formdata-node';
|
|
4
|
+
import { fileFromPath } from 'formdata-node/file-from-path';
|
|
5
|
+
export type FormDataResolvable = Array<FormDataResolvable> | {
|
|
6
|
+
[key: string]: FormDataResolvable;
|
|
7
|
+
} | FormDataEntryValue | undefined | boolean | number | Blob | Date | null;
|
|
8
|
+
export declare const file: typeof fileFromPath;
|
|
9
|
+
export declare function convert(source: Record<string, FormDataResolvable>, form?: FormData, parentKey?: string | null): FormData;
|
package/dist/node/form.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { FormData, File } from 'formdata-node';
|
|
2
2
|
import { fileFromPath } from 'formdata-node/file-from-path';
|
|
3
3
|
|
|
4
|
-
const file = fileFromPath;
|
|
5
|
-
function convert(source, form = new FormData(), parentKey = null) {
|
|
6
|
-
source = source || {};
|
|
7
|
-
for (const key in source) {
|
|
8
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
9
|
-
append(form, toKey(parentKey, key), source[key]);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return form;
|
|
13
|
-
}
|
|
14
|
-
function append(form, key, value) {
|
|
15
|
-
if (Array.isArray(value)) {
|
|
16
|
-
return Array.from(value.keys()).forEach(index => append(form, toKey(key, index.toString()), value[index]));
|
|
17
|
-
}
|
|
18
|
-
else if (value instanceof Date) {
|
|
19
|
-
return form.append(key, value.toISOString());
|
|
20
|
-
}
|
|
21
|
-
else if (value instanceof File) {
|
|
22
|
-
return form.append(key, value, value.name);
|
|
23
|
-
}
|
|
24
|
-
else if (value instanceof Blob) {
|
|
25
|
-
return form.append(key, value);
|
|
26
|
-
}
|
|
27
|
-
else if (typeof value === 'boolean') {
|
|
28
|
-
return form.append(key, value ? '1' : '0');
|
|
29
|
-
}
|
|
30
|
-
else if (typeof value === 'string') {
|
|
31
|
-
return form.append(key, value);
|
|
32
|
-
}
|
|
33
|
-
else if (typeof value === 'number') {
|
|
34
|
-
return form.append(key, `${value}`);
|
|
35
|
-
}
|
|
36
|
-
else if (value === null || value === undefined) {
|
|
37
|
-
return form.append(key, '');
|
|
38
|
-
}
|
|
39
|
-
convert(value, form, key);
|
|
40
|
-
}
|
|
41
|
-
function toKey(parent, key) {
|
|
42
|
-
return parent ? `${parent}[${key}]` : key;
|
|
4
|
+
const file = fileFromPath;
|
|
5
|
+
function convert(source, form = new FormData(), parentKey = null) {
|
|
6
|
+
source = source || {};
|
|
7
|
+
for (const key in source) {
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
9
|
+
append(form, toKey(parentKey, key), source[key]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return form;
|
|
13
|
+
}
|
|
14
|
+
function append(form, key, value) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return Array.from(value.keys()).forEach(index => append(form, toKey(key, index.toString()), value[index]));
|
|
17
|
+
}
|
|
18
|
+
else if (value instanceof Date) {
|
|
19
|
+
return form.append(key, value.toISOString());
|
|
20
|
+
}
|
|
21
|
+
else if (value instanceof File) {
|
|
22
|
+
return form.append(key, value, value.name);
|
|
23
|
+
}
|
|
24
|
+
else if (value instanceof Blob) {
|
|
25
|
+
return form.append(key, value);
|
|
26
|
+
}
|
|
27
|
+
else if (typeof value === 'boolean') {
|
|
28
|
+
return form.append(key, value ? '1' : '0');
|
|
29
|
+
}
|
|
30
|
+
else if (typeof value === 'string') {
|
|
31
|
+
return form.append(key, value);
|
|
32
|
+
}
|
|
33
|
+
else if (typeof value === 'number') {
|
|
34
|
+
return form.append(key, `${value}`);
|
|
35
|
+
}
|
|
36
|
+
else if (value === null || value === undefined) {
|
|
37
|
+
return form.append(key, '');
|
|
38
|
+
}
|
|
39
|
+
convert(value, form, key);
|
|
40
|
+
}
|
|
41
|
+
function toKey(parent, key) {
|
|
42
|
+
return parent ? `${parent}[${key}]` : key;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export { convert, file };
|