bimba-cli 0.1.2 → 0.1.3

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 CHANGED
@@ -1,15 +1,49 @@
1
- # bimba-cli
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
- To install dependencies:
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 install
7
+ bun add bimba-cli
7
8
  ```
8
9
 
9
- To run:
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
- bun run index.ts
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
- This project was created using `bun init` in bun v1.0.26. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
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,20 +50,14 @@ 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 as the first argument.");
55
- console.log("By default the provided .imba file will be launched (the project will be compiled on the fly by Bun):");
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("To compile Imba project to .js file the outdir should be specified:");
59
- console.log(" "+theme.flags('--outdir <folder>')+" Compile imba files to specified folder");
60
- console.log("");
61
- console.log("There are other options that could be used when compiling .imba files:");
62
- console.log(" "+theme.flags('--minify')+" Minify compiled .js files");
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
  }
@@ -73,23 +66,26 @@ if(flags.help) {
73
66
  // no entrypoint
74
67
  if(!flags.entry) {
75
68
  console.log("");
76
- console.log("No entrypoint provided: "+theme.flags('bimba file.imba'));
69
+ console.log("No entrypoint provided: "+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
- // build
75
+ // no outdir
84
76
  if(flags.outdir){
85
- bundle();
86
- watch(bundle);
87
- }
88
- else {
89
- run();
90
- watch(run);
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);
91
82
  }
92
83
 
84
+
85
+ // build
86
+ bundle();
87
+ watch(bundle);
88
+
93
89
  function watch(callback) {
94
90
  if (flags.watch) {
95
91
  const watcher = fs.watch(path.dirname(flags.entry), {recursive: true}, async (event, filename) => ( callback() ));
@@ -103,11 +99,6 @@ function watch(callback) {
103
99
  }
104
100
  }
105
101
 
106
- async function run() {
107
- await $`bun run ${path.resolve(flags.entry)}`;
108
- }
109
-
110
-
111
102
  async function bundle() {
112
103
  if (!fs.existsSync(flags.entry)) {
113
104
  console.log(theme.failure('Error.') + ` The specified entrypoint does not exist: ${theme.filedir(flags.entry)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "repository": "github:HeapVoid/bimba",
5
5
  "module": "index.ts",
6
6
  "bin": {
package/bunfig.toml DELETED
@@ -1 +0,0 @@
1
- preload = ["./plugin.ts"]