@youcan/cli-kit 2.1.4 → 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.
- package/dist/common/string.d.ts +2 -2
- package/dist/common/string.js +11 -11
- package/dist/index.d.ts +18 -17
- package/dist/index.js +2 -0
- package/dist/internal/node/constants.d.ts +5 -5
- package/dist/internal/node/constants.js +10 -10
- package/dist/internal/node/ui.d.ts +11 -11
- package/dist/internal/node/ui.js +40 -40
- package/dist/node/callback.d.ts +5 -5
- package/dist/node/callback.js +53 -53
- package/dist/node/cli.d.ts +21 -21
- package/dist/node/cli.js +61 -61
- package/dist/node/config.d.ts +20 -20
- package/dist/node/config.js +20 -22
- package/dist/node/context/helpers.d.ts +1 -1
- package/dist/node/context/helpers.js +5 -5
- package/dist/node/context/local.d.ts +2 -2
- package/dist/node/context/local.js +2 -2
- package/dist/node/crypto.d.ts +12 -9
- package/dist/node/crypto.js +23 -23
- package/dist/node/env.d.ts +5 -6
- package/dist/node/env.js +36 -47
- package/dist/node/filesystem.d.ts +30 -29
- package/dist/node/filesystem.js +81 -78
- package/dist/node/form.d.ts +9 -9
- package/dist/node/form.js +39 -39
- package/dist/node/git.d.ts +10 -10
- package/dist/node/git.js +46 -46
- package/dist/node/github.d.ts +6 -6
- package/dist/node/github.js +8 -8
- package/dist/node/http.d.ts +4 -4
- package/dist/node/http.js +35 -32
- package/dist/node/path.d.ts +5 -5
- package/dist/node/path.js +14 -14
- package/dist/node/session.d.ts +8 -8
- package/dist/node/session.js +92 -78
- package/dist/node/system.d.ts +23 -21
- package/dist/node/system.js +74 -58
- package/dist/node/tasks.d.ts +8 -7
- package/dist/node/tasks.js +33 -25
- package/dist/node/worker.d.ts +16 -19
- package/dist/node/worker.js +43 -30
- package/dist/ui/components/DevOutput.d.ts +27 -0
- package/dist/ui/components/DevOutput.js +60 -0
- package/dist/ui/components/HotKeys.d.ts +12 -0
- package/dist/ui/components/HotKeys.js +25 -0
- package/dist/ui/components/utils/symbols.d.ts +3 -0
- package/dist/ui/components/utils/symbols.js +7 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/package.json +6 -2
package/dist/node/worker.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Writable } from 'stream';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
}
|
package/dist/node/worker.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
color
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
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 };
|
package/dist/ui/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youcan/cli-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
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",
|
|
@@ -28,15 +28,18 @@
|
|
|
28
28
|
"env-paths": "^3.0.0",
|
|
29
29
|
"execa": "^6.1.0",
|
|
30
30
|
"find-process": "^1.4.7",
|
|
31
|
-
"formdata-node": "^
|
|
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
|
},
|