@mojir/lits 2.4.0 → 2.4.1
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 +34 -4
- package/dist/cli/cli.js +47 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,17 +41,47 @@ npm install --global @mojir/lits
|
|
|
41
41
|
$ lits
|
|
42
42
|
|
|
43
43
|
# Evaluate Lits code directly
|
|
44
|
-
$ lits
|
|
45
|
-
$ lits
|
|
44
|
+
$ lits eval "5 + 3"
|
|
45
|
+
$ lits eval "[1, 2, 3, 4] filter odd? map inc"
|
|
46
46
|
|
|
47
47
|
# Run a Lits file
|
|
48
|
-
$ lits
|
|
49
|
-
|
|
48
|
+
$ lits run script.lits
|
|
49
|
+
|
|
50
|
+
# Bundle a multi-file project into a single .json file
|
|
51
|
+
$ lits bundle main.lits -o bundle.json
|
|
52
|
+
|
|
53
|
+
# Run a bundle
|
|
54
|
+
$ lits run-bundle bundle.json
|
|
55
|
+
|
|
56
|
+
# Run tests
|
|
57
|
+
$ lits test tests.test.lits
|
|
50
58
|
|
|
51
59
|
# Get help
|
|
52
60
|
$ lits --help
|
|
53
61
|
```
|
|
54
62
|
|
|
63
|
+
**Subcommands:**
|
|
64
|
+
|
|
65
|
+
| Subcommand | Description |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `run <file>` | Run a `.lits` source file |
|
|
68
|
+
| `run-bundle <file>` | Run a `.json` bundle (with validation) |
|
|
69
|
+
| `eval <expression>` | Evaluate a Lits expression |
|
|
70
|
+
| `bundle <entry>` | Bundle a multi-file project into a single JSON file |
|
|
71
|
+
| `test <file>` | Run a `.test.lits` test file |
|
|
72
|
+
| `repl` | Start an interactive REPL (default when no subcommand) |
|
|
73
|
+
|
|
74
|
+
**Common options:**
|
|
75
|
+
|
|
76
|
+
| Option | Applies to | Description |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `-c, --context=<json>` | `run`, `run-bundle`, `eval`, `repl` | Provide context as a JSON string |
|
|
79
|
+
| `-C, --context-file=<file>` | `run`, `run-bundle`, `eval`, `repl` | Provide context from a `.json` file |
|
|
80
|
+
| `-s, --silent` | `run`, `run-bundle`, `eval` | Suppress printing the result |
|
|
81
|
+
| `-o, --output=<file>` | `bundle` | Write bundle to file (default: stdout) |
|
|
82
|
+
| `--pattern=<regex>` | `test` | Only run tests matching pattern |
|
|
83
|
+
| `-l, --load=<file>` | `repl` | Preload a `.lits` file into the REPL |
|
|
84
|
+
|
|
55
85
|
The REPL provides an interactive environment where you can experiment with Lits code, test functions, and explore the language features in real-time.
|
|
56
86
|
|
|
57
87
|
## Quick Start
|
package/dist/cli/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ var readline = require('node:readline');
|
|
|
7
7
|
var os = require('node:os');
|
|
8
8
|
var process$1 = require('node:process');
|
|
9
9
|
|
|
10
|
-
var version = "2.4.
|
|
10
|
+
var version = "2.4.1";
|
|
11
11
|
|
|
12
12
|
function getCodeMarker(sourceCodeInfo) {
|
|
13
13
|
if (!sourceCodeInfo.position || !sourceCodeInfo.code)
|
|
@@ -34647,18 +34647,35 @@ switch (config.subcommand) {
|
|
|
34647
34647
|
const lits = createLits(config.context);
|
|
34648
34648
|
try {
|
|
34649
34649
|
const content = fs.readFileSync(config.filename, { encoding: 'utf-8' });
|
|
34650
|
-
|
|
34651
|
-
|
|
34650
|
+
const result = lits.run(content);
|
|
34651
|
+
if (config.printResult) {
|
|
34652
|
+
console.log(result);
|
|
34653
|
+
}
|
|
34654
|
+
process.exit(0);
|
|
34655
|
+
}
|
|
34656
|
+
catch (error) {
|
|
34657
|
+
printErrorMessage(`${error}`);
|
|
34658
|
+
process.exit(1);
|
|
34659
|
+
}
|
|
34660
|
+
break;
|
|
34661
|
+
}
|
|
34662
|
+
case 'run-bundle': {
|
|
34663
|
+
const lits = createLits(config.context);
|
|
34664
|
+
try {
|
|
34665
|
+
const content = fs.readFileSync(config.filename, { encoding: 'utf-8' });
|
|
34666
|
+
let parsed;
|
|
34652
34667
|
try {
|
|
34653
|
-
|
|
34654
|
-
if (isLitsBundle(parsed)) {
|
|
34655
|
-
programOrBundle = parsed;
|
|
34656
|
-
}
|
|
34668
|
+
parsed = JSON.parse(content);
|
|
34657
34669
|
}
|
|
34658
34670
|
catch {
|
|
34659
|
-
|
|
34671
|
+
printErrorMessage(`Invalid bundle: ${config.filename} is not valid JSON`);
|
|
34672
|
+
process.exit(1);
|
|
34673
|
+
}
|
|
34674
|
+
if (!isLitsBundle(parsed)) {
|
|
34675
|
+
printErrorMessage(`Invalid bundle: ${config.filename} is not a valid Lits bundle (expected "program" string and "fileModules" array)`);
|
|
34676
|
+
process.exit(1);
|
|
34660
34677
|
}
|
|
34661
|
-
const result = lits.run(
|
|
34678
|
+
const result = lits.run(parsed);
|
|
34662
34679
|
if (config.printResult) {
|
|
34663
34680
|
console.log(result);
|
|
34664
34681
|
}
|
|
@@ -34786,7 +34803,7 @@ function setReplHistoryVariables(context) {
|
|
|
34786
34803
|
}
|
|
34787
34804
|
function parseOption(args, i) {
|
|
34788
34805
|
const option = args[i];
|
|
34789
|
-
if (option === '-
|
|
34806
|
+
if (option === '-s') {
|
|
34790
34807
|
return { option, argument: null, count: 1 };
|
|
34791
34808
|
}
|
|
34792
34809
|
if (/^-[a-z]$/i.test(option))
|
|
@@ -34846,16 +34863,16 @@ function parseContextOptions(args, startIndex) {
|
|
|
34846
34863
|
return { options, nextIndex: i };
|
|
34847
34864
|
}
|
|
34848
34865
|
function parsePrintOptions(args, startIndex) {
|
|
34849
|
-
const options = { printResult:
|
|
34866
|
+
const options = { printResult: true };
|
|
34850
34867
|
let i = startIndex;
|
|
34851
34868
|
while (i < args.length) {
|
|
34852
34869
|
const parsed = parseOption(args, i);
|
|
34853
34870
|
if (!parsed)
|
|
34854
34871
|
break;
|
|
34855
34872
|
switch (parsed.option) {
|
|
34856
|
-
case '-
|
|
34857
|
-
case '--
|
|
34858
|
-
options.printResult =
|
|
34873
|
+
case '-s':
|
|
34874
|
+
case '--silent':
|
|
34875
|
+
options.printResult = false;
|
|
34859
34876
|
i += parsed.count;
|
|
34860
34877
|
break;
|
|
34861
34878
|
default:
|
|
@@ -34866,7 +34883,7 @@ function parsePrintOptions(args, startIndex) {
|
|
|
34866
34883
|
}
|
|
34867
34884
|
function parseRunEvalOptions(args, startIndex) {
|
|
34868
34885
|
let context = {};
|
|
34869
|
-
let printResult =
|
|
34886
|
+
let printResult = true;
|
|
34870
34887
|
let i = startIndex;
|
|
34871
34888
|
while (i < args.length) {
|
|
34872
34889
|
const parsed = parseOption(args, i);
|
|
@@ -34882,8 +34899,8 @@ function parseRunEvalOptions(args, startIndex) {
|
|
|
34882
34899
|
i = result.nextIndex;
|
|
34883
34900
|
break;
|
|
34884
34901
|
}
|
|
34885
|
-
case '-
|
|
34886
|
-
case '--
|
|
34902
|
+
case '-s':
|
|
34903
|
+
case '--silent': {
|
|
34887
34904
|
const result = parsePrintOptions(args, i);
|
|
34888
34905
|
printResult = result.options.printResult;
|
|
34889
34906
|
i = result.nextIndex;
|
|
@@ -34922,6 +34939,15 @@ function processArguments(args) {
|
|
|
34922
34939
|
const { context, printResult } = parseRunEvalOptions(args, 2);
|
|
34923
34940
|
return { subcommand: 'run', filename, context, printResult };
|
|
34924
34941
|
}
|
|
34942
|
+
case 'run-bundle': {
|
|
34943
|
+
const filename = args[1];
|
|
34944
|
+
if (!filename || filename.startsWith('-')) {
|
|
34945
|
+
printErrorMessage('Missing filename after "run-bundle"');
|
|
34946
|
+
process.exit(1);
|
|
34947
|
+
}
|
|
34948
|
+
const { context, printResult } = parseRunEvalOptions(args, 2);
|
|
34949
|
+
return { subcommand: 'run-bundle', filename, context, printResult };
|
|
34950
|
+
}
|
|
34925
34951
|
case 'eval': {
|
|
34926
34952
|
const expression = args[1];
|
|
34927
34953
|
if (!expression || expression.startsWith('-')) {
|
|
@@ -35109,17 +35135,18 @@ function printUsage() {
|
|
|
35109
35135
|
Usage: lits [subcommand] [options]
|
|
35110
35136
|
|
|
35111
35137
|
Subcommands:
|
|
35112
|
-
run <file> [options] Run a .lits file
|
|
35138
|
+
run <file> [options] Run a .lits file
|
|
35139
|
+
run-bundle <file> [options] Run a .json bundle
|
|
35113
35140
|
eval <expression> [options] Evaluate a Lits expression
|
|
35114
35141
|
bundle <entry> [options] Bundle a multi-file project
|
|
35115
35142
|
test <file> [options] Run a .test.lits test file
|
|
35116
35143
|
repl [options] Start an interactive REPL
|
|
35117
35144
|
help Show this help
|
|
35118
35145
|
|
|
35119
|
-
Run/Eval options:
|
|
35146
|
+
Run/Run-bundle/Eval options:
|
|
35120
35147
|
-c, --context=<json> Context as a JSON string
|
|
35121
35148
|
-C, --context-file=<file> Context from a .json file
|
|
35122
|
-
-
|
|
35149
|
+
-s, --silent Suppress printing the result
|
|
35123
35150
|
|
|
35124
35151
|
Bundle options:
|
|
35125
35152
|
-o, --output=<file> Write bundle to file (default: stdout)
|