@danielx/civet 0.5.26 → 0.5.28
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 +43 -5
- package/dist/browser.js +560 -408
- package/dist/civet +48 -11
- package/dist/main.js +560 -408
- package/dist/main.mjs +560 -408
- package/package.json +5 -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 {
|
|
@@ -132,6 +137,8 @@ readFiles = async function* (filenames, options) {
|
|
|
132
137
|
filename = await fs.realpath("/dev/stdin");
|
|
133
138
|
} catch (error1) {
|
|
134
139
|
}
|
|
140
|
+
}
|
|
141
|
+
if (filename === "<stdin>") {
|
|
135
142
|
lines = [];
|
|
136
143
|
rl = require("readline").createInterface(process.stdin, process.stdout);
|
|
137
144
|
rl.on("line", function(buffer) {
|
|
@@ -158,14 +165,35 @@ readFiles = async function* (filenames, options) {
|
|
|
158
165
|
};
|
|
159
166
|
repl = function(options) {
|
|
160
167
|
var nodeRepl, r, vm;
|
|
161
|
-
console.log(`Civet ${version()} REPL. Enter a blank line to
|
|
168
|
+
console.log(`Civet ${version()} REPL. Enter a blank line to ${function() {
|
|
169
|
+
switch (false) {
|
|
170
|
+
case !options.ast:
|
|
171
|
+
return "parse";
|
|
172
|
+
case !options.compile:
|
|
173
|
+
return "transpile";
|
|
174
|
+
default:
|
|
175
|
+
return "execute";
|
|
176
|
+
}
|
|
177
|
+
}()} code.`);
|
|
162
178
|
global.quit = global.exit = function() {
|
|
163
179
|
return process.exit(0);
|
|
164
180
|
};
|
|
165
181
|
nodeRepl = require("repl");
|
|
166
182
|
vm = require("vm");
|
|
167
183
|
return r = nodeRepl.start({
|
|
168
|
-
prompt:
|
|
184
|
+
prompt: function() {
|
|
185
|
+
switch (false) {
|
|
186
|
+
case !options.ast:
|
|
187
|
+
return "\u{1F332}> ";
|
|
188
|
+
case !options.compile:
|
|
189
|
+
return "\u{1F408}> ";
|
|
190
|
+
default:
|
|
191
|
+
return "\u{1F431}> ";
|
|
192
|
+
}
|
|
193
|
+
}(),
|
|
194
|
+
writer: options.compile && !options.ast ? function(obj) {
|
|
195
|
+
return obj != null ? obj.replace(/\n*$/, "") : void 0;
|
|
196
|
+
} : void 0,
|
|
169
197
|
eval: function(input, context, filename, callback) {
|
|
170
198
|
var error, output, result;
|
|
171
199
|
if (input === "\n") {
|
|
@@ -179,13 +207,17 @@ repl = function(options) {
|
|
|
179
207
|
error = error1;
|
|
180
208
|
return callback(error);
|
|
181
209
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
210
|
+
if (options.compile || options.ast) {
|
|
211
|
+
return callback(null, output);
|
|
212
|
+
} else {
|
|
213
|
+
try {
|
|
214
|
+
result = vm.runInContext(output, context, { filename });
|
|
215
|
+
} catch (error1) {
|
|
216
|
+
error = error1;
|
|
217
|
+
return callback(error);
|
|
218
|
+
}
|
|
219
|
+
return callback(null, result);
|
|
187
220
|
}
|
|
188
|
-
return callback(null, result);
|
|
189
221
|
} else {
|
|
190
222
|
return callback(new nodeRepl.Recoverable("Enter a blank line to execute code."));
|
|
191
223
|
}
|
|
@@ -196,10 +228,10 @@ cli = async function() {
|
|
|
196
228
|
var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
|
|
197
229
|
({ filenames, scriptArgs, options } = parseArgs());
|
|
198
230
|
if (!filenames.length) {
|
|
199
|
-
options.compile = true;
|
|
200
231
|
if (process.stdin.isTTY) {
|
|
201
232
|
options.repl = true;
|
|
202
233
|
} else {
|
|
234
|
+
options.compile = true;
|
|
203
235
|
filenames = ["-"];
|
|
204
236
|
}
|
|
205
237
|
}
|
|
@@ -247,7 +279,7 @@ cli = async function() {
|
|
|
247
279
|
} catch (error1) {
|
|
248
280
|
stat = null;
|
|
249
281
|
}
|
|
250
|
-
if (stat != null ? stat.isDirectory() : void 0) {
|
|
282
|
+
if ((stat != null ? stat.isDirectory() : void 0) || options.output.endsWith(path.sep) || options.output.endsWith("/")) {
|
|
251
283
|
outputPath.dir = options.output;
|
|
252
284
|
} else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
|
|
253
285
|
outputPath.ext = optionsPath.base;
|
|
@@ -258,6 +290,11 @@ cli = async function() {
|
|
|
258
290
|
outputPath = optionsPath;
|
|
259
291
|
}
|
|
260
292
|
}
|
|
293
|
+
if (outputPath.dir) {
|
|
294
|
+
fs.mkdir(outputPath.dir, {
|
|
295
|
+
recursive: true
|
|
296
|
+
});
|
|
297
|
+
}
|
|
261
298
|
outputFilename = path.format(outputPath);
|
|
262
299
|
try {
|
|
263
300
|
results.push(await fs.writeFile(outputFilename, output));
|