bimba-cli 0.1.4 → 0.1.6
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 +68 -48
- package/{index.ts → index.js} +119 -128
- package/package.json +15 -16
- package/{plugin.ts → plugin.js} +25 -49
- package/utils.js +30 -0
- package/tsconfig.json +0 -22
package/README.md
CHANGED
|
@@ -1,49 +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.
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
`--
|
|
40
|
-
|
|
41
|
-
`--
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
|
|
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,129 +1,120 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { parseArgs } from "util";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import fs from 'fs'
|
|
7
|
-
import path from 'path';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.log(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
console.log("");
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
console.log("
|
|
60
|
-
console.log("
|
|
61
|
-
console.log("");
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
console.log(theme.start(theme.failure("Failure.") +` Imba compiler failed to proceed ${theme.count(stats.failed)} file${stats.failed > 1 ? 's' : ''}`));
|
|
121
|
-
else
|
|
122
|
-
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)}`));
|
|
123
|
-
|
|
124
|
-
if(!result.success && !stats.errors){
|
|
125
|
-
for (const log of result.logs) {
|
|
126
|
-
console.log(log);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
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
|
+
}
|
|
129
120
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "bimba-cli",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"repository": "github:HeapVoid/bimba",
|
|
5
|
-
"module": "index.
|
|
6
|
-
"bin": {
|
|
7
|
-
"bimba": "./index.
|
|
8
|
-
},
|
|
9
|
-
"description": "The CLI tool to run Imba projects under Bun",
|
|
10
|
-
"keywords": ["imba", "bun", "plugin"],
|
|
11
|
-
"license": "MIT",
|
|
12
|
-
"type": "module",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "bimba-cli",
|
|
3
|
+
"version": "0.1.6",
|
|
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
|
+
}
|
|
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.js';
|
|
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.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
// theme for messages printed in terminal
|
|
11
|
+
// https://i.stack.imgur.com/KTSQa.png
|
|
12
|
+
export const theme = {
|
|
13
|
+
code: (text:string) => colorize(text, 252, 238),
|
|
14
|
+
margin: (text:string) => colorize(text, 229, 145),
|
|
15
|
+
error: (text:string) => colorize(text, 196 , 52),
|
|
16
|
+
ecode: (text:string) => colorize(text, 196, 238),
|
|
17
|
+
action: (text:string) => colorize(text, 237),
|
|
18
|
+
folder: (text:string) => colorize(text, 240),
|
|
19
|
+
filename: (text:string) => colorize(text, 15),
|
|
20
|
+
success: (text:string) => colorize(text, 40),
|
|
21
|
+
failure: (text:string) => colorize(text, 15, 124),
|
|
22
|
+
|
|
23
|
+
flags: (text:string) => colorize(text, 5),
|
|
24
|
+
count: (text:string) => colorize(text, 15),
|
|
25
|
+
start: (text:string) => colorize(text, 252, 233),
|
|
26
|
+
filedir: (text:string) => colorize(text, 15),
|
|
27
|
+
time: (text:string) => colorize(text, 41),
|
|
28
|
+
link: (text:string) => colorize(text, 15),
|
|
29
|
+
online: (text:string) => colorize(text, 40, 22)
|
|
30
|
+
}
|
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
|
-
}
|