plainscript-lang 1.0.3 → 1.0.36

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.
Files changed (93) hide show
  1. package/README.md +836 -188
  2. package/compiler/cli.js +68 -4
  3. package/compiler/dependency-detector.js +6 -2
  4. package/compiler/generator.js +737 -51
  5. package/compiler/lexer.js +12 -0
  6. package/compiler/parser.js +184 -14
  7. package/compiler/version.js +1 -1
  8. package/docs/CAPABILITY_GAP_AUDIT.md +32 -5
  9. package/docs/GAME-PROMPT.md +915 -0
  10. package/docs/PLAINSCRIPT-SPEC.md +264 -3
  11. package/docs/index.html +41 -33
  12. package/docs/logo-pln.jpg +0 -0
  13. package/docs/visualization-example.svg +32 -0
  14. package/docs/website/script.js +130 -1
  15. package/docs/website/style.css +253 -122
  16. package/examples/ai-providers.pln +1 -1
  17. package/examples/arrays.pln +1 -1
  18. package/examples/async-errors.pln +1 -1
  19. package/examples/auth-api.pln +1 -1
  20. package/examples/auth-sessions.pln +1 -1
  21. package/examples/basics.pln +1 -1
  22. package/examples/bots.pln +1 -1
  23. package/examples/browser-interactive/README.md +29 -0
  24. package/examples/browser-interactive/public/index.html +83 -0
  25. package/examples/browser-interactive/public/interactive.js +27 -0
  26. package/examples/browser-interactive/src/interactive.pln +34 -0
  27. package/examples/cache-and-jobs.pln +1 -1
  28. package/examples/cache-schedule.pln +1 -1
  29. package/examples/canvas-game/README.md +34 -0
  30. package/examples/canvas-game/public/game.js +131 -0
  31. package/examples/canvas-game/public/index.html +48 -0
  32. package/examples/canvas-game/src/game.pln +139 -0
  33. package/examples/collections.pln +1 -1
  34. package/examples/concurrency.pln +1 -1
  35. package/examples/conditions.pln +1 -1
  36. package/examples/database.pln +1 -1
  37. package/examples/day2.pln +1 -1
  38. package/examples/day3.pln +1 -1
  39. package/examples/deployment.pln +1 -1
  40. package/examples/email-send.pln +1 -1
  41. package/examples/error-handling.pln +1 -1
  42. package/examples/expressions.pln +1 -1
  43. package/examples/file-uploads.pln +1 -1
  44. package/examples/files-and-config.pln +1 -1
  45. package/examples/files.pln +1 -1
  46. package/examples/football-backend/app.pln +1 -1
  47. package/examples/functions.pln +1 -1
  48. package/examples/hello.pln +1 -1
  49. package/examples/http-client.pln +1 -1
  50. package/examples/http.pln +1 -1
  51. package/examples/id-verification/app.pln +1 -1
  52. package/examples/javascript-library/README.md +54 -0
  53. package/examples/javascript-library/package-lock.json +21 -0
  54. package/examples/javascript-library/package.json +8 -0
  55. package/examples/javascript-library/public/config.json +4 -0
  56. package/examples/javascript-library/public/index.html +40 -0
  57. package/examples/javascript-library/src/interop.pln +53 -0
  58. package/examples/json.pln +1 -1
  59. package/examples/loops.pln +1 -1
  60. package/examples/modules/app.pln +1 -1
  61. package/examples/modules/main.pln +1 -1
  62. package/examples/modules/math.pln +1 -1
  63. package/examples/mongo.pln +1 -1
  64. package/examples/objects.pln +1 -1
  65. package/examples/ocr.pln +1 -1
  66. package/examples/packages.pln +1 -1
  67. package/examples/record-kinds.pln +1 -1
  68. package/examples/records.pln +1 -1
  69. package/examples/rest-api-fetch.pln +1 -1
  70. package/examples/rest-api.pln +1 -1
  71. package/examples/scheduled-tasks.pln +1 -1
  72. package/examples/search-and-filter.pln +1 -1
  73. package/examples/server.pln +1 -1
  74. package/examples/sessions-and-cookies.pln +1 -1
  75. package/examples/sqlite.pln +1 -1
  76. package/examples/start.pln +1 -1
  77. package/examples/stdlib.pln +1 -1
  78. package/examples/string-verbs.pln +1 -1
  79. package/examples/telegram-ai-bot.pln +1 -1
  80. package/examples/telegram-bot.pln +1 -1
  81. package/examples/testing.pln +1 -1
  82. package/examples/three-dimensional/README.md +51 -0
  83. package/examples/three-dimensional/public/index.html +33 -0
  84. package/examples/three-dimensional/src/scene.pln +34 -0
  85. package/examples/visualization.pln +12 -0
  86. package/examples/web-api.pln +1 -1
  87. package/examples/web-app.pln +1 -1
  88. package/examples/websocket-server.pln +1 -1
  89. package/examples/websocket.pln +1 -1
  90. package/examples/whatsapp-bot/pairing.pln +24 -2
  91. package/examples/whatsapp-bot/qr.pln +18 -2
  92. package/package.json +5 -3
  93. package/docs/logo.jpg +0 -0
package/compiler/cli.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // Usage:
5
5
  // plainscript run <file.pln> install missing dependencies, compile and execute
6
6
  // plainscript build [file.pln] compile src/ (or one file) to dist/, names preserved
7
+ // plainscript build <file.pln> -o <out.js> compile one file to a chosen output path
7
8
  // plainscript check [target] fully validate source(s): imports + generate + JS syntax
8
9
  // (target: a .pln file, a directory, or none to scan the project)
9
10
  // plainscript fmt <file.pln> format a PlainScript file in-place
@@ -61,6 +62,8 @@ ${section('START')}
61
62
  ${section('BUILD & CHECK')}
62
63
  plainscript build Compile every .pln under src/ into dist/
63
64
  plainscript build <file.pln> Compile one file into dist/ (name preserved)
65
+ plainscript build <file.pln> -o <out.js> Compile one file to an explicit path
66
+
64
67
  plainscript check [target] Validate imports + generate + JS output (no writes)
65
68
  target: a .pln file, a directory, or none = project scan
66
69
  --json emits deterministic machine-readable output
@@ -501,6 +504,38 @@ function buildOne(filePath, srcDir, outDir, options = {}) {
501
504
  return path.relative(process.cwd(), outPath) || outPath;
502
505
  }
503
506
 
507
+ // `plainscript build <file.pln> -o <out.js>` — compile one entry to an explicit
508
+ // output path (same compilation pipeline as buildOne, including source maps
509
+ // when requested). Valuable for browser payloads such as the v1.0.36
510
+ // requestAnimationFrame / addEventListener helpers, which are meant to run as
511
+ // a single script tag.
512
+ function writeOneFile(filePath, outputFile) {
513
+ const absFile = path.resolve(filePath);
514
+ if (!fs.existsSync(absFile)) {
515
+ console.error(`File not found: ${filePath}`);
516
+ process.exit(1);
517
+ }
518
+ const outPath = path.resolve(outputFile);
519
+
520
+ const isSourcemap = process.argv.includes('--sourcemap') || process.argv.includes('-m') || process.env.PLAINSCRIPT_SOURCEMAP === 'true';
521
+
522
+ let code, mapObject;
523
+ if (isSourcemap) {
524
+ const res = compile(absFile, { sourceMap: true, outputFile: path.basename(outPath) });
525
+ code = res.code + `\n//# sourceMappingURL=${path.basename(outPath)}.map\n`;
526
+ mapObject = res.mapObject;
527
+ } else {
528
+ code = compile(absFile);
529
+ }
530
+
531
+ fs.mkdirSync(path.dirname(outPath), { recursive: true });
532
+ fs.writeFileSync(outPath, code, 'utf8');
533
+ if (mapObject) {
534
+ fs.writeFileSync(outPath + '.map', JSON.stringify(mapObject, null, 2), 'utf8');
535
+ }
536
+ return path.relative(process.cwd(), outPath) || outPath;
537
+ }
538
+
504
539
  // `plainscript build` — TypeScript-style production build:
505
540
  //
506
541
  // Zero config (default):
@@ -514,16 +549,24 @@ function buildOne(filePath, srcDir, outDir, options = {}) {
514
549
  //
515
550
  // With an explicit file argument only that entry is compiled; without one,
516
551
  // every .pln under the discovered source root builds to the output directory.
517
- async function cmdBuild(filePath) {
552
+ // The optional -o/--output <path> flag (single-file builds only) redirects the
553
+ // output to an explicit file instead of the dist layout.
554
+ async function cmdBuild(filePath, outputPath) {
518
555
  const opts = readCompilerOptions();
519
556
  const srcDir = resolveSrcDir(opts);
520
557
  const outDir = resolveOutDir(opts);
521
558
  const exclude = opts && opts.exclude;
522
559
  if (filePath) {
523
- const outPath = buildOne(filePath, srcDir, outDir);
560
+ const outPath = outputPath
561
+ ? writeOneFile(filePath, outputPath)
562
+ : buildOne(filePath, srcDir, outDir);
524
563
  console.log(`\nOutput written to ${outPath}`);
525
564
  return;
526
565
  }
566
+ if (outputPath) {
567
+ console.error('Usage: plainscript build <file.pln> -o <output.js>\n\n-o/--output needs a single .pln file to compile.');
568
+ process.exit(1);
569
+ }
527
570
  const sources = discoverSources(srcDir, outDir, exclude);
528
571
  if (sources.length === 0) {
529
572
  console.error(`No .pln files found under "${srcDir}".`);
@@ -588,7 +631,7 @@ done
588
631
  route get "/api/status"
589
632
  reply json
590
633
  status is "ok"
591
- version is "1.0.3"
634
+ version is "1.0.36"
592
635
  done
593
636
  done
594
637
 
@@ -970,7 +1013,28 @@ async function main() {
970
1013
 
971
1014
  switch (command) {
972
1015
  case 'run': await cmdRun(fileArg, positional.slice(2)); break;
973
- case 'build': await cmdBuild(fileArg); break;
1016
+ case 'build': {
1017
+ // v1.0.36 — optional -o/--output <path>. "-o" is a single-dash flag, so
1018
+ // it survives the "--filtered" positional list; pull it out here before
1019
+ // building the positional file argument for cmdBuild.
1020
+ let outputPath = null;
1021
+ const positionalOnly = [];
1022
+ for (let i = 0; i < args.length; i++) {
1023
+ const a = args[i];
1024
+ if (a === '-o' || a === '--output') {
1025
+ if (i + 1 < args.length && !args[i + 1].startsWith('-')) {
1026
+ outputPath = args[++i];
1027
+ } else {
1028
+ console.error('Usage: plainscript build <file.pln> -o <output.js>');
1029
+ process.exit(1);
1030
+ }
1031
+ } else if (!a.startsWith('-')) {
1032
+ positionalOnly.push(a);
1033
+ }
1034
+ }
1035
+ await cmdBuild(positionalOnly[1] || '', outputPath);
1036
+ break;
1037
+ }
974
1038
  case 'check': cmdCheck(fileArg, json); break;
975
1039
  case 'fmt': cmdFmt(fileArg); break;
976
1040
  case 'new': cmdNew(fileArg); break;
@@ -31,7 +31,9 @@ const PACKAGE_MAP = Object.freeze({
31
31
  'wasm-sqlite': 'sql.js',
32
32
  // v2.1.1 — WhatsApp bots run on Baileys; QR codes render in the terminal
33
33
  // through qrcode-terminal. Neither package ever appears in PlainScript source.
34
- whatsapp: '@whiskeysockets/baileys',
34
+ // The default Baileys is the maintained @qwerty-xcv fork (reliable pairing);
35
+ // users can override it per-block with `use baileys "<pkg>"`.
36
+ whatsapp: '@qwerty-xcv/baileys',
35
37
  'wa-qrcode': 'qrcode-terminal',
36
38
  // v2.2.0 — MongoDB driver.
37
39
  mongodb: 'mongodb',
@@ -116,7 +118,9 @@ function visit(node, onUse) {
116
118
  } else if (node.type === 'WhatsAppBotStatement') {
117
119
  // v2.1.1 — WhatsApp bots run on Baileys and render QR codes with
118
120
  // qrcode-terminal; both are implementation packages, never source.
119
- onUse('whatsapp');
121
+ // The user may override the Baileys package per-block with
122
+ // `use baileys "<pkg>"`; otherwise the default is used.
123
+ onUse(node.baileysModule || 'whatsapp');
120
124
  onUse('wa-qrcode');
121
125
  }
122
126