@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.
Files changed (116) hide show
  1. package/bin/exec.cmd +3 -0
  2. package/bin/exec.js +8 -0
  3. package/dist/cli/commands/auth/login.d.ts +4 -2
  4. package/dist/cli/commands/auth/login.js +7 -85
  5. package/dist/cli/commands/auth/logout.d.ts +4 -2
  6. package/dist/cli/commands/auth/logout.js +9 -18
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.js +20 -2
  9. package/package.json +56 -38
  10. package/bin/index.js +0 -2
  11. package/dist/cli/commands/apps/create.d.ts +0 -2
  12. package/dist/cli/commands/apps/create.js +0 -65
  13. package/dist/cli/commands/apps/install.d.ts +0 -2
  14. package/dist/cli/commands/apps/install.js +0 -28
  15. package/dist/cli/commands/auth/types.d.ts +0 -6
  16. package/dist/cli/commands/index.d.ts +0 -12
  17. package/dist/cli/commands/index.js +0 -14
  18. package/dist/cli/commands/store/info.d.ts +0 -2
  19. package/dist/cli/commands/store/info.js +0 -29
  20. package/dist/cli/commands/store/switch.d.ts +0 -2
  21. package/dist/cli/commands/store/switch.js +0 -59
  22. package/dist/cli/commands/store/types.d.ts +0 -4
  23. package/dist/cli/commands/theme/delete.d.ts +0 -2
  24. package/dist/cli/commands/theme/delete.js +0 -46
  25. package/dist/cli/commands/theme/dev.d.ts +0 -2
  26. package/dist/cli/commands/theme/dev.js +0 -199
  27. package/dist/cli/commands/theme/init.d.ts +0 -2
  28. package/dist/cli/commands/theme/init.js +0 -86
  29. package/dist/cli/commands/theme/list.d.ts +0 -2
  30. package/dist/cli/commands/theme/list.js +0 -35
  31. package/dist/cli/commands/theme/pack.d.ts +0 -2
  32. package/dist/cli/commands/theme/pack.js +0 -31
  33. package/dist/cli/commands/theme/pull.d.ts +0 -2
  34. package/dist/cli/commands/theme/pull.js +0 -56
  35. package/dist/cli/commands/theme/types.d.ts +0 -17
  36. package/dist/cli/commands/types.d.ts +0 -22
  37. package/dist/cli/index.d.ts +0 -12
  38. package/dist/cli/index.js +0 -53
  39. package/dist/config/index.d.ts +0 -21
  40. package/dist/config/index.js +0 -25
  41. package/dist/config/messages.d.ts +0 -36
  42. package/dist/config/messages.js +0 -37
  43. package/dist/core/client/client.d.ts +0 -23
  44. package/dist/core/client/client.js +0 -83
  45. package/dist/core/client/types.d.ts +0 -80
  46. package/dist/core/themes/preview.d.ts +0 -1
  47. package/dist/core/themes/preview.js +0 -37
  48. package/dist/lib/cli/commands/apps/create.d.ts +0 -2
  49. package/dist/lib/cli/commands/apps/install.d.ts +0 -2
  50. package/dist/lib/cli/commands/auth/login.d.ts +0 -2
  51. package/dist/lib/cli/commands/auth/logout.d.ts +0 -2
  52. package/dist/lib/cli/commands/auth/types.d.ts +0 -6
  53. package/dist/lib/cli/commands/index.d.ts +0 -12
  54. package/dist/lib/cli/commands/store/info.d.ts +0 -2
  55. package/dist/lib/cli/commands/store/switch.d.ts +0 -2
  56. package/dist/lib/cli/commands/store/types.d.ts +0 -4
  57. package/dist/lib/cli/commands/theme/delete.d.ts +0 -2
  58. package/dist/lib/cli/commands/theme/dev.d.ts +0 -2
  59. package/dist/lib/cli/commands/theme/init.d.ts +0 -2
  60. package/dist/lib/cli/commands/theme/list.d.ts +0 -2
  61. package/dist/lib/cli/commands/theme/pack.d.ts +0 -2
  62. package/dist/lib/cli/commands/theme/pull.d.ts +0 -2
  63. package/dist/lib/cli/commands/theme/types.d.ts +0 -17
  64. package/dist/lib/cli/commands/types.d.ts +0 -22
  65. package/dist/lib/cli/index.d.ts +0 -12
  66. package/dist/lib/config/index.d.ts +0 -21
  67. package/dist/lib/config/messages.d.ts +0 -36
  68. package/dist/lib/core/client/client.d.ts +0 -23
  69. package/dist/lib/core/client/types.d.ts +0 -80
  70. package/dist/lib/core/themes/preview.d.ts +0 -1
  71. package/dist/lib/index.d.ts +0 -1
  72. package/dist/lib/utils/common.d.ts +0 -22
  73. package/dist/lib/utils/git/cloneRepository.d.ts +0 -6
  74. package/dist/lib/utils/helpers.d.ts +0 -3
  75. package/dist/lib/utils/http.d.ts +0 -11
  76. package/dist/lib/utils/network.d.ts +0 -2
  77. package/dist/lib/utils/system/deleteFile.d.ts +0 -5
  78. package/dist/lib/utils/system/ls.d.ts +0 -1
  79. package/dist/lib/utils/system/openLink.d.ts +0 -1
  80. package/dist/lib/utils/system/saveFile.d.ts +0 -1
  81. package/dist/lib/utils/system/stdout.d.ts +0 -20
  82. package/dist/lib/utils/system/writeToFile.d.ts +0 -6
  83. package/dist/lib/utils/system/zipFolder.d.ts +0 -5
  84. package/dist/lib/utils/system.d.ts +0 -1
  85. package/dist/test/commands/auth/login.d.ts +0 -2
  86. package/dist/test/commands/auth/logout.d.ts +0 -2
  87. package/dist/test/commands/help.d.ts +0 -2
  88. package/dist/test/commands/theme/delete.d.ts +0 -2
  89. package/dist/test/commands/theme/dev.d.ts +0 -2
  90. package/dist/test/commands/theme/init.d.ts +0 -2
  91. package/dist/test/index.test.d.ts +0 -1
  92. package/dist/utils/common.d.ts +0 -22
  93. package/dist/utils/common.js +0 -67
  94. package/dist/utils/git/cloneRepository.d.ts +0 -6
  95. package/dist/utils/git/cloneRepository.js +0 -18
  96. package/dist/utils/helpers.d.ts +0 -3
  97. package/dist/utils/helpers.js +0 -35
  98. package/dist/utils/http.d.ts +0 -11
  99. package/dist/utils/http.js +0 -26
  100. package/dist/utils/network.d.ts +0 -2
  101. package/dist/utils/network.js +0 -81
  102. package/dist/utils/system/deleteFile.d.ts +0 -5
  103. package/dist/utils/system/deleteFile.js +0 -13
  104. package/dist/utils/system/ls.d.ts +0 -1
  105. package/dist/utils/system/ls.js +0 -9
  106. package/dist/utils/system/openLink.d.ts +0 -1
  107. package/dist/utils/system/saveFile.d.ts +0 -1
  108. package/dist/utils/system/saveFile.js +0 -9
  109. package/dist/utils/system/stdout.d.ts +0 -17
  110. package/dist/utils/system/stdout.js +0 -35
  111. package/dist/utils/system/writeToFile.d.ts +0 -1
  112. package/dist/utils/system/writeToFile.js +0 -7
  113. package/dist/utils/system/zipFolder.d.ts +0 -5
  114. package/dist/utils/system/zipFolder.js +0 -57
  115. package/dist/utils/system.d.ts +0 -1
  116. package/dist/utils/system.js +0 -18
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1 +0,0 @@
1
- export {};
@@ -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;
@@ -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,6 +0,0 @@
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,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 };
@@ -1,3 +0,0 @@
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[][];
@@ -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 };
@@ -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>;
@@ -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 };
@@ -1,2 +0,0 @@
1
- export declare function isPortAvailable(port: string | number): Promise<boolean>;
2
- export declare function getPidByPort(port: number | string): Promise<number | null>;
@@ -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,5 +0,0 @@
1
- /**
2
- * @param filePath - The path of the file to delete.
3
- *
4
- */
5
- export default function deleteFile(filePath: string): void;
@@ -1,13 +0,0 @@
1
- import fs from 'node:fs';
2
-
3
- /**
4
- * @param filePath - The path of the file to delete.
5
- *
6
- */
7
- function deleteFile(filePath) {
8
- if (fs.existsSync(filePath)) {
9
- fs.unlinkSync(filePath);
10
- }
11
- }
12
-
13
- export { deleteFile as default };
@@ -1 +0,0 @@
1
- export declare function lsDir(path: string): string[];
@@ -1,9 +0,0 @@
1
- import { readdirSync, statSync } from 'node:fs';
2
-
3
- function lsDir(path) {
4
- return readdirSync(path).filter((file) => {
5
- return statSync(`${path}/${file}`).isDirectory() && file[0] !== '.';
6
- });
7
- }
8
-
9
- export { lsDir };
@@ -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,9 +0,0 @@
1
- import fs from 'node:fs';
2
- import { pipeline } from 'node:stream/promises';
3
-
4
- async function saveHttpFile(res, filename) {
5
- const fileStream = fs.createWriteStream(filename);
6
- return await pipeline(res.body, fileStream);
7
- }
8
-
9
- export { saveHttpFile };
@@ -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,7 +0,0 @@
1
- import fs from 'node:fs';
2
-
3
- function writeToFile(filePath, content) {
4
- return fs.writeFileSync(filePath, content, { encoding: 'utf-8', flag: 'w' });
5
- }
6
-
7
- export { writeToFile as default };
@@ -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 };
@@ -1 +0,0 @@
1
- export declare const kill: (pid: number, signal?: string, timeout?: number) => Promise<void>;
@@ -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 };