bimba-cli 0.1.5 → 0.1.7

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,69 +1,69 @@
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
-
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
-
5
- First of all install this tool like any other npm package:
6
- ```bash
7
- bun add bimba-cli
8
- ```
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.js"]
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
- ```
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:
29
- ```bash
30
- bunx bimba src/index.imba --outdir public
31
- ```
32
- Or with the watch argument:
33
- ```bash
34
- bunx bimba src/index.imba --outdir public --watch
35
- ```
36
-
37
- Here are all the available argumentsthat you can pass to the bimba:
38
-
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
-
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
-
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
- ```
64
-
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).
67
- It does everything needed out of the box.
68
-
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
+
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
+
5
+ First of all install this tool like any other npm package:
6
+ ```bash
7
+ bun add bimba-cli -d
8
+ ```
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.js"]
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
+ ```
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:
29
+ ```bash
30
+ bunx bimba src/index.imba --outdir public
31
+ ```
32
+ Or with the watch argument:
33
+ ```bash
34
+ bunx bimba src/index.imba --outdir public --watch
35
+ ```
36
+
37
+ Here are all the available argumentsthat you can pass to the bimba:
38
+
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
+
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
+
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
+ ```
64
+
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).
67
+ It does everything needed out of the box.
68
+
69
69
  Just let bimba rebuild the sources on change and Lite Server will reload the page in the browser.
package/index.js CHANGED
@@ -1,120 +1,120 @@
1
- #!/usr/bin/env bun
2
-
3
- import { parseArgs } from "util";
4
- import { imbaPlugin, stats, cache } from './plugin.js'
5
- import {theme} from './utils.ts';
6
- import fs from 'fs'
7
- import path from 'path';
8
- import { rmSync } from "node:fs";
9
-
10
-
11
- let flags = {}
12
- let entrypoint = ''
13
-
14
- try {
15
- const { values, positionals } = parseArgs({
16
- args: Bun.argv,
17
- options: {
18
- watch: { type: 'boolean' },
19
- outdir: { type: 'string' },
20
- help: { type: 'boolean' },
21
- clearcache: { type: 'boolean' },
22
- minify: { type: 'boolean' },
23
- target: { type: 'string' },
24
- sourcemap: { type: 'string' },
25
- },
26
- strict: true,
27
- allowPositionals: true,
28
- });
29
- flags = values;
30
- entrypoint = Bun.argv[2];
31
- }
32
- catch (error) {
33
- if (error instanceof Error)
34
- console.log(error.message);
35
- else
36
- console.log("Could not resolve CLI arguments. Read help to know them: " + theme.flags('--entry file.imba'));
37
- process.exit(0);
38
- }
39
-
40
- // help: more on bun building params here: https://bun.sh/docs/bundler
41
- if(flags.help) {
42
- console.log("");
43
- console.log("Bimba requeres an .imba file and a folder where to put compiled .js files.");
44
- console.log("For example like this: "+theme.filedir('bimba file.imba --outdir public'));
45
- console.log("");
46
- console.log(" "+theme.flags('--outdir <folder>')+" Compile imba files to the specified folder");
47
- console.log(" "+theme.flags('--minify')+" Minify compiled .js files");
48
- console.log(" "+theme.flags('--sourcemap <inline|external|none>')+" How should sourcemap files be included in the .js");
49
- console.log(" "+theme.flags('--platform <browser|node>')+" Flag that will be passed to Imba compiler ('node' value does not work in Bun)");
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");
52
- console.log("");
53
- process.exit(0);
54
- }
55
-
56
-
57
- // no entrypoint or outdir
58
- if(!entrypoint || !flags.outdir) {
59
- console.log("");
60
- console.log("You should provide entrypoint and the output dir: "+theme.flags('bimba file.imba --outdir public'));
61
- console.log("For more information: "+theme.flags('--help'));
62
- console.log("");
63
- process.exit(1);
64
- }
65
-
66
- // build
67
- bundle();
68
- watch(bundle);
69
-
70
- function watch(callback) {
71
- if (flags.watch) {
72
- const watcher = fs.watch(path.dirname(entrypoint), {recursive: true}, async (event, filename) => ( callback() ));
73
-
74
- process.on("SIGINT", () => {
75
- if(flags.clearcache) rmSync(cache, { recursive: true, force: true });
76
-
77
- if(watcher) {
78
- watcher.close();
79
- process.exit(0);
80
- }
81
- });
82
- }
83
- }
84
-
85
- async function bundle() {
86
- if (!fs.existsSync(entrypoint)) {
87
- console.log(theme.failure('Error.') + ` The specified entrypoint does not exist: ${theme.filedir(entrypoint)}`);
88
- process.exit(0);
89
- }
90
-
91
- stats.failed = 0
92
- stats.compiled = 0
93
- stats.errors = 0
94
- stats.bundled = 0
95
-
96
- const start = Date.now();
97
-
98
- console.log("──────────────────────────────────────────────────────────────────────");
99
- console.log(theme.start(`Start building the Imba entrypoint: ${theme.filedir(entrypoint)}`));
100
-
101
- const result = await Bun.build({
102
- entrypoints: [entrypoint],
103
- outdir: flags.outdir,
104
- target: flags.target || 'browser',
105
- sourcemap: flags.sourcemap || 'none',
106
- minify: flags.minify || true,
107
- plugins: [imbaPlugin]
108
- });
109
-
110
- if(stats.failed)
111
- console.log(theme.start(theme.failure("Failure.") +` Imba compiler failed to proceed ${theme.count(stats.failed)} file${stats.failed > 1 ? 's' : ''}`));
112
- else
113
- console.log(theme.start(theme.success("Success.") +` It took ${theme.time(Date.now() - start)} ms to bundle ${theme.count(stats.bundled)} file${stats.bundled > 1 ? 's' : ''} to the folder: ${theme.filedir(flags.outdir)}`));
114
-
115
- if(!result.success && !stats.errors){
116
- for (const log of result.logs) {
117
- console.log(log);
118
- }
119
- }
1
+ #!/usr/bin/env bun
2
+
3
+ import { parseArgs } from "util";
4
+ import { imbaPlugin, stats, cache } from './plugin.js'
5
+ import {theme} from './utils.js';
6
+ import fs from 'fs'
7
+ import path from 'path';
8
+ import { rmSync } from "node:fs";
9
+
10
+
11
+ let flags = {}
12
+ let entrypoint = ''
13
+
14
+ try {
15
+ const { values, positionals } = parseArgs({
16
+ args: Bun.argv,
17
+ options: {
18
+ watch: { type: 'boolean' },
19
+ outdir: { type: 'string' },
20
+ help: { type: 'boolean' },
21
+ clearcache: { type: 'boolean' },
22
+ minify: { type: 'boolean' },
23
+ target: { type: 'string' },
24
+ sourcemap: { type: 'string' },
25
+ },
26
+ strict: true,
27
+ allowPositionals: true,
28
+ });
29
+ flags = values;
30
+ entrypoint = Bun.argv[2];
31
+ }
32
+ catch (error) {
33
+ if (error instanceof Error)
34
+ console.log(error.message);
35
+ else
36
+ console.log("Could not resolve CLI arguments. Read help to know them: " + theme.flags('--entry file.imba'));
37
+ process.exit(0);
38
+ }
39
+
40
+ // help: more on bun building params here: https://bun.sh/docs/bundler
41
+ if(flags.help) {
42
+ console.log("");
43
+ console.log("Bimba requeres an .imba file and a folder where to put compiled .js files.");
44
+ console.log("For example like this: "+theme.filedir('bimba file.imba --outdir public'));
45
+ console.log("");
46
+ console.log(" "+theme.flags('--outdir <folder>')+" Compile imba files to the specified folder");
47
+ console.log(" "+theme.flags('--minify')+" Minify compiled .js files");
48
+ console.log(" "+theme.flags('--sourcemap <inline|external|none>')+" How should sourcemap files be included in the .js");
49
+ console.log(" "+theme.flags('--platform <browser|node>')+" Flag that will be passed to Imba compiler ('node' value does not work in Bun)");
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");
52
+ console.log("");
53
+ process.exit(0);
54
+ }
55
+
56
+
57
+ // no entrypoint or outdir
58
+ if(!entrypoint || !flags.outdir) {
59
+ console.log("");
60
+ console.log("You should provide entrypoint and the output dir: "+theme.flags('bimba file.imba --outdir public'));
61
+ console.log("For more information: "+theme.flags('--help'));
62
+ console.log("");
63
+ process.exit(1);
64
+ }
65
+
66
+ // build
67
+ bundle();
68
+ watch(bundle);
69
+
70
+ function watch(callback) {
71
+ if (flags.watch) {
72
+ const watcher = fs.watch(path.dirname(entrypoint), {recursive: true}, async (event, filename) => ( callback() ));
73
+
74
+ process.on("SIGINT", () => {
75
+ if(flags.clearcache) rmSync(cache, { recursive: true, force: true });
76
+
77
+ if(watcher) {
78
+ watcher.close();
79
+ process.exit(0);
80
+ }
81
+ });
82
+ }
83
+ }
84
+
85
+ async function bundle() {
86
+ if (!fs.existsSync(entrypoint)) {
87
+ console.log(theme.failure('Error.') + ` The specified entrypoint does not exist: ${theme.filedir(entrypoint)}`);
88
+ process.exit(0);
89
+ }
90
+
91
+ stats.failed = 0
92
+ stats.compiled = 0
93
+ stats.errors = 0
94
+ stats.bundled = 0
95
+
96
+ const start = Date.now();
97
+
98
+ console.log("──────────────────────────────────────────────────────────────────────");
99
+ console.log(theme.start(`Start building the Imba entrypoint: ${theme.filedir(entrypoint)}`));
100
+
101
+ const result = await Bun.build({
102
+ entrypoints: [entrypoint],
103
+ outdir: flags.outdir,
104
+ target: flags.target || 'browser',
105
+ sourcemap: flags.sourcemap || 'none',
106
+ minify: flags.minify || true,
107
+ plugins: [imbaPlugin]
108
+ });
109
+
110
+ if(stats.failed)
111
+ console.log(theme.start(theme.failure("Failure.") +` Imba compiler failed to proceed ${theme.count(stats.failed)} file${stats.failed > 1 ? 's' : ''}`));
112
+ else
113
+ console.log(theme.start(theme.success("Success.") +` It took ${theme.time(Date.now() - start)} ms to bundle ${theme.count(stats.bundled)} file${stats.bundled > 1 ? 's' : ''} to the folder: ${theme.filedir(flags.outdir)}`));
114
+
115
+ if(!result.success && !stats.errors){
116
+ for (const log of result.logs) {
117
+ console.log(log);
118
+ }
119
+ }
120
120
  }
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
- {
2
- "name": "bimba-cli",
3
- "version": "0.1.5",
4
- "repository": "github:HeapVoid/bimba",
5
- "module": "index.js",
6
- "bin": {
7
- "bimba": "./index.js"
8
- },
9
- "description": "The CLI tool to run Imba projects under Bun",
10
- "keywords": ["imba", "bun", "plugin"],
11
- "license": "MIT",
12
- "type": "module",
13
- "devDependencies": {
14
- "imba": "^2.0.0-alpha.234"
15
- }
1
+ {
2
+ "name": "bimba-cli",
3
+ "version": "0.1.7",
4
+ "repository": "github:HeapVoid/bimba",
5
+ "module": "index.js",
6
+ "bin": {
7
+ "bimba": "./index.js"
8
+ },
9
+ "description": "The CLI tool to run Imba projects under Bun",
10
+ "keywords": ["imba", "bun", "plugin"],
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "devDependencies": {
14
+ "imba": "^2.0.0-alpha.234"
15
+ }
16
16
  }
package/plugin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { plugin } from "bun";
2
- import {theme} from './utils.ts';
2
+ import {theme} from './utils.js';
3
3
  import * as compiler from 'imba/compiler'
4
4
  import dir from 'path'
5
5
  import fs from 'fs'
@@ -86,7 +86,7 @@ export const imbaPlugin = {
86
86
 
87
87
  // clear previous cached version
88
88
  const glob = new Glob(Bun.hash(path) + '_' + "*.js");
89
- for await (const file of glob.scan(cache)) unlink(cache + '/' + file);
89
+ for await (const file of glob.scan(cache)) unlink(cache + file);
90
90
 
91
91
  // if no cached version read and compile it with the imba compiler
92
92
  const file = await Bun.file(path).text();
package/utils.js ADDED
@@ -0,0 +1,30 @@
1
+ function colorize(text, fg, bg) {
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
+ // theme for messages printed in terminal
11
+ // https://i.stack.imgur.com/KTSQa.png
12
+ export const theme = {
13
+ code: (text) => colorize(text, 252, 238),
14
+ margin: (text) => colorize(text, 229, 145),
15
+ error: (text) => colorize(text, 196 , 52),
16
+ ecode: (text) => colorize(text, 196, 238),
17
+ action: (text) => colorize(text, 237),
18
+ folder: (text) => colorize(text, 240),
19
+ filename: (text) => colorize(text, 15),
20
+ success: (text) => colorize(text, 40),
21
+ failure: (text) => colorize(text, 15, 124),
22
+
23
+ flags: (text) => colorize(text, 5),
24
+ count: (text) => colorize(text, 15),
25
+ start: (text) => colorize(text, 252, 233),
26
+ filedir: (text) => colorize(text, 15),
27
+ time: (text) => colorize(text, 41),
28
+ link: (text) => colorize(text, 15),
29
+ online: (text) => colorize(text, 40, 22)
30
+ }
package/utils.ts DELETED
@@ -1,46 +0,0 @@
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
- }