@danielx/civet 0.5.25 → 0.5.27
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 +47 -5
- package/dist/browser.js +606 -453
- package/dist/civet +40 -10
- package/dist/esbuild-plugin.js +17 -0
- package/dist/main.js +606 -453
- package/dist/main.mjs +606 -453
- package/package.json +7 -6
package/dist/civet
CHANGED
|
@@ -20,7 +20,9 @@ if (process.argv.includes("--help")) {
|
|
|
20
20
|
|
|
21
21
|
Usage:
|
|
22
22
|
|
|
23
|
-
civet
|
|
23
|
+
civet # REPL for executing code
|
|
24
|
+
civet -c # REPL for transpiling code
|
|
25
|
+
civet --ast # REPL for parsing code
|
|
24
26
|
civet [options] -c input.civet # -> input.civet.tsx
|
|
25
27
|
civet [options] -c input.civet -o .ts # -> input.ts
|
|
26
28
|
civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
|
|
@@ -108,6 +110,9 @@ parseArgs = function(args = process.argv.slice(2)) {
|
|
|
108
110
|
endOfArgs(++i);
|
|
109
111
|
break;
|
|
110
112
|
default:
|
|
113
|
+
if (arg.startsWith("-")) {
|
|
114
|
+
throw new Error(`Invalid command-line argument ${arg}`);
|
|
115
|
+
}
|
|
111
116
|
if (options.run) {
|
|
112
117
|
endOfArgs(i);
|
|
113
118
|
} else {
|
|
@@ -158,14 +163,35 @@ readFiles = async function* (filenames, options) {
|
|
|
158
163
|
};
|
|
159
164
|
repl = function(options) {
|
|
160
165
|
var nodeRepl, r, vm;
|
|
161
|
-
console.log(`Civet ${version()} REPL. Enter a blank line to
|
|
166
|
+
console.log(`Civet ${version()} REPL. Enter a blank line to ${function() {
|
|
167
|
+
switch (false) {
|
|
168
|
+
case !options.ast:
|
|
169
|
+
return "parse";
|
|
170
|
+
case !options.compile:
|
|
171
|
+
return "transpile";
|
|
172
|
+
default:
|
|
173
|
+
return "execute";
|
|
174
|
+
}
|
|
175
|
+
}()} code.`);
|
|
162
176
|
global.quit = global.exit = function() {
|
|
163
177
|
return process.exit(0);
|
|
164
178
|
};
|
|
165
179
|
nodeRepl = require("repl");
|
|
166
180
|
vm = require("vm");
|
|
167
181
|
return r = nodeRepl.start({
|
|
168
|
-
prompt:
|
|
182
|
+
prompt: function() {
|
|
183
|
+
switch (false) {
|
|
184
|
+
case !options.ast:
|
|
185
|
+
return "\u{1F332}> ";
|
|
186
|
+
case !options.compile:
|
|
187
|
+
return "\u{1F408}> ";
|
|
188
|
+
default:
|
|
189
|
+
return "\u{1F431}> ";
|
|
190
|
+
}
|
|
191
|
+
}(),
|
|
192
|
+
writer: options.compile && !options.ast ? function(obj) {
|
|
193
|
+
return obj != null ? obj.replace(/\n*$/, "") : void 0;
|
|
194
|
+
} : void 0,
|
|
169
195
|
eval: function(input, context, filename, callback) {
|
|
170
196
|
var error, output, result;
|
|
171
197
|
if (input === "\n") {
|
|
@@ -179,13 +205,17 @@ repl = function(options) {
|
|
|
179
205
|
error = error1;
|
|
180
206
|
return callback(error);
|
|
181
207
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
208
|
+
if (options.compile || options.ast) {
|
|
209
|
+
return callback(null, output);
|
|
210
|
+
} else {
|
|
211
|
+
try {
|
|
212
|
+
result = vm.runInContext(output, context, { filename });
|
|
213
|
+
} catch (error1) {
|
|
214
|
+
error = error1;
|
|
215
|
+
return callback(error);
|
|
216
|
+
}
|
|
217
|
+
return callback(null, result);
|
|
187
218
|
}
|
|
188
|
-
return callback(null, result);
|
|
189
219
|
} else {
|
|
190
220
|
return callback(new nodeRepl.Recoverable("Enter a blank line to execute code."));
|
|
191
221
|
}
|
|
@@ -196,10 +226,10 @@ cli = async function() {
|
|
|
196
226
|
var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
|
|
197
227
|
({ filenames, scriptArgs, options } = parseArgs());
|
|
198
228
|
if (!filenames.length) {
|
|
199
|
-
options.compile = true;
|
|
200
229
|
if (process.stdin.isTTY) {
|
|
201
230
|
options.repl = true;
|
|
202
231
|
} else {
|
|
232
|
+
options.compile = true;
|
|
203
233
|
filenames = ["-"];
|
|
204
234
|
}
|
|
205
235
|
}
|
package/dist/esbuild-plugin.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file esbuild plugin for Civet language
|
|
3
|
+
|
|
4
|
+
@example
|
|
5
|
+
```javascript
|
|
6
|
+
import esbuild from 'esbuild'
|
|
7
|
+
import civetPlugin from '@danielx/civet/esbuild-plugin'
|
|
8
|
+
|
|
9
|
+
esbuild.build({
|
|
10
|
+
...,
|
|
11
|
+
plugins: [
|
|
12
|
+
civetPlugin
|
|
13
|
+
]
|
|
14
|
+
}).catch(() => process.exit(1))
|
|
15
|
+
```
|
|
16
|
+
*/
|
|
17
|
+
|
|
1
18
|
const { readFile } = require('fs/promises')
|
|
2
19
|
const path = require('path')
|
|
3
20
|
|