@youcan/cli 1.1.0-beta.0 → 1.1.0-beta.10
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 +55 -40
- 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/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,23 +0,0 @@
|
|
|
1
|
-
import type { CreateAppRequest, CreateAppResponse, DeleteThemeFileRequestData, GenerateAppInstallationUrlResponse, InitThemeRequest as InitThemeRequestData, LoginRequest, LoginResponse, SelectStoreRequest, SelectStoreResponse, StoreInfoResponse, ThemeMetaResponse, UpdateThemeFileRequestData } from './types';
|
|
2
|
-
import type { listStoresResponse } from '@/cli/commands/store/types';
|
|
3
|
-
export default class Client {
|
|
4
|
-
private accessToken;
|
|
5
|
-
constructor();
|
|
6
|
-
setAccessToken(token: string): void;
|
|
7
|
-
getAccessToken(): string | null;
|
|
8
|
-
isAuthenticated(): boolean;
|
|
9
|
-
auth(data: LoginRequest): Promise<LoginResponse>;
|
|
10
|
-
listStores(): Promise<listStoresResponse>;
|
|
11
|
-
selectStore(data: SelectStoreRequest): Promise<SelectStoreResponse>;
|
|
12
|
-
initTheme(data: InitThemeRequestData): Promise<string>;
|
|
13
|
-
getThemeMeta(themeId: string): Promise<ThemeMetaResponse>;
|
|
14
|
-
pullTheme(themeId: string): Promise<import("node-fetch").Response>;
|
|
15
|
-
listThemes(): Promise<unknown>;
|
|
16
|
-
deleteTheme(themeId: string): Promise<unknown>;
|
|
17
|
-
updateFile(themeId: string, data: UpdateThemeFileRequestData): Promise<void>;
|
|
18
|
-
deleteFile(themeId: string, data: DeleteThemeFileRequestData): Promise<void>;
|
|
19
|
-
getStoreInfo(): Promise<StoreInfoResponse>;
|
|
20
|
-
createApp(data: CreateAppRequest): Promise<CreateAppResponse>;
|
|
21
|
-
generateAppInstallationUrl(name: string): Promise<GenerateAppInstallationUrlResponse>;
|
|
22
|
-
private withDefaults;
|
|
23
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { FormData } from 'formdata-node';
|
|
2
|
-
import { mergeDeepLeft } from 'ramda';
|
|
3
|
-
import fetch from 'node-fetch';
|
|
4
|
-
import { post, get } from '../../utils/http.js';
|
|
5
|
-
import config from '../../config/index.js';
|
|
6
|
-
import { delay } from '../../utils/common.js';
|
|
7
|
-
|
|
8
|
-
class Client {
|
|
9
|
-
accessToken = null;
|
|
10
|
-
constructor() { }
|
|
11
|
-
setAccessToken(token) {
|
|
12
|
-
this.accessToken = token;
|
|
13
|
-
}
|
|
14
|
-
getAccessToken() {
|
|
15
|
-
return this.accessToken;
|
|
16
|
-
}
|
|
17
|
-
isAuthenticated() {
|
|
18
|
-
return this.accessToken != null;
|
|
19
|
-
}
|
|
20
|
-
async auth(data) {
|
|
21
|
-
const form = new FormData();
|
|
22
|
-
Object.entries(data).forEach(([key, value]) => form.append(key, value));
|
|
23
|
-
return await post(`${config.SELLER_AREA_API_BASE_URI}/auth/login`, this.withDefaults({ body: form }));
|
|
24
|
-
}
|
|
25
|
-
async listStores() {
|
|
26
|
-
return await get(`${config.SELLER_AREA_API_BASE_URI}/stores`, this.withDefaults({}));
|
|
27
|
-
}
|
|
28
|
-
async selectStore(data) {
|
|
29
|
-
return await post(`${config.SELLER_AREA_API_BASE_URI}/switch-store/${data.id}`, this.withDefaults({}));
|
|
30
|
-
}
|
|
31
|
-
async initTheme(data) {
|
|
32
|
-
const form = new FormData();
|
|
33
|
-
Object.entries(data).forEach(([key, value]) => form.append(key, value));
|
|
34
|
-
const { id } = await post(`${config.SELLER_AREA_API_BASE_URI}/themes/init`, this.withDefaults({ body: form }));
|
|
35
|
-
return id;
|
|
36
|
-
}
|
|
37
|
-
async getThemeMeta(themeId) {
|
|
38
|
-
return await get(`${config.SELLER_AREA_API_BASE_URI}/themes/${themeId}/metadata`, this.withDefaults({}));
|
|
39
|
-
}
|
|
40
|
-
async pullTheme(themeId) {
|
|
41
|
-
return await fetch(`${config.SELLER_AREA_API_BASE_URI}/themes/${themeId}`, this.withDefaults({}));
|
|
42
|
-
}
|
|
43
|
-
async listThemes() {
|
|
44
|
-
return await get(`${config.SELLER_AREA_API_BASE_URI}/themes`, this.withDefaults({}));
|
|
45
|
-
}
|
|
46
|
-
async deleteTheme(themeId) {
|
|
47
|
-
return await post(`${config.SELLER_AREA_API_BASE_URI}/themes/${themeId}/delete`, this.withDefaults({}));
|
|
48
|
-
}
|
|
49
|
-
async updateFile(themeId, data) {
|
|
50
|
-
const form = new FormData();
|
|
51
|
-
Object.entries(data).forEach(([key, value]) => form.append(key, value));
|
|
52
|
-
await post(`${config.SELLER_AREA_API_BASE_URI}/themes/${themeId}/update`, this.withDefaults({ body: form }));
|
|
53
|
-
await delay(100);
|
|
54
|
-
}
|
|
55
|
-
async deleteFile(themeId, data) {
|
|
56
|
-
const form = new FormData();
|
|
57
|
-
Object.entries(data).forEach(([key, value]) => form.append(key, value));
|
|
58
|
-
await post(`${config.SELLER_AREA_API_BASE_URI}/themes/${themeId}/update`, this.withDefaults({ body: form }));
|
|
59
|
-
await delay(100);
|
|
60
|
-
}
|
|
61
|
-
async getStoreInfo() {
|
|
62
|
-
return await get(`${config.SELLER_AREA_API_BASE_URI}/me`, this.withDefaults());
|
|
63
|
-
}
|
|
64
|
-
async createApp(data) {
|
|
65
|
-
const form = new FormData();
|
|
66
|
-
Object.entries(data).forEach(([key, value]) => form.append(key, value));
|
|
67
|
-
return await post(`${config.SELLER_AREA_API_BASE_URI}/apps/draft/create`, this.withDefaults({ body: form }));
|
|
68
|
-
}
|
|
69
|
-
async generateAppInstallationUrl(name) {
|
|
70
|
-
return await get(`${config.SELLER_AREA_API_BASE_URI}/apps/draft/generate-installation-url?name=${name}`, this.withDefaults());
|
|
71
|
-
}
|
|
72
|
-
withDefaults(override = {}) {
|
|
73
|
-
return mergeDeepLeft(override, {
|
|
74
|
-
headers: {
|
|
75
|
-
Accept: 'application/json',
|
|
76
|
-
Authorization: `Bearer ${this.accessToken}`,
|
|
77
|
-
},
|
|
78
|
-
hostname: config.SELLER_AREA_API_BASE_URI,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { Client as default };
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { File } from 'formdata-node';
|
|
2
|
-
export interface InitThemeRequest {
|
|
3
|
-
archive: File;
|
|
4
|
-
theme_name: string;
|
|
5
|
-
theme_author: string;
|
|
6
|
-
theme_version: string;
|
|
7
|
-
theme_support_url: string;
|
|
8
|
-
theme_documentation_url: string;
|
|
9
|
-
}
|
|
10
|
-
export interface LoginRequest {
|
|
11
|
-
email: string;
|
|
12
|
-
password: string;
|
|
13
|
-
}
|
|
14
|
-
export interface LoginResponse {
|
|
15
|
-
token: string;
|
|
16
|
-
stores: Store[];
|
|
17
|
-
}
|
|
18
|
-
export interface SelectStoreRequest {
|
|
19
|
-
id: string;
|
|
20
|
-
}
|
|
21
|
-
export interface SelectStoreResponse {
|
|
22
|
-
token: string;
|
|
23
|
-
}
|
|
24
|
-
export interface Store {
|
|
25
|
-
store_id: string;
|
|
26
|
-
slug: string;
|
|
27
|
-
is_active: boolean;
|
|
28
|
-
}
|
|
29
|
-
export interface UpdateThemeFileRequestData {
|
|
30
|
-
file_type: string;
|
|
31
|
-
file_name: string;
|
|
32
|
-
file_content: File;
|
|
33
|
-
file_operation: 'save';
|
|
34
|
-
}
|
|
35
|
-
export interface DeleteThemeFileRequestData {
|
|
36
|
-
file_type: string;
|
|
37
|
-
file_name: string;
|
|
38
|
-
file_operation: 'delete';
|
|
39
|
-
}
|
|
40
|
-
export interface InitThemeResponse {
|
|
41
|
-
id: string;
|
|
42
|
-
}
|
|
43
|
-
export interface StoreInfoResponse {
|
|
44
|
-
name: string;
|
|
45
|
-
slug: string;
|
|
46
|
-
domain: string;
|
|
47
|
-
}
|
|
48
|
-
export interface ThemeFileInfo {
|
|
49
|
-
id: string;
|
|
50
|
-
type: string;
|
|
51
|
-
name: string;
|
|
52
|
-
file_name: string;
|
|
53
|
-
updated: boolean;
|
|
54
|
-
deleted: boolean;
|
|
55
|
-
size: number;
|
|
56
|
-
hash: string;
|
|
57
|
-
}
|
|
58
|
-
export interface ThemeMetaResponse {
|
|
59
|
-
theme_name: string;
|
|
60
|
-
theme_author: string;
|
|
61
|
-
theme_version: string;
|
|
62
|
-
theme_support_url: string;
|
|
63
|
-
theme_documentation_url: string;
|
|
64
|
-
config: ThemeFileInfo[];
|
|
65
|
-
layout: ThemeFileInfo[];
|
|
66
|
-
sections: ThemeFileInfo[];
|
|
67
|
-
templates: ThemeFileInfo[];
|
|
68
|
-
locales: ThemeFileInfo[];
|
|
69
|
-
snippets: ThemeFileInfo[];
|
|
70
|
-
assets: ThemeFileInfo[];
|
|
71
|
-
}
|
|
72
|
-
export interface CreateAppRequest {
|
|
73
|
-
name: string;
|
|
74
|
-
}
|
|
75
|
-
export interface CreateAppResponse {
|
|
76
|
-
name: string;
|
|
77
|
-
}
|
|
78
|
-
export interface GenerateAppInstallationUrlResponse {
|
|
79
|
-
url: string;
|
|
80
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function previewTheme(url: string, options: Record<string, string>): Promise<void>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createServer } from 'node:http';
|
|
2
|
-
import { Server } from 'socket.io';
|
|
3
|
-
import puppeteer from 'puppeteer';
|
|
4
|
-
import stdout from '../../utils/system/stdout.js';
|
|
5
|
-
import config from '../../config/index.js';
|
|
6
|
-
|
|
7
|
-
async function openPreviewPage(url, disableHardwareAcceleration) {
|
|
8
|
-
const options = {
|
|
9
|
-
headless: false,
|
|
10
|
-
defaultViewport: null,
|
|
11
|
-
userDataDir: '/tmp/youcan_puppeteer',
|
|
12
|
-
};
|
|
13
|
-
if (disableHardwareAcceleration) {
|
|
14
|
-
options.args = ['--disable-gpu'];
|
|
15
|
-
}
|
|
16
|
-
const browser = await puppeteer.launch(options);
|
|
17
|
-
browser.on('disconnected', () => {
|
|
18
|
-
stdout.info('Browser closed');
|
|
19
|
-
return process.exit(0);
|
|
20
|
-
});
|
|
21
|
-
const page = await browser.newPage();
|
|
22
|
-
await page.goto(url);
|
|
23
|
-
return page;
|
|
24
|
-
}
|
|
25
|
-
async function previewTheme(url, options) {
|
|
26
|
-
const httpServer = createServer();
|
|
27
|
-
const io = new Server(httpServer);
|
|
28
|
-
const previewPage = await openPreviewPage(url, options.disableHardwareAcceleration);
|
|
29
|
-
io.on('connection', (socket) => {
|
|
30
|
-
socket.on('theme:update', async () => {
|
|
31
|
-
await previewPage.reload({ waitUntil: 'domcontentloaded' });
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
httpServer.listen(config.PREVIEW_SERVER_PORT);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { previewTheme as default };
|
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>;
|