@skillstech/thunderlang 1.2.0 → 1.4.0

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 (63) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/dist/core.cjs +6718 -1232
  3. package/dist/index.cjs +17490 -12204
  4. package/dist/learn.cjs +5866 -497
  5. package/package.json +6 -2
  6. package/src/cli-home.mjs +1 -1
  7. package/src/cli.mjs +54 -6
  8. package/src/core/ThunderRuntime.cs +1367 -0
  9. package/src/core/check.mjs +158 -2
  10. package/src/core/cli.mjs +148 -8
  11. package/src/core/csharp-run.mjs +184 -0
  12. package/src/core/diagnostics.mjs +13 -1
  13. package/src/core/engine-core.mjs +285 -2
  14. package/src/core/engine-values.mjs +1 -1
  15. package/src/core/format.mjs +191 -3
  16. package/src/core/go-run.mjs +106 -0
  17. package/src/core/index.mjs +2 -1
  18. package/src/core/java/thunder/T.java +6 -0
  19. package/src/core/java/thunder/ThunderRuntime.java +1374 -0
  20. package/src/core/java-run.mjs +89 -0
  21. package/src/core/parser.mjs +331 -5
  22. package/src/core/project.mjs +31 -6
  23. package/src/core/react-run.mjs +96 -0
  24. package/src/core/runtime-go/thunder_runtime.go +3038 -0
  25. package/src/core/runtime-react.mjs +133 -0
  26. package/src/core/rust/thunder_runtime.rs +1645 -0
  27. package/src/core/rust-run.mjs +192 -0
  28. package/src/core/screen-values.mjs +30 -0
  29. package/src/core/target-csharp.mjs +484 -0
  30. package/src/core/target-go.mjs +555 -0
  31. package/src/core/target-java.mjs +587 -0
  32. package/src/core/target-react.mjs +270 -0
  33. package/src/core/target-rust.mjs +534 -0
  34. package/src/core/target-typescript.mjs +2 -2
  35. package/src/core.d.ts +59 -0
  36. package/src/core.mjs +14 -0
  37. package/src/emit.mjs +1 -1
  38. package/src/faithful.mjs +34 -1
  39. package/src/flow/access.mjs +1451 -0
  40. package/src/flow/ts-parse.mjs +772 -0
  41. package/src/index.d.ts +3 -0
  42. package/src/index.mjs +3 -0
  43. package/src/libraries.mjs +32 -4
  44. package/src/model.mjs +72 -9
  45. package/src/passport-cli.mjs +101 -0
  46. package/src/passport-fs.d.mts +9 -0
  47. package/src/passport-fs.mjs +180 -0
  48. package/src/passport.d.mts +46 -0
  49. package/src/passport.mjs +255 -0
  50. package/src/program.d.mts +31 -0
  51. package/src/program.mjs +14 -0
  52. package/src/read-level.mjs +48 -2
  53. package/src/read-repo-fs.mjs +3 -1
  54. package/src/read.mjs +64 -5
  55. package/src/replay-cli.mjs +123 -0
  56. package/src/review.mjs +31 -3
  57. package/src/say-less.mjs +168 -13
  58. package/src/screens.mjs +833 -0
  59. package/src/steps.mjs +443 -20
  60. package/src/term.mjs +43 -0
  61. package/src/things-langs.mjs +20 -3
  62. package/src/write-across-cli.mjs +143 -0
  63. package/src/write-across.mjs +168 -0
@@ -0,0 +1,96 @@
1
+ // Writing a compiled React app to disk (thunder build --target react).
2
+ //
3
+ // generated/react/ is a small Vite app: index.html, main.tsx (mounts ThunderApp), <module>.tsx for the program,
4
+ // thunder_runtime.mjs and its types, thunder.css, package.json, and tsconfig.json. Run it with: npm install && npm run dev
5
+ import { writeFileSync, mkdirSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ import { toReact, hasScreens } from './target-react.mjs';
8
+ import { pythonOnlyUses } from './target-typescript.mjs';
9
+ import { REACT_RUNTIME, REACT_RUNTIME_DTS } from './runtime-react.mjs';
10
+ import { diag } from './diagnostics.mjs';
11
+
12
+ /** What stops a file from becoming a React app: a Python module (TC405), or steps outside a screen (TC406). */
13
+ export function reactDiagnostics(result, { entry = false } = {}) {
14
+ const out = pythonOnlyUses(result.info).map((u) => diag('TC405', u.line,
15
+ `"${u.module}" is a Python module, and this program is built as a React app, which cannot use it.`,
16
+ 'Build for Python (target = "python") to use Python modules. Thunder never swaps in a different library.'));
17
+ const main = result.program.main ?? [];
18
+ if (main.length && hasScreens(result.info)) {
19
+ out.push(diag('TC406', main[0].line, 'A React app shows its screens; the steps outside a screen have nowhere to run.',
20
+ 'Put steps under a button ("When pressed:"), or in a function ("To …:") that a screen uses. thunder run still runs them before it shows the screen.'));
21
+ }
22
+ if (entry && !hasScreens(result.info)) {
23
+ out.push(diag('TC406', 1, 'A React app is built from screens, and this program has no "Screen".',
24
+ 'Write one: Screen Home: then what it shows (Show a heading "Hello"). Or build it for another target: --target typescript.'));
25
+ }
26
+ return out;
27
+ }
28
+
29
+ export const REACT_TSCONFIG = `${JSON.stringify({
30
+ compilerOptions: { strict: true, noEmit: true, target: 'es2022', module: 'esnext', moduleResolution: 'bundler', jsx: 'react-jsx', allowImportingTsExtensions: true, skipLibCheck: true, lib: ['es2022', 'dom'] },
31
+ include: ['*.tsx'],
32
+ }, null, 2)}\n`;
33
+
34
+ export const REACT_CSS = `/* thunder.css: calm defaults for a Thunder app. Change them freely. */
35
+ body { margin: 0; font-family: system-ui, sans-serif; line-height: 1.5; color: #1f2328; background: #ffffff; }
36
+ .thunder-screen { max-width: 40rem; margin: 2rem auto; padding: 0 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
37
+ .thunder-screen .thunder-screen { margin: 0.5rem 0; padding: 1rem; border: 1px solid #d0d7de; border-radius: 8px; }
38
+ .thunder-screen h1, .thunder-screen p { margin: 0; }
39
+ .thunder-row { display: flex; gap: 1rem; align-items: baseline; }
40
+ .thunder-box { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; }
41
+ .thunder-box input { font: inherit; font-weight: 400; padding: 0.4rem 0.5rem; border: 1px solid #8c959f; border-radius: 6px; }
42
+ button { font: inherit; padding: 0.45rem 0.9rem; border-radius: 6px; border: 1px solid #1f6feb; background: #1f6feb; color: #ffffff; cursor: pointer; align-self: flex-start; }
43
+ button:disabled { background: #eaeef2; border-color: #d0d7de; color: #6e7781; cursor: not-allowed; }
44
+ ul { margin: 0; padding-left: 1.25rem; }
45
+ .thunder-problem, .thunder-failed { margin: 0; padding: 0.5rem 0.75rem; border-left: 4px solid #cf222e; background: #ffebe9; color: #82071e; }
46
+ @media (prefers-color-scheme: dark) {
47
+ body { color: #e6edf3; background: #0d1117; }
48
+ .thunder-screen .thunder-screen { border-color: #30363d; }
49
+ .thunder-box input { background: #161b22; color: inherit; border-color: #484f58; }
50
+ button:disabled { background: #21262d; border-color: #30363d; color: #7d8590; }
51
+ .thunder-problem, .thunder-failed { background: #3c1618; color: #ffa198; }
52
+ }
53
+ `;
54
+
55
+ /** Write the app: every src file with screens to <module>.tsx; the entry file's ThunderApp is the app. */
56
+ export function writeReact(results, outDir, { entry }) {
57
+ mkdirSync(outDir, { recursive: true });
58
+ const name = entry.file.split('/').pop().replace(/\.thunder$/, '');
59
+ for (const r of results.filter((x) => x.kind !== 'test' && hasScreens(x.info))) {
60
+ writeFileSync(join(outDir, `${r.module}.tsx`), toReact(r.program, r.info, { source: r.file }));
61
+ }
62
+ writeFileSync(join(outDir, 'main.tsx'), [
63
+ '// Generated by the Thunder compiler: starts the app.',
64
+ "import { createRoot } from 'react-dom/client';",
65
+ `import { ThunderApp } from './${entry.module}.tsx';`,
66
+ "import './thunder.css';",
67
+ '',
68
+ "createRoot(document.getElementById('root')!).render(<ThunderApp />);",
69
+ '',
70
+ ].join('\n'));
71
+ writeFileSync(join(outDir, 'index.html'), `<!doctype html>
72
+ <html lang="en">
73
+ <head>
74
+ <meta charset="utf-8" />
75
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
76
+ <title>${name}</title>
77
+ </head>
78
+ <body>
79
+ <div id="root"></div>
80
+ <script type="module" src="./main.tsx"></script>
81
+ </body>
82
+ </html>
83
+ `);
84
+ writeFileSync(join(outDir, 'thunder_runtime.mjs'), REACT_RUNTIME);
85
+ writeFileSync(join(outDir, 'thunder_runtime.d.mts'), REACT_RUNTIME_DTS);
86
+ writeFileSync(join(outDir, 'thunder.css'), REACT_CSS);
87
+ writeFileSync(join(outDir, 'tsconfig.json'), REACT_TSCONFIG);
88
+ writeFileSync(join(outDir, 'package.json'), `${JSON.stringify({
89
+ name: name.toLowerCase().replace(/[^a-z0-9-]+/g, '-') || 'thunder-app',
90
+ private: true,
91
+ type: 'module',
92
+ scripts: { dev: 'vite', build: 'vite build', preview: 'vite preview', typecheck: 'tsc -p .' },
93
+ dependencies: { react: '^18.3.1', 'react-dom': '^18.3.1' },
94
+ devDependencies: { '@types/react': '^18.3.3', '@types/react-dom': '^18.3.0', typescript: '^5.5.3', vite: '^5.4.0' },
95
+ }, null, 2)}\n`);
96
+ }