@youcan/cli 1.0.7 → 1.0.8

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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/bin/index.js +1 -1
  3. package/dist/cli/commands/apps/create.js +65 -0
  4. package/dist/cli/commands/apps/install.d.ts +2 -0
  5. package/dist/cli/commands/apps/install.js +28 -0
  6. package/dist/cli/commands/auth/login.d.ts +2 -0
  7. package/dist/cli/commands/auth/login.js +3 -4
  8. package/dist/cli/commands/auth/logout.d.ts +2 -0
  9. package/dist/cli/commands/auth/logout.js +2 -1
  10. package/dist/cli/commands/auth/types.d.ts +6 -0
  11. package/dist/cli/commands/index.d.ts +12 -0
  12. package/dist/cli/commands/index.js +2 -0
  13. package/dist/cli/commands/store/info.d.ts +2 -0
  14. package/dist/cli/commands/store/info.js +2 -1
  15. package/dist/cli/commands/store/switch.d.ts +2 -0
  16. package/dist/cli/commands/store/switch.js +6 -3
  17. package/dist/cli/commands/store/types.d.ts +4 -0
  18. package/dist/cli/commands/theme/delete.d.ts +2 -0
  19. package/dist/cli/commands/theme/delete.js +6 -3
  20. package/dist/cli/commands/theme/dev.d.ts +2 -0
  21. package/dist/cli/commands/theme/dev.js +24 -16
  22. package/dist/cli/commands/theme/init.d.ts +2 -0
  23. package/dist/cli/commands/theme/init.js +7 -6
  24. package/dist/cli/commands/theme/list.d.ts +2 -0
  25. package/dist/cli/commands/theme/list.js +4 -2
  26. package/dist/cli/commands/theme/pack.d.ts +2 -0
  27. package/dist/cli/commands/theme/pack.js +5 -3
  28. package/dist/cli/commands/theme/pull.d.ts +2 -0
  29. package/dist/cli/commands/theme/pull.js +5 -3
  30. package/dist/cli/commands/theme/types.d.ts +17 -0
  31. package/dist/cli/commands/types.d.ts +22 -0
  32. package/dist/cli/index.d.ts +12 -0
  33. package/dist/cli/index.js +10 -8
  34. package/dist/config/index.d.ts +21 -0
  35. package/dist/config/index.js +3 -3
  36. package/dist/config/messages.d.ts +36 -0
  37. package/dist/core/client/client.d.ts +23 -0
  38. package/dist/core/client/client.js +10 -3
  39. package/dist/core/client/types.d.ts +80 -0
  40. package/dist/core/themes/preview.d.ts +1 -0
  41. package/dist/core/themes/preview.js +3 -2
  42. package/dist/index.d.ts +1 -0
  43. package/dist/lib/cli/commands/apps/create.d.ts +2 -0
  44. package/dist/lib/cli/commands/apps/install.d.ts +2 -0
  45. package/dist/lib/cli/commands/index.d.ts +2 -0
  46. package/dist/lib/cli/index.d.ts +1 -1
  47. package/dist/lib/core/client/client.d.ts +3 -1
  48. package/dist/lib/core/client/types.d.ts +9 -0
  49. package/dist/utils/common.d.ts +22 -0
  50. package/dist/utils/common.js +8 -5
  51. package/dist/utils/git/cloneRepository.d.ts +6 -0
  52. package/dist/utils/git/cloneRepository.js +1 -1
  53. package/dist/utils/helpers.d.ts +3 -0
  54. package/dist/utils/helpers.js +6 -3
  55. package/dist/utils/http.d.ts +11 -0
  56. package/dist/utils/http.js +3 -2
  57. package/dist/utils/network.d.ts +2 -0
  58. package/dist/utils/network.js +12 -7
  59. package/dist/utils/system/deleteFile.d.ts +5 -0
  60. package/dist/utils/system/deleteFile.js +3 -2
  61. package/dist/utils/system/ls.d.ts +1 -0
  62. package/dist/utils/system/ls.js +1 -1
  63. package/dist/utils/system/openLink.d.ts +1 -0
  64. package/dist/utils/system/saveFile.d.ts +1 -0
  65. package/dist/utils/system/saveFile.js +2 -2
  66. package/dist/utils/system/stdout.d.ts +17 -0
  67. package/dist/utils/system/stdout.js +30 -11
  68. package/dist/utils/system/writeToFile.d.ts +1 -0
  69. package/dist/utils/system/writeToFile.js +1 -6
  70. package/dist/utils/system/zipFolder.d.ts +5 -0
  71. package/dist/utils/system/zipFolder.js +3 -3
  72. package/dist/utils/system.d.ts +1 -0
  73. package/dist/utils/system.js +2 -1
  74. package/package.json +19 -26
  75. package/README.md +0 -18
  76. package/dist/utils/system/openLink.js +0 -15
  77. /package/dist/{lib/cli/commands/theme/switch-store.d.ts → cli/commands/apps/create.d.ts} +0 -0
@@ -0,0 +1,21 @@
1
+ declare const _default: {
2
+ OAUTH_CLIENT_ID: number;
3
+ OAUTH_CALLBACK_PORT: number;
4
+ OAUTH_CALLBACK_SERVER_TIMEOUT: number;
5
+ OAUTH_CALLBACK_URL: string;
6
+ OAUTH_CLIENT_SECRET: string;
7
+ OAUTH_AUTH_CODE_URL: string;
8
+ OAUTH_ACCESS_TOKEN_URL: string;
9
+ SELLER_AREA_API_BASE_URI: string;
10
+ SELLER_AREA_WEB_BASE_URI: string;
11
+ STARTER_THEME_GIT_REPOSITORY: string;
12
+ AVAILABLE_THEMES: {
13
+ name: string;
14
+ repository: string;
15
+ }[];
16
+ CLI_GLOBAL_CONFIG_DIR: string;
17
+ CLI_GLOBAL_CONFIG_PATH: string;
18
+ THEME_FILE_TYPES: string[];
19
+ PREVIEW_SERVER_PORT: number;
20
+ };
21
+ export default _default;
@@ -1,9 +1,9 @@
1
- import { homedir } from 'os';
2
- import path from 'path';
1
+ import { homedir } from 'node:os';
2
+ import path from 'node:path';
3
3
 
4
4
  var config = {
5
5
  OAUTH_CLIENT_ID: 8,
6
- OAUTH_CALLBACK_PORT: 3000,
6
+ OAUTH_CALLBACK_PORT: 3_000,
7
7
  OAUTH_CALLBACK_SERVER_TIMEOUT: 5 * 60 * 100,
8
8
  OAUTH_CALLBACK_URL: 'http://localhost:3000/',
9
9
  OAUTH_CLIENT_SECRET: 'lvUw2mQ7nXp4WqZ9CZlURMgRGAra3KuOrYhFlU7X',
@@ -0,0 +1,36 @@
1
+ declare const _default: {
2
+ LOGIN_OPEN_LINK: string;
3
+ LOGIN_SUCCESS: string;
4
+ FETCHING_CURRENT_STORE_INFO: string;
5
+ CURRENT_DEVELOPMENT_STORE: string;
6
+ ERROR_WHILE_FETCHING_CURRENT_STORE_INFO: string;
7
+ SELECT_STORE: string;
8
+ NO_STORE_FOUND: string;
9
+ NO_STORE_SELECTED: string;
10
+ SELECT_STORE_IN_PROGRESS: string;
11
+ CANNOT_SELECT_STORE: string;
12
+ STORE_SELECTED: string;
13
+ FETCHING_DEV_THEMES: string;
14
+ ERROR_WHILE_FETCHING_DEV_THEMES: string;
15
+ INIT_SUCCESS: string;
16
+ INIT_CLONE_START: string;
17
+ AUTH_USER_NOT_LOGGED_IN: string;
18
+ AUTH_USER_LOGGED_OUT: string;
19
+ DELETE_NO_THEME_SELECTED: string;
20
+ DELETE_THEME_DELETED: string;
21
+ NO_REMOTE_THEMES: string;
22
+ DELETE_SELECT_THEME: string;
23
+ DELETE_IN_PROGRESS: string;
24
+ DELETE_ERROR: string;
25
+ DEV_PREVIEW_SERVER_CONNECTED: string;
26
+ DEV_WATCHING_FILES: string;
27
+ DEV_NO_THEME_DETECTED: string;
28
+ PULL_NO_THEME_FOUND: string;
29
+ PULL_PULLING_THEME: string;
30
+ PULL_UNPACKING_THEME: string;
31
+ PULL_THEME_PULLED: string;
32
+ PREVIEW_BROWSER_CLOSED: string;
33
+ PREVIEW_THEME_UPDATED: string;
34
+ PREVIEW_RELOADED: string;
35
+ };
36
+ export default _default;
@@ -0,0 +1,23 @@
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
+ }
@@ -6,9 +6,8 @@ import config from '../../config/index.js';
6
6
  import { delay } from '../../utils/common.js';
7
7
 
8
8
  class Client {
9
- constructor() {
10
- this.accessToken = null;
11
- }
9
+ accessToken = null;
10
+ constructor() { }
12
11
  setAccessToken(token) {
13
12
  this.accessToken = token;
14
13
  }
@@ -62,6 +61,14 @@ class Client {
62
61
  async getStoreInfo() {
63
62
  return await get(`${config.SELLER_AREA_API_BASE_URI}/me`, this.withDefaults());
64
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
+ }
65
72
  withDefaults(override = {}) {
66
73
  return mergeDeepLeft(override, {
67
74
  headers: {
@@ -0,0 +1,80 @@
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
+ }
@@ -0,0 +1 @@
1
+ export default function previewTheme(url: string, options: Record<string, string>): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { createServer } from 'http';
1
+ import { createServer } from 'node:http';
2
2
  import { Server } from 'socket.io';
3
3
  import puppeteer from 'puppeteer';
4
4
  import stdout from '../../utils/system/stdout.js';
@@ -10,8 +10,9 @@ async function openPreviewPage(url, disableHardwareAcceleration) {
10
10
  defaultViewport: null,
11
11
  userDataDir: '/tmp/youcan_puppeteer',
12
12
  };
13
- if (disableHardwareAcceleration)
13
+ if (disableHardwareAcceleration) {
14
14
  options.args = ['--disable-gpu'];
15
+ }
15
16
  const browser = await puppeteer.launch(options);
16
17
  browser.on('disconnected', () => {
17
18
  stdout.info('Browser closed');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(_cli: CLI): CommandDefinition;
@@ -0,0 +1,2 @@
1
+ import type { CLI, CommandDefinition } from '@/cli/commands/types';
2
+ export default function command(_cli: CLI): CommandDefinition;
@@ -8,3 +8,5 @@ export { default as ThemePullCommand } from './theme/pull';
8
8
  export { default as ThemePackCommand } from './theme/pack';
9
9
  export { default as StoreInfoCommand } from './store/info';
10
10
  export { default as StoreSwitchCommand } from './store/switch';
11
+ export { default as CreateAppCommand } from './apps/create';
12
+ export { default as InstallAppCommand } from './apps/install';
@@ -5,7 +5,7 @@ declare const cli: {
5
5
  client: Client;
6
6
  handler: import("cac").CAC;
7
7
  registerCommand(command: (cli: typeof this) => CommandDefinition): void;
8
- getAvailableCommands(): (typeof commands.LoginCommand | typeof commands.LogoutCommand | typeof commands.ThemeInitCommand | typeof commands.ThemeListCommand | typeof commands.ThemeDevCommand | typeof commands.ThemeDeleteCommand | typeof commands.ThemePullCommand | typeof commands.ThemePackCommand | typeof commands.StoreInfoCommand | typeof commands.StoreSwitchCommand)[];
8
+ getAvailableCommands(): (typeof commands.LoginCommand | typeof commands.LogoutCommand | typeof commands.ThemeInitCommand | typeof commands.ThemeListCommand | typeof commands.ThemeDevCommand | typeof commands.ThemeDeleteCommand | typeof commands.ThemePullCommand | typeof commands.ThemePackCommand | typeof commands.StoreInfoCommand | typeof commands.StoreSwitchCommand | typeof commands.CreateAppCommand | typeof commands.InstallAppCommand)[];
9
9
  init(): Promise<void>;
10
10
  prepareClient(): Promise<void>;
11
11
  };
@@ -1,4 +1,4 @@
1
- import type { DeleteThemeFileRequestData, InitThemeRequest as InitThemeRequestData, LoginRequest, LoginResponse, SelectStoreRequest, SelectStoreResponse, StoreInfoResponse, ThemeMetaResponse, UpdateThemeFileRequestData } from './types';
1
+ import type { CreateAppRequest, CreateAppResponse, DeleteThemeFileRequestData, GenerateAppInstallationUrlResponse, InitThemeRequest as InitThemeRequestData, LoginRequest, LoginResponse, SelectStoreRequest, SelectStoreResponse, StoreInfoResponse, ThemeMetaResponse, UpdateThemeFileRequestData } from './types';
2
2
  import type { listStoresResponse } from '@/cli/commands/store/types';
3
3
  export default class Client {
4
4
  private accessToken;
@@ -17,5 +17,7 @@ export default class Client {
17
17
  updateFile(themeId: string, data: UpdateThemeFileRequestData): Promise<void>;
18
18
  deleteFile(themeId: string, data: DeleteThemeFileRequestData): Promise<void>;
19
19
  getStoreInfo(): Promise<StoreInfoResponse>;
20
+ createApp(data: CreateAppRequest): Promise<CreateAppResponse>;
21
+ generateAppInstallationUrl(name: string): Promise<GenerateAppInstallationUrlResponse>;
20
22
  private withDefaults;
21
23
  }
@@ -69,3 +69,12 @@ export interface ThemeMetaResponse {
69
69
  snippets: ThemeFileInfo[];
70
70
  assets: ThemeFileInfo[];
71
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
+ }
@@ -0,0 +1,22 @@
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;
@@ -1,17 +1,20 @@
1
- import os from 'os';
2
- import fs from 'fs';
3
- import path from 'path';
1
+ import os from 'node:os';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
4
  import kleur from 'kleur';
5
5
 
6
6
  os.homedir();
7
7
  async function getCurrentThemeId(dir) {
8
8
  const filepath = path.resolve(dir.toString(), '.youcan');
9
- if (!fs.existsSync(filepath))
9
+ if (!fs.existsSync(filepath)) {
10
10
  return null;
11
+ }
11
12
  return await fs.promises.readFile(filepath, 'utf-8')
12
13
  .then(b => JSON.parse(b).theme_id);
13
14
  }
14
15
  class LoadingSpinner {
16
+ message;
17
+ timer;
15
18
  constructor(message) {
16
19
  this.message = message;
17
20
  this.message = message;
@@ -41,7 +44,7 @@ class LoadingSpinner {
41
44
  error(message = null) {
42
45
  this.flush();
43
46
  process.stdout.write('\r');
44
- process.stdout.write(kleur.red(`✖ ${message !== null && message !== void 0 ? message : this.message}\n`));
47
+ process.stdout.write(kleur.red(`✖ ${message ?? this.message}\n`));
45
48
  return this;
46
49
  }
47
50
  static async exec(message, closure) {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Clone a git repository
3
+ * @param url - URL to open
4
+ * @param folder
5
+ */
6
+ export default function cloneRepository(url: string, folder: string): boolean;
@@ -1,4 +1,4 @@
1
- import { execSync } from 'child_process';
1
+ import { execSync } from 'node:child_process';
2
2
 
3
3
  /**
4
4
  * Clone a git repository
@@ -0,0 +1,3 @@
1
+ export declare function stripln(buffer: string, ln: number): string;
2
+ export declare function splitln(buffer: string, limit: number): string[];
3
+ export declare function getcols(buffer: string, indices: number[], limit?: number | null): string[][];
@@ -2,22 +2,25 @@ function stripln(buffer, ln) {
2
2
  let index = 0;
3
3
  while (ln-- > 0) {
4
4
  const lfIndex = buffer.indexOf('\n', index);
5
- if (lfIndex >= 0)
5
+ if (lfIndex >= 0) {
6
6
  index = lfIndex + 1;
7
+ }
7
8
  }
8
9
  return index > 0 ? buffer.substring(index) : buffer;
9
10
  }
10
11
  function splitln(buffer, limit) {
11
12
  const cols = buffer.trim().split(/\s+/);
12
- if (cols.length > limit)
13
+ if (cols.length > limit) {
13
14
  cols[limit - 1] = cols.slice(limit - 1).join(' ');
15
+ }
14
16
  return cols;
15
17
  }
16
18
  function getcols(buffer, indices, limit = null) {
17
19
  const lines = buffer.split(/(\r\n|\n|\r)/);
18
20
  const cols = [];
19
- if (!limit)
21
+ if (!limit) {
20
22
  limit = Math.max.apply(null, indices) + 1;
23
+ }
21
24
  lines.forEach((ln) => {
22
25
  const lncols = splitln(ln, limit);
23
26
  const lncol = [];
@@ -0,0 +1,11 @@
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>;
@@ -1,4 +1,4 @@
1
- import { Agent } from 'https';
1
+ import { Agent } from 'node:https';
2
2
  import fetch from 'node-fetch';
3
3
  import { mergeDeepLeft } from 'ramda';
4
4
 
@@ -11,8 +11,9 @@ const DEFAULT_HTTP_CLIENT_OPTIONS = {
11
11
  };
12
12
  async function request(endpoint, options = {}) {
13
13
  const response = await fetch(endpoint, mergeDeepLeft(options, DEFAULT_HTTP_CLIENT_OPTIONS));
14
- if (!response.ok)
14
+ if (!response.ok) {
15
15
  throw new Error(await response.text(), { cause: response });
16
+ }
16
17
  return response.json();
17
18
  }
18
19
  async function get(endpoint, options = {}) {
@@ -0,0 +1,2 @@
1
+ export declare function isPortAvailable(port: string | number): Promise<boolean>;
2
+ export declare function getPidByPort(port: number | string): Promise<number | null>;
@@ -1,5 +1,5 @@
1
- import { createServer } from 'net';
2
- import { platform } from 'process';
1
+ import { createServer } from 'node:net';
2
+ import { platform } from 'node:process';
3
3
  import { execaCommand } from 'execa';
4
4
  import stdout from './system/stdout.js';
5
5
  import { stripln, getcols } from './helpers.js';
@@ -9,8 +9,9 @@ async function isPortAvailable(port) {
9
9
  const server = createServer();
10
10
  server.once('error', (err) => {
11
11
  server.close();
12
- if (err.code === 'EADDRINUSE')
12
+ if (err.code === 'EADDRINUSE') {
13
13
  resolve(false);
14
+ }
14
15
  reject(err);
15
16
  });
16
17
  server.once('listening', () => {
@@ -32,8 +33,9 @@ const PID_GETTER_CLASS_MAP = {
32
33
  const matches = col[1].match(/\.(\d+)$/);
33
34
  return matches && matches[1] === String(port);
34
35
  });
35
- if (col && col[2].length)
36
+ if (col && col[2].length) {
36
37
  return (parseInt(col[2], 10));
38
+ }
37
39
  return null;
38
40
  },
39
41
  async linux(port) {
@@ -47,8 +49,9 @@ const PID_GETTER_CLASS_MAP = {
47
49
  });
48
50
  if (cols && cols[1]) {
49
51
  const pid = cols[1].split('/', 1)[0];
50
- if (pid.length)
52
+ if (pid.length) {
51
53
  return parseInt(pid, 10);
54
+ }
52
55
  }
53
56
  return null;
54
57
  },
@@ -61,14 +64,16 @@ const PID_GETTER_CLASS_MAP = {
61
64
  const matches = col[0].match(/:(\d+)$/);
62
65
  return matches && matches[1] === String(port);
63
66
  });
64
- if (cols && cols[1].length && parseInt(cols[1], 10) > 0)
67
+ if (cols && cols[1].length && parseInt(cols[1], 10) > 0) {
65
68
  return parseInt(cols[1], 10);
69
+ }
66
70
  return null;
67
71
  },
68
72
  };
69
73
  async function getPidByPort(port) {
70
- if (!(platform in PID_GETTER_CLASS_MAP))
74
+ if (!(platform in PID_GETTER_CLASS_MAP)) {
71
75
  throw new Error('Unsupported platform, process will have to be killed manually.');
76
+ }
72
77
  const getter = PID_GETTER_CLASS_MAP[platform];
73
78
  return await getter(port);
74
79
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param filePath - The path of the file to delete.
3
+ *
4
+ */
5
+ export default function deleteFile(filePath: string): void;
@@ -1,12 +1,13 @@
1
- import fs from 'fs';
1
+ import fs from 'node:fs';
2
2
 
3
3
  /**
4
4
  * @param filePath - The path of the file to delete.
5
5
  *
6
6
  */
7
7
  function deleteFile(filePath) {
8
- if (fs.existsSync(filePath))
8
+ if (fs.existsSync(filePath)) {
9
9
  fs.unlinkSync(filePath);
10
+ }
10
11
  }
11
12
 
12
13
  export { deleteFile as default };
@@ -0,0 +1 @@
1
+ export declare function lsDir(path: string): string[];
@@ -1,4 +1,4 @@
1
- import { readdirSync, statSync } from 'fs';
1
+ import { readdirSync, statSync } from 'node:fs';
2
2
 
3
3
  function lsDir(path) {
4
4
  return readdirSync(path).filter((file) => {
@@ -0,0 +1 @@
1
+ export default function openLink(url: string): void;
@@ -0,0 +1 @@
1
+ export declare function saveHttpFile(res: any, filename: string): Promise<void>;
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import { pipeline } from 'stream/promises';
1
+ import fs from 'node:fs';
2
+ import { pipeline } from 'node:stream/promises';
3
3
 
4
4
  async function saveHttpFile(res, filename) {
5
5
  const fileStream = fs.createWriteStream(filename);
@@ -0,0 +1,17 @@
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,16 +1,35 @@
1
1
  import kleur from 'kleur';
2
2
 
3
3
  const stdout = console;
4
- /**
5
- * Print to standard output with meaningful colors
6
- */
7
- function log(arg) { return stdout.log(kleur.gray(arg)); }
8
- function info(arg) { return log(kleur.blue(arg)); }
9
- function warn(arg) { return log(kleur.yellow(arg)); }
10
- function error(arg) { return log(kleur.bgRed().white(arg)); }
11
- function success(arg) { return log(kleur.green(arg)); }
12
- function clear() { return stdout.clear(); }
13
- function table(arg) { return stdout.table(arg); }
14
- var stdout$1 = { log, info, warn, error, clear, success, table };
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
+ };
15
34
 
16
35
  export { stdout$1 as default };
@@ -0,0 +1 @@
1
+ export default function writeToFile(filePath: string, content: string): void;
@@ -1,10 +1,5 @@
1
- import fs from 'fs';
1
+ import fs from 'node:fs';
2
2
 
3
- /**
4
- * @param filePath - The path to the file to write to.
5
- * @param content - The content to write to the file.
6
- * @returns A promise that resolves when the file has been written.
7
- */
8
3
  function writeToFile(filePath, content) {
9
4
  return fs.writeFileSync(filePath, content, { encoding: 'utf-8', flag: 'w' });
10
5
  }
@@ -0,0 +1,5 @@
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,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import archiver from 'archiver';
4
4
  import { lsDir } from './ls.js';
5
5
 
@@ -30,7 +30,7 @@ async function zipFolder(folderPath, folderName) {
30
30
  });
31
31
  }
32
32
  async function zipDirectory(dirPath, folderName, only) {
33
- const ls = lsDir(dirPath).filter(folder => only === null || only === void 0 ? void 0 : only.includes(folder));
33
+ const ls = lsDir(dirPath).filter(folder => only?.includes(folder));
34
34
  return new Promise((resolve, reject) => {
35
35
  try {
36
36
  const zip = path.resolve(dirPath, `${folderName}.zip`);
@@ -0,0 +1 @@
1
+ export declare const kill: (pid: number, signal?: string, timeout?: number) => Promise<void>;
@@ -9,8 +9,9 @@ const kill = (pid, signal = 'SIGTERM', timeout = 1000) => new Promise((resolve,
9
9
  resolve();
10
10
  }
11
11
  count += 100;
12
- if (count > timeout)
12
+ if (count > timeout) {
13
13
  reject(new Error('Timeout process kill'));
14
+ }
14
15
  }, 100);
15
16
  });
16
17