bimba-cli 0.1.2 → 0.1.4
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 +40 -6
- package/index.ts +12 -31
- package/package.json +1 -1
- package/bunfig.toml +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
This tool helps to work with [Imba](https://imba.io) projects under [Bun](https://bun.sh). That is why it is called Bun+IMBA = BIMBA 😉
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
It includes the plugin for Bun to compile .imba files and also the CLI tool for buiding .imba files, since the plugins can't be passed to Bun via shell command `bun build`.
|
|
4
4
|
|
|
5
|
+
First of all install this tool like any other npm package:
|
|
5
6
|
```bash
|
|
6
|
-
bun
|
|
7
|
+
bun add bimba-cli
|
|
7
8
|
```
|
|
8
9
|
|
|
9
|
-
|
|
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
|
+
```bash
|
|
12
|
+
preload = ["bimba-cli/plugin.ts"]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You are done!
|
|
16
|
+
|
|
17
|
+
### Backend development
|
|
18
|
+
Now to run an .imba file in Bun's environment you can use the usual Bun syntax:
|
|
19
|
+
```bash
|
|
20
|
+
bun run src/index.imba
|
|
21
|
+
```
|
|
22
|
+
Or with the watch argument:
|
|
23
|
+
```bash
|
|
24
|
+
bun --watch run src/index.imba
|
|
25
|
+
```
|
|
10
26
|
|
|
27
|
+
###Frontend development
|
|
28
|
+
For frontend you will need to compile and bundle your source code from .imba to .js. And here the bimba-cli will help:
|
|
11
29
|
```bash
|
|
12
|
-
|
|
30
|
+
bunx bimba src/index.imba --outdir public
|
|
13
31
|
```
|
|
32
|
+
Or with the watch argument:
|
|
33
|
+
```bash
|
|
34
|
+
bunx bimba src/index.imba --outdir public --watch
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
There are additional arguments that you can pass to the bimba:
|
|
38
|
+
|
|
39
|
+
`--sourcemap` - to tell Bun how to inculde sourcemap files in the final .js. It is `none` by default.
|
|
40
|
+
|
|
41
|
+
`--minify` - to minify the final JS code in the bundle produced by Bun. It is `false` by default.
|
|
42
|
+
|
|
43
|
+
`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.
|
|
44
|
+
|
|
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).
|
|
47
|
+
It does everything needed out of the box.
|
|
14
48
|
|
|
15
|
-
|
|
49
|
+
Just let bimba rebuild the sources on change and Lite Server will reload the page in the browser.
|
package/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import ansis from 'ansis';
|
|
|
5
5
|
import { imbaPlugin, stats } from './plugin.ts'
|
|
6
6
|
import fs from 'fs'
|
|
7
7
|
import path from 'path';
|
|
8
|
-
import { $ } from "bun";
|
|
9
8
|
|
|
10
9
|
let flags = {};
|
|
11
10
|
let folders = {};
|
|
@@ -51,44 +50,31 @@ const theme = {
|
|
|
51
50
|
// help: more on bun building params here: https://bun.sh/docs/bundler
|
|
52
51
|
if(flags.help) {
|
|
53
52
|
console.log("");
|
|
54
|
-
console.log("Bimba requeres an .imba file
|
|
55
|
-
console.log("
|
|
56
|
-
console.log(" "+theme.flags('bimba <file.imba>')+" The entrypoint of the imba project");
|
|
53
|
+
console.log("Bimba requeres an .imba file and a folder where to put compiled .js files.");
|
|
54
|
+
console.log("For example like this: "+theme.filedir('bimba file.imba --outdir public'));
|
|
57
55
|
console.log("");
|
|
58
|
-
console.log("
|
|
59
|
-
console.log(" "+theme.flags('--
|
|
60
|
-
console.log("");
|
|
61
|
-
console.log("
|
|
62
|
-
console.log(" "+theme.flags('--
|
|
63
|
-
console.log(" "+theme.flags('--sourcemap <inline|external|none>')+" How should be sourcemap files be included in the .js");
|
|
64
|
-
console.log(" "+theme.flags('--platform <browser|node>')+" Flag that will be passed to Imba compiler ('node' value does not work in Bun)");
|
|
65
|
-
console.log("");
|
|
66
|
-
console.log("The watch switch is applied in both scenarios (when running and when building Imba sources):");
|
|
67
|
-
console.log(" "+theme.flags('--watch')+" Watch for changes in the entrypoint folder");
|
|
56
|
+
console.log(" "+theme.flags('--outdir <folder>')+" Compile imba files to the specified folder");
|
|
57
|
+
console.log(" "+theme.flags('--minify')+" Minify compiled .js files");
|
|
58
|
+
console.log(" "+theme.flags('--sourcemap <inline|external|none>')+" How should sourcemap files be included in the .js");
|
|
59
|
+
console.log(" "+theme.flags('--platform <browser|node>')+" Flag that will be passed to Imba compiler ('node' value does not work in Bun)");
|
|
60
|
+
console.log(" "+theme.flags('--watch')+" Watch for changes in the entrypoint folder");
|
|
68
61
|
console.log("");
|
|
69
62
|
process.exit(1);
|
|
70
63
|
}
|
|
71
64
|
|
|
72
65
|
|
|
73
|
-
// no entrypoint
|
|
74
|
-
if(!flags.entry) {
|
|
66
|
+
// no entrypoint or outdir
|
|
67
|
+
if(!flags.entry || !flags.outdir) {
|
|
75
68
|
console.log("");
|
|
76
|
-
console.log("
|
|
69
|
+
console.log("You should provide entrypoint and the output dir: "+theme.flags('bimba file.imba --outdir public'));
|
|
77
70
|
console.log("For more information: "+theme.flags('--help'));
|
|
78
71
|
console.log("");
|
|
79
72
|
process.exit(1);
|
|
80
73
|
}
|
|
81
74
|
|
|
82
|
-
|
|
83
75
|
// build
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
watch(bundle);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
run();
|
|
90
|
-
watch(run);
|
|
91
|
-
}
|
|
76
|
+
bundle();
|
|
77
|
+
watch(bundle);
|
|
92
78
|
|
|
93
79
|
function watch(callback) {
|
|
94
80
|
if (flags.watch) {
|
|
@@ -103,11 +89,6 @@ function watch(callback) {
|
|
|
103
89
|
}
|
|
104
90
|
}
|
|
105
91
|
|
|
106
|
-
async function run() {
|
|
107
|
-
await $`bun run ${path.resolve(flags.entry)}`;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
92
|
async function bundle() {
|
|
112
93
|
if (!fs.existsSync(flags.entry)) {
|
|
113
94
|
console.log(theme.failure('Error.') + ` The specified entrypoint does not exist: ${theme.filedir(flags.entry)}`);
|
package/package.json
CHANGED
package/bunfig.toml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
preload = ["./plugin.ts"]
|