bunosh 0.1.4 → 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.
@@ -0,0 +1,43 @@
1
+ import { BaseFormatter } from './base.js';
2
+
3
+ export class GitHubActionsFormatter extends BaseFormatter {
4
+ format(taskName, status, taskType, extra = {}) {
5
+ const taskTypePrefix = taskType ? `[${taskType}] ` : '';
6
+ const fullTaskName = `${taskTypePrefix}${taskName}`;
7
+
8
+ switch (status) {
9
+ case 'start':
10
+ return `::group::${fullTaskName}`;
11
+
12
+ case 'finish':
13
+ const duration = extra.duration ? `${extra.duration}ms` : '';
14
+ const extraInfo = Object.entries(extra)
15
+ .filter(([k, v]) => v !== null && v !== undefined && k !== 'duration')
16
+ .map(([k, v]) => `${k}: ${v}`)
17
+ .join(', ');
18
+ const details = [duration, extraInfo].filter(Boolean).join(', ');
19
+ return `::endgroup::\n::notice::✅ ${fullTaskName}${details ? ` (${details})` : ''}`;
20
+
21
+ case 'error':
22
+ const errorDetails = extra.error ? ` - ${extra.error}` : '';
23
+ return `::endgroup::\n::error::❌ ${fullTaskName}${errorDetails}`;
24
+
25
+ case 'output':
26
+ return taskName;
27
+
28
+ case 'info':
29
+ return `::debug::${taskName}`;
30
+
31
+ default:
32
+ return taskName;
33
+ }
34
+ }
35
+
36
+ formatOutput(line, isError = false) {
37
+ return line;
38
+ }
39
+
40
+ static detect() {
41
+ return process.env.GITHUB_ACTIONS === 'true';
42
+ }
43
+ }
package/src/init.js CHANGED
@@ -1,11 +1,13 @@
1
- import { BUNOSHFILE } from "./program";
2
- import color from "picocolors";
1
+ import { BUNOSHFILE, banner } from "./program.js";
2
+ import color from "chalk";
3
3
  import fs from 'fs';
4
4
 
5
5
  const template = `
6
- import { exec, fetch, ignoreFail } from 'bunosh';
7
- import { say, yell } from 'bunosh/io';
8
- import { writeToFile } from 'bunosh/files';
6
+ // tasks
7
+ const { exec, fetch, writeToFile, task } = global.bunosh;
8
+
9
+ // input/output
10
+ const { say, ask, yell } = global.bunosh;
9
11
 
10
12
  /**
11
13
  * 🎉 Hello world command
@@ -34,7 +36,12 @@ export async function helloWorld() {
34
36
 
35
37
  export default function init() {
36
38
  if (!fs.existsSync(BUNOSHFILE)) {
37
- Bun.write(BUNOSHFILE, template);
39
+ // Use fs.writeFileSync for Node.js compatibility instead of Bun.write
40
+ if (typeof Bun !== 'undefined') {
41
+ Bun.write(BUNOSHFILE, template);
42
+ } else {
43
+ fs.writeFileSync(BUNOSHFILE, template, 'utf8');
44
+ }
38
45
  console.log(color.bold(`🎉 Bunosh ${BUNOSHFILE} file created`));
39
46
  console.log(' Edit it with "bunosh edit" command');
40
47
  console.log(' Or open it in your favorite editor');
package/src/io.js ADDED
@@ -0,0 +1,20 @@
1
+ import inquirer from 'inquirer';
2
+ import chalk from 'chalk';
3
+ import cprint from './font.js';
4
+
5
+ export function say(...args) {
6
+ console.log('!', ...args);
7
+ }
8
+
9
+ export async function ask(question, opts = {}) {
10
+ const answers = await inquirer.prompt({ name: question, message: question, ...opts })
11
+ return Object.values(answers)[0];
12
+ }
13
+
14
+ export function yell(text) {
15
+ console.log();
16
+
17
+ console.log(chalk.bold.yellow(cprint(text, { symbol: '■' })));
18
+
19
+ console.log();
20
+ }
package/src/printer.js ADDED
@@ -0,0 +1,91 @@
1
+ import chalk from 'chalk';
2
+ import { createFormatter } from './formatters/factory.js';
3
+ import { getTaskPrefix } from './task.js';
4
+
5
+ export class Printer {
6
+ constructor(taskType, taskId = null) {
7
+ this.taskType = taskType;
8
+ this.taskId = taskId;
9
+ this.startTime = null;
10
+ this.startTimeout = null;
11
+ this.hasStarted = false;
12
+ this.formatter = createFormatter();
13
+ }
14
+
15
+ print(taskName, status, extra = {}) {
16
+ if (status === 'start' && !this.startTime) {
17
+ this.startTime = Date.now();
18
+ }
19
+
20
+ if ((status === 'finish' || status === 'error') && this.startTime) {
21
+ extra.duration = Date.now() - this.startTime;
22
+ }
23
+
24
+ // Add task prefix for parallel tasks
25
+ const prefix = this.taskId ? getTaskPrefix(this.taskId) : '';
26
+ const prefixedTaskName = prefix ? `${prefix} ${taskName}` : taskName;
27
+
28
+ const output = this.formatter.format(prefixedTaskName, status, this.taskType, extra);
29
+ if (output) {
30
+ console.log(output);
31
+ }
32
+ }
33
+
34
+ start(taskName, extra = {}) {
35
+ this.startTime = Date.now();
36
+ const delay = this.formatter.getStartDelay ? this.formatter.getStartDelay() : 50;
37
+
38
+ if (this.formatter.shouldDelayStart && this.formatter.shouldDelayStart()) {
39
+ this.startTimeout = setTimeout(() => {
40
+ this.hasStarted = true;
41
+ this.print(taskName, 'start', extra);
42
+ }, delay);
43
+ } else {
44
+ this.hasStarted = true;
45
+ this.print(taskName, 'start', extra);
46
+ }
47
+ }
48
+
49
+ finish(taskName, extra = {}) {
50
+ if (this.startTimeout) {
51
+ clearTimeout(this.startTimeout);
52
+ this.startTimeout = null;
53
+ }
54
+ this.print(taskName, 'finish', extra);
55
+ }
56
+
57
+ error(taskName, error = null, extra = {}) {
58
+ if (this.startTimeout) {
59
+ clearTimeout(this.startTimeout);
60
+ this.startTimeout = null;
61
+ }
62
+ if (error) {
63
+ extra.error = typeof error === 'string' ? error : error.message;
64
+ }
65
+ this.print(taskName, 'error', extra);
66
+ }
67
+
68
+ output(line, isError = false) {
69
+ if (!line.trim()) return;
70
+
71
+ // Add task prefix for parallel tasks on output lines
72
+ const prefix = this.taskId ? getTaskPrefix(this.taskId) : '';
73
+ const prefixedLine = prefix ? `${chalk.gray.dim(prefix)} ${line}` : line;
74
+
75
+ const formattedLine = this.formatter.formatOutput(prefixedLine, isError);
76
+ if (formattedLine) {
77
+ console.log(formattedLine);
78
+ }
79
+ }
80
+
81
+ info(message) {
82
+ this.print(message, 'info');
83
+ }
84
+
85
+ static log(taskName, status, extra = {}) {
86
+ const printer = new Printer('');
87
+ printer.print(taskName, status, extra);
88
+ }
89
+ }
90
+
91
+ export default Printer;