plainscript-lang 1.0.0 → 1.0.2
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 +157 -150
- package/compiler/bundler.js +2 -2
- package/compiler/cli.js +172 -65
- package/compiler/formatter.js +1 -1
- package/compiler/generator.js +905 -184
- package/compiler/lexer.js +128 -54
- package/compiler/parser.js +1075 -155
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +131 -30
- package/docs/PLAINSCRIPT-SPEC.md +584 -0
- package/docs/index.html +48 -52
- package/docs/website/script.js +110 -24
- package/docs/website/style.css +4 -4
- package/examples/arrays.pln +12 -0
- package/examples/{auth-api.ps → auth-api.pln} +3 -3
- package/examples/{cache-and-jobs.ps → cache-and-jobs.pln} +1 -1
- package/examples/{concurrency.ps → concurrency.pln} +8 -8
- package/examples/{database.ps → database.pln} +1 -1
- package/examples/{deployment.ps → deployment.pln} +2 -2
- package/examples/{email-send.ps → email-send.pln} +1 -1
- package/examples/{error-handling.ps → error-handling.pln} +8 -7
- package/examples/{expressions.ps → expressions.pln} +1 -1
- package/examples/{file-uploads.ps → file-uploads.pln} +4 -4
- package/examples/{files-and-config.ps → files-and-config.pln} +4 -4
- package/examples/football-backend/{app.ps → app.pln} +2 -2
- package/examples/{http-client.ps → http-client.pln} +18 -18
- package/examples/id-verification/{app.ps → app.pln} +1 -1
- package/examples/{loops.ps → loops.pln} +2 -3
- package/examples/modules/{app.ps → app.pln} +4 -4
- package/examples/modules/{math.ps → math.pln} +1 -1
- package/examples/{record-kinds.ps → record-kinds.pln} +4 -4
- package/examples/{rest-api-fetch.ps → rest-api-fetch.pln} +1 -1
- package/examples/{rest-api.ps → rest-api.pln} +5 -5
- package/examples/{scheduled-tasks.ps → scheduled-tasks.pln} +2 -2
- package/examples/{search-and-filter.ps → search-and-filter.pln} +5 -5
- package/examples/{sessions-and-cookies.ps → sessions-and-cookies.pln} +2 -2
- package/examples/start.pln +2 -0
- package/examples/{stdlib.ps → stdlib.pln} +2 -2
- package/examples/{telegram-bot.ps → telegram-bot.pln} +2 -2
- package/examples/{websocket-server.ps → websocket-server.pln} +1 -1
- package/package.json +2 -2
- package/docs/PLINJS_SPEC.md +0 -1151
- package/examples/arrays.ps +0 -13
- package/examples/start.ps +0 -2
- /package/examples/{day2.ps → day2.pln} +0 -0
- /package/examples/{day3.ps → day3.pln} +0 -0
- /package/examples/{hello.ps → hello.pln} +0 -0
- /package/examples/{objects.ps → objects.pln} +0 -0
- /package/examples/{server.ps → server.pln} +0 -0
- /package/examples/{web-app.ps → web-app.pln} +0 -0
- /package/examples/whatsapp-bot/{pairing.ps → pairing.pln} +0 -0
- /package/examples/whatsapp-bot/{qr.ps → qr.pln} +0 -0
package/compiler/bundler.js
CHANGED
|
@@ -45,8 +45,8 @@ function resolveDependencies(entryPath) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// Parse the file to discover its own imports.
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Annotate any tokenise/parse error with the filename so callers see
|
|
49
|
+
// "file.pln — Line N, Column N: …" rather than a bare positional message.
|
|
50
50
|
const source = fs.readFileSync(absPath, 'utf8');
|
|
51
51
|
let tokens, ast;
|
|
52
52
|
try {
|
package/compiler/cli.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// CLI: compile and run PlainScript (.
|
|
2
|
+
// CLI: compile and run PlainScript (.pln) files.
|
|
3
3
|
//
|
|
4
|
-
// Usage:
|
|
5
|
-
// plainscript run <file.
|
|
6
|
-
// plainscript build [file.
|
|
7
|
-
// plainscript check
|
|
8
|
-
//
|
|
9
|
-
// plainscript
|
|
10
|
-
// plainscript
|
|
11
|
-
// plainscript
|
|
12
|
-
// plainscript
|
|
13
|
-
// plainscript
|
|
14
|
-
// plainscript
|
|
15
|
-
// plainscript
|
|
16
|
-
// plainscript
|
|
17
|
-
// plainscript
|
|
4
|
+
// Usage:
|
|
5
|
+
// plainscript run <file.pln> install missing dependencies, compile and execute
|
|
6
|
+
// plainscript build [file.pln] compile src/ (or one file) to dist/, names preserved
|
|
7
|
+
// plainscript check [target] fully validate source(s): imports + generate + JS syntax
|
|
8
|
+
// (target: a .pln file, a directory, or none to scan the project)
|
|
9
|
+
// plainscript fmt <file.pln> format a PlainScript file in-place
|
|
10
|
+
// plainscript new [name] scaffold a new PlainScript project
|
|
11
|
+
// plainscript install install dependencies detected in the project's sources
|
|
12
|
+
// plainscript start build src/app.pln (or index.pln) and run its dist output
|
|
13
|
+
// plainscript doctor check the PlainScript project environment
|
|
14
|
+
// plainscript add <package> install a package into the project
|
|
15
|
+
// plainscript remove <package> uninstall a package from the project
|
|
16
|
+
// plainscript update update all installed packages
|
|
17
|
+
// plainscript version print the compiler version
|
|
18
|
+
// plainscript help print this help text
|
|
18
19
|
|
|
19
20
|
const fs = require('fs');
|
|
20
21
|
const path = require('path');
|
|
22
|
+
const vm = require('vm');
|
|
21
23
|
const { execFileSync } = require('child_process');
|
|
22
24
|
const { tokenize } = require('./lexer');
|
|
23
25
|
const { parse } = require('./parser');
|
|
@@ -49,18 +51,20 @@ function warn(message) {
|
|
|
49
51
|
const section = (title) => `\n${clrCyan(clrBold(title))}`;
|
|
50
52
|
|
|
51
53
|
const HELP = `
|
|
52
|
-
${clrBold(`PlainScript v${VERSION}`)} ${clrDim('· .
|
|
54
|
+
${clrBold(`PlainScript v${VERSION}`)} ${clrDim('· .pln compiles to readable Node.js')}
|
|
53
55
|
|
|
54
56
|
${section('START')}
|
|
55
|
-
plainscript new [name] Scaffold a new project with a working app.
|
|
56
|
-
plainscript run <file.
|
|
57
|
-
plainscript start Build src/app.
|
|
57
|
+
plainscript new [name] Scaffold a new project with a working app.pln
|
|
58
|
+
plainscript run <file.pln> Install missing deps, compile, execute
|
|
59
|
+
plainscript start Build src/app.pln and run it from dist/
|
|
58
60
|
|
|
59
61
|
${section('BUILD & CHECK')}
|
|
60
|
-
plainscript build Compile every .
|
|
61
|
-
plainscript build <file.
|
|
62
|
-
plainscript check
|
|
63
|
-
|
|
62
|
+
plainscript build Compile every .pln under src/ into dist/
|
|
63
|
+
plainscript build <file.pln> Compile one file into dist/ (name preserved)
|
|
64
|
+
plainscript check [target] Validate imports + generate + JS output (no writes)
|
|
65
|
+
target: a .pln file, a directory, or none = project scan
|
|
66
|
+
--json emits deterministic machine-readable output
|
|
67
|
+
plainscript fmt <file.pln> Format a file in place
|
|
64
68
|
|
|
65
69
|
${section('PACKAGES')}
|
|
66
70
|
plainscript install Install everything your source needs
|
|
@@ -94,7 +98,7 @@ ${section('ALSO SHIPPED')}
|
|
|
94
98
|
|
|
95
99
|
${section('FIRST RUN')}
|
|
96
100
|
plainscript new hello scaffolds hello/ with a live web app
|
|
97
|
-
plainscript run hello/app.
|
|
101
|
+
plainscript run hello/app.pln serves it at http://localhost:3000
|
|
98
102
|
`.trim();
|
|
99
103
|
|
|
100
104
|
// ── npm invocation ────────────────────────────────────────────────────────────
|
|
@@ -147,8 +151,8 @@ function isValidPackageName(name) {
|
|
|
147
151
|
// "exclude": ["vendor"] } }
|
|
148
152
|
//
|
|
149
153
|
// Filenames and folder structure are always preserved:
|
|
150
|
-
// src/messi.
|
|
151
|
-
// src/helpers/math.
|
|
154
|
+
// src/messi.pln → dist/messi.js
|
|
155
|
+
// src/helpers/math.pln → dist/helpers/math.js
|
|
152
156
|
const SOURCE_DIR = 'src';
|
|
153
157
|
const DEFAULT_OUT_DIR = 'dist';
|
|
154
158
|
|
|
@@ -181,7 +185,7 @@ function resolveOutDir(opts) {
|
|
|
181
185
|
return DEFAULT_OUT_DIR;
|
|
182
186
|
}
|
|
183
187
|
|
|
184
|
-
// Every .
|
|
188
|
+
// Every .pln file under srcDir, recursively, as paths relative to srcDir.
|
|
185
189
|
// Deterministic order (sorted); node_modules, hidden directories, the output
|
|
186
190
|
// directory, and any user-specified exclude patterns are skipped.
|
|
187
191
|
function discoverSources(srcDir, outDir, exclude) {
|
|
@@ -204,7 +208,7 @@ function discoverSources(srcDir, outDir, exclude) {
|
|
|
204
208
|
try { stat = fs.statSync(full); } catch (_) { continue; }
|
|
205
209
|
if (stat.isDirectory()) {
|
|
206
210
|
walk(full);
|
|
207
|
-
} else if (name.endsWith('.
|
|
211
|
+
} else if (name.endsWith('.pln')) {
|
|
208
212
|
found.push(path.relative(root, full));
|
|
209
213
|
}
|
|
210
214
|
}
|
|
@@ -401,7 +405,7 @@ function nodeModulesSearchPaths(entryDir) {
|
|
|
401
405
|
|
|
402
406
|
async function cmdRun(filePath, extraArgs = []) {
|
|
403
407
|
if (!filePath) {
|
|
404
|
-
console.error('Usage: plainscript run <file.
|
|
408
|
+
console.error('Usage: plainscript run <file.pln>');
|
|
405
409
|
process.exit(1);
|
|
406
410
|
}
|
|
407
411
|
const js = compile(filePath);
|
|
@@ -438,8 +442,8 @@ function buildOne(filePath, srcDir, outDir) {
|
|
|
438
442
|
}
|
|
439
443
|
const js = compile(absFile);
|
|
440
444
|
const srcRoot = path.resolve(srcDir);
|
|
441
|
-
let rel = path.relative(srcRoot, absFile).replace(/\.
|
|
442
|
-
if (rel.startsWith('..') || path.isAbsolute(rel)) rel = path.basename(absFile).replace(/\.
|
|
445
|
+
let rel = path.relative(srcRoot, absFile).replace(/\.pln$/, '.js');
|
|
446
|
+
if (rel.startsWith('..') || path.isAbsolute(rel)) rel = path.basename(absFile).replace(/\.pln$/, '.js');
|
|
443
447
|
const outPath = path.join(path.resolve(outDir), rel);
|
|
444
448
|
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
445
449
|
fs.writeFileSync(outPath, js, 'utf8');
|
|
@@ -449,16 +453,16 @@ function buildOne(filePath, srcDir, outDir) {
|
|
|
449
453
|
// `plainscript build` — TypeScript-style production build:
|
|
450
454
|
//
|
|
451
455
|
// Zero config (default):
|
|
452
|
-
// messi.
|
|
453
|
-
// src/index.
|
|
454
|
-
// src/a/b.
|
|
456
|
+
// messi.pln → dist/messi.js (project-root sources)
|
|
457
|
+
// src/index.pln → dist/index.js (src/ is the source root)
|
|
458
|
+
// src/a/b.pln → dist/a/b.js (structure preserved)
|
|
455
459
|
//
|
|
456
460
|
// With plainscript.config.json:
|
|
457
461
|
// { "compilerOptions": { "outDir": "./build", "rootDir": "./lib" } }
|
|
458
|
-
// lib/app.
|
|
462
|
+
// lib/app.pln → build/app.js
|
|
459
463
|
//
|
|
460
464
|
// With an explicit file argument only that entry is compiled; without one,
|
|
461
|
-
// every .
|
|
465
|
+
// every .pln under the discovered source root builds to the output directory.
|
|
462
466
|
async function cmdBuild(filePath) {
|
|
463
467
|
const opts = readCompilerOptions();
|
|
464
468
|
const srcDir = resolveSrcDir(opts);
|
|
@@ -471,7 +475,7 @@ async function cmdBuild(filePath) {
|
|
|
471
475
|
}
|
|
472
476
|
const sources = discoverSources(srcDir, outDir, exclude);
|
|
473
477
|
if (sources.length === 0) {
|
|
474
|
-
console.error(`No .
|
|
478
|
+
console.error(`No .pln files found under "${srcDir}".`);
|
|
475
479
|
process.exit(1);
|
|
476
480
|
}
|
|
477
481
|
QUIET_STAGES = true;
|
|
@@ -496,7 +500,7 @@ async function cmdStart(extraArgs = []) {
|
|
|
496
500
|
const outDir = resolveOutDir(opts);
|
|
497
501
|
const entryPath = findEntry(opts);
|
|
498
502
|
if (!entryPath) {
|
|
499
|
-
console.error('No entry file found. Expected "src/app.
|
|
503
|
+
console.error('No entry file found. Expected "src/app.pln" or "src/index.pln".');
|
|
500
504
|
process.exit(1);
|
|
501
505
|
}
|
|
502
506
|
const outFile = buildOne(entryPath, srcDir, outDir);
|
|
@@ -521,8 +525,8 @@ function cmdNew(projectName) {
|
|
|
521
525
|
fs.mkdirSync(path.join(dir, 'public'));
|
|
522
526
|
fs.mkdirSync(path.join(dir, 'src'));
|
|
523
527
|
|
|
524
|
-
// src/app.
|
|
525
|
-
fs.writeFileSync(path.join(dir, 'src', 'app.
|
|
528
|
+
// src/app.pln — starter Express app
|
|
529
|
+
fs.writeFileSync(path.join(dir, 'src', 'app.pln'), `use express
|
|
526
530
|
|
|
527
531
|
remember app as express()
|
|
528
532
|
|
|
@@ -548,7 +552,7 @@ done
|
|
|
548
552
|
// deployment only needs the generated dist/ output.
|
|
549
553
|
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({
|
|
550
554
|
name,
|
|
551
|
-
version: '1.0.
|
|
555
|
+
version: '1.0.1',
|
|
552
556
|
description: `A PlainScript v${VERSION} application`,
|
|
553
557
|
main: 'dist/app.js',
|
|
554
558
|
scripts: {
|
|
@@ -580,7 +584,7 @@ Then open http://localhost:3000 in your browser.
|
|
|
580
584
|
`);
|
|
581
585
|
|
|
582
586
|
console.log(`✓ Created project "${name}"`);
|
|
583
|
-
console.log(`\nNext steps:\n cd ${name}\n npm install\n npx plainscript run src/app.
|
|
587
|
+
console.log(`\nNext steps:\n cd ${name}\n npm install\n npx plainscript run src/app.pln`);
|
|
584
588
|
}
|
|
585
589
|
|
|
586
590
|
// ── plainscript install ────────────────────────────────────────────────────────────
|
|
@@ -590,11 +594,11 @@ Then open http://localhost:3000 in your browser.
|
|
|
590
594
|
function findEntry(opts) {
|
|
591
595
|
const srcDir = resolveSrcDir(opts);
|
|
592
596
|
const candidates = [
|
|
593
|
-
path.join(srcDir, 'app.
|
|
594
|
-
path.join(srcDir, 'index.
|
|
597
|
+
path.join(srcDir, 'app.pln'),
|
|
598
|
+
path.join(srcDir, 'index.pln'),
|
|
595
599
|
];
|
|
596
600
|
if (srcDir !== '.') {
|
|
597
|
-
candidates.push('app.
|
|
601
|
+
candidates.push('app.pln', 'index.pln');
|
|
598
602
|
}
|
|
599
603
|
return candidates.find((c) => fs.existsSync(path.resolve(c))) || null;
|
|
600
604
|
}
|
|
@@ -609,7 +613,7 @@ function collectSourceAsts() {
|
|
|
609
613
|
const exclude = opts && opts.exclude;
|
|
610
614
|
const sources = discoverSources(srcDir, outDir, exclude);
|
|
611
615
|
if (sources.length === 0) {
|
|
612
|
-
console.error(`No .
|
|
616
|
+
console.error(`No .pln source files found under "${srcDir}".`);
|
|
613
617
|
process.exit(1);
|
|
614
618
|
}
|
|
615
619
|
const root = path.resolve(srcDir);
|
|
@@ -665,14 +669,14 @@ function cmdDoctor() {
|
|
|
665
669
|
check('Runtime', fs.existsSync(path.join(__dirname, 'generator.js')));
|
|
666
670
|
console.log('');
|
|
667
671
|
|
|
668
|
-
// Source discovery check: does the project have any .
|
|
672
|
+
// Source discovery check: does the project have any .pln files?
|
|
669
673
|
const opts = readCompilerOptions();
|
|
670
674
|
const srcDir = resolveSrcDir(opts);
|
|
671
675
|
const outDir = resolveOutDir(opts);
|
|
672
676
|
const exclude = opts && opts.exclude;
|
|
673
677
|
const sources = discoverSources(srcDir, outDir, exclude);
|
|
674
678
|
check('Source files', sources.length > 0,
|
|
675
|
-
sources.length > 0 ? `"${srcDir}/" discovered (${sources.length} file(s))` : `no .
|
|
679
|
+
sources.length > 0 ? `"${srcDir}/" discovered (${sources.length} file(s))` : `no .pln files under "${srcDir}"`);
|
|
676
680
|
if (sources.length === 0) return;
|
|
677
681
|
|
|
678
682
|
// Dependency check: scan every source file for npm imports
|
|
@@ -747,31 +751,133 @@ function cmdUpdate() {
|
|
|
747
751
|
}
|
|
748
752
|
|
|
749
753
|
// Check syntax of a PlainScript file without generating JavaScript or executing.
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
const
|
|
756
|
-
if (!fs.existsSync(absPath)) {
|
|
757
|
-
console.error(`File not found: ${filePath}`);
|
|
758
|
-
process.exit(1);
|
|
759
|
-
}
|
|
754
|
+
// Full validation of a single .pln entry: resolve imports, parse+generate every
|
|
755
|
+
// file in dependency order, and verify the emitted JavaScript is syntactically
|
|
756
|
+
// valid — all without writing anything to disk. Returns a deterministic
|
|
757
|
+
// result record; `deps` are the npm packages the sources require.
|
|
758
|
+
function validateSource(absPath) {
|
|
759
|
+
const rel = path.relative(process.cwd(), absPath) || absPath;
|
|
760
760
|
const t0 = Date.now();
|
|
761
761
|
try {
|
|
762
|
-
resolveDependencies
|
|
763
|
-
|
|
764
|
-
|
|
762
|
+
// resolveDependencies parses each file too, so a parse error anywhere in
|
|
763
|
+
// the import graph surfaces here with a "file.pln — Line:Col" prefix.
|
|
764
|
+
const files = resolveDependencies(absPath);
|
|
765
|
+
const context = createGenerationContext();
|
|
766
|
+
let js = files.map(({ ast }) => generate(ast, context)).filter(s => s.trim()).join('\n');
|
|
767
|
+
if (context.needsAsync) js = wrapAsync(js);
|
|
768
|
+
|
|
769
|
+
// The compiler must never emit broken JavaScript. Parsing the output with
|
|
770
|
+
// the V8 compiler catches generator regressions at check time.
|
|
771
|
+
new vm.Script(js);
|
|
772
|
+
|
|
773
|
+
// Collect unique npm dependencies across the file and its imports.
|
|
774
|
+
const deps = [];
|
|
775
|
+
for (const { absPath: f } of files) {
|
|
776
|
+
let source;
|
|
777
|
+
try { source = fs.readFileSync(f, 'utf8'); } catch (_) { continue; }
|
|
778
|
+
for (const d of detectDependencies(source)) {
|
|
779
|
+
if (!deps.includes(d)) deps.push(d);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return { file: rel, ok: true, deps, ms: Date.now() - t0 };
|
|
765
783
|
} catch (err) {
|
|
766
|
-
|
|
784
|
+
return { file: rel, ok: false, error: err.message, ms: Date.now() - t0 };
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// `plainscript check [target] [--json]`
|
|
789
|
+
//
|
|
790
|
+
// Fully validates one .pln file, every .pln under a directory, or (with no
|
|
791
|
+
// target) the project sources, deterministically and non-interactively:
|
|
792
|
+
// resolve imports, parse + generate, and confirm the JS output parses. Never
|
|
793
|
+
// prompts, never writes files, never installs packages.
|
|
794
|
+
//
|
|
795
|
+
// plainscript check validate every .pln in the project source root
|
|
796
|
+
// plainscript check app.pln validate one file (and its imports)
|
|
797
|
+
// plainscript check src/ validate every .pln under a directory
|
|
798
|
+
// plainscript check --json machine-readable JSON on stdout
|
|
799
|
+
function cmdCheck(target, json) {
|
|
800
|
+
const opts = readCompilerOptions();
|
|
801
|
+
const srcDir = resolveSrcDir(opts);
|
|
802
|
+
const outDir = resolveOutDir(opts);
|
|
803
|
+
const exclude = opts && opts.exclude;
|
|
804
|
+
|
|
805
|
+
let sources;
|
|
806
|
+
if (target) {
|
|
807
|
+
const abs = path.resolve(target);
|
|
808
|
+
if (fs.existsSync(abs) && fs.statSync(abs).isDirectory()) {
|
|
809
|
+
sources = discoverSources(abs, outDir, exclude).map(r => path.join(abs, r));
|
|
810
|
+
} else if (/\.pln$/.test(target) && !fs.existsSync(abs)) {
|
|
811
|
+
if (json) {
|
|
812
|
+
console.log(JSON.stringify({
|
|
813
|
+
plainscript: VERSION, ok: false,
|
|
814
|
+
sources: [], summary: { total: 0, passed: 0, failed: 1 },
|
|
815
|
+
errors: [{ file: target, error: `File not found: ${target}` }],
|
|
816
|
+
}));
|
|
817
|
+
} else {
|
|
818
|
+
console.error(`File not found: ${target}`);
|
|
819
|
+
}
|
|
820
|
+
process.exit(1);
|
|
821
|
+
} else {
|
|
822
|
+
sources = [abs];
|
|
823
|
+
}
|
|
824
|
+
} else {
|
|
825
|
+
const root = path.resolve(srcDir);
|
|
826
|
+
sources = discoverSources(srcDir, outDir, exclude).map(r => path.join(root, r));
|
|
827
|
+
if (sources.length === 0) {
|
|
828
|
+
const msg = `No .pln files found under "${srcDir}".`;
|
|
829
|
+
if (json) console.log(JSON.stringify({ plainscript: VERSION, ok: false, sources: [], summary: { total: 0, passed: 0, failed: 1 }, errors: [{ file: srcDir, error: msg }] }));
|
|
830
|
+
else console.error(msg);
|
|
831
|
+
process.exit(1);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
sources.sort(); // deterministic regardless of filesystem order
|
|
836
|
+
const results = sources.map(validateSource);
|
|
837
|
+
const passed = results.filter(r => r.ok);
|
|
838
|
+
const failed = results.filter(r => !r.ok);
|
|
839
|
+
|
|
840
|
+
if (json) {
|
|
841
|
+
const dependencySummary = [];
|
|
842
|
+
const depIndex = new Map();
|
|
843
|
+
for (const r of passed) {
|
|
844
|
+
for (const d of r.deps) {
|
|
845
|
+
if (!depIndex.has(d)) { depIndex.set(d, []); dependencySummary.push(d); }
|
|
846
|
+
depIndex.get(d).push(r.file);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
console.log(JSON.stringify({
|
|
850
|
+
plainscript: VERSION,
|
|
851
|
+
ok: failed.length === 0,
|
|
852
|
+
sources: results,
|
|
853
|
+
summary: { total: results.length, passed: passed.length, failed: failed.length },
|
|
854
|
+
dependencySummary: dependencySummary.map(d => ({ package: d, usedBy: depIndex.get(d) })),
|
|
855
|
+
}));
|
|
856
|
+
process.exit(failed.length ? 1 : 0);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
for (const r of results) {
|
|
860
|
+
if (r.ok) {
|
|
861
|
+
console.log(`${clrGreen('✓')} ${r.file} — ok${clrDim(` (${r.ms}ms)`)}`);
|
|
862
|
+
} else {
|
|
863
|
+
console.log(`${clrRed('✗')} ${r.file}`);
|
|
864
|
+
console.error(r.error);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
if (failed.length > 0) {
|
|
869
|
+
console.error(`\n${failed.length} of ${results.length} file(s) failed validation.`);
|
|
767
870
|
process.exit(1);
|
|
768
871
|
}
|
|
872
|
+
if (results.length > 0) {
|
|
873
|
+
console.log(clrGreen(`\n✓ ${results.length} file(s) validated.`));
|
|
874
|
+
}
|
|
769
875
|
}
|
|
770
876
|
|
|
771
877
|
// Format a PlainScript file in-place.
|
|
772
878
|
function cmdFmt(filePath) {
|
|
773
879
|
if (!filePath) {
|
|
774
|
-
console.error('Usage: plainscript fmt <file.
|
|
880
|
+
console.error('Usage: plainscript fmt <file.pln>');
|
|
775
881
|
process.exit(1);
|
|
776
882
|
}
|
|
777
883
|
const absPath = path.resolve(filePath);
|
|
@@ -805,6 +911,7 @@ async function main() {
|
|
|
805
911
|
// Global flags — recognized anywhere in the argument list.
|
|
806
912
|
const quiet = args.includes('--quiet');
|
|
807
913
|
const verbose = args.includes('--verbose');
|
|
914
|
+
const json = args.includes('--json');
|
|
808
915
|
if (quiet) { stage = stageQuiet; QUIET_STAGES = true; }
|
|
809
916
|
if (verbose) { stage = stageVerbose; VERBOSE = true; }
|
|
810
917
|
|
|
@@ -817,7 +924,7 @@ async function main() {
|
|
|
817
924
|
switch (command) {
|
|
818
925
|
case 'run': await cmdRun(fileArg, positional.slice(2)); break;
|
|
819
926
|
case 'build': await cmdBuild(fileArg); break;
|
|
820
|
-
case 'check': cmdCheck(fileArg);
|
|
927
|
+
case 'check': cmdCheck(fileArg, json); break;
|
|
821
928
|
case 'fmt': cmdFmt(fileArg); break;
|
|
822
929
|
case 'new': cmdNew(fileArg); break;
|
|
823
930
|
case 'install': cmdInstall(); break;
|
|
@@ -830,7 +937,7 @@ async function main() {
|
|
|
830
937
|
case 'help': cmdHelp(); break;
|
|
831
938
|
default:
|
|
832
939
|
// Backwards-compatible: treat the first arg as a file to run directly
|
|
833
|
-
if (command && command.endsWith('.
|
|
940
|
+
if (command && command.endsWith('.pln')) {
|
|
834
941
|
await cmdRun(command);
|
|
835
942
|
} else {
|
|
836
943
|
console.error(`Unknown command: "${command}". Run "plainscript help" for usage.`);
|
package/compiler/formatter.js
CHANGED
|
@@ -17,7 +17,7 @@ const INDENT_STARTERS = [
|
|
|
17
17
|
/^make\s+\S+\s*\(/, // make name(...)
|
|
18
18
|
/^if\s+/, // if ...
|
|
19
19
|
/^otherwise\b/, // otherwise
|
|
20
|
-
/^for\s+
|
|
20
|
+
/^for\s+each\s+/, // for each ...
|
|
21
21
|
/^while\s+/, // while ...
|
|
22
22
|
/^when\s+someone\s+visits/, // when someone visits ...
|
|
23
23
|
/^when\s+someone\s+(sends|clicks)\b/, // when someone sends / clicks (Telegram)
|