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.
- package/README.md +836 -188
- package/compiler/cli.js +68 -4
- package/compiler/dependency-detector.js +6 -2
- package/compiler/generator.js +737 -51
- package/compiler/lexer.js +12 -0
- package/compiler/parser.js +184 -14
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +32 -5
- package/docs/GAME-PROMPT.md +915 -0
- package/docs/PLAINSCRIPT-SPEC.md +264 -3
- package/docs/index.html +41 -33
- package/docs/logo-pln.jpg +0 -0
- package/docs/visualization-example.svg +32 -0
- package/docs/website/script.js +130 -1
- package/docs/website/style.css +253 -122
- package/examples/ai-providers.pln +1 -1
- package/examples/arrays.pln +1 -1
- package/examples/async-errors.pln +1 -1
- package/examples/auth-api.pln +1 -1
- package/examples/auth-sessions.pln +1 -1
- package/examples/basics.pln +1 -1
- package/examples/bots.pln +1 -1
- package/examples/browser-interactive/README.md +29 -0
- package/examples/browser-interactive/public/index.html +83 -0
- package/examples/browser-interactive/public/interactive.js +27 -0
- package/examples/browser-interactive/src/interactive.pln +34 -0
- package/examples/cache-and-jobs.pln +1 -1
- package/examples/cache-schedule.pln +1 -1
- package/examples/canvas-game/README.md +34 -0
- package/examples/canvas-game/public/game.js +131 -0
- package/examples/canvas-game/public/index.html +48 -0
- package/examples/canvas-game/src/game.pln +139 -0
- package/examples/collections.pln +1 -1
- package/examples/concurrency.pln +1 -1
- package/examples/conditions.pln +1 -1
- package/examples/database.pln +1 -1
- package/examples/day2.pln +1 -1
- package/examples/day3.pln +1 -1
- package/examples/deployment.pln +1 -1
- package/examples/email-send.pln +1 -1
- package/examples/error-handling.pln +1 -1
- package/examples/expressions.pln +1 -1
- package/examples/file-uploads.pln +1 -1
- package/examples/files-and-config.pln +1 -1
- package/examples/files.pln +1 -1
- package/examples/football-backend/app.pln +1 -1
- package/examples/functions.pln +1 -1
- package/examples/hello.pln +1 -1
- package/examples/http-client.pln +1 -1
- package/examples/http.pln +1 -1
- package/examples/id-verification/app.pln +1 -1
- package/examples/javascript-library/README.md +54 -0
- package/examples/javascript-library/package-lock.json +21 -0
- package/examples/javascript-library/package.json +8 -0
- package/examples/javascript-library/public/config.json +4 -0
- package/examples/javascript-library/public/index.html +40 -0
- package/examples/javascript-library/src/interop.pln +53 -0
- package/examples/json.pln +1 -1
- package/examples/loops.pln +1 -1
- package/examples/modules/app.pln +1 -1
- package/examples/modules/main.pln +1 -1
- package/examples/modules/math.pln +1 -1
- package/examples/mongo.pln +1 -1
- package/examples/objects.pln +1 -1
- package/examples/ocr.pln +1 -1
- package/examples/packages.pln +1 -1
- package/examples/record-kinds.pln +1 -1
- package/examples/records.pln +1 -1
- package/examples/rest-api-fetch.pln +1 -1
- package/examples/rest-api.pln +1 -1
- package/examples/scheduled-tasks.pln +1 -1
- package/examples/search-and-filter.pln +1 -1
- package/examples/server.pln +1 -1
- package/examples/sessions-and-cookies.pln +1 -1
- package/examples/sqlite.pln +1 -1
- package/examples/start.pln +1 -1
- package/examples/stdlib.pln +1 -1
- package/examples/string-verbs.pln +1 -1
- package/examples/telegram-ai-bot.pln +1 -1
- package/examples/telegram-bot.pln +1 -1
- package/examples/testing.pln +1 -1
- package/examples/three-dimensional/README.md +51 -0
- package/examples/three-dimensional/public/index.html +33 -0
- package/examples/three-dimensional/src/scene.pln +34 -0
- package/examples/visualization.pln +12 -0
- package/examples/web-api.pln +1 -1
- package/examples/web-app.pln +1 -1
- package/examples/websocket-server.pln +1 -1
- package/examples/websocket.pln +1 -1
- package/examples/whatsapp-bot/pairing.pln +24 -2
- package/examples/whatsapp-bot/qr.pln +18 -2
- package/package.json +5 -3
- 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
|
-
|
|
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 =
|
|
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.
|
|
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':
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|