bunosh 0.1.5 → 0.2.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.
- package/COMPLETION.md +214 -0
- package/README.md +489 -73
- package/UPGRADE.md +200 -0
- package/bunosh.js +56 -0
- package/index.js +9 -11
- package/package.json +31 -25
- package/src/completion.js +341 -0
- package/src/font.js +258 -0
- package/src/formatters/base.js +17 -0
- package/src/formatters/console.js +81 -0
- package/src/formatters/factory.js +17 -0
- package/src/formatters/github-actions.js +43 -0
- package/src/init.js +13 -6
- package/src/io.js +20 -0
- package/src/printer.js +91 -0
- package/src/program.js +374 -154
- package/src/task.js +148 -0
- package/src/tasks/copyFile.js +21 -0
- package/src/tasks/exec.js +204 -0
- package/src/tasks/fetch.js +47 -0
- package/src/tasks/{writeToFile.jsx → writeToFile.js} +18 -16
- package/src/upgrade.js +255 -0
- package/types.d.ts +44 -0
- package/run.js +0 -42
- package/src/io.jsx +0 -47
- package/src/output.js +0 -37
- package/src/task.jsx +0 -209
- package/src/tasks/copyFile.jsx +0 -14
- package/src/tasks/exec.jsx +0 -104
- package/src/tasks/fetch.jsx +0 -74
- package/templates/banner.js +0 -8
package/src/tasks/exec.jsx
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { $ } from "bun";
|
|
2
|
-
import React, {useState, useEffect} from 'react';
|
|
3
|
-
import { Text, Box } from 'ink';
|
|
4
|
-
import { debugTask, isStaticOutput } from '../output.js';
|
|
5
|
-
import { renderTask, TaskInfo, TaskResult } from '../task.jsx';
|
|
6
|
-
|
|
7
|
-
const DEFAULT_OUTPUT_SIZE = 10;
|
|
8
|
-
|
|
9
|
-
export default function exec(strings, ...values) {
|
|
10
|
-
|
|
11
|
-
const cmd = strings.reduce((accumulator, str, i) => {
|
|
12
|
-
return accumulator + str + (values[i] || '');
|
|
13
|
-
}, '');
|
|
14
|
-
|
|
15
|
-
let resolve, reject;
|
|
16
|
-
const cmdPromise = new Promise((res, rej) => {
|
|
17
|
-
resolve = res;
|
|
18
|
-
reject = rej;
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
let envs = null
|
|
22
|
-
cmdPromise.env = (newEnvs) => {
|
|
23
|
-
envs = newEnvs;
|
|
24
|
-
return cmdPromise;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let cwd = null;
|
|
28
|
-
cmdPromise.cwd = (newCwd) => {
|
|
29
|
-
cwd = newCwd;
|
|
30
|
-
return cmdPromise;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const ExecOutput = () => {
|
|
34
|
-
const stackOutput = [];
|
|
35
|
-
|
|
36
|
-
const [printedLines, setPrintedLines] = useState([]);
|
|
37
|
-
const [exitCode, setExitCode] = useState(null);
|
|
38
|
-
|
|
39
|
-
const readNextChunk = async () => {
|
|
40
|
-
let shell = $(strings, ...values);
|
|
41
|
-
|
|
42
|
-
if (cwd) {
|
|
43
|
-
shell = shell.cwd(cwd);
|
|
44
|
-
}
|
|
45
|
-
if (envs) {
|
|
46
|
-
shell = shell.env(envs);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// there should be API to read stderr line by line...
|
|
50
|
-
for await (let line of shell.lines()) {
|
|
51
|
-
debugTask(cmd, line);
|
|
52
|
-
stackOutput.push(line);
|
|
53
|
-
setPrintedLines(stackOutput.slice(-DEFAULT_OUTPUT_SIZE));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const { exitCode, stderr } = await shell;
|
|
57
|
-
|
|
58
|
-
if (stderr) {
|
|
59
|
-
debugTask(cmd, stderr.toString());
|
|
60
|
-
stackOutput.push(stderr.toString())
|
|
61
|
-
setPrintedLines(stackOutput.slice(-DEFAULT_OUTPUT_SIZE));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const code = parseInt(exitCode, 10);
|
|
65
|
-
setExitCode(code);
|
|
66
|
-
if (code == 0) resolve(TaskResult.success(stackOutput.join('\n')));
|
|
67
|
-
if (code !== 0) resolve(TaskResult.fail(stackOutput.join('\n')));
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
readNextChunk();
|
|
72
|
-
}, []);
|
|
73
|
-
|
|
74
|
-
if (isStaticOutput) return <></>
|
|
75
|
-
|
|
76
|
-
return <>
|
|
77
|
-
<Box marginBottom={1} flexDirection="column">
|
|
78
|
-
{printedLines.length > 0 && <Box borderStyle="round" padding={1} flexDirection="column" >
|
|
79
|
-
{printedLines.map((line, i) => <Text wrap="truncate" key={i}>{line.trim()}</Text>)}
|
|
80
|
-
</Box>}
|
|
81
|
-
<Box>
|
|
82
|
-
{exitCode === 0 && <Text dimColor>Success! Exit code: {exitCode}</Text>}
|
|
83
|
-
{exitCode !== null && exitCode != 0 && <Text dimColor color="red">Failure! Exit code: <Text bold>{exitCode}</Text></Text>}
|
|
84
|
-
</Box>
|
|
85
|
-
</Box>
|
|
86
|
-
</>
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
let extraText = '';
|
|
91
|
-
if (cwd) extraText += `at ${cwd}`;
|
|
92
|
-
if (envs) extraText += ` with ${envs}`;
|
|
93
|
-
|
|
94
|
-
renderTask(new TaskInfo({
|
|
95
|
-
promise: cmdPromise,
|
|
96
|
-
kind: 'exec',
|
|
97
|
-
text: cmd,
|
|
98
|
-
extraText: extraText,
|
|
99
|
-
}), <ExecOutput />);
|
|
100
|
-
}, 0);
|
|
101
|
-
|
|
102
|
-
return cmdPromise;
|
|
103
|
-
}
|
|
104
|
-
|
package/src/tasks/fetch.jsx
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React, {useState, useEffect} from 'react';
|
|
2
|
-
import { Text, Box } from 'ink';
|
|
3
|
-
import { debugTask, isStaticOutput } from '../output.js';
|
|
4
|
-
import { renderTask, TaskInfo, TaskResult } from '../task.jsx';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const DEFAULT_OUTPUT_SIZE = 10;
|
|
8
|
-
|
|
9
|
-
export default async function httpFetch() {
|
|
10
|
-
const textDecoder = new TextDecoder();
|
|
11
|
-
|
|
12
|
-
const url = arguments[0];
|
|
13
|
-
const method = arguments[1]?.method || 'GET';
|
|
14
|
-
const text = `${method} ${url}`;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let resolve, reject;
|
|
18
|
-
let promise = new Promise((res, rej) => {
|
|
19
|
-
resolve = res;
|
|
20
|
-
reject = rej;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const FetchOutput = () => {
|
|
24
|
-
const fetchPromise = fetch(...arguments);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const stackOutput = [];
|
|
28
|
-
|
|
29
|
-
const [response, setResponse] = useState(null);
|
|
30
|
-
const [printedLines, setPrintedLines] = useState([]);
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
fetchPromise.then(async (response) => {
|
|
34
|
-
setResponse(response);
|
|
35
|
-
|
|
36
|
-
setPrintedLines(['a', 'b', 'c']);
|
|
37
|
-
for await (const chunk of response.body) {
|
|
38
|
-
|
|
39
|
-
const lines = textDecoder.decode(chunk, { stream: true }).toString().split('\n');
|
|
40
|
-
lines.forEach((line) => {
|
|
41
|
-
debugTask(text, line);
|
|
42
|
-
stackOutput.push(line);
|
|
43
|
-
setPrintedLines(stackOutput.slice(-DEFAULT_OUTPUT_SIZE));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
resolve(TaskResult.success(stackOutput.join('\n')));
|
|
48
|
-
resolve(TaskResult.fail(stackOutput.join('\n')));
|
|
49
|
-
});
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
if (isStaticOutput) return <></>
|
|
53
|
-
|
|
54
|
-
return <>
|
|
55
|
-
<Box marginBottom={1} flexDirection="column">
|
|
56
|
-
{printedLines && <Box borderStyle="round" padding={1} flexDirection="column" >
|
|
57
|
-
{printedLines.map((line, i) => <Text wrap="truncate" key={i}>{line.trim()}</Text>)}
|
|
58
|
-
</Box>}
|
|
59
|
-
<Box>
|
|
60
|
-
{response && response.ok && <Text dimColor>Success. Status: {response.statusText} ({response.status}) {response.headers.get('Content-Type')}</Text>}
|
|
61
|
-
{response && !response.ok && <Text dimColor color="red">Failure! Status: <Text bold>{response.statusText} ({response.status})</Text></Text>}
|
|
62
|
-
</Box>
|
|
63
|
-
</Box>
|
|
64
|
-
</>
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
renderTask(new TaskInfo({
|
|
68
|
-
promise,
|
|
69
|
-
kind: 'fetch',
|
|
70
|
-
text,
|
|
71
|
-
}), <FetchOutput />);
|
|
72
|
-
|
|
73
|
-
return promise;
|
|
74
|
-
}
|
package/templates/banner.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import color from "chalk";
|
|
2
|
-
import cfonts from "cfonts";
|
|
3
|
-
|
|
4
|
-
export default `
|
|
5
|
-
${cfonts.render('Bunosh', { font: 'pallet', gradient: ['blue','yellow'], colors: ['system'], space: false}).string}
|
|
6
|
-
|
|
7
|
-
🍲 ${color.bold(color.dim.white('Bunosh'))} - your ${color.bold('exceptional')} task runner powered by Bun
|
|
8
|
-
`.trim();
|