Current section
Files
Jump to
Current section
Files
priv/dist/mod.js
import { t as __exportAll } from "./chunk-D7D4PA-g.js";
import * as kindly from "./kindly.js";
import { main } from "./kindly.js";
import path from "node:path";
//#region prelude.mjs
var CustomType = class {
withFields(fields) {
let properties = Object.keys(this).map((label) => label in fields ? fields[label] : this[label]);
return new this.constructor(...properties);
}
};
var List = class {
static fromArray(array, tail) {
let t = tail || new Empty();
for (let i = array.length - 1; i >= 0; --i) t = new NonEmpty(array[i], t);
return t;
}
[Symbol.iterator]() {
return new ListIterator(this);
}
toArray() {
return [...this];
}
atLeastLength(desired) {
let current = this;
while (desired-- > 0 && current) current = current.tail;
return current !== void 0;
}
hasLength(desired) {
let current = this;
while (desired-- > 0 && current) current = current.tail;
return desired === -1 && current instanceof Empty;
}
countLength() {
let current = this;
let length = 0;
while (current) {
current = current.tail;
length++;
}
return length - 1;
}
};
function toList(elements, tail) {
return List.fromArray(elements, tail);
}
var ListIterator = class {
#current;
constructor(current) {
this.#current = current;
}
next() {
if (this.#current instanceof Empty) return { done: true };
else {
let { head, tail } = this.#current;
this.#current = tail;
return {
value: head,
done: false
};
}
}
};
var Empty = class extends List {};
var NonEmpty = class extends List {
constructor(head, tail) {
super();
this.head = head;
this.tail = tail;
}
};
var Result = class Result extends CustomType {
static isResult(data) {
return data instanceof Result;
}
};
var Ok = class extends Result {
constructor(value) {
super();
this[0] = value;
}
isOk() {
return true;
}
};
const Result$Ok = (value) => new Ok(value);
const Result$isOk = (value) => value instanceof Ok;
const Result$Ok$0 = (value) => value[0];
var Error$1 = class extends Result {
constructor(detail) {
super();
this[0] = detail;
}
isOk() {
return false;
}
};
const Result$Error = (detail) => new Error$1(detail);
//#endregion
//#region src/generated.ts
var generated_default = {
version: new Uint8Array([
48,
46,
50,
46,
49
]),
description: new Uint8Array([
65,
32,
110,
105,
99,
101,
32,
108,
105,
116,
116,
108,
101,
32,
116,
97,
115,
107,
32,
114,
117,
110,
110,
101,
114
]),
min_gleam_version: new Uint8Array([
49,
46,
49,
52,
46,
48
]),
completion: {
bash: new Uint8Array([
99,
111,
109,
112,
108,
101,
116,
101,
32,
45,
111,
32,
100,
101,
102,
97,
117,
108,
116,
32,
45,
70,
32,
95,
107,
105,
110,
100,
108,
121,
32,
107,
105,
110,
100,
108,
121,
10,
10,
95,
107,
105,
110,
100,
108,
121,
40,
41,
32,
123,
10,
32,
32,
108,
111,
99,
97,
108,
32,
99,
117,
114,
10,
32,
32,
108,
111,
99,
97,
108,
32,
45,
105,
32,
99,
119,
111,
114,
100,
10,
32,
32,
108,
111,
99,
97,
108,
32,
45,
97,
32,
119,
111,
114,
100,
115,
10,
10,
32,
32,
67,
79,
77,
80,
82,
69,
80,
76,
89,
61,
40,
41,
10,
32,
32,
105,
102,
32,
100,
101,
99,
108,
97,
114,
101,
32,
45,
70,
32,
95,
105,
110,
105,
116,
95,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
32,
62,
47,
100,
101,
118,
47,
110,
117,
108,
108,
32,
50,
62,
38,
49,
59,
32,
116,
104,
101,
110,
10,
32,
32,
32,
32,
95,
105,
110,
105,
116,
95,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
32,
45,
110,
32,
61,
58,
32,
124,
124,
32,
114,
101,
116,
117,
114,
110,
10,
32,
32,
101,
108,
115,
101,
10,
32,
32,
32,
32,
95,
103,
101,
116,
95,
99,
111,
109,
112,
95,
119,
111,
114,
100,
115,
95,
98,
121,
95,
114,
101,
102,
32,
45,
110,
32,
61,
58,
32,
99,
117,
114,
32,
112,
114,
101,
118,
32,
119,
111,
114,
100,
115,
32,
99,
119,
111,
114,
100,
32,
124,
124,
32,
114,
101,
116,
117,
114,
110,
10,
32,
32,
102,
105,
10,
10,
32,
32,
108,
111,
99,
97,
108,
32,
120,
10,
32,
32,
119,
104,
105,
108,
101,
32,
73,
70,
83,
61,
34,
34,
32,
114,
101,
97,
100,
32,
45,
114,
32,
120,
59,
32,
100,
111,
10,
32,
32,
32,
32,
67,
79,
77,
80,
82,
69,
80,
76,
89,
43,
61,
40,
34,
36,
123,
120,
125,
34,
41,
10,
32,
32,
100,
111,
110,
101,
32,
60,
32,
60,
40,
10,
32,
32,
32,
32,
101,
120,
112,
111,
114,
116,
32,
67,
79,
76,
85,
77,
78,
83,
10,
10,
32,
32,
32,
32,
108,
111,
99,
97,
108,
32,
97,
114,
103,
115,
61,
40,
34,
36,
123,
119,
111,
114,
100,
115,
91,
64,
93,
58,
49,
58,
36,
123,
99,
119,
111,
114,
100,
125,
45,
49,
125,
34,
41,
10,
10,
32,
32,
32,
32,
107,
105,
110,
100,
108,
121,
32,
45,
45,
99,
117,
101,
32,
98,
97,
115,
104,
32,
45,
45,
32,
34,
36,
123,
97,
114,
103,
115,
91,
64,
93,
125,
34,
32,
34,
36,
123,
99,
117,
114,
125,
34,
32,
50,
62,
47,
100,
101,
118,
47,
110,
117,
108,
108,
10,
10,
32,
32,
32,
32,
112,
114,
105,
110,
116,
102,
32,
37,
115,
32,
34,
36,
123,
63,
125,
34,
10,
32,
32,
41,
10,
10,
32,
32,
99,
97,
115,
101,
32,
34,
36,
123,
120,
125,
44,
36,
40,
116,
121,
112,
101,
32,
45,
116,
32,
99,
111,
109,
112,
111,
112,
116,
41,
34,
32,
105,
110,
10,
32,
32,
32,
32,
48,
44,
98,
117,
105,
108,
116,
105,
110,
41,
32,
99,
111,
109,
112,
111,
112,
116,
32,
45,
111,
32,
110,
111,
115,
111,
114,
116,
32,
59,
59,
10,
32,
32,
32,
32,
42,
44,
98,
117,
105,
108,
116,
105,
110,
41,
32,
99,
111,
109,
112,
111,
112,
116,
32,
43,
111,
32,
100,
101,
102,
97,
117,
108,
116,
32,
59,
59,
10,
32,
32,
101,
115,
97,
99,
32,
62,
47,
100,
101,
118,
47,
110,
117,
108,
108,
32,
50,
62,
38,
49,
10,
125,
10
]),
fish: new Uint8Array([
99,
111,
109,
112,
108,
101,
116,
101,
32,
45,
101,
99,
32,
107,
105,
110,
100,
108,
121,
10,
10,
99,
111,
109,
112,
108,
101,
116,
101,
32,
45,
99,
32,
107,
105,
110,
100,
108,
121,
32,
45,
107,
120,
97,
32,
34,
40,
95,
95,
107,
105,
110,
100,
108,
121,
95,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
41,
34,
10,
10,
99,
111,
109,
112,
108,
101,
116,
101,
32,
45,
99,
32,
107,
105,
110,
100,
108,
121,
32,
45,
70,
110,
32,
39,
10,
32,
32,
32,
32,
115,
101,
116,
32,
120,
115,
32,
40,
95,
95,
107,
105,
110,
100,
108,
121,
95,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
41,
10,
32,
32,
32,
32,
97,
110,
100,
32,
110,
111,
116,
32,
99,
111,
117,
110,
116,
32,
36,
120,
115,
39,
10,
10,
102,
117,
110,
99,
116,
105,
111,
110,
32,
95,
95,
107,
105,
110,
100,
108,
121,
95,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
10,
32,
32,
32,
32,
115,
101,
116,
32,
45,
108,
120,
32,
67,
79,
76,
85,
77,
78,
83,
32,
36,
67,
79,
76,
85,
77,
78,
83,
10,
10,
32,
32,
32,
32,
115,
101,
116,
32,
45,
108,
32,
97,
114,
103,
115,
32,
40,
99,
111,
109,
109,
97,
110,
100,
108,
105,
110,
101,
32,
45,
99,
111,
112,
41,
91,
50,
46,
46,
93,
10,
32,
32,
32,
32,
115,
101,
116,
32,
45,
108,
32,
99,
117,
114,
114,
101,
110,
116,
32,
40,
99,
111,
109,
109,
97,
110,
100,
108,
105,
110,
101,
32,
45,
99,
116,
41,
10,
10,
32,
32,
32,
32,
107,
105,
110,
100,
108,
121,
32,
45,
45,
99,
117,
101,
32,
102,
105,
115,
104,
32,
45,
45,
32,
36,
97,
114,
103,
115,
32,
36,
99,
117,
114,
114,
101,
110,
116,
32,
50,
62,
47,
100,
101,
118,
47,
110,
117,
108,
108,
10,
101,
110,
100,
10
]),
pwsh: new Uint8Array([
117,
115,
105,
110,
103,
32,
110,
97,
109,
101,
115,
112,
97,
99,
101,
32,
83,
121,
115,
116,
101,
109,
46,
77,
97,
110,
97,
103,
101,
109,
101,
110,
116,
46,
65,
117,
116,
111,
109,
97,
116,
105,
111,
110,
10,
117,
115,
105,
110,
103,
32,
110,
97,
109,
101,
115,
112,
97,
99,
101,
32,
83,
121,
115,
116,
101,
109,
46,
77,
97,
110,
97,
103,
101,
109,
101,
110,
116,
46,
65,
117,
116,
111,
109,
97,
116,
105,
111,
110,
46,
76,
97,
110,
103,
117,
97,
103,
101,
10,
117,
115,
105,
110,
103,
32,
110,
97,
109,
101,
115,
112,
97,
99,
101,
32,
83,
121,
115,
116,
101,
109,
46,
84,
101,
120,
116,
10,
10,
82,
101,
103,
105,
115,
116,
101,
114,
45,
65,
114,
103,
117,
109,
101,
110,
116,
67,
111,
109,
112,
108,
101,
116,
101,
114,
32,
45,
78,
97,
116,
105,
118,
101,
32,
45,
67,
111,
109,
109,
97,
110,
100,
78,
97,
109,
101,
32,
107,
105,
110,
100,
108,
121,
32,
45,
83,
99,
114,
105,
112,
116,
66,
108,
111,
99,
107,
32,
123,
10,
32,
32,
32,
32,
112,
97,
114,
97,
109,
40,
10,
32,
32,
32,
32,
32,
32,
32,
32,
91,
115,
116,
114,
105,
110,
103,
93,
32,
36,
87,
111,
114,
100,
84,
111,
67,
111,
109,
112,
108,
101,
116,
101,
44,
10,
32,
32,
32,
32,
32,
32,
32,
32,
91,
67,
111,
109,
109,
97,
110,
100,
65,
115,
116,
93,
32,
36,
67,
111,
109,
109,
97,
110,
100,
65,
115,
116,
44,
10,
32,
32,
32,
32,
32,
32,
32,
32,
91,
105,
110,
116,
93,
32,
36,
67,
117,
114,
115,
111,
114,
80,
111,
115,
105,
116,
105,
111,
110,
10,
32,
32,
32,
32,
41,
10,
10,
32,
32,
32,
32,
91,
67,
111,
110,
115,
111,
108,
101,
93,
58,
58,
73,
110,
112,
117,
116,
69,
110,
99,
111,
100,
105,
110,
103,
32,
61,
32,
91,
69,
110,
99,
111,
100,
105,
110,
103,
93,
58,
58,
85,
84,
70,
56,
10,
32,
32,
32,
32,
91,
67,
111,
110,
115,
111,
108,
101,
93,
58,
58,
79,
117,
116,
112,
117,
116,
69,
110,
99,
111,
100,
105,
110,
103,
32,
61,
32,
91,
69,
110,
99,
111,
100,
105,
110,
103,
93,
58,
58,
85,
84,
70,
56,
10,
32,
32,
32,
32,
36,
79,
117,
116,
112,
117,
116,
69,
110,
99,
111,
100,
105,
110,
103,
32,
61,
32,
91,
69,
110,
99,
111,
100,
105,
110,
103,
93,
58,
58,
85,
84,
70,
56,
10,
10,
32,
32,
32,
32,
36,
101,
110,
118,
58,
67,
79,
76,
85,
77,
78,
83,
32,
61,
32,
40,
71,
101,
116,
45,
72,
111,
115,
116,
41,
46,
85,
73,
46,
82,
97,
119,
85,
73,
46,
87,
105,
110,
100,
111,
119,
83,
105,
122,
101,
46,
87,
105,
100,
116,
104,
10,
10,
32,
32,
32,
32,
36,
97,
114,
103,
115,
32,
61,
32,
64,
40,
41,
10,
10,
32,
32,
32,
32,
36,
95,
44,
32,
36,
120,
115,
32,
61,
32,
36,
67,
111,
109,
109,
97,
110,
100,
65,
115,
116,
46,
67,
111,
109,
109,
97,
110,
100,
69,
108,
101,
109,
101,
110,
116,
115,
10,
10,
32,
32,
32,
32,
102,
111,
114,
101,
97,
99,
104,
32,
40,
36,
120,
32,
105,
110,
32,
36,
120,
115,
41,
32,
123,
10,
32,
32,
32,
32,
32,
32,
32,
32,
105,
102,
32,
40,
36,
120,
46,
69,
120,
116,
101,
110,
116,
46,
83,
116,
97,
114,
116,
79,
102,
102,
115,
101,
116,
32,
45,
103,
116,
32,
36,
67,
117,
114,
115,
111,
114,
80,
111,
115,
105,
116,
105,
111,
110,
41,
32,
123,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
98,
114,
101,
97,
107,
10,
32,
32,
32,
32,
32,
32,
32,
32,
125,
10,
10,
32,
32,
32,
32,
32,
32,
32,
32,
36,
97,
114,
103,
115,
32,
43,
61,
32,
36,
120,
46,
69,
120,
116,
101,
110,
116,
10,
32,
32,
32,
32,
125,
10,
10,
32,
32,
32,
32,
105,
102,
32,
40,
45,
110,
111,
116,
32,
36,
87,
111,
114,
100,
84,
111,
67,
111,
109,
112,
108,
101,
116,
101,
41,
32,
123,
10,
32,
32,
32,
32,
32,
32,
32,
32,
36,
97,
114,
103,
115,
32,
43,
61,
32,
34,
34,
10,
32,
32,
32,
32,
125,
10,
10,
32,
32,
32,
32,
38,
32,
107,
105,
110,
100,
108,
121,
32,
45,
45,
99,
117,
101,
32,
112,
119,
115,
104,
32,
45,
45,
32,
64,
97,
114,
103,
115,
32,
50,
62,
36,
110,
117,
108,
108,
32,
124,
32,
37,
32,
123,
10,
32,
32,
32,
32,
32,
32,
32,
32,
36,
120,
115,
32,
61,
32,
36,
95,
32,
45,
115,
112,
108,
105,
116,
32,
34,
96,
116,
34,
10,
10,
32,
32,
32,
32,
32,
32,
32,
32,
36,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
32,
61,
32,
64,
40,
36,
120,
115,
91,
48,
93,
41,
32,
42,
32,
51,
10,
10,
32,
32,
32,
32,
32,
32,
32,
32,
102,
111,
114,
101,
97,
99,
104,
32,
40,
36,
105,
32,
105,
110,
32,
49,
46,
46,
50,
41,
32,
123,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
105,
102,
32,
40,
36,
120,
115,
91,
36,
105,
93,
41,
32,
123,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
36,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
91,
36,
105,
93,
32,
61,
32,
36,
120,
115,
91,
36,
105,
93,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
125,
10,
32,
32,
32,
32,
32,
32,
32,
32,
125,
10,
10,
32,
32,
32,
32,
32,
32,
32,
32,
91,
67,
111,
109,
112,
108,
101,
116,
105,
111,
110,
82,
101,
115,
117,
108,
116,
93,
58,
58,
110,
101,
119,
40,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
36,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
91,
48,
93,
44,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
36,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
91,
49,
93,
44,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
91,
67,
111,
109,
112,
108,
101,
116,
105,
111,
110,
82,
101,
115,
117,
108,
116,
84,
121,
112,
101,
93,
58,
58,
80,
97,
114,
97,
109,
101,
116,
101,
114,
86,
97,
108,
117,
101,
44,
10,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
32,
36,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
91,
50,
93,
10,
32,
32,
32,
32,
32,
32,
32,
32,
41,
10,
32,
32,
32,
32,
125,
10,
125,
10
]),
zsh: new Uint8Array([
35,
99,
111,
109,
112,
100,
101,
102,
32,
107,
105,
110,
100,
108,
121,
10,
99,
111,
109,
112,
100,
101,
102,
32,
95,
107,
105,
110,
100,
108,
121,
32,
107,
105,
110,
100,
108,
121,
10,
10,
122,
115,
116,
121,
108,
101,
32,
34,
58,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
58,
42,
58,
42,
58,
107,
105,
110,
100,
108,
121,
58,
42,
34,
32,
108,
105,
115,
116,
45,
103,
114,
111,
117,
112,
101,
100,
32,
102,
97,
108,
115,
101,
10,
10,
95,
107,
105,
110,
100,
108,
121,
40,
41,
32,
123,
10,
32,
32,
108,
111,
99,
97,
108,
32,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
61,
40,
41,
10,
32,
32,
108,
111,
99,
97,
108,
32,
120,
10,
32,
32,
119,
104,
105,
108,
101,
32,
73,
70,
83,
61,
34,
34,
32,
114,
101,
97,
100,
32,
45,
114,
32,
120,
59,
32,
100,
111,
10,
32,
32,
32,
32,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
43,
61,
34,
36,
123,
120,
125,
34,
10,
32,
32,
100,
111,
110,
101,
32,
60,
32,
60,
40,
10,
32,
32,
32,
32,
101,
120,
112,
111,
114,
116,
32,
67,
79,
76,
85,
77,
78,
83,
10,
10,
32,
32,
32,
32,
108,
111,
99,
97,
108,
32,
97,
114,
103,
115,
61,
40,
34,
36,
123,
61,
119,
111,
114,
100,
115,
91,
50,
44,
67,
85,
82,
82,
69,
78,
84,
93,
125,
34,
41,
10,
10,
32,
32,
32,
32,
107,
105,
110,
100,
108,
121,
32,
45,
45,
99,
117,
101,
32,
122,
115,
104,
32,
45,
45,
32,
34,
36,
123,
97,
114,
103,
115,
91,
64,
93,
125,
34,
32,
50,
62,
47,
100,
101,
118,
47,
110,
117,
108,
108,
10,
10,
32,
32,
32,
32,
112,
114,
105,
110,
116,
102,
32,
37,
115,
32,
34,
36,
123,
63,
125,
34,
10,
32,
32,
41,
10,
10,
32,
32,
99,
97,
115,
101,
32,
34,
36,
123,
120,
125,
44,
36,
123,
35,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
125,
34,
32,
105,
110,
10,
32,
32,
32,
32,
48,
44,
48,
41,
32,
95,
97,
114,
103,
117,
109,
101,
110,
116,
115,
32,
34,
42,
58,
102,
105,
108,
101,
110,
97,
109,
101,
58,
95,
102,
105,
108,
101,
115,
34,
32,
59,
59,
10,
32,
32,
32,
32,
42,
44,
42,
41,
32,
95,
100,
101,
115,
99,
114,
105,
98,
101,
32,
45,
86,
120,
32,
34,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
34,
32,
99,
111,
109,
112,
108,
101,
116,
105,
111,
110,
115,
32,
59,
59,
10,
32,
32,
101,
115,
97,
99,
10,
125,
10,
10,
99,
97,
115,
101,
32,
34,
36,
123,
102,
117,
110,
99,
115,
116,
97,
99,
107,
91,
49,
93,
125,
34,
32,
105,
110,
10,
32,
32,
95,
107,
105,
110,
100,
108,
121,
41,
32,
95,
107,
105,
110,
100,
108,
121,
32,
59,
59,
10,
101,
115,
97,
99,
10
])
}
};
//#endregion
//#region src/kindly_ffi.ts
const { events, fs, process, spawn } = await (async () => !globalThis.Deno ? {
events: await import("node:events"),
fs: await import("node:fs/promises"),
process: (await import("node:process")).default,
spawn: (await import("node:child_process")).spawn
} : {})();
const Nil = void 0;
const handbook_runner_dir = path.join("build", "kindly", "handbook_runner");
const handbook_modules = [
[path.join("dev", "handbook.gleam"), path.join(handbook_runner_dir, "build", "dev", "javascript", "kindly_handbook_runner", "handbook.mjs")],
["handbook.ts", Nil],
["handbook.mjs", Nil],
["handbook.js", Nil]
];
const project_root_indicators = [
".git",
".jj",
"biome.json",
"biome.jsonc",
"bunfig.toml",
"deno.json",
"deno.jsonc",
"erlang.mk",
"gleam.toml",
"jsconfig.json",
"jsr.json",
"jsr.jsonc",
"mix.exs",
"package.json",
"rebar.config",
"tsconfig.json"
];
const kindly_global = globalThis;
let Kindly = kindly_global.Kindly;
if (!Kindly) {
const decoder = new TextDecoder("utf-8");
kindly_global.Kindly = Kindly = {
should_style: env("NO_COLOR") || env("NO_COLOUR") ? "never" : env("COLOR") ?? env("COLOUR") ?? "auto",
is_terminal: {
stdin: (() => {
try {
return process ? process.stdin.isTTY : Deno.stdin.isTerminal();
} catch {
return false;
}
})(),
stdout: process ? process.stdout.isTTY : Deno.stdout.isTerminal(),
stderr: process ? process.stderr.isTTY : Deno.stderr.isTerminal()
},
stdin: "",
version: decoder.decode(generated_default.version),
description: decoder.decode(generated_default.description),
min_gleam_version: decoder.decode(generated_default.min_gleam_version),
project_root: current_directory(),
gleam_project: "",
handbook_module: ""
};
if (!Kindly.is_terminal.stdin) try {
for await (const chunk of process ? process.stdin : Deno.stdin.readable) Kindly.stdin += decoder.decode(chunk);
} catch {}
let dir = Kindly.project_root;
let seen = "";
search: while (dir !== seen) {
for (const [handbook, compiled] of handbook_modules) {
if (await file_is_readable(path.join(dir, handbook))) {
await set_gleam_project(dir);
Kindly.project_root = dir;
Kindly.handbook_module = path.join(dir, compiled ?? handbook);
break search;
}
if (Kindly.project_root !== current_directory() && dir !== path_dirname(Kindly.project_root) && dir !== path_dirname(path_dirname(Kindly.project_root))) break search;
if ((await Promise.all(project_root_indicators.map((x) => file_is_readable(path.join(dir, x))))).some(Boolean)) {
const { project_root } = Kindly;
Kindly.project_root = dir;
if (project_root !== current_directory()) break search;
}
}
seen = dir;
dir = path.dirname(dir);
}
}
function env(name) {
return process ? process.env[name] : Deno.env.get(name);
}
/**
* Promises to set global state for `gleam_project` after trying to read a
* project name from `gleam.toml`.
*
* @internal
*/
async function set_gleam_project(dir) {
const content = await file_read(path.join(dir, "gleam.toml"), "utf-8") ?? "";
const re = new RegExp([
"(?:^|\n)",
"name",
"=",
`["'](.*?)["']`,
"(?:\n|$)"
].join("(?: | )*"));
Kindly.gleam_project = re.exec(content)?.[1] ?? "";
}
/**
* Returns a `Bool` indicating whether the given Standard IO stream is a
* terminal (TTY).
*/
function is_terminal(stream) {
return Kindly.is_terminal[stream];
}
/**
* Results in the value of the given environment variable on success, or
* `undefined` if the variable is unset.
*/
function get_env(name) {
const value = env(name);
return Nil !== value ? Result$Ok(value) : Result$Error(value);
}
/**
* Sets an environment variable to the given value.
*/
function set_env(name, value) {
if (process) process.env[name] = value;
else Deno.env.set(name, value);
}
/**
* Ensures the given environment variable is no longer set.
*/
function unset_env(name) {
if (process) delete process.env[name];
else Deno.env.delete(name);
}
/**
* Returns a monotonic timestamp for the current time in milliseconds, rounded
* down.
*/
function now() {
return Math.floor(globalThis.performance.now());
}
/**
* Returns the given `content` with ANSI `styles` applied, ending with a style
* reset.
*
* Returns the given `content` unstyled when the `NO_COLOR` or `NO_COLOUR`
* environment variable is truthy; likewise, if `kindly`'s output is piped to
* `stdin`, unless the `COLOR` or `COLOUR` environment variable is `always`.
*/
function ansi(content, style, ...styles) {
if ("never" === Kindly.should_style || "always" !== Kindly.should_style && !is_terminal("stdout")) return content;
style = typeof style === "number" ? [style] : style;
styles = [...style, ...styles];
if (!styles.length) return content;
const start = styles.length ? "\x1B[" + styles.join(";") + "m" : "";
const end = "\x1B[m\x1B[K";
return start + content + (content.endsWith(end) ? "" : end);
}
/**
* Runs the given external binary with any given arguments.
*
* The command is executed as transparently as possible (capturing nothing).
*
* Promises to return a `Result<undefined, undefined>` indicating the command's
* success.
*/
async function command(bin, arg, ...args) {
arg = typeof arg === "string" ? [arg] : arg;
args = [...arg, ...args];
return (await do_command(bin, args))?.success ? Result$Ok(Nil) : Result$Error(Nil);
}
async function do_command(bin, args, options = {}) {
options.cwd ??= ".";
options.stdin ??= "inherit";
options.stdout ??= "inherit";
options.stderr ??= "inherit";
const { cwd, stdin, stdout, stderr } = options;
const output = {
code: 1,
stderr: "",
stdout: "",
success: false
};
const decoder = new TextDecoder("utf-8");
const pass_on = () => Nil;
if (events && process) process.on("SIGINT", pass_on);
else Deno.addSignalListener("SIGINT", pass_on);
try {
if (spawn) return await new Promise((resolve) => {
const child_process = spawn(bin, args, {
cwd,
env: process.env,
stdio: [
stdin === "null" ? "ignore" : stdin,
stdout === "piped" ? "pipe" : stdout,
stderr === "piped" ? "pipe" : stderr
],
windowsHide: true
});
child_process.stderr?.on("data", (data) => {
output.stderr += decoder.decode(data);
});
child_process.stdout?.on("data", (data) => {
output.stdout += decoder.decode(data);
});
child_process.on("close", (code) => {
output.code = code ?? 1;
output.success = !output.code;
resolve(code !== null ? output : Nil);
});
});
const command_output = await new Deno.Command(bin, {
args,
cwd,
env: Deno.env.toObject(),
stdin,
stdout,
stderr
}).output();
output.code = command_output.code;
if (stderr === "piped") output.stderr = decoder.decode(command_output.stderr);
if (stdout === "piped") output.stdout = decoder.decode(command_output.stdout);
output.success = command_output.success;
return output;
} catch {
return;
} finally {
if (events && process) process.off("SIGINT", pass_on);
else Deno.removeSignalListener("SIGINT", pass_on);
}
}
/**
* Returns a function that discards its arguments and just runs `command` with
* the given arguments.
*/
function just(bin, arg, ...args) {
return () => command(bin, arg, ...args);
}
/**
* Returns a function that styles a `string` with the given ANSI codes.
*/
function styler(style, ...styles) {
return (content) => ansi(content, style, ...styles);
}
/**
* Returns the path of the current working directory.
*/
function current_directory() {
return (process ? process : Deno).cwd();
}
/**
* Promises to determine whether the given path exists and is readable.
*/
async function file_is_readable(path) {
try {
(await (fs ? fs.open(path, "r") : Deno.open(path, { read: true }))).close();
return true;
} catch {
return false;
}
}
async function file_read(path, encoding) {
try {
const content = await (fs ? fs.readFile(path) : Deno.readFile(path));
const bytes = new Uint8Array(content);
return encoding !== Nil ? new TextDecoder(encoding).decode(bytes) : bytes;
} catch {
return;
}
}
/**
* Returns the directory path of the given path.
*/
function path_dirname(pathname) {
return path.dirname(pathname);
}
//#endregion
//#region src/javascript_api.ts
var javascript_api_exports = /* @__PURE__ */ __exportAll({
ansi: () => ansi,
command: () => command,
command_step: () => command_step,
default_theme: () => default_theme,
get_env: () => get_env,
gleam_theme: () => gleam_theme,
handbook: () => handbook,
is_terminal: () => is_terminal,
just: () => just,
now: () => now,
plain_theme: () => plain_theme,
reject: () => reject,
resolve: () => resolve,
set_env: () => set_env,
step: () => step,
styler: () => styler,
unset_env: () => unset_env
});
const option_to_optional = kindly.option_to_optional;
function toList$(xs) {
return toList([...xs]);
}
const handbook$ = kindly.handbook;
const theme$ = kindly.theme;
const task$ = kindly.task;
const task_with_tasks$ = kindly.task_with_tasks;
const map$ = kindly.map;
const group$ = kindly.group;
/**
* Returns Kindly's default display `Theme`.
*
* This theme uses a selection of the terminal's configured colours.
*/
const default_theme = kindly.default_theme;
/**
* Returns a Gleam-inspired `Theme`.
*/
const gleam_theme = kindly.gleam_theme;
/**
* Returns a `Theme` that uses the terminal's default display style.
*/
const plain_theme = kindly.plain_theme;
/**
* A Kindly `Handbook`.
*/
var Handbook = class {
handbook;
constructor(name) {
this.handbook = handbook$(name);
}
/**
* Applies the given `Theme` to Kindly output.
*/
theme(theme) {
const new_theme = kindly.default_theme();
for (const [key, value] of Object.entries(theme)) if (key in new_theme) new_theme[key] = value;
this.handbook = theme$(this.handbook, new_theme);
return this;
}
task(doc_or_task, maybe_tags, maybe_action) {
const { doc, tags, action } = typeof doc_or_task === "object" ? doc_or_task : {
doc: doc_or_task,
tags: maybe_tags,
action: maybe_action
};
this.handbook = task$(this.handbook, doc, toList$(tags), (args) => action([...args]));
return this;
}
task_with_tasks(doc_or_task, maybe_tags, maybe_action) {
const { doc, tags, action } = typeof doc_or_task === "object" ? doc_or_task : {
doc: doc_or_task,
tags: maybe_tags,
action: maybe_action
};
this.handbook = task_with_tasks$(this.handbook, doc, toList$(tags), (args, tasks) => action([...args], [...tasks].map((task) => Object.assign({}, task, { group_doc: option_to_optional(task.group_doc) }))));
return this;
}
group(doc_or_group, maybe_tags, maybe_apply) {
const { doc, tags, apply: f } = typeof doc_or_group === "object" ? doc_or_group : {
doc: doc_or_group,
tags: maybe_tags,
apply: maybe_apply
};
this.handbook = group$(this.handbook, doc, toList$(tags), (handbook$) => {
this.handbook = handbook$;
return f(this).handbook;
});
return this;
}
map(apply_or_map) {
const { apply: f } = typeof apply_or_map === "object" ? apply_or_map : { apply: apply_or_map };
this.handbook = map$(this.handbook, (handbook$) => {
this.handbook = handbook$;
return f(this).handbook;
});
return this;
}
};
function handbook(name_or_def) {
const { for: name } = typeof name_or_def === "object" ? name_or_def : { for: name_or_def };
return new Handbook(name);
}
/**
* A multistep `Task` pipeline.
*/
var Steps = class Steps {
steps;
constructor(f) {
this.steps = f;
}
/**
* Calls and awaits the given function's `Result`. On success, promises to
* return the callback function's `Result`. If either `Result` is an `Error`,
* an `Error<Nil>` is promised instead.
*
* Enables chaining function calls such that each `step` can only run after
* the previous `step` succeeded.
*/
step(then) {
return new Steps(() => do_step(this.steps, then));
}
/**
* Combines `step` and `command`, enabling function chains akin to shell `&&`
* sequences.
*/
command_step(bin, arg, ...args) {
return this.step((_value) => command(bin, arg, ...args));
}
/**
* Promises to return an `Ok<Nil>` result. Useful for ending a multistep
* `Task` successfully.
*/
resolve() {
return do_step(this.steps, (_value) => resolve());
}
/**
* Promises to return an `Error<Nil>` result. Useful for ending a multistep
* `Task` in failure.
*/
reject() {
return do_step(this.steps, (_value) => reject());
}
};
/**
* Calls and awaits the given function's `Result`. On success, promises to
* return the callback function's `Result`. If either `Result` is an `Error`,
* an `Error<Nil>` is promised instead.
*
* Enables chaining function calls such that each `step` can only run after the
* previous `step` succeeded.
*/
function step(f) {
return new Steps(f);
}
async function do_step(f, then) {
const result = await f();
if (!Result$isOk(result)) return Result$Error(void 0);
const next = await then(Result$Ok$0(result));
return Result$isOk(next) ? next : Result$Error(void 0);
}
/**
* Combines `step` and `command`, enabling function chains akin to shell `&&`
* sequences.
*/
function command_step(bin, arg, ...args) {
return new Steps(() => command(bin, arg, ...args));
}
/**
* Promises to return an `Ok<Nil>` result. Useful for ending a multistep `Task`
* successfully.
*/
function resolve() {
return Promise.resolve(Result$Ok(void 0));
}
/**
* Promises to return an `Error<Nil>` result. Useful for ending a multistep
* `Task` in failure.
*/
function reject() {
return Promise.resolve(Result$Error(void 0));
}
//#endregion
//#region mod.ts
if (import.meta.main) main();
//#endregion
export { ansi, command, command_step, javascript_api_exports as default, default_theme, get_env, gleam_theme, handbook, is_terminal, just, now, plain_theme, reject, resolve, set_env, step, styler, unset_env };