@youcan/cli-kit 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/common/string.d.ts +2 -2
  2. package/dist/common/string.js +11 -11
  3. package/dist/index.d.ts +18 -17
  4. package/dist/index.js +2 -0
  5. package/dist/internal/node/constants.d.ts +5 -5
  6. package/dist/internal/node/constants.js +10 -10
  7. package/dist/internal/node/ui.d.ts +11 -11
  8. package/dist/internal/node/ui.js +40 -40
  9. package/dist/node/callback.d.ts +5 -5
  10. package/dist/node/callback.js +53 -53
  11. package/dist/node/cli.d.ts +21 -21
  12. package/dist/node/cli.js +61 -61
  13. package/dist/node/config.d.ts +20 -20
  14. package/dist/node/config.js +20 -22
  15. package/dist/node/context/helpers.d.ts +1 -1
  16. package/dist/node/context/helpers.js +5 -5
  17. package/dist/node/context/local.d.ts +2 -2
  18. package/dist/node/context/local.js +2 -2
  19. package/dist/node/crypto.d.ts +12 -9
  20. package/dist/node/crypto.js +23 -23
  21. package/dist/node/env.d.ts +5 -6
  22. package/dist/node/env.js +36 -47
  23. package/dist/node/filesystem.d.ts +30 -29
  24. package/dist/node/filesystem.js +81 -78
  25. package/dist/node/form.d.ts +9 -9
  26. package/dist/node/form.js +39 -39
  27. package/dist/node/git.d.ts +10 -10
  28. package/dist/node/git.js +46 -46
  29. package/dist/node/github.d.ts +6 -6
  30. package/dist/node/github.js +8 -8
  31. package/dist/node/http.d.ts +4 -4
  32. package/dist/node/http.js +35 -32
  33. package/dist/node/path.d.ts +5 -5
  34. package/dist/node/path.js +14 -14
  35. package/dist/node/session.d.ts +8 -8
  36. package/dist/node/session.js +92 -78
  37. package/dist/node/system.d.ts +23 -21
  38. package/dist/node/system.js +74 -58
  39. package/dist/node/tasks.d.ts +8 -7
  40. package/dist/node/tasks.js +33 -25
  41. package/dist/node/worker.d.ts +16 -19
  42. package/dist/node/worker.js +43 -30
  43. package/dist/ui/components/DevOutput.d.ts +27 -0
  44. package/dist/ui/components/DevOutput.js +60 -0
  45. package/dist/ui/components/HotKeys.d.ts +12 -0
  46. package/dist/ui/components/HotKeys.js +25 -0
  47. package/dist/ui/components/utils/symbols.d.ts +3 -0
  48. package/dist/ui/components/utils/symbols.js +7 -0
  49. package/dist/ui/index.d.ts +2 -0
  50. package/dist/ui/index.js +2 -0
  51. package/package.json +7 -3
@@ -1,19 +1,16 @@
1
- /// <reference types="node" />
2
- import { Writable } from 'stream';
3
- import type { Color } from '..';
4
- export interface Interface {
5
- run(): Promise<void>;
6
- boot(): Promise<void>;
7
- }
8
- export declare class Logger extends Writable {
9
- private channel;
10
- private type;
11
- private color;
12
- constructor(channel: 'stdout' | 'stderr', type: string, color: Color.Color);
13
- write(chunk: unknown): boolean;
14
- private pad;
15
- }
16
- export declare abstract class Abstract implements Interface {
17
- abstract boot(): Promise<void>;
18
- abstract run(): Promise<void>;
19
- }
1
+ /// <reference types="node" />
2
+ import { Writable } from 'stream';
3
+ export interface Interface {
4
+ run(): Promise<void>;
5
+ boot(): Promise<void>;
6
+ }
7
+ export declare class Logger extends Writable {
8
+ private readonly type;
9
+ private readonly color;
10
+ constructor(type: string, color: 'yellow' | 'cyan' | 'magenta' | 'green' | 'blue' | 'red' | 'dim');
11
+ write(chunk: unknown): boolean;
12
+ }
13
+ export declare abstract class Abstract implements Interface {
14
+ abstract run(): Promise<void>;
15
+ abstract boot(): Promise<void>;
16
+ }
@@ -1,36 +1,49 @@
1
1
  import { Writable } from 'node:stream';
2
- import { stdout, stderr } from 'node:process';
3
2
  import dayjs from 'dayjs';
3
+ import './cli.js';
4
+ import 'simple-git';
5
+ import 'execa';
6
+ import 'tcp-port-used';
7
+ import 'find-process';
8
+ import 'env-paths';
9
+ import 'node-fetch';
10
+ import 'ramda';
11
+ import 'change-case';
12
+ import 'formdata-node';
13
+ import 'formdata-node/file-from-path';
14
+ import 'kleur';
15
+ import 'conf';
16
+ import './filesystem.js';
17
+ import { renderDevOutput } from '../ui/components/DevOutput.js';
18
+ import 'react';
19
+ import 'ink';
4
20
 
5
- class Logger extends Writable {
6
- channel;
7
- type;
8
- color;
9
- constructor(channel, type, color) {
10
- super();
11
- this.channel = channel;
12
- this.type = type;
13
- this.color = color;
14
- }
15
- write(chunk) {
16
- if (!(chunk instanceof Buffer) && typeof chunk !== 'string') {
17
- return false;
18
- }
19
- const channel = this.channel === 'stdout' ? stdout : stderr;
20
- const time = dayjs().format('HH:mm:ss:SSS');
21
- const lines = chunk.toString().split('\n').map(s => s.trim()).filter(s => s !== '');
22
- for (let i = 0; i < lines.length; i++) {
23
- i === 0
24
- ? channel.write(this.color(`${time} | ${this.pad(this.type, 10)} | ${lines[i]}\n`))
25
- : channel.write(this.color(` | ${lines[i]}\n`));
26
- }
27
- return true;
28
- }
29
- pad(subject, length, char = ' ') {
30
- return subject.padEnd(length, char);
31
- }
32
- }
33
- class Abstract {
21
+ class Logger extends Writable {
22
+ type;
23
+ color;
24
+ constructor(type, color) {
25
+ super();
26
+ this.type = type;
27
+ this.color = color;
28
+ }
29
+ write(chunk) {
30
+ if (!(chunk instanceof Buffer) && typeof chunk !== 'string') {
31
+ return false;
32
+ }
33
+ const time = dayjs().format('HH:mm:ss:SSS');
34
+ const lines = chunk.toString().split('\n').map(s => s.trim()).filter(s => s !== '');
35
+ for (const line of lines) {
36
+ renderDevOutput.outputSubject.emit({
37
+ timestamp: time,
38
+ color: this.color,
39
+ label: this.type,
40
+ buffer: line,
41
+ });
42
+ }
43
+ return true;
44
+ }
45
+ }
46
+ class Abstract {
34
47
  }
35
48
 
36
49
  export { Abstract, Logger };
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { Instance, Text } from 'ink';
3
+ import { HotKeysPropsType } from './HotKeys';
4
+ import { Command } from '@/node/cli';
5
+ interface SubjectDataType {
6
+ timestamp: string;
7
+ buffer: string;
8
+ label: string;
9
+ color: Parameters<typeof Text>[0]['color'];
10
+ }
11
+ declare class OutputSubject {
12
+ private readonly subject;
13
+ listen(handler: (data: SubjectDataType) => void): void;
14
+ emit(data: SubjectDataType): void;
15
+ private pad;
16
+ }
17
+ export type DevOutputPropsType = {
18
+ hotKeys?: HotKeysPropsType['hotKeys'];
19
+ cmd: Command;
20
+ };
21
+ interface RenderDevOutputType {
22
+ (props: DevOutputPropsType): Instance;
23
+ outputSubject: OutputSubject;
24
+ }
25
+ export declare const DevOutput: ({ cmd, hotKeys }: DevOutputPropsType) => React.JSX.Element;
26
+ declare const renderDevOutput: RenderDevOutputType;
27
+ export { renderDevOutput };
@@ -0,0 +1,60 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { useInput, Static, Box, Text, render } from 'ink';
3
+ import { HotKeys } from './HotKeys.js';
4
+ import { VerticalDivider } from './utils/symbols.js';
5
+ import { map } from 'rxjs/operators';
6
+ import { ReplaySubject } from 'rxjs';
7
+
8
+ class OutputSubject {
9
+ subject = new ReplaySubject;
10
+ listen(handler) {
11
+ let lastLineKey = null;
12
+ this.subject.pipe(map(item => {
13
+ const currentLineKey = `${item.label}-${item.color}`;
14
+ if (currentLineKey !== lastLineKey) {
15
+ lastLineKey = currentLineKey;
16
+ return { ...item, label: this.pad(item.label, 10) };
17
+ }
18
+ return { ...item, label: this.pad('', 10) };
19
+ }))
20
+ .subscribe(handler);
21
+ }
22
+ emit(data) {
23
+ this.subject.next(data);
24
+ }
25
+ pad(subject, length, char = ' ') {
26
+ return subject.padEnd(length, char);
27
+ }
28
+ }
29
+ const outputSubject = new OutputSubject;
30
+ const DevOutput = ({ cmd, hotKeys = [] }) => {
31
+ const [linesBuffers, setLinesBuffers] = useState([]);
32
+ useInput((input, key) => {
33
+ if (input === 'c' && key.ctrl)
34
+ cmd.exit(130);
35
+ });
36
+ useEffect(() => {
37
+ outputSubject.listen((data) => {
38
+ setLinesBuffers((previousLines) => [...previousLines, data]);
39
+ });
40
+ }, []);
41
+ return (React.createElement(React.Fragment, null,
42
+ React.createElement(Static, { items: linesBuffers }, (line, i) => (React.createElement(Box, { flexDirection: 'column', key: i },
43
+ React.createElement(Text, null,
44
+ React.createElement(Text, { dimColor: true }, line.timestamp),
45
+ ' ',
46
+ React.createElement(VerticalDivider, null),
47
+ ' ',
48
+ React.createElement(Text, { color: line.color }, line.label),
49
+ React.createElement(Text, null,
50
+ ' ',
51
+ React.createElement(VerticalDivider, null),
52
+ ' ',
53
+ line.buffer))))),
54
+ React.createElement(Box, { flexDirection: 'column', paddingTop: 1 },
55
+ React.createElement(HotKeys, { hotKeys: hotKeys }))));
56
+ };
57
+ const renderDevOutput = ((props) => render(React.createElement(DevOutput, { ...props }), { exitOnCtrlC: false }));
58
+ renderDevOutput.outputSubject = outputSubject;
59
+
60
+ export { DevOutput, renderDevOutput };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ type KeyType = {
3
+ keyboardKey: string;
4
+ description: string;
5
+ handler: () => void;
6
+ };
7
+ export type HotKeysPropsType = {
8
+ hotKeys: KeyType[];
9
+ };
10
+ export declare const HotKeys: ({ hotKeys }: HotKeysPropsType) => React.JSX.Element;
11
+ export declare const renderHotKeys: (props: HotKeysPropsType) => import("ink").Instance;
12
+ export {};
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { RightChevron, VerticalDivider } from './utils/symbols.js';
3
+ import { Box, render, useInput, Text } from 'ink';
4
+
5
+ const HotKey = ({ keyboardKey, description, handler }) => {
6
+ useInput((input) => {
7
+ if (input === keyboardKey)
8
+ handler();
9
+ });
10
+ return (React.createElement(Box, { flexDirection: 'column' },
11
+ React.createElement(Text, null,
12
+ React.createElement(RightChevron, null),
13
+ " Press ",
14
+ React.createElement(Text, { dimColor: true }, keyboardKey),
15
+ " ",
16
+ React.createElement(VerticalDivider, null),
17
+ " ",
18
+ description)));
19
+ };
20
+ const HotKeys = ({ hotKeys }) => {
21
+ return (React.createElement(Box, { flexDirection: 'column' }, hotKeys.map((hotKey) => React.createElement(HotKey, { key: hotKey.keyboardKey, ...hotKey }))));
22
+ };
23
+ const renderHotKeys = (props) => render(React.createElement(HotKeys, { ...props }), { exitOnCtrlC: false });
24
+
25
+ export { HotKeys, renderHotKeys };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare const VerticalDivider: () => React.JSX.Element;
3
+ export declare const RightChevron: () => React.JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { Text } from 'ink';
2
+ import React from 'react';
3
+
4
+ const VerticalDivider = () => React.createElement(Text, null, "\u2502");
5
+ const RightChevron = () => React.createElement(Text, null, "\u203A");
6
+
7
+ export { RightChevron, VerticalDivider };
@@ -0,0 +1,2 @@
1
+ export { renderDevOutput } from './components/DevOutput';
2
+ export { renderHotKeys } from './components/HotKeys';
@@ -0,0 +1,2 @@
1
+ export { renderDevOutput } from './components/DevOutput.js';
2
+ export { renderHotKeys } from './components/HotKeys.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@youcan/cli-kit",
3
3
  "type": "module",
4
- "version": "2.1.3",
4
+ "version": "2.2.0",
5
5
  "description": "Utilities for the YouCan CLI",
6
6
  "author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
7
7
  "license": "MIT",
@@ -22,21 +22,24 @@
22
22
  "@oclif/core": "^2.15.0",
23
23
  "archiver": "^5.3.2",
24
24
  "change-case": "^4.1.2",
25
- "chokidar": "^3.5.3",
25
+ "chokidar": "^4.0.1",
26
26
  "conf": "^11.0.2",
27
27
  "dayjs": "^1.11.10",
28
28
  "env-paths": "^3.0.0",
29
29
  "execa": "^6.1.0",
30
30
  "find-process": "^1.4.7",
31
- "formdata-node": "^5.0.1",
31
+ "formdata-node": "^6.0.3",
32
32
  "fs-extra": "^11.1.1",
33
33
  "glob": "^11.0.0",
34
+ "ink": "^5.1.0",
34
35
  "kill-port-process": "^3.2.0",
35
36
  "kleur": "^4.1.5",
36
37
  "node-fetch": "^3.3.2",
37
38
  "open": "^9.1.0",
38
39
  "prompts": "^2.4.2",
39
40
  "ramda": "^0.28.0",
41
+ "react": "^18.3.1",
42
+ "rxjs": "^7.8.1",
40
43
  "simple-git": "^3.20.0",
41
44
  "tcp-port-used": "^1.0.2",
42
45
  "tempy": "^3.1.0",
@@ -48,6 +51,7 @@
48
51
  "@types/node": "^18.18.0",
49
52
  "@types/prompts": "^2.4.5",
50
53
  "@types/ramda": "^0.28.25",
54
+ "@types/react": "^18.3.12",
51
55
  "@types/tcp-port-used": "^1.0.2",
52
56
  "shx": "^0.3.4"
53
57
  },