@youcan/cli 1.0.8 → 1.1.0-beta.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.
- package/bin/exec.cmd +3 -0
- package/bin/exec.js +8 -0
- package/dist/cli/commands/auth/login.d.ts +4 -2
- package/dist/cli/commands/auth/login.js +7 -85
- package/dist/cli/commands/auth/logout.d.ts +4 -2
- package/dist/cli/commands/auth/logout.js +9 -18
- package/dist/index.d.ts +2 -1
- package/dist/index.js +20 -2
- package/package.json +56 -38
- package/bin/index.js +0 -2
- package/dist/cli/commands/apps/create.d.ts +0 -2
- package/dist/cli/commands/apps/create.js +0 -65
- package/dist/cli/commands/apps/install.d.ts +0 -2
- package/dist/cli/commands/apps/install.js +0 -28
- package/dist/cli/commands/auth/types.d.ts +0 -6
- package/dist/cli/commands/index.d.ts +0 -12
- package/dist/cli/commands/index.js +0 -14
- package/dist/cli/commands/store/info.d.ts +0 -2
- package/dist/cli/commands/store/info.js +0 -29
- package/dist/cli/commands/store/switch.d.ts +0 -2
- package/dist/cli/commands/store/switch.js +0 -59
- package/dist/cli/commands/store/types.d.ts +0 -4
- package/dist/cli/commands/theme/delete.d.ts +0 -2
- package/dist/cli/commands/theme/delete.js +0 -46
- package/dist/cli/commands/theme/dev.d.ts +0 -2
- package/dist/cli/commands/theme/dev.js +0 -199
- package/dist/cli/commands/theme/init.d.ts +0 -2
- package/dist/cli/commands/theme/init.js +0 -86
- package/dist/cli/commands/theme/list.d.ts +0 -2
- package/dist/cli/commands/theme/list.js +0 -35
- package/dist/cli/commands/theme/pack.d.ts +0 -2
- package/dist/cli/commands/theme/pack.js +0 -31
- package/dist/cli/commands/theme/pull.d.ts +0 -2
- package/dist/cli/commands/theme/pull.js +0 -56
- package/dist/cli/commands/theme/types.d.ts +0 -17
- package/dist/cli/commands/types.d.ts +0 -22
- package/dist/cli/index.d.ts +0 -12
- package/dist/cli/index.js +0 -53
- package/dist/config/index.d.ts +0 -21
- package/dist/config/index.js +0 -25
- package/dist/config/messages.d.ts +0 -36
- package/dist/config/messages.js +0 -37
- package/dist/core/client/client.d.ts +0 -23
- package/dist/core/client/client.js +0 -83
- package/dist/core/client/types.d.ts +0 -80
- package/dist/core/themes/preview.d.ts +0 -1
- package/dist/core/themes/preview.js +0 -37
- package/dist/lib/cli/commands/apps/create.d.ts +0 -2
- package/dist/lib/cli/commands/apps/install.d.ts +0 -2
- package/dist/lib/cli/commands/auth/login.d.ts +0 -2
- package/dist/lib/cli/commands/auth/logout.d.ts +0 -2
- package/dist/lib/cli/commands/auth/types.d.ts +0 -6
- package/dist/lib/cli/commands/index.d.ts +0 -12
- package/dist/lib/cli/commands/store/info.d.ts +0 -2
- package/dist/lib/cli/commands/store/switch.d.ts +0 -2
- package/dist/lib/cli/commands/store/types.d.ts +0 -4
- package/dist/lib/cli/commands/theme/delete.d.ts +0 -2
- package/dist/lib/cli/commands/theme/dev.d.ts +0 -2
- package/dist/lib/cli/commands/theme/init.d.ts +0 -2
- package/dist/lib/cli/commands/theme/list.d.ts +0 -2
- package/dist/lib/cli/commands/theme/pack.d.ts +0 -2
- package/dist/lib/cli/commands/theme/pull.d.ts +0 -2
- package/dist/lib/cli/commands/theme/types.d.ts +0 -17
- package/dist/lib/cli/commands/types.d.ts +0 -22
- package/dist/lib/cli/index.d.ts +0 -12
- package/dist/lib/config/index.d.ts +0 -21
- package/dist/lib/config/messages.d.ts +0 -36
- package/dist/lib/core/client/client.d.ts +0 -23
- package/dist/lib/core/client/types.d.ts +0 -80
- package/dist/lib/core/themes/preview.d.ts +0 -1
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/utils/common.d.ts +0 -22
- package/dist/lib/utils/git/cloneRepository.d.ts +0 -6
- package/dist/lib/utils/helpers.d.ts +0 -3
- package/dist/lib/utils/http.d.ts +0 -11
- package/dist/lib/utils/network.d.ts +0 -2
- package/dist/lib/utils/system/deleteFile.d.ts +0 -5
- package/dist/lib/utils/system/ls.d.ts +0 -1
- package/dist/lib/utils/system/openLink.d.ts +0 -1
- package/dist/lib/utils/system/saveFile.d.ts +0 -1
- package/dist/lib/utils/system/stdout.d.ts +0 -20
- package/dist/lib/utils/system/writeToFile.d.ts +0 -6
- package/dist/lib/utils/system/zipFolder.d.ts +0 -5
- package/dist/lib/utils/system.d.ts +0 -1
- package/dist/test/commands/auth/login.d.ts +0 -2
- package/dist/test/commands/auth/logout.d.ts +0 -2
- package/dist/test/commands/help.d.ts +0 -2
- package/dist/test/commands/theme/delete.d.ts +0 -2
- package/dist/test/commands/theme/dev.d.ts +0 -2
- package/dist/test/commands/theme/init.d.ts +0 -2
- package/dist/test/index.test.d.ts +0 -1
- package/dist/utils/common.d.ts +0 -22
- package/dist/utils/common.js +0 -67
- package/dist/utils/git/cloneRepository.d.ts +0 -6
- package/dist/utils/git/cloneRepository.js +0 -18
- package/dist/utils/helpers.d.ts +0 -3
- package/dist/utils/helpers.js +0 -35
- package/dist/utils/http.d.ts +0 -11
- package/dist/utils/http.js +0 -26
- package/dist/utils/network.d.ts +0 -2
- package/dist/utils/network.js +0 -81
- package/dist/utils/system/deleteFile.d.ts +0 -5
- package/dist/utils/system/deleteFile.js +0 -13
- package/dist/utils/system/ls.d.ts +0 -1
- package/dist/utils/system/ls.js +0 -9
- package/dist/utils/system/openLink.d.ts +0 -1
- package/dist/utils/system/saveFile.d.ts +0 -1
- package/dist/utils/system/saveFile.js +0 -9
- package/dist/utils/system/stdout.d.ts +0 -17
- package/dist/utils/system/stdout.js +0 -35
- package/dist/utils/system/writeToFile.d.ts +0 -1
- package/dist/utils/system/writeToFile.js +0 -7
- package/dist/utils/system/zipFolder.d.ts +0 -5
- package/dist/utils/system/zipFolder.js +0 -57
- package/dist/utils/system.d.ts +0 -1
- package/dist/utils/system.js +0 -18
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils/common.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import type { PathLike } from 'fs';
|
|
4
|
-
export declare const homeDir: string;
|
|
5
|
-
/**
|
|
6
|
-
* Get youcan token from $HOME/.youcan file
|
|
7
|
-
* @returns string - youcan token
|
|
8
|
-
*/
|
|
9
|
-
export declare function getUserToken(): Promise<string>;
|
|
10
|
-
export declare function getCurrentThemeId(dir: PathLike): Promise<string | null>;
|
|
11
|
-
export declare class LoadingSpinner {
|
|
12
|
-
private message;
|
|
13
|
-
timer: NodeJS.Timeout | null;
|
|
14
|
-
constructor(message: string);
|
|
15
|
-
start(): this;
|
|
16
|
-
private flush;
|
|
17
|
-
stop(): this;
|
|
18
|
-
error(message?: string | null): this;
|
|
19
|
-
static exec(message: string, closure: (spinner: LoadingSpinner) => Promise<void>): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
export declare function delay(ms: number): Promise<void>;
|
|
22
|
-
export declare function getCurrentDate(): string;
|
package/dist/utils/common.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import kleur from 'kleur';
|
|
5
|
-
|
|
6
|
-
os.homedir();
|
|
7
|
-
async function getCurrentThemeId(dir) {
|
|
8
|
-
const filepath = path.resolve(dir.toString(), '.youcan');
|
|
9
|
-
if (!fs.existsSync(filepath)) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return await fs.promises.readFile(filepath, 'utf-8')
|
|
13
|
-
.then(b => JSON.parse(b).theme_id);
|
|
14
|
-
}
|
|
15
|
-
class LoadingSpinner {
|
|
16
|
-
message;
|
|
17
|
-
timer;
|
|
18
|
-
constructor(message) {
|
|
19
|
-
this.message = message;
|
|
20
|
-
this.message = message;
|
|
21
|
-
this.timer = null;
|
|
22
|
-
}
|
|
23
|
-
start() {
|
|
24
|
-
process.stdout.write('\x1B[?25l');
|
|
25
|
-
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
26
|
-
let i = 0;
|
|
27
|
-
this.timer = setInterval(() => {
|
|
28
|
-
process.stdout.write(`\r${frames[i = ++i % frames.length]} ${this.message}`);
|
|
29
|
-
}, 100);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
flush() {
|
|
33
|
-
if (this.timer) {
|
|
34
|
-
clearInterval(this.timer);
|
|
35
|
-
this.timer = null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
stop() {
|
|
39
|
-
this.flush();
|
|
40
|
-
process.stdout.write('\r');
|
|
41
|
-
process.stdout.write(kleur.green(`✔ ${this.message}\n`));
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
error(message = null) {
|
|
45
|
-
this.flush();
|
|
46
|
-
process.stdout.write('\r');
|
|
47
|
-
process.stdout.write(kleur.red(`✖ ${message ?? this.message}\n`));
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
static async exec(message, closure) {
|
|
51
|
-
const spinner = new LoadingSpinner(message).start();
|
|
52
|
-
await closure(spinner);
|
|
53
|
-
spinner.timer && spinner.stop();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function delay(ms) {
|
|
57
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
58
|
-
}
|
|
59
|
-
function getCurrentDate() {
|
|
60
|
-
const date = new Date();
|
|
61
|
-
const day = date.getDate();
|
|
62
|
-
const month = date.getMonth() + 1;
|
|
63
|
-
const year = date.getFullYear();
|
|
64
|
-
return `${day}-${month}-${year}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export { LoadingSpinner, delay, getCurrentDate, getCurrentThemeId };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'node:child_process';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Clone a git repository
|
|
5
|
-
* @param url - URL to open
|
|
6
|
-
* @param folder
|
|
7
|
-
*/
|
|
8
|
-
function cloneRepository(url, folder) {
|
|
9
|
-
try {
|
|
10
|
-
execSync(`git clone '${url}' '${folder}'`);
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { cloneRepository as default };
|
package/dist/utils/helpers.d.ts
DELETED
package/dist/utils/helpers.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function stripln(buffer, ln) {
|
|
2
|
-
let index = 0;
|
|
3
|
-
while (ln-- > 0) {
|
|
4
|
-
const lfIndex = buffer.indexOf('\n', index);
|
|
5
|
-
if (lfIndex >= 0) {
|
|
6
|
-
index = lfIndex + 1;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return index > 0 ? buffer.substring(index) : buffer;
|
|
10
|
-
}
|
|
11
|
-
function splitln(buffer, limit) {
|
|
12
|
-
const cols = buffer.trim().split(/\s+/);
|
|
13
|
-
if (cols.length > limit) {
|
|
14
|
-
cols[limit - 1] = cols.slice(limit - 1).join(' ');
|
|
15
|
-
}
|
|
16
|
-
return cols;
|
|
17
|
-
}
|
|
18
|
-
function getcols(buffer, indices, limit = null) {
|
|
19
|
-
const lines = buffer.split(/(\r\n|\n|\r)/);
|
|
20
|
-
const cols = [];
|
|
21
|
-
if (!limit) {
|
|
22
|
-
limit = Math.max.apply(null, indices) + 1;
|
|
23
|
-
}
|
|
24
|
-
lines.forEach((ln) => {
|
|
25
|
-
const lncols = splitln(ln, limit);
|
|
26
|
-
const lncol = [];
|
|
27
|
-
indices.forEach((index) => {
|
|
28
|
-
lncol.push(lncols[index] || '');
|
|
29
|
-
});
|
|
30
|
-
cols.push(lncol);
|
|
31
|
-
});
|
|
32
|
-
return cols;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { getcols, splitln, stripln };
|
package/dist/utils/http.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Agent } from 'https';
|
|
3
|
-
import type { RequestInit } from 'node-fetch';
|
|
4
|
-
export declare const DEFAULT_HTTP_CLIENT_OPTIONS: {
|
|
5
|
-
headers: {
|
|
6
|
-
Accept: string;
|
|
7
|
-
};
|
|
8
|
-
agent: Agent;
|
|
9
|
-
};
|
|
10
|
-
export declare function get<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
|
11
|
-
export declare function post<T>(endpoint: string, options?: RequestInit): Promise<T>;
|
package/dist/utils/http.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Agent } from 'node:https';
|
|
2
|
-
import fetch from 'node-fetch';
|
|
3
|
-
import { mergeDeepLeft } from 'ramda';
|
|
4
|
-
|
|
5
|
-
const HttpsAgent = new Agent({ keepAlive: true, keepAliveMsecs: 5 * 60 * 1000 });
|
|
6
|
-
const DEFAULT_HTTP_CLIENT_OPTIONS = {
|
|
7
|
-
headers: {
|
|
8
|
-
Accept: 'application/json',
|
|
9
|
-
},
|
|
10
|
-
agent: HttpsAgent,
|
|
11
|
-
};
|
|
12
|
-
async function request(endpoint, options = {}) {
|
|
13
|
-
const response = await fetch(endpoint, mergeDeepLeft(options, DEFAULT_HTTP_CLIENT_OPTIONS));
|
|
14
|
-
if (!response.ok) {
|
|
15
|
-
throw new Error(await response.text(), { cause: response });
|
|
16
|
-
}
|
|
17
|
-
return response.json();
|
|
18
|
-
}
|
|
19
|
-
async function get(endpoint, options = {}) {
|
|
20
|
-
return request(endpoint, { ...options, method: 'GET' });
|
|
21
|
-
}
|
|
22
|
-
async function post(endpoint, options = {}) {
|
|
23
|
-
return request(endpoint, { ...options, method: 'POST' });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { DEFAULT_HTTP_CLIENT_OPTIONS, get, post };
|
package/dist/utils/network.d.ts
DELETED
package/dist/utils/network.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:net';
|
|
2
|
-
import { platform } from 'node:process';
|
|
3
|
-
import { execaCommand } from 'execa';
|
|
4
|
-
import stdout from './system/stdout.js';
|
|
5
|
-
import { stripln, getcols } from './helpers.js';
|
|
6
|
-
|
|
7
|
-
async function isPortAvailable(port) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const server = createServer();
|
|
10
|
-
server.once('error', (err) => {
|
|
11
|
-
server.close();
|
|
12
|
-
if (err.code === 'EADDRINUSE') {
|
|
13
|
-
resolve(false);
|
|
14
|
-
}
|
|
15
|
-
reject(err);
|
|
16
|
-
});
|
|
17
|
-
server.once('listening', () => {
|
|
18
|
-
server.close();
|
|
19
|
-
resolve(true);
|
|
20
|
-
});
|
|
21
|
-
server.listen(port);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const PID_GETTER_CLASS_MAP = {
|
|
25
|
-
async darwin(port) {
|
|
26
|
-
const { stdout: out, stderr: err } = await execaCommand('netstat -anv -p TCP && netstat -anv -p UDP');
|
|
27
|
-
const warning = err.toString().trim();
|
|
28
|
-
warning && stdout.warn(warning);
|
|
29
|
-
const line = stripln(out, 2);
|
|
30
|
-
const col = getcols(line, [0, 3, 8], 10)
|
|
31
|
-
.filter(col => !!col[0].match(/^(udp|tcp)/))
|
|
32
|
-
.find((col) => {
|
|
33
|
-
const matches = col[1].match(/\.(\d+)$/);
|
|
34
|
-
return matches && matches[1] === String(port);
|
|
35
|
-
});
|
|
36
|
-
if (col && col[2].length) {
|
|
37
|
-
return (parseInt(col[2], 10));
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
},
|
|
41
|
-
async linux(port) {
|
|
42
|
-
const { stdout: out, stderr: err } = await execaCommand('netstat -tunlp');
|
|
43
|
-
const warning = err.toString().trim();
|
|
44
|
-
warning && stdout.warn(warning);
|
|
45
|
-
const data = stripln(out.toString(), 2);
|
|
46
|
-
const cols = getcols(data, [3, 6], 7).find((col) => {
|
|
47
|
-
const matches = col[0].match(/:(\d+)$/);
|
|
48
|
-
return matches && matches[1] === String(port);
|
|
49
|
-
});
|
|
50
|
-
if (cols && cols[1]) {
|
|
51
|
-
const pid = cols[1].split('/', 1)[0];
|
|
52
|
-
if (pid.length) {
|
|
53
|
-
return parseInt(pid, 10);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
},
|
|
58
|
-
async win32(port) {
|
|
59
|
-
const { stdout: out, stderr: err } = await execaCommand('netstat -ano');
|
|
60
|
-
const warning = err.toString().trim();
|
|
61
|
-
warning && stdout.warn(warning);
|
|
62
|
-
const data = stripln(out.toString(), 4);
|
|
63
|
-
const cols = getcols(data, [1, 4], 5).find((col) => {
|
|
64
|
-
const matches = col[0].match(/:(\d+)$/);
|
|
65
|
-
return matches && matches[1] === String(port);
|
|
66
|
-
});
|
|
67
|
-
if (cols && cols[1].length && parseInt(cols[1], 10) > 0) {
|
|
68
|
-
return parseInt(cols[1], 10);
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
async function getPidByPort(port) {
|
|
74
|
-
if (!(platform in PID_GETTER_CLASS_MAP)) {
|
|
75
|
-
throw new Error('Unsupported platform, process will have to be killed manually.');
|
|
76
|
-
}
|
|
77
|
-
const getter = PID_GETTER_CLASS_MAP[platform];
|
|
78
|
-
return await getter(port);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export { getPidByPort, isPortAvailable };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function lsDir(path: string): string[];
|
package/dist/utils/system/ls.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function openLink(url: string): void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function saveHttpFile(res: any, filename: string): Promise<void>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare function log(arg: string): void;
|
|
2
|
-
declare function info(arg: string): void;
|
|
3
|
-
declare function warn(arg: string): void;
|
|
4
|
-
declare function error(arg: string): void;
|
|
5
|
-
declare function success(arg: string): void;
|
|
6
|
-
declare function clear(): void;
|
|
7
|
-
declare function table(arg: any): void;
|
|
8
|
-
declare const _default: {
|
|
9
|
-
log: typeof log;
|
|
10
|
-
info: typeof info;
|
|
11
|
-
warn: typeof warn;
|
|
12
|
-
error: typeof error;
|
|
13
|
-
clear: typeof clear;
|
|
14
|
-
success: typeof success;
|
|
15
|
-
table: typeof table;
|
|
16
|
-
};
|
|
17
|
-
export default _default;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import kleur from 'kleur';
|
|
2
|
-
|
|
3
|
-
const stdout = console;
|
|
4
|
-
function log(arg) {
|
|
5
|
-
return stdout.log(kleur.gray(arg));
|
|
6
|
-
}
|
|
7
|
-
function info(arg) {
|
|
8
|
-
return log(kleur.blue(arg));
|
|
9
|
-
}
|
|
10
|
-
function warn(arg) {
|
|
11
|
-
return log(kleur.yellow(arg));
|
|
12
|
-
}
|
|
13
|
-
function error(arg) {
|
|
14
|
-
return log(kleur.bgRed().white(arg));
|
|
15
|
-
}
|
|
16
|
-
function success(arg) {
|
|
17
|
-
return log(kleur.green(arg));
|
|
18
|
-
}
|
|
19
|
-
function clear() {
|
|
20
|
-
return stdout.clear();
|
|
21
|
-
}
|
|
22
|
-
function table(arg) {
|
|
23
|
-
return stdout.table(arg);
|
|
24
|
-
}
|
|
25
|
-
var stdout$1 = {
|
|
26
|
-
log,
|
|
27
|
-
info,
|
|
28
|
-
warn,
|
|
29
|
-
error,
|
|
30
|
-
clear,
|
|
31
|
-
success,
|
|
32
|
-
table,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export { stdout$1 as default };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function writeToFile(filePath: string, content: string): void;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zip folder and save it to a given path and return zip folder path
|
|
3
|
-
*/
|
|
4
|
-
export declare function zipFolder(folderPath: string, folderName: string): Promise<string>;
|
|
5
|
-
export declare function zipDirectory(dirPath: string, folderName: string, only?: string[]): Promise<unknown>;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import archiver from 'archiver';
|
|
4
|
-
import { lsDir } from './ls.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Zip folder and save it to a given path and return zip folder path
|
|
8
|
-
*/
|
|
9
|
-
async function zipFolder(folderPath, folderName) {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
try {
|
|
12
|
-
const zipPath = path.resolve(folderPath, `${folderName}.zip`);
|
|
13
|
-
const output = fs.createWriteStream(zipPath);
|
|
14
|
-
const archive = archiver('zip', {
|
|
15
|
-
zlib: { level: 9 },
|
|
16
|
-
});
|
|
17
|
-
output.on('close', () => {
|
|
18
|
-
resolve(zipPath);
|
|
19
|
-
});
|
|
20
|
-
archive.on('error', (err) => {
|
|
21
|
-
reject(err);
|
|
22
|
-
});
|
|
23
|
-
archive.pipe(output);
|
|
24
|
-
archive.directory(path.resolve(folderPath, folderName), false);
|
|
25
|
-
archive.finalize();
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
reject(err);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
async function zipDirectory(dirPath, folderName, only) {
|
|
33
|
-
const ls = lsDir(dirPath).filter(folder => only?.includes(folder));
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
try {
|
|
36
|
-
const zip = path.resolve(dirPath, `${folderName}.zip`);
|
|
37
|
-
const output = fs.createWriteStream(zip);
|
|
38
|
-
const archive = archiver('zip', {
|
|
39
|
-
zlib: { level: 9 },
|
|
40
|
-
});
|
|
41
|
-
output.on('close', () => {
|
|
42
|
-
resolve(zip);
|
|
43
|
-
});
|
|
44
|
-
archive.on('error', (err) => {
|
|
45
|
-
reject(err);
|
|
46
|
-
});
|
|
47
|
-
archive.pipe(output);
|
|
48
|
-
ls.forEach(folder => archive.directory(path.resolve(dirPath, folder), folder));
|
|
49
|
-
archive.finalize();
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
reject(err);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { zipDirectory, zipFolder };
|
package/dist/utils/system.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const kill: (pid: number, signal?: string, timeout?: number) => Promise<void>;
|
package/dist/utils/system.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const kill = (pid, signal = 'SIGTERM', timeout = 1000) => new Promise((resolve, reject) => {
|
|
2
|
-
process.kill(pid, signal);
|
|
3
|
-
let count = 0;
|
|
4
|
-
setInterval(() => {
|
|
5
|
-
try {
|
|
6
|
-
process.kill(pid, 0);
|
|
7
|
-
}
|
|
8
|
-
catch (e) {
|
|
9
|
-
resolve();
|
|
10
|
-
}
|
|
11
|
-
count += 100;
|
|
12
|
-
if (count > timeout) {
|
|
13
|
-
reject(new Error('Timeout process kill'));
|
|
14
|
-
}
|
|
15
|
-
}, 100);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export { kill };
|