@lango-project/lango-client 0.0.0-stage → 0.2.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 (110) hide show
  1. package/LICENSE +200 -0
  2. package/NOTICE +2 -0
  3. package/README.md +877 -2
  4. package/dist/.lango/bignumber.mjs +3119 -0
  5. package/dist/.lango/runtime.mjs +607 -0
  6. package/dist/.lango/xmldom/conventions.js +429 -0
  7. package/dist/.lango/xmldom/dom-parser.js +591 -0
  8. package/dist/.lango/xmldom/dom.js +3759 -0
  9. package/dist/.lango/xmldom/entities.js +2171 -0
  10. package/dist/.lango/xmldom/errors.js +205 -0
  11. package/dist/.lango/xmldom/grammar.js +559 -0
  12. package/dist/.lango/xmldom/index.js +41 -0
  13. package/dist/.lango/xmldom/package.json +1 -0
  14. package/dist/.lango/xmldom/sax.js +983 -0
  15. package/dist/.lango/xmldom.LICENSE.md +8 -0
  16. package/dist/application.mjs +429 -0
  17. package/dist/application.mjs.map +1 -0
  18. package/dist/coordinator.mjs +91 -0
  19. package/dist/coordinator.mjs.map +1 -0
  20. package/dist/demo.mjs +110 -0
  21. package/dist/demo.mjs.map +1 -0
  22. package/dist/demo_controls.mjs +59 -0
  23. package/dist/demo_controls.mjs.map +1 -0
  24. package/dist/errors.mjs +201 -0
  25. package/dist/errors.mjs.map +1 -0
  26. package/dist/form_state.mjs +266 -0
  27. package/dist/form_state.mjs.map +1 -0
  28. package/dist/heartbeat.mjs +330 -0
  29. package/dist/heartbeat.mjs.map +1 -0
  30. package/dist/inheritance.mjs +240 -0
  31. package/dist/inheritance.mjs.map +1 -0
  32. package/dist/input_values.mjs +65 -0
  33. package/dist/input_values.mjs.map +1 -0
  34. package/dist/library.mjs +792 -0
  35. package/dist/library.mjs.map +1 -0
  36. package/dist/navigation.mjs +466 -0
  37. package/dist/navigation.mjs.map +1 -0
  38. package/dist/node/.lango/bignumber.mjs +3119 -0
  39. package/dist/node/.lango/runtime.mjs +609 -0
  40. package/dist/node/.lango/xmldom/conventions.js +429 -0
  41. package/dist/node/.lango/xmldom/dom-parser.js +591 -0
  42. package/dist/node/.lango/xmldom/dom.js +3759 -0
  43. package/dist/node/.lango/xmldom/entities.js +2171 -0
  44. package/dist/node/.lango/xmldom/errors.js +205 -0
  45. package/dist/node/.lango/xmldom/grammar.js +559 -0
  46. package/dist/node/.lango/xmldom/index.js +41 -0
  47. package/dist/node/.lango/xmldom/package.json +1 -0
  48. package/dist/node/.lango/xmldom/sax.js +983 -0
  49. package/dist/node/.lango/xmldom.LICENSE.md +8 -0
  50. package/dist/node/browser_host.mjs +351 -0
  51. package/dist/node/browser_host.mjs.map +1 -0
  52. package/dist/node/create_app.mjs +118 -0
  53. package/dist/node/create_app.mjs.map +1 -0
  54. package/dist/presentation.mjs +89 -0
  55. package/dist/presentation.mjs.map +1 -0
  56. package/dist/protocol.mjs +706 -0
  57. package/dist/protocol.mjs.map +1 -0
  58. package/dist/session.mjs +431 -0
  59. package/dist/session.mjs.map +1 -0
  60. package/dist/tokens.mjs +298 -0
  61. package/dist/tokens.mjs.map +1 -0
  62. package/examples/contacts.lango +302 -0
  63. package/examples/contacts_flow.lango +174 -0
  64. package/examples/contacts_store.lango +109 -0
  65. package/examples/contacts_store_test.lango +65 -0
  66. package/examples/demo.css +72 -0
  67. package/examples/demo_test.lango +356 -0
  68. package/examples/index.html +28 -0
  69. package/examples/pages.lango +180 -0
  70. package/examples/server.lango +189 -0
  71. package/examples/worker.lango +142 -0
  72. package/package.json +64 -4
  73. package/src/application.lango +327 -0
  74. package/src/browser_host.lango +276 -0
  75. package/src/coordinator.lango +57 -0
  76. package/src/demo.lango +110 -0
  77. package/src/demo_controls.lango +53 -0
  78. package/src/errors.lango +149 -0
  79. package/src/errors_test.lango +157 -0
  80. package/src/form_state.lango +168 -0
  81. package/src/heartbeat.lango +230 -0
  82. package/src/heartbeat_test.lango +479 -0
  83. package/src/inheritance.lango +167 -0
  84. package/src/input_values.lango +37 -0
  85. package/src/library.lango +571 -0
  86. package/src/logout_test.lango +564 -0
  87. package/src/navigation.lango +309 -0
  88. package/src/navigation_test.lango +556 -0
  89. package/src/presentation.lango +55 -0
  90. package/src/protocol.lango +787 -0
  91. package/src/renderer_test.lango +1986 -0
  92. package/src/session.lango +313 -0
  93. package/src/session_test.lango +455 -0
  94. package/src/tabs_test.lango +216 -0
  95. package/src/tokens.lango +215 -0
  96. package/template/.vscode/extensions.json +3 -0
  97. package/template/.vscode/settings.json +9 -0
  98. package/template/README.md +40 -0
  99. package/template/gitignore +4 -0
  100. package/template/package.json +22 -0
  101. package/template/public/app.css +4 -0
  102. package/template/public/index.html +24 -0
  103. package/template/src/client.lango +78 -0
  104. package/template/src/pages.lango +55 -0
  105. package/template/src/server.lango +24 -0
  106. package/template/src/worker.lango +77 -0
  107. package/template/test/app.lango +9 -0
  108. package/tools/create_app.lango +88 -0
  109. package/tools/create_app_test.lango +43 -0
  110. package/tools/starter_test.lango +227 -0
@@ -0,0 +1,215 @@
1
+ import js global Promise
2
+ import js global localStorage
3
+ import js global fetch
4
+ export browserTokenStore(key = "lango:last-token")
5
+
6
+
7
+ export class TokenStore
8
+ methods
9
+ latest()
10
+ save(token)
11
+ initialize(path, previousToken = null)
12
+ ready()
13
+ initializing()
14
+ initialized(token, generation)
15
+ current(generation)
16
+ cancelInitialization()
17
+ clear()
18
+ logout(path)
19
+ logoutReady(path, generation)
20
+ loggedOut(previousToken, generation)
21
+ bootstrapSeed(previousToken)
22
+
23
+ TokenStore(storage = null, key = "lango:last-token")
24
+ if !is_string(key) or key == ""
25
+ throw "UiTokenStorageKeyRequired"
26
+ @storage = storage
27
+ @key = key
28
+ @latest = null
29
+ @ready = Promise/resolve()
30
+ @initializing = false
31
+ @generation = 0
32
+ if storage != null
33
+ try
34
+ token = storage.getItem(key)
35
+ if is_string(token) and token != "" and token.length <= 16384
36
+ @latest = token
37
+ catch error
38
+ storageUnavailable()
39
+
40
+ TokenStore:latest()
41
+ return @latest
42
+
43
+ TokenStore:ready()
44
+ return @ready
45
+
46
+ TokenStore:initializing()
47
+ return @initializing
48
+
49
+ TokenStore:current(generation)
50
+ return generation == @generation
51
+
52
+ TokenStore:initialized(token, generation)
53
+ if !current(generation)
54
+ throw "UiTokenOperationSuperseded"
55
+ if token != null
56
+ save(token)
57
+ @initializing = false
58
+ return token
59
+
60
+ TokenStore:cancelInitialization()
61
+ @generation++
62
+ @initializing = false
63
+ @ready = Promise/resolve(@latest)
64
+ return null
65
+
66
+ TokenStore:clear()
67
+ previous = @latest
68
+ cancelInitialization()
69
+ @latest = null
70
+ @ready = Promise/resolve()
71
+ if @storage != null
72
+ try
73
+ persisted = @storage.getItem(@key)
74
+ if previous != null and persisted == previous
75
+ @storage.removeItem(@key)
76
+ catch error
77
+ storageUnavailable()
78
+ return null
79
+
80
+ TokenStore:initialize(path, previousToken = null)
81
+ if !is_string(path) or !path.startsWith("/") or path.startsWith("//") or path.includes("\\")
82
+ throw "UiTokenBootstrapRequiresSameOriginPath"
83
+ cancelInitialization()
84
+ generation = @generation
85
+ headers = {
86
+ "Content-Type": "application/json"
87
+ }
88
+ previousToken = bootstrapSeed(previousToken)
89
+ if previousToken != null
90
+ headers.Authorization = "Bearer ${previousToken}"
91
+ @initializing = true
92
+ pending = fetch(path, {
93
+ method: "POST"
94
+ headers: headers
95
+ body: "{}"
96
+ cache: "no-store"
97
+ redirect: "error"
98
+ }).then((response)
99
+ capture generation
100
+ return initializedToken(@this, response, generation)
101
+ )
102
+ @ready = pending
103
+ pending.catch((error)
104
+ capture generation
105
+ bootstrapFailed(@this, generation)
106
+ )
107
+ return pending
108
+
109
+ TokenStore:bootstrapSeed(previousToken)
110
+ if previousToken != null
111
+ return previousToken
112
+ if @storage != null
113
+ try
114
+ persisted = @storage.getItem(@key)
115
+ if is_string(persisted) and persisted != "" and persisted.length <= 16384
116
+ return persisted
117
+ catch error
118
+ storageUnavailable()
119
+ return @latest
120
+
121
+ initializedToken(store, response, generation)
122
+ token = response.headers.get("X-Lango-Token")
123
+ if !response.ok or token == null
124
+ throw "UiTokenBootstrapFailed"
125
+ return response.json().then((body)
126
+ capture store
127
+ capture token
128
+ capture generation
129
+ return store.initialized(token, generation)
130
+ )
131
+
132
+ bootstrapFailed(store, generation)
133
+ context log
134
+ if !store.current(generation)
135
+ return null
136
+ log.err("Token bootstrap failed")
137
+ store.initialized(null, generation)
138
+ return null
139
+
140
+ TokenStore:logout(path)
141
+ if !is_string(path) or !path.startsWith("/") or path.startsWith("//") or path.includes("\\")
142
+ throw "UiLogoutRequiresSameOriginPath"
143
+ generation = @generation
144
+ waiting = @ready
145
+ ready = waiting.catch((error)
146
+ return null
147
+ )
148
+ return ready.then(()
149
+ capture path
150
+ capture generation
151
+ return logoutReady(path, generation)
152
+ )
153
+
154
+ TokenStore:logoutReady(path, generation)
155
+ if !current(generation)
156
+ throw "UiTokenOperationSuperseded"
157
+ previous = @latest
158
+ if previous == null
159
+ throw "UiLogoutTokenRequired"
160
+ return fetch(path, {
161
+ method: "POST"
162
+ headers: {
163
+ "Content-Type": "application/json"
164
+ Authorization: "Bearer ${previous}"
165
+ }
166
+ body: "{}"
167
+ cache: "no-store"
168
+ redirect: "error"
169
+ }).then((response)
170
+ capture previous
171
+ capture generation
172
+ return readLogout(@this, response, previous, generation)
173
+ )
174
+
175
+ readLogout(store, response, previous, generation)
176
+ if !response.ok
177
+ throw "UiLogoutHttpError: ${response.status}"
178
+ return response.json().then((body)
179
+ capture store
180
+ capture previous
181
+ capture generation
182
+ if !is_object(body) or body.loggedOut != true
183
+ throw "UiInvalidLogoutResponse"
184
+ return store.loggedOut(previous, generation)
185
+ )
186
+
187
+ TokenStore:loggedOut(previousToken, generation)
188
+ if !current(generation)
189
+ throw "UiTokenOperationSuperseded"
190
+ clear()
191
+ return previousToken
192
+
193
+ TokenStore:save(token)
194
+ if !is_string(token) or token == "" or token.length > 16384
195
+ throw "UiInvalidToken"
196
+ @latest = token
197
+ if @storage != null
198
+ try
199
+ @storage.setItem(@key, token)
200
+ catch error
201
+ storageUnavailable()
202
+ return null
203
+
204
+ browserTokenStore(key = "lango:last-token")
205
+ storage = null
206
+ try
207
+ storage = localStorage
208
+ catch error
209
+ storageUnavailable()
210
+ return new TokenStore(storage, key)
211
+
212
+ storageUnavailable()
213
+ context log
214
+ log.warn("Token persistence is unavailable; this session continues in memory")
215
+ return null
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["lango-project.lango-vscode"]
3
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "files.associations": {
3
+ "*.lango": "lango"
4
+ },
5
+ "[lango]": {
6
+ "editor.tabSize": 4,
7
+ "editor.insertSpaces": true
8
+ }
9
+ }
@@ -0,0 +1,40 @@
1
+ # {{APP_NAME}}
2
+
3
+ A Lango API/UI application using protocol 1. Requires Node.js 24 or newer.
4
+
5
+ ```sh
6
+ npm install
7
+ npm test
8
+ npm run build
9
+ npm start
10
+ ```
11
+
12
+ Open http://localhost:8080/ (or refresh http://localhost:8080/home directly).
13
+ Stop with Ctrl+C. Change the two local ports in `src/server.lango` if needed.
14
+ Rebuild and restart after changing source or assets.
15
+ BrowserHost limits incoming bodies to 1 MiB and a 30-second upload deadline.
16
+ Set `bodyLimit` and `bodyTimeoutMs` in its options to change both the proxy and
17
+ worker API limits. The worker API's loopback port provides GET `/health`
18
+ (liveness) and `/ready` (admission capacity).
19
+ Optional `rateLimit`, `rateWindowMs` and `rateMaxClients` protect the browser
20
+ POST entry; the general rate limit defaults to disabled.
21
+ The browser's ErrorReporter sends only fixed categories and bounded repeat counts
22
+ to `/_lango/client-error`; raw messages, stacks, URLs and form values are omitted.
23
+
24
+ - `src/client.lango` mounts the browser application, URL handling and dirty guards.
25
+ - `src/pages.lango` defines the shared page/template registry.
26
+ - `src/worker.lango` handles synchronous API/UI events and server validation.
27
+ - `src/server.lango` starts the local BrowserHost with explicit asset paths.
28
+ - `public/` contains the HTML shell, import map and theme CSS.
29
+
30
+ Save validates the form and acknowledges the displayed name. This starter does
31
+ not persist business data; add a repository when saving to a database. Runtime
32
+ JWT keys and replay state are stored in the ignored `.lango/state/` directory.
33
+ Dependencies are pinned to one package release set; commit the lock
34
+ file produced by `npm install`. Build artifacts stay in ignored `dist/` folders.
35
+
36
+ Install the Lango VS Code extension (Marketplace or manual VSIX). The repository
37
+ includes extension recommendations and four-space settings.
38
+
39
+ BrowserHost listens on loopback and supplies same-origin HTML/assets/API for
40
+ local development. Configure external hosting separately when deploying.
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ dist/
3
+ .lango/
4
+ *.log
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "{{APP_NAME}}",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "lango build src/client.lango --out dist/browser/client.mjs --target browser && lango build src/worker.lango --out dist/server/worker.mjs && lango build src/server.lango --out dist/server/server.mjs --executable",
8
+ "start": "node dist/server/server.mjs",
9
+ "test": "lango test test/app.lango --build-dir .lango/test"
10
+ },
11
+ "dependencies": {
12
+ "@lango-project/lango-api": "{{API_VERSION}}",
13
+ "@lango-project/lango-ui": "{{UI_VERSION}}",
14
+ "@lango-project/lango-client": "{{CLIENT_VERSION}}"
15
+ },
16
+ "devDependencies": {
17
+ "@lango-project/lango-js": "{{JS_VERSION}}"
18
+ },
19
+ "engines": {
20
+ "node": ">=24"
21
+ }
22
+ }
@@ -0,0 +1,4 @@
1
+ body { max-width: 40rem; margin: 2rem auto; padding: 0 1rem; font: 1rem system-ui, sans-serif; }
2
+ input, button { display: block; padding: 0.6rem; margin-block: 0.75rem; font: inherit; }
3
+ [aria-invalid="true"] { outline: 2px solid #b91c1c; }
4
+ #error { color: #b91c1c; }
@@ -0,0 +1,24 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>{{APP_NAME}}</title>
7
+ <link rel="stylesheet" href="/assets/app.css">
8
+ <script type="importmap">
9
+ {
10
+ "imports": {
11
+ "@lango-project/lango-client/application": "/vendor/lango-client/application.mjs",
12
+ "@lango-project/lango-client/navigation": "/vendor/lango-client/navigation.mjs",
13
+ "@lango-project/lango-client/errors": "/vendor/lango-client/errors.mjs"
14
+ }
15
+ }
16
+ </script>
17
+ </head>
18
+ <body>
19
+ <h1>{{APP_NAME}}</h1>
20
+ <main id="app"></main>
21
+ <p id="error" role="alert"></p>
22
+ <script type="module" src="/app/client.mjs"></script>
23
+ </body>
24
+ </html>
@@ -0,0 +1,78 @@
1
+ import js global document
2
+ import js global window
3
+ import js "@lango-project/lango-client/application" as ui
4
+ import js "@lango-project/lango-client/navigation" as routing
5
+ import js "@lango-project/lango-client/errors" as reports
6
+
7
+ global app = start()
8
+
9
+ class Errors
10
+ methods
11
+ error(error)
12
+ clear()
13
+
14
+ Errors(reporter)
15
+ @reporter = reporter
16
+
17
+ Errors:error(error)
18
+ @reporter.error(error)
19
+ element = document.getElementById("error")
20
+ element.textContent = "Please correct the form or try the request again."
21
+
22
+ Errors:clear()
23
+ element = document.getElementById("error")
24
+ element.textContent = ""
25
+
26
+ start()
27
+ reporter = new reports/ErrorReporter({
28
+ window: window
29
+ })
30
+ errors = new Errors(reporter)
31
+ application = new ui/Application(document, document.getElementById("app"), {
32
+ type: "Form"
33
+ name: "page"
34
+ controls: [{
35
+ type: "Value"
36
+ name: "url"
37
+ value: ""
38
+ }, {
39
+ type: "Value"
40
+ name: "template"
41
+ value: null
42
+ }, {
43
+ type: "Container"
44
+ name: "content"
45
+ controls: []
46
+ }]
47
+ }, {
48
+ bootstrapPath: "/_lango/start"
49
+ storageKey: "{{APP_NAME}}:token"
50
+ window: window
51
+ errors: errors
52
+ })
53
+ root = application.control
54
+ url = root.controls[0]
55
+ changed = (event)
56
+ capture application
57
+ capture url
58
+ url.setValue(event.url)
59
+ session = application.session("page")
60
+ return session.send("/app/url", "url", null)
61
+ canLeave = (event)
62
+ capture application
63
+ return application.confirmDiscard(window)
64
+ navigation = new routing/Navigation(window, {
65
+ rootRedirect: "/home"
66
+ onUrl: changed
67
+ beforeNavigate: canLeave
68
+ })
69
+ opening = navigation.start()
70
+ opening.catch((error)
71
+ capture errors
72
+ errors.error(error)
73
+ )
74
+ return {
75
+ application: application
76
+ navigation: navigation
77
+ reporter: reporter
78
+ }
@@ -0,0 +1,55 @@
1
+ import js "@lango-project/lango-ui" as ui
2
+
3
+ export createPages()
4
+
5
+ createPages()
6
+ pages = new ui/Pages()
7
+ pages.template({
8
+ path: "/"
9
+ function: layout
10
+ })
11
+ pages.page({
12
+ path: "/home"
13
+ function: home
14
+ })
15
+ return pages
16
+
17
+ layout(selected)
18
+ return {
19
+ type: "Container"
20
+ controls: [{
21
+ type: "Container"
22
+ name: "__content__"
23
+ controls: []
24
+ }]
25
+ }
26
+
27
+ home(selected)
28
+ return {
29
+ type: "Form"
30
+ name: "__content__"
31
+ controls: [{
32
+ type: "Text"
33
+ name: "fullName"
34
+ label: "Your name"
35
+ value: ""
36
+ validation: {
37
+ required: true
38
+ minLength: 2
39
+ maxLength: 100
40
+ }
41
+ }, {
42
+ type: "Button"
43
+ name: "saveButton"
44
+ text: "Save"
45
+ event: "/app/save"
46
+ validate: true
47
+ }, {
48
+ type: "Text"
49
+ name: "status"
50
+ label: "Save status"
51
+ value: "Enter your name, then save."
52
+ enabled: false
53
+ trackChanges: false
54
+ }]
55
+ }
@@ -0,0 +1,24 @@
1
+ import js "node:path" as path
2
+ import js global process
3
+ import js "@lango-project/lango-client/host" as web
4
+ import "./pages"
5
+ createPages()
6
+
7
+ export main(args)
8
+
9
+ main(args)
10
+ host = new web/BrowserHost({
11
+ appRoot: process.cwd()
12
+ pages: createPages()
13
+ worker: "dist/server/worker.mjs"
14
+ shell: "public/index.html"
15
+ port: 8080
16
+ apiPort: 8081
17
+ assets: {
18
+ "/app/client.mjs": "dist/browser/client.mjs"
19
+ "/app/.lango/runtime.mjs": "dist/browser/.lango/runtime.mjs"
20
+ "/app/.lango/bignumber.mjs": "dist/browser/.lango/bignumber.mjs"
21
+ "/assets/app.css": "public/app.css"
22
+ }
23
+ })
24
+ return host.start()
@@ -0,0 +1,77 @@
1
+ import js "@lango-project/lango-api" as api
2
+ import js "@lango-project/lango-ui" as ui
3
+ import "./pages"
4
+ createPages()
5
+
6
+ export createWorker(options)
7
+
8
+ global dispatcher = null
9
+ global pages = null
10
+
11
+ createWorker(options)
12
+ global dispatcher
13
+ global pages
14
+ pages = createPages()
15
+ dispatcher = new ui/Dispatcher(options.appRoot)
16
+ dispatcher.event({
17
+ path: "/app/url"
18
+ function: page
19
+ })
20
+ dispatcher.event({
21
+ path: "/app/save"
22
+ function: save
23
+ })
24
+ routes = new api/Routes()
25
+ routes.endpoint({
26
+ path: "/app/*"
27
+ function: handle
28
+ anonymous: true
29
+ })
30
+ return {
31
+ routes: routes.values()
32
+ preload: [pages, dispatcher]
33
+ }
34
+
35
+ handle(input)
36
+ global dispatcher
37
+ context request
38
+ context response
39
+ if !is_string(request.headers.authorization)
40
+ response.status(401).send({
41
+ error: "BootstrapRequired"
42
+ })
43
+ return null
44
+ return dispatcher.handle(input)
45
+
46
+ page(input)
47
+ global pages
48
+ context form
49
+ context response
50
+ rendered = pages.render({
51
+ url: form.url.value
52
+ template: form.template.value
53
+ })
54
+ result = new ui/Response(input.formId, input.seqno)
55
+ result.replace(rendered.target, rendered.control)
56
+ result.value("template", rendered.template)
57
+ response.send(result.result())
58
+ return null
59
+
60
+ save(input)
61
+ context form
62
+ context response
63
+ name = input.values.fullName
64
+ if !is_string(name)
65
+ response.status(400).send({
66
+ error: "InvalidName"
67
+ })
68
+ return null
69
+ name = name.trim()
70
+ if name.length < 2 or name.length > 100
71
+ form.fullName.error = "Enter a name of 2 to 100 characters."
72
+ return null
73
+ form.fullName.savedValue = name
74
+ form.status.value = "Saved: ${name}"
75
+ return {
76
+ fullName: name
77
+ }
@@ -0,0 +1,9 @@
1
+ import js "@lango-project/lango-ui" as ui
2
+
3
+ test "UI protocol and basic response are available"
4
+ assert ui/protocolVersion() == 1
5
+ response = new ui/Response("profile", 1)
6
+ response.value("fullName", "Ada")
7
+ result = response.result()
8
+ assert result.protocol == 1
9
+ assert result.vals.fullName == "Ada"
@@ -0,0 +1,88 @@
1
+ import js "node:fs" as fs
2
+ import js "node:path" as path
3
+ import js global process
4
+ import js global RegExp
5
+
6
+ export main(args)
7
+
8
+ main(args)
9
+ try
10
+ return createProject(args)
11
+ catch error
12
+ process.stderr.write("${error}\n")
13
+ process.exitCode = 2
14
+ return null
15
+
16
+ createProject(args)
17
+ if args.length != 1 or args[0] == "--help"
18
+ println("Usage: lango-create-app <directory>")
19
+ if args.length != 1
20
+ process.exitCode = 2
21
+ return null
22
+ target = path.resolve(args[0])
23
+ name = path.basename(target)
24
+ pattern = new RegExp("^[a-z][a-z0-9-]*$")
25
+ if !pattern.test(name)
26
+ throw "StarterDirectoryNameMustBeLowercaseKebabCase"
27
+ if fs.existsSync(target)
28
+ for fs.readdirSync(target) as entry
29
+ if entry != ".git"
30
+ throw "StarterRequiresEmptyDirectory"
31
+ root = packageRoot()
32
+ manifest = from_json(fs.readFileSync(path.join(root, "package.json"), "utf8"))
33
+ release = manifest.langoStarter
34
+ replacements = {
35
+ APP_NAME: name
36
+ JS_VERSION: release.compiler
37
+ API_VERSION: release.api
38
+ UI_VERSION: release.ui
39
+ CLIENT_VERSION: manifest.version
40
+ }
41
+ files = []
42
+ readTemplate(path.join(root, "template"), "", files, replacements)
43
+ fs.mkdirSync(target, {
44
+ recursive: true
45
+ })
46
+ for files as file
47
+ output = path.join(target, file.name)
48
+ fs.mkdirSync(path.dirname(output), {
49
+ recursive: true
50
+ })
51
+ fs.writeFileSync(output, file.content, {
52
+ flag: "wx"
53
+ })
54
+ println("Created ${name}. Run npm install, npm run build, then npm start in ${target}.")
55
+
56
+ packageRoot()
57
+ current = path.dirname(fs.realpathSync(process.argv[1]))
58
+ loop
59
+ file = path.join(current, "package.json")
60
+ if fs.existsSync(file)
61
+ metadata = from_json(fs.readFileSync(file, "utf8"))
62
+ if metadata.name == "@lango-project/lango-client"
63
+ return current
64
+ parent = path.dirname(current)
65
+ if parent == current
66
+ throw "StarterPackageNotFound"
67
+ current = parent
68
+
69
+ readTemplate(directory, prefix, files, replacements)
70
+ entries = fs.readdirSync(directory, {
71
+ withFileTypes: true
72
+ })
73
+ for entries as entry
74
+ source = path.join(directory, entry.name)
75
+ name = path.join(prefix, entry.name)
76
+ if entry.isDirectory()
77
+ readTemplate(source, name, files, replacements)
78
+ else
79
+ if entry.isFile()
80
+ if entry.name == "gitignore"
81
+ name = ".gitignore"
82
+ content = fs.readFileSync(source, "utf8")
83
+ for replacements as key: value
84
+ content = content.replaceAll("{{${key}}}", value)
85
+ files.add({
86
+ name: name
87
+ content: content
88
+ })