bimba-cli 0.1.3 → 0.1.5
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/README.md +28 -8
- package/{index.ts → index.js} +22 -41
- package/package.json +4 -5
- package/{plugin.ts → plugin.js} +25 -49
- package/utils.ts +46 -0
- package/tsconfig.json +0 -22
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ bun add bimba-cli
|
|
|
9
9
|
|
|
10
10
|
Then create a `bunfig.toml` file in the root folder of your project, and add only one line in it (I could not find any workaround to do this automatically):
|
|
11
11
|
```bash
|
|
12
|
-
preload = ["bimba-cli/plugin.
|
|
12
|
+
preload = ["bimba-cli/plugin.js"]
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
You are done!
|
|
@@ -24,7 +24,7 @@ Or with the watch argument:
|
|
|
24
24
|
bun --watch run src/index.imba
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
###Frontend development
|
|
27
|
+
### Frontend development
|
|
28
28
|
For frontend you will need to compile and bundle your source code from .imba to .js. And here the bimba-cli will help:
|
|
29
29
|
```bash
|
|
30
30
|
bunx bimba src/index.imba --outdir public
|
|
@@ -34,16 +34,36 @@ Or with the watch argument:
|
|
|
34
34
|
bunx bimba src/index.imba --outdir public --watch
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
Here are all the available argumentsthat you can pass to the bimba:
|
|
38
38
|
|
|
39
|
-
`--
|
|
39
|
+
`--watch` - Monitors changes in the directory where the entry point is located, and rebuilds the projects when the change occures. Keep entrypoint file in the subfolder, otherwise Bun will trigger several times since the cache dir update also triggers rebuilding.
|
|
40
40
|
|
|
41
|
-
`--
|
|
41
|
+
`--clearcache` - If is set, the cache directory is deleted when bimba exits. Works only in the watch mode, since when bundling cache will be used next time to speed up the compiling time.
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
```bash
|
|
44
|
+
bunx bimba src/index.imba --outdir public --watch --clearcache
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`--sourcemap` - Tells Bun how to inculde sourcemap files in the final .js. It is `none` by default.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
bunx bimba src/index.imba --outdir public --sourcemap inline
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`--minify` - If is set the final JS code in the bundle produced by Bun will be minified. It is `false` by default.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
bunx bimba src/index.imba --outdir public --minify
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`--platform` - The value of this argument will be passed to the Imba compiler. By default it is `browswer`. The value `node` does not work under Bun.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bunx bimba src/index.imba --outdir public --platform browser
|
|
63
|
+
```
|
|
44
64
|
|
|
45
|
-
####Live reload
|
|
46
|
-
Initially I implemented the live reload functionality, but then decided to refuse it. There is a pretty good VS Code extension: [Lite Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer).
|
|
65
|
+
#### Live reload
|
|
66
|
+
Initially I have implemented the live reload functionality, but then decided to refuse it. There is a pretty good VS Code extension: [Lite Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer).
|
|
47
67
|
It does everything needed out of the box.
|
|
48
68
|
|
|
49
69
|
Just let bimba rebuild the sources on change and Lite Server will reload the page in the browser.
|
package/{index.ts → index.js}
RENAMED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
import { parseArgs } from "util";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import { imbaPlugin, stats, cache } from './plugin.js'
|
|
5
|
+
import {theme} from './utils.ts';
|
|
6
6
|
import fs from 'fs'
|
|
7
7
|
import path from 'path';
|
|
8
|
+
import { rmSync } from "node:fs";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
let
|
|
10
|
+
|
|
11
|
+
let flags = {}
|
|
12
|
+
let entrypoint = ''
|
|
11
13
|
|
|
12
14
|
try {
|
|
13
15
|
const { values, positionals } = parseArgs({
|
|
@@ -16,6 +18,7 @@ try {
|
|
|
16
18
|
watch: { type: 'boolean' },
|
|
17
19
|
outdir: { type: 'string' },
|
|
18
20
|
help: { type: 'boolean' },
|
|
21
|
+
clearcache: { type: 'boolean' },
|
|
19
22
|
minify: { type: 'boolean' },
|
|
20
23
|
target: { type: 'string' },
|
|
21
24
|
sourcemap: { type: 'string' },
|
|
@@ -24,29 +27,16 @@ try {
|
|
|
24
27
|
allowPositionals: true,
|
|
25
28
|
});
|
|
26
29
|
flags = values;
|
|
27
|
-
|
|
28
|
-
folders = positionals;
|
|
30
|
+
entrypoint = Bun.argv[2];
|
|
29
31
|
}
|
|
30
32
|
catch (error) {
|
|
31
33
|
if (error instanceof Error)
|
|
32
34
|
console.log(error.message);
|
|
33
35
|
else
|
|
34
36
|
console.log("Could not resolve CLI arguments. Read help to know them: " + theme.flags('--entry file.imba'));
|
|
35
|
-
process.exit(
|
|
37
|
+
process.exit(0);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
const theme = {
|
|
39
|
-
flags: ansis.fg(5),
|
|
40
|
-
count: ansis.fg(15).bold,
|
|
41
|
-
start: ansis.fg(252).bg(233),
|
|
42
|
-
filedir: ansis.fg(15),
|
|
43
|
-
success: ansis.fg(40),
|
|
44
|
-
failure: ansis.fg(196),
|
|
45
|
-
time: ansis.fg(41),
|
|
46
|
-
link: ansis.fg(15),
|
|
47
|
-
online: ansis.fg(40).bg(22)
|
|
48
|
-
};
|
|
49
|
-
|
|
50
40
|
// help: more on bun building params here: https://bun.sh/docs/bundler
|
|
51
41
|
if(flags.help) {
|
|
52
42
|
console.log("");
|
|
@@ -58,39 +48,32 @@ if(flags.help) {
|
|
|
58
48
|
console.log(" "+theme.flags('--sourcemap <inline|external|none>')+" How should sourcemap files be included in the .js");
|
|
59
49
|
console.log(" "+theme.flags('--platform <browser|node>')+" Flag that will be passed to Imba compiler ('node' value does not work in Bun)");
|
|
60
50
|
console.log(" "+theme.flags('--watch')+" Watch for changes in the entrypoint folder");
|
|
51
|
+
console.log(" "+theme.flags('--clearcache')+" Clear cache on exit, works only when in watch mode");
|
|
61
52
|
console.log("");
|
|
62
|
-
process.exit(
|
|
53
|
+
process.exit(0);
|
|
63
54
|
}
|
|
64
55
|
|
|
65
56
|
|
|
66
|
-
// no entrypoint
|
|
67
|
-
if(!flags.
|
|
57
|
+
// no entrypoint or outdir
|
|
58
|
+
if(!entrypoint || !flags.outdir) {
|
|
68
59
|
console.log("");
|
|
69
|
-
console.log("
|
|
60
|
+
console.log("You should provide entrypoint and the output dir: "+theme.flags('bimba file.imba --outdir public'));
|
|
70
61
|
console.log("For more information: "+theme.flags('--help'));
|
|
71
62
|
console.log("");
|
|
72
63
|
process.exit(1);
|
|
73
64
|
}
|
|
74
65
|
|
|
75
|
-
// no outdir
|
|
76
|
-
if(flags.outdir){
|
|
77
|
-
console.log("");
|
|
78
|
-
console.log("No output dir is provided: "+theme.flags('bimba file.imba --outdir public'));
|
|
79
|
-
console.log("For more information: "+theme.flags('--help'));
|
|
80
|
-
console.log("");
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
66
|
// build
|
|
86
67
|
bundle();
|
|
87
68
|
watch(bundle);
|
|
88
69
|
|
|
89
70
|
function watch(callback) {
|
|
90
71
|
if (flags.watch) {
|
|
91
|
-
const watcher = fs.watch(path.dirname(
|
|
72
|
+
const watcher = fs.watch(path.dirname(entrypoint), {recursive: true}, async (event, filename) => ( callback() ));
|
|
92
73
|
|
|
93
74
|
process.on("SIGINT", () => {
|
|
75
|
+
if(flags.clearcache) rmSync(cache, { recursive: true, force: true });
|
|
76
|
+
|
|
94
77
|
if(watcher) {
|
|
95
78
|
watcher.close();
|
|
96
79
|
process.exit(0);
|
|
@@ -100,13 +83,11 @@ function watch(callback) {
|
|
|
100
83
|
}
|
|
101
84
|
|
|
102
85
|
async function bundle() {
|
|
103
|
-
if (!fs.existsSync(
|
|
104
|
-
console.log(theme.failure('Error.') + ` The specified entrypoint does not exist: ${theme.filedir(
|
|
105
|
-
process.exit(
|
|
86
|
+
if (!fs.existsSync(entrypoint)) {
|
|
87
|
+
console.log(theme.failure('Error.') + ` The specified entrypoint does not exist: ${theme.filedir(entrypoint)}`);
|
|
88
|
+
process.exit(0);
|
|
106
89
|
}
|
|
107
90
|
|
|
108
|
-
//if (!fs.existsSync(flags.bundle)){ fs.mkdirSync(flags.bundle);}
|
|
109
|
-
|
|
110
91
|
stats.failed = 0
|
|
111
92
|
stats.compiled = 0
|
|
112
93
|
stats.errors = 0
|
|
@@ -115,10 +96,10 @@ async function bundle() {
|
|
|
115
96
|
const start = Date.now();
|
|
116
97
|
|
|
117
98
|
console.log("──────────────────────────────────────────────────────────────────────");
|
|
118
|
-
console.log(theme.start(`Start building the Imba entrypoint: ${theme.filedir(
|
|
99
|
+
console.log(theme.start(`Start building the Imba entrypoint: ${theme.filedir(entrypoint)}`));
|
|
119
100
|
|
|
120
101
|
const result = await Bun.build({
|
|
121
|
-
entrypoints: [
|
|
102
|
+
entrypoints: [entrypoint],
|
|
122
103
|
outdir: flags.outdir,
|
|
123
104
|
target: flags.target || 'browser',
|
|
124
105
|
sourcemap: flags.sourcemap || 'none',
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bimba-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"repository": "github:HeapVoid/bimba",
|
|
5
|
-
"module": "index.
|
|
5
|
+
"module": "index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"bimba": "./index.
|
|
7
|
+
"bimba": "./index.js"
|
|
8
8
|
},
|
|
9
9
|
"description": "The CLI tool to run Imba projects under Bun",
|
|
10
10
|
"keywords": ["imba", "bun", "plugin"],
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"type": "module",
|
|
13
|
-
"
|
|
14
|
-
"ansis": "^2.2.0",
|
|
13
|
+
"devDependencies": {
|
|
15
14
|
"imba": "^2.0.0-alpha.234"
|
|
16
15
|
}
|
|
17
16
|
}
|
package/{plugin.ts → plugin.js}
RENAMED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import { plugin
|
|
2
|
-
import
|
|
1
|
+
import { plugin } from "bun";
|
|
2
|
+
import {theme} from './utils.ts';
|
|
3
3
|
import * as compiler from 'imba/compiler'
|
|
4
4
|
import dir from 'path'
|
|
5
5
|
import fs from 'fs'
|
|
6
|
+
import { Glob } from "bun";
|
|
7
|
+
import { unlink } from "node:fs/promises";
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
// color pallete can be seen here: https://raw.githubusercontent.com/webdiscus/ansis/master/docs/img/ansi256.png
|
|
9
|
-
// for more details read the project page: https://github.com/webdiscus/ansis
|
|
10
|
-
const theme = {
|
|
11
|
-
action: ansis.fg(237),
|
|
12
|
-
folder: ansis.fg(240),
|
|
13
|
-
filename: ansis.fg(15),
|
|
14
|
-
success: ansis.fg(40),
|
|
15
|
-
failure: ansis.fg(15).bg(124),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const cache = process.cwd() + '/.cache/';
|
|
9
|
+
export const cache = process.cwd() + '/.cache/';
|
|
19
10
|
if (!fs.existsSync(cache)){ fs.mkdirSync(cache);}
|
|
20
11
|
|
|
21
12
|
// this should be reset from outside to get results of entrypoint building
|
|
@@ -27,7 +18,7 @@ export let stats = {
|
|
|
27
18
|
errors: 0
|
|
28
19
|
};
|
|
29
20
|
|
|
30
|
-
export const imbaPlugin
|
|
21
|
+
export const imbaPlugin = {
|
|
31
22
|
name: "imba",
|
|
32
23
|
async setup(build) {
|
|
33
24
|
|
|
@@ -82,7 +73,7 @@ export const imbaPlugin: BunPlugin = {
|
|
|
82
73
|
let contents = '';
|
|
83
74
|
|
|
84
75
|
// return the cached version if it exists
|
|
85
|
-
const cached = cache + Bun.hash(path + fs.statSync(path).mtimeMs
|
|
76
|
+
const cached = cache + Bun.hash(path) + '_' + fs.statSync(path).mtimeMs + '.js';
|
|
86
77
|
if (fs.existsSync(cached)) {
|
|
87
78
|
stats.bundled++;
|
|
88
79
|
stats.cached++;
|
|
@@ -93,6 +84,10 @@ export const imbaPlugin: BunPlugin = {
|
|
|
93
84
|
};
|
|
94
85
|
}
|
|
95
86
|
|
|
87
|
+
// clear previous cached version
|
|
88
|
+
const glob = new Glob(Bun.hash(path) + '_' + "*.js");
|
|
89
|
+
for await (const file of glob.scan(cache)) unlink(cache + '/' + file);
|
|
90
|
+
|
|
96
91
|
// if no cached version read and compile it with the imba compiler
|
|
97
92
|
const file = await Bun.file(path).text();
|
|
98
93
|
const out = compiler.compile(file, {
|
|
@@ -137,32 +132,13 @@ plugin(imbaPlugin);
|
|
|
137
132
|
// print pretty messages produced by the imba compiler
|
|
138
133
|
// -------------------------------------------------------------------------------
|
|
139
134
|
|
|
140
|
-
type imbaCompilerError = {
|
|
141
|
-
toSnippet: Function;
|
|
142
|
-
toError: Function;
|
|
143
|
-
message: string;
|
|
144
|
-
range: {
|
|
145
|
-
start: {
|
|
146
|
-
line: number
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
135
|
// print an error generated by the imba compiler
|
|
152
|
-
function printerr(err
|
|
136
|
+
function printerr(err) {
|
|
153
137
|
|
|
154
138
|
// halper function to produce empty strings
|
|
155
139
|
const fill = (len = 0) => {return new Array(len + 1).join(' ')}
|
|
156
140
|
|
|
157
|
-
|
|
158
|
-
const colors = {
|
|
159
|
-
code: ansis.fg(252).bg(238),
|
|
160
|
-
margin: ansis.fg(229).bg(145),
|
|
161
|
-
error: ansis.fg(196).bg(52),
|
|
162
|
-
ecode: ansis.fg(196).bg(238).bold,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// gather the needed information from the compiler error
|
|
141
|
+
// gather the needed information from the compiler error
|
|
166
142
|
const snippet = err.toSnippet().split("\n");
|
|
167
143
|
const display = {
|
|
168
144
|
error: " " + err.message + " ",
|
|
@@ -186,21 +162,21 @@ function printerr(err: imbaCompilerError) {
|
|
|
186
162
|
// print line with the error message
|
|
187
163
|
console.log(
|
|
188
164
|
display.outdent +
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
165
|
+
theme.margin(fill(Math.min(start, display.margin.length))) +
|
|
166
|
+
theme.code(fill(Math.max(0, start - display.margin.length))) +
|
|
167
|
+
theme.error(display.error) +
|
|
168
|
+
theme.margin(fill(Math.max(0, display.margin.length - end))) +
|
|
169
|
+
theme.code(fill(Math.min(total - display.margin.length, total - end)))
|
|
194
170
|
);
|
|
195
171
|
|
|
196
172
|
// print line with the source code
|
|
197
173
|
console.log(
|
|
198
174
|
display.outdent +
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
175
|
+
theme.margin(display.margin) +
|
|
176
|
+
theme.code(display.source.slice(0,display.errs)) +
|
|
177
|
+
theme.error(display.source.slice(display.errs,display.erre)) +
|
|
178
|
+
theme.code(display.source.slice(display.erre)) +
|
|
179
|
+
theme.code(fill(total - display.source.length - display.margin.length))
|
|
204
180
|
);
|
|
205
181
|
|
|
206
182
|
// print empty line to balance the view
|
|
@@ -208,8 +184,8 @@ function printerr(err: imbaCompilerError) {
|
|
|
208
184
|
// for example a link to online docs about the error
|
|
209
185
|
console.log(
|
|
210
186
|
display.outdent +
|
|
211
|
-
|
|
212
|
-
|
|
187
|
+
theme.margin(fill(display.margin.length)) +
|
|
188
|
+
theme.code(fill(total - display.margin.length))
|
|
213
189
|
);
|
|
214
190
|
|
|
215
191
|
// print emtpy line
|
package/utils.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function colorize(text:string, fg?:number, bg?:number) {
|
|
2
|
+
let result = ''
|
|
3
|
+
if(fg) result += "\x1b[38;5;" + fg.toString() + "m"
|
|
4
|
+
if(bg) result += "\x1b[48;5;" + bg.toString() + "m"
|
|
5
|
+
result += text
|
|
6
|
+
if(fg || bg) result += "\x1b[0m"
|
|
7
|
+
return result
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// const theme = {
|
|
11
|
+
// action: ansis.fg(237),
|
|
12
|
+
// folder: ansis.fg(240),
|
|
13
|
+
// filename: ansis.fg(15),
|
|
14
|
+
// success: ansis.fg(40),
|
|
15
|
+
// failure: ansis.fg(15).bg(124),
|
|
16
|
+
// };
|
|
17
|
+
|
|
18
|
+
// // set color theme for an error message
|
|
19
|
+
// const colors = {
|
|
20
|
+
// code: ansis.fg(252).bg(238),
|
|
21
|
+
// margin: ansis.fg(229).bg(145),
|
|
22
|
+
// error: ansis.fg(196).bg(52),
|
|
23
|
+
// ecode: ansis.fg(196).bg(238).bold,
|
|
24
|
+
// };
|
|
25
|
+
|
|
26
|
+
// theme for messages printed in terminal
|
|
27
|
+
// https://i.stack.imgur.com/KTSQa.png
|
|
28
|
+
export const theme = {
|
|
29
|
+
code: (text:string) => colorize(text, 252, 238),
|
|
30
|
+
margin: (text:string) => colorize(text, 229, 145),
|
|
31
|
+
error: (text:string) => colorize(text, 196 , 52),
|
|
32
|
+
ecode: (text:string) => colorize(text, 196, 238),
|
|
33
|
+
action: (text:string) => colorize(text, 237),
|
|
34
|
+
folder: (text:string) => colorize(text, 240),
|
|
35
|
+
filename: (text:string) => colorize(text, 15),
|
|
36
|
+
success: (text:string) => colorize(text, 40),
|
|
37
|
+
failure: (text:string) => colorize(text, 15, 124),
|
|
38
|
+
|
|
39
|
+
flags: (text:string) => colorize(text, 5),
|
|
40
|
+
count: (text:string) => colorize(text, 15),
|
|
41
|
+
start: (text:string) => colorize(text, 252, 233),
|
|
42
|
+
filedir: (text:string) => colorize(text, 15),
|
|
43
|
+
time: (text:string) => colorize(text, 41),
|
|
44
|
+
link: (text:string) => colorize(text, 15),
|
|
45
|
+
online: (text:string) => colorize(text, 40, 22)
|
|
46
|
+
}
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"],
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleDetection": "force",
|
|
7
|
-
"jsx": "react-jsx",
|
|
8
|
-
"allowJs": true,
|
|
9
|
-
|
|
10
|
-
/* Bundler mode */
|
|
11
|
-
"moduleResolution": "bundler",
|
|
12
|
-
"allowImportingTsExtensions": true,
|
|
13
|
-
"verbatimModuleSyntax": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
|
|
16
|
-
/* Linting */
|
|
17
|
-
"skipLibCheck": true,
|
|
18
|
-
"strict": true,
|
|
19
|
-
"noFallthroughCasesInSwitch": true,
|
|
20
|
-
"forceConsistentCasingInFileNames": true
|
|
21
|
-
}
|
|
22
|
-
}
|