@danielx/civet 0.6.70 → 0.6.72

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/dist/civet CHANGED
@@ -62,6 +62,7 @@ Options:
62
62
  -o / --output XX Specify output directory and/or extension, or filename
63
63
  -c / --compile Compile input files to TypeScript (or JavaScript)
64
64
  --config XX Specify a config file (default scans for a config.civet, civet.json, civetconfig.civet or civetconfig.json file, optionally in a .config directory, or starting with a .)
65
+ --civet XX Specify civet compiler flag, as in "civet XX" prologue
65
66
  --no-config Don't scan for a config file
66
67
  --js Strip out all type annotations; default to .jsx extension
67
68
  --ast Print the AST instead of the compiled code
@@ -70,6 +71,9 @@ Options:
70
71
 
71
72
  You can use - to read from stdin or (prefixed by -o) write to stdout.
72
73
 
74
+ By default, .civet imports get rewritten to use the output extension.
75
+ You can override this behavior via: --civet rewriteCivetImports=.ext
76
+
73
77
  `);
74
78
  process.exit(0);
75
79
  }
@@ -128,6 +132,15 @@ function parseArgs(args) {
128
132
  options.config = false;
129
133
  break;
130
134
  }
135
+ case "--civet": {
136
+ Object.assign(
137
+ options.parseOptions ??= {},
138
+ (0, import_main.parse)(`civet ${args[++i]}`, {
139
+ startRule: "CivetPrologueContent"
140
+ }).config
141
+ );
142
+ break;
143
+ }
131
144
  case "--ast": {
132
145
  options.ast = true;
133
146
  break;
@@ -320,6 +333,29 @@ async function cli() {
320
333
  if (options.repl) {
321
334
  return repl(options);
322
335
  }
336
+ let outputDir, outputExt, outputPath;
337
+ if (options.output) {
338
+ const optionsPath = import_path.default.parse(options.output);
339
+ let stat;
340
+ try {
341
+ stat = await import_promises.default.stat(options.output);
342
+ } catch {
343
+ stat = null;
344
+ }
345
+ if (stat?.isDirectory() || options.output.endsWith(import_path.default.sep) || options.output.endsWith("/")) {
346
+ outputDir = options.output;
347
+ } else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
348
+ outputExt = optionsPath.base;
349
+ if (optionsPath.dir) {
350
+ outputDir = optionsPath.dir;
351
+ }
352
+ } else {
353
+ outputPath = optionsPath;
354
+ }
355
+ if (options.output !== "-") {
356
+ (options.parseOptions ??= {}).rewriteCivetImports ??= outputExt ?? ".civet" + (options.js ? ".jsx" : ".tsx");
357
+ }
358
+ }
323
359
  const results3 = [];
324
360
  for await (const { filename, error, content, stdin } of readFiles(filenames)) {
325
361
  if (error) {
@@ -340,40 +376,30 @@ async function cli() {
340
376
  if (stdin && !options.output || options.output === "-") {
341
377
  results3.push(process.stdout.write(output));
342
378
  } else {
343
- let outputPath = import_path.default.parse(filename);
344
- delete outputPath.base;
379
+ let targetPath = import_path.default.parse(filename);
380
+ delete targetPath.base;
345
381
  if (options.js) {
346
- outputPath.ext += ".jsx";
382
+ targetPath.ext += ".jsx";
347
383
  } else {
348
- outputPath.ext += ".tsx";
384
+ targetPath.ext += ".tsx";
349
385
  }
350
- if (options.output) {
351
- const optionsPath = import_path.default.parse(options.output);
352
- let stat;
353
- try {
354
- stat = await import_promises.default.stat(options.output);
355
- } catch {
356
- stat = null;
357
- }
358
- if (stat?.isDirectory() || options.output.endsWith(import_path.default.sep) || options.output.endsWith("/")) {
359
- outputPath.dir = options.output;
360
- } else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
361
- outputPath.ext = optionsPath.base;
362
- if (optionsPath.dir) {
363
- outputPath.dir = optionsPath.dir;
364
- }
365
- } else {
366
- outputPath = optionsPath;
367
- }
386
+ if (outputDir != null) {
387
+ targetPath.dir = outputDir;
388
+ }
389
+ if (outputExt != null) {
390
+ targetPath.ext = outputExt;
391
+ }
392
+ if (outputPath != null) {
393
+ targetPath = outputPath;
368
394
  }
369
- if (outputPath.dir) {
370
- import_promises.default.mkdir(outputPath.dir, { recursive: true });
395
+ if (targetPath.dir) {
396
+ import_promises.default.mkdir(targetPath.dir, { recursive: true });
371
397
  }
372
- const outputFilename = import_path.default.format(outputPath);
398
+ const targetFilename = import_path.default.format(targetPath);
373
399
  try {
374
- results3.push(await import_promises.default.writeFile(outputFilename, output));
400
+ results3.push(await import_promises.default.writeFile(targetFilename, output));
375
401
  } catch (error2) {
376
- console.error(`${outputFilename} failed to write:`);
402
+ console.error(`${targetFilename} failed to write:`);
377
403
  results3.push(console.error(error2));
378
404
  }
379
405
  }