scaffold-sesi 1.0.1 → 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.
Files changed (38) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +216 -216
  3. package/bin/scaffold-sesi.cjs +48 -48
  4. package/lib/cli.sesi +464 -0
  5. package/lib/local.sesi +52 -52
  6. package/lib/term.sesi +4 -4
  7. package/lib/utils.sesi +29 -27
  8. package/main.sesi +325 -307
  9. package/package.json +42 -42
  10. package/src/lint.sesi +1091 -1615
  11. package/src/os.sesi +544 -0
  12. package/src/test.sesi +271 -271
  13. package/templates/api/config.sesi +1 -1
  14. package/templates/api/lib/test.sesi +1 -1
  15. package/templates/api/main.sesi +6 -6
  16. package/templates/api/src/app.sesi +10 -10
  17. package/templates/api/src/handlers.sesi +11 -11
  18. package/templates/api/tests/test_api.sesi +20 -20
  19. package/templates/api.sesi +6 -6
  20. package/templates/basic.sesi +4 -4
  21. package/templates/cli/lib/test.sesi +1 -1
  22. package/templates/cli/main.sesi +4 -4
  23. package/templates/cli/src/commands.sesi +21 -10
  24. package/templates/cli/src/greeting.sesi +4 -4
  25. package/templates/cli/tests/test_cli.sesi +12 -12
  26. package/templates/cli.sesi +6 -6
  27. package/templates/shared/load.sesi +15 -15
  28. package/templates/web/config.sesi +1 -1
  29. package/templates/web/lib/test.sesi +1 -1
  30. package/templates/web/main.sesi +5 -5
  31. package/templates/web/src/client/controller.sesi +19 -19
  32. package/templates/web/src/client/state.sesi +18 -18
  33. package/templates/web/src/handlers.sesi +21 -21
  34. package/templates/web/src/render.sesi +21 -21
  35. package/templates/web/src/styles.css +9 -9
  36. package/templates/web/src/templates/home.html +20 -20
  37. package/templates/web/tests/test_web.sesi +56 -56
  38. package/templates/web.sesi +6 -6
package/lib/cli.sesi ADDED
@@ -0,0 +1,464 @@
1
+ /**
2
+ Finds an option definition object by its name or short single-character flag.
3
+
4
+ Parameters:
5
+ - `definitions`: An array of option definition objects to search through.
6
+ - `name`: The option identifier or single-letter short flag name to look up.
7
+ - `shortName`: A boolean indicating whether to search against the `short` field (`true`) or the long `name` field (`false`). Defaults to `false`.
8
+
9
+ Returns:
10
+ - The matching option definition object if found, or `null` if no match exists.
11
+
12
+ Example:
13
+ ```sesi
14
+ let defs = [
15
+ {name: "port", short: "p", type: "number"},
16
+ {name: "verbose", short: "v", type: "bool"}
17
+ ]
18
+ let match = cli_find(defs, "p", true)
19
+ show match.name // port
20
+ ```
21
+
22
+ Notes:
23
+ - Performs a linear search across the definitions array and returns on first match.
24
+ */
25
+ fn cli_find(definitions, name, shortName = false) {
26
+ for definition in definitions {
27
+ if shortName {
28
+ if definition.short == name { return definition }
29
+ } else {
30
+ if definition.name == name { return definition }
31
+ }
32
+ }
33
+ return null
34
+ }
35
+
36
+ /**
37
+ Coerces a raw command-line string value into a typed representation based on the expected type.
38
+
39
+ Parameters:
40
+ - `raw`: The raw string or input value from the command line.
41
+ - `type`: The target data type name (`"boolean"`, `"bool"`, `"number"`, `"num"`, or `"string"`).
42
+
43
+ Returns:
44
+ - An object containing `{ok: bool, value: any}` where `ok` indicates if the conversion succeeded and `value` holds the coerced value.
45
+
46
+ Example:
47
+ ```sesi
48
+ let res = cli_convert("8080", "number")
49
+ if res.ok {
50
+ show "Parsed port:" res.value
51
+ }
52
+ ```
53
+
54
+ Notes:
55
+ - Boolean conversion accepts `"true"`, `"1"`, `"yes"`, and `"on"` as `true`, and `"false"`, `"0"`, `"no"`, and `"off"` as `false` (case-insensitive).
56
+ - Number conversion checks for empty strings and invalid numeric values (`NaN`).
57
+ - Unrecognized types default to returning `{ok: true, value: str(raw)}`.
58
+ */
59
+ fn cli_convert(raw, type) {
60
+ if type == "boolean" || type == "bool" {
61
+ let value = to_lower(str(raw))
62
+ if value == "true" || value == "1" || value == "yes" || value == "on" {
63
+ return {ok: true, value: true}
64
+ }
65
+ if value == "false" || value == "0" || value == "no" || value == "off" {
66
+ return {ok: true, value: false}
67
+ }
68
+ return {ok: false, value: null}
69
+ }
70
+
71
+ if type == "number" || type == "num" {
72
+ if trim(str(raw)) == "" { return {ok: false, value: null} }
73
+ let value = num(raw)
74
+ if value == null || value != value { return {ok: false, value: null} }
75
+ return {ok: true, value: value}
76
+ }
77
+
78
+ return {ok: true, value: str(raw)}
79
+ }
80
+
81
+ /**
82
+ Expands combined short-flag tokens into normalized individual command-line tokens.
83
+
84
+ Parameters:
85
+ - `argv`: An array of raw argument tokens passed into the program.
86
+ - `definitions`: An array of option definition objects used to determine flag types and value requirements.
87
+
88
+ Returns:
89
+ - An array of normalized string tokens with combined short flags unpacked.
90
+
91
+ Example:
92
+ ```sesi
93
+ let defs = [
94
+ {name: "all", short: "a", type: "bool"},
95
+ {name: "force", short: "f", type: "bool"},
96
+ {name: "output", short: "o", type: "string"}
97
+ ]
98
+ let expanded = cli_expand(["-afo", "out.txt"], defs)
99
+ show expanded // ["-a", "-f", "-o", "out.txt"]
100
+ ```
101
+
102
+ Notes:
103
+ - Handles grouped boolean flags (e.g., `-xzf` expands to `["-x", "-z", "-f"]`).
104
+ - Supports inline non-boolean argument values attached to short flags (e.g., `-oFile` expands to `"-o=File"`).
105
+ */
106
+ fn cli_expand(argv, definitions) {
107
+ let expanded = []
108
+
109
+ for token in argv {
110
+ let characters = split(token, "")
111
+ if len(characters) < 3 || characters[0] != "-" || characters[1] == "-" {
112
+ push(expanded, token)
113
+ continue
114
+ }
115
+
116
+ let first = cli_find(definitions, characters[1], true)
117
+ if first == null {
118
+ push(expanded, token)
119
+ continue
120
+ }
121
+
122
+ let index = 1
123
+ while index < len(characters) {
124
+ let shortName = characters[index]
125
+ let definition = cli_find(definitions, shortName, true)
126
+
127
+ if definition == null {
128
+ push(expanded, "-" + shortName)
129
+ index = index + 1
130
+ continue
131
+ }
132
+
133
+ let type = definition.type || "string"
134
+ if type == "boolean" || type == "bool" {
135
+ push(expanded, "-" + shortName)
136
+ index = index + 1
137
+ continue
138
+ }
139
+
140
+ let remainder = join(slice(characters, index + 1, len(characters)), "")
141
+ if remainder == "" {
142
+ push(expanded, "-" + shortName)
143
+ } else if split(remainder, "")[0] == "=" {
144
+ push(expanded, "-" + shortName + remainder)
145
+ } else {
146
+ push(expanded, "-" + shortName + "=" + remainder)
147
+ }
148
+ break
149
+ }
150
+ }
151
+
152
+ return expanded
153
+ }
154
+
155
+ /**
156
+ Parses raw CLI arguments into options, positional arguments, and validation error messages according to provided schemas.
157
+
158
+ Parameters:
159
+ - `argv`: An array of raw command-line string arguments (such as the global `args`).
160
+ - `definitions`: An array of option definition objects containing flags and configuration schema.
161
+ - `positionalDefinitions`: An optional array of schema definitions for positional arguments. Defaults to `[]`.
162
+
163
+ Returns:
164
+ - An object containing parsed CLI state:
165
+ - `options`: Key-value map of parsed option flags.
166
+ - `positionals`: Array of positional argument strings in order.
167
+ - `namedPositionals`: Key-value map of bound positional arguments based on `positionalDefinitions`.
168
+ - `errors`: Array of validation or parsing error strings encountered.
169
+ - `ok`: Boolean indicating whether parsing completed without errors (`len(errors) == 0`).
170
+ - `help`: Boolean indicating if `--help` or `-h` was present.
171
+
172
+ Example:
173
+ ```sesi
174
+ let optDefs = [
175
+ {name: "port", short: "p", type: "number", default: 8080},
176
+ {name: "verbose", short: "v", type: "bool"}
177
+ ]
178
+ let posDefs = [
179
+ {name: "file", required: true}
180
+ ]
181
+
182
+ let parsed = parse(args, optDefs, posDefs)
183
+ if !parsed.ok {
184
+ show "Parse error:" parsed.errors[0]
185
+ } else {
186
+ show "Port:" parsed.options.port
187
+ show "Target file:" parsed.namedPositionals.file
188
+ }
189
+ ```
190
+
191
+ Notes:
192
+ - Terminates option parsing when encountering the standard `--` separator token.
193
+ - Supports `--key=value` and `--key value` formats, as well as multiple values for options flagged with `multiple: true`.
194
+ - Automatically verifies required options and positional parameters unless `help` is triggered.
195
+ */
196
+ export fn parse(argv, definitions, positionalDefinitions = []) {
197
+ let options = {}
198
+ let positionals = []
199
+ let errors = []
200
+ let help = false
201
+ let tokens = cli_expand(argv, definitions)
202
+ for definition in definitions {
203
+ if definition.multiple { options[definition.name] = []
204
+ } else if includes(keys(definition), "default") { options[definition.name] = definition.default
205
+ } else if definition.type == "boolean" || definition.type == "bool" { options[definition.name] = false
206
+ } else { options[definition.name] = null }
207
+ }
208
+ let index = 0
209
+ let endOfOptions = false
210
+ while index < len(tokens) {
211
+ let token = tokens[index]
212
+ let characters = split(token, "")
213
+ if !endOfOptions && token == "--" {
214
+ endOfOptions = true
215
+ index = index + 1
216
+ continue
217
+ }
218
+ if !endOfOptions && (token == "--help" || token == "-h") {
219
+ help = true
220
+ index = index + 1
221
+ continue
222
+ }
223
+ if endOfOptions || len(characters) < 2 || characters[0] != "-" || token == "-" {
224
+ push(positionals, token)
225
+ index = index + 1
226
+ continue
227
+ }
228
+ let isLong = characters[1] == "-"
229
+ let prefixLength = 1
230
+ if isLong { prefixLength = 2 }
231
+ let body = join(slice(characters, prefixLength, len(characters)), "")
232
+ let parts = split(body, "=")
233
+ let name = parts[0]
234
+ let definition = cli_find(definitions, name, !isLong)
235
+ if definition == null {
236
+ push(errors, "Unknown option: " + token)
237
+ index = index + 1
238
+ continue
239
+ }
240
+ let type = definition.type || "string"
241
+ let raw = any
242
+ if len(parts) > 1 { raw = join(slice(parts, 1, len(parts)), "=")
243
+ } else if type == "boolean" || type == "bool" { raw = "true"
244
+ } else if index + 1 < len(tokens) {
245
+ index = index + 1
246
+ raw = tokens[index]
247
+ } else {
248
+ push(errors, "Missing value for --" + definition.name)
249
+ index = index + 1
250
+ continue
251
+ }
252
+ let converted = cli_convert(raw, type)
253
+ if !converted.ok { push(errors, "Invalid " + type + " value for --" + definition.name + ": " + str(raw))
254
+ } else if definition.multiple { push(options[definition.name], converted.value)
255
+ } else { options[definition.name] = converted.value }
256
+ index = index + 1
257
+ }
258
+ for definition in definitions {
259
+ if definition.required && !help {
260
+ let value = options[definition.name]
261
+ if value == null || (definition.multiple && len(value) == 0) { push(errors, "Missing required option: --" + definition.name) }
262
+ }
263
+ }
264
+ let namedPositionals = {}
265
+ for position = 0 to len(positionalDefinitions) {
266
+ let definition = positionalDefinitions[position]
267
+ let raw = positionals[position]
268
+ if raw == null {
269
+ if contains(keys(definition), "default") { namedPositionals[definition.name] = definition.default
270
+ } else {
271
+ namedPositionals[definition.name] = null
272
+ if definition.required && !help { push(errors, "Missing positional argument: " + definition.name) }
273
+ }
274
+ continue
275
+ }
276
+ let type = definition.type || "string"
277
+ let converted = cli_convert(raw, type)
278
+ if converted.ok { namedPositionals[definition.name] = converted.value
279
+ } else {
280
+ namedPositionals[definition.name] = null
281
+ push(errors, "Invalid " + type + " value for " + definition.name + ": " + raw)
282
+ }
283
+ }
284
+ return {
285
+ options: options,
286
+ positionals: positionals,
287
+ namedPositionals: namedPositionals,
288
+ errors: errors,
289
+ ok: len(errors) == 0,
290
+ help: help
291
+ }
292
+ }
293
+ /**
294
+ Generates a formatted CLI help and usage string from program details and definition schemas.
295
+
296
+ Parameters:
297
+ - `program`: The executable or script command name.
298
+ - `description`: A brief summary of what the CLI tool does.
299
+ - `definitions`: An array of option definitions detailing flags, types, defaults, and descriptions.
300
+ - `positionalDefinitions`: An optional array of positional parameter definitions. Defaults to `[]`.
301
+
302
+ Returns:
303
+ - A formatted multiline string suitable for printing to stdout when `--help` or `-h` is passed.
304
+
305
+ Example:
306
+ ```sesi
307
+ let optDefs = [
308
+ {name: "port", short: "p", type: "number", default: 3000, description: "Port to bind"},
309
+ {name: "host", type: "string", description: "Bind host address"}
310
+ ]
311
+ let posDefs = [
312
+ {name: "config", required: true, description: "Path to config file"}
313
+ ]
314
+ let helpText = help("myserver", "Runs the application server", optDefs, posDefs)
315
+ show helpText
316
+ ```
317
+
318
+ Notes:
319
+ - Distinguishes between required positionals (`<arg>`) and optional positionals (`[arg]`).
320
+ - Automatically appends `-h, --help` option line to the end of the options section.
321
+ */
322
+ export fn help(program, description, definitions, positionalDefinitions = []) {
323
+ let lines = []
324
+ let usage = "Usage: " + program + " [options]"
325
+ for definition in positionalDefinitions {
326
+ if definition.required { usage = usage + " <" + definition.name + ">"
327
+ } else { usage = usage + " [" + definition.name + "]" }
328
+ }
329
+ push(lines, usage)
330
+ if description {
331
+ push(lines, "")
332
+ push(lines, description)
333
+ }
334
+ if len(positionalDefinitions) > 0 {
335
+ push(lines, "")
336
+ push(lines, "Arguments:")
337
+ for definition in positionalDefinitions {
338
+ let detail = definition.description || ""
339
+ push(lines, " " + definition.name + " " + detail)
340
+ }
341
+ }
342
+ push(lines, "")
343
+ push(lines, "Options:")
344
+ for definition in definitions {
345
+ let label = " --" + definition.name
346
+ if definition.short { label = label + ", -" + definition.short }
347
+ let type = definition.type || "string"
348
+ if type != "boolean" && type != "bool" { label = label + " <" + type + ">" }
349
+ let detail = definition.description || ""
350
+ if definition.required { detail = detail + " (required)" }
351
+ if includes(keys(definition), "default") { detail = detail + " (default: " + str(definition.default) + ")" }
352
+ push(lines, label + " " + trim(detail))
353
+ }
354
+ push(lines, " --help, -h Show this help")
355
+ let newline = "
356
+ "
357
+ return join(lines, newline)
358
+ }
359
+ /**
360
+ Prompts the user interactively via standard input with an optional default value.
361
+
362
+ Parameters:
363
+ - `label`: The prompt message or question displayed to the user.
364
+ - `defaultValue`: An optional fallback value returned if the user presses enter with no input. Defaults to `null`.
365
+
366
+ Returns:
367
+ - The trimmed string entered by the user, or `defaultValue` if the user provided empty input.
368
+
369
+ Example:
370
+ ```sesi
371
+ let username = ask("Enter your name", "guest")
372
+ show "Hello," username
373
+ ```
374
+
375
+ Notes:
376
+ - Displays the default value in brackets `[default]` when provided.
377
+ */
378
+ export fn ask(label, defaultValue = null) {
379
+ let _prompt = label
380
+ if defaultValue != null { _prompt = _prompt + " [" + str(defaultValue) + "]" }
381
+ let answer = trim(input(_prompt + ": "))
382
+ if answer == "" { return defaultValue }
383
+ return answer
384
+ }
385
+ /**
386
+ Displays an interactive yes/no confirmation prompt and blocks until a valid answer is provided.
387
+
388
+ Parameters:
389
+ - `label`: The prompt message or question displayed to the user.
390
+ - `defaultValue`: The default boolean returned if the user presses enter without typing an answer. Defaults to `false`.
391
+
392
+ Returns:
393
+ - `true` if the user confirms with yes/y, or `false` if the user rejects with no/n.
394
+
395
+ Example:
396
+ ```sesi
397
+ let proceed = confirm("Do you want to continue?", false)
398
+ if proceed {
399
+ show "Proceeding with deployment..."
400
+ } else {
401
+ show "Aborted."
402
+ }
403
+ ```
404
+
405
+ Notes:
406
+ - Appends `[Y/n]: ` when `defaultValue` is `true`, and `[y/N]: ` when `defaultValue` is `false`.
407
+ - Re-prompts continuously until a recognizable answer (`"y"`, `"yes"`, `"n"`, `"no"`, or empty for default) is entered.
408
+ */
409
+ export fn confirm(label, defaultValue = false) {
410
+ let suffix = " [y/N]: "
411
+ if defaultValue { suffix = " [Y/n]: " }
412
+ while true {
413
+ let answer = to_lower(trim(input(label + suffix)))
414
+ if answer == "" { return defaultValue }
415
+ if answer == "y" || answer == "yes" { return true }
416
+ if answer == "n" || answer == "no" { return false }
417
+ show "Please enter yes or no."
418
+ }
419
+ }
420
+ /**
421
+ Presents a numbered menu of options to the user and waits for a valid selection.
422
+
423
+ Parameters:
424
+ - `label`: The heading or prompt question displayed above the choices.
425
+ - `choices`: An array of choices, which can be plain strings or objects with `{label, value}` keys.
426
+
427
+ Returns:
428
+ - The selected choice value or object. Returns `null` if the `choices` array is empty.
429
+
430
+ Example:
431
+ ```sesi
432
+ let environments = [
433
+ {label: "Development", value: "dev"},
434
+ {label: "Staging", value: "stage"},
435
+ {label: "Production", value: "prod"}
436
+ ]
437
+ let selected = choose("Select target environment:", environments)
438
+ show "Selected environment:" selected
439
+ ```
440
+
441
+ Notes:
442
+ - Re-prompts the user until an integer within the 1-based index range `[1, len(choices)]` is entered.
443
+ - Extracts and returns the `.value` field if the selected item is an object with a `value` key; otherwise returns the choice element directly.
444
+ */
445
+ export fn choose(label, choices) {
446
+ if len(choices) == 0 { return null }
447
+ show label
448
+ for index = 0 to len(choices) {
449
+ let choice = choices[index]
450
+ let display = choice
451
+ if includes(keys(choice), "label") { display = choice.label }
452
+ show index + 1 ")" display
453
+ }
454
+ while true {
455
+ let answer = trim(input("Choose a number: "))
456
+ let selection = num(answer)
457
+ if answer != "" && selection != null && selection == floor(selection) && selection >= 1 && selection <= len(choices) {
458
+ let choice = choices[selection - 1]
459
+ if includes(keys(choice), "value") { return choice.value }
460
+ return choice
461
+ }
462
+ show "Please choose a number from 1 to" len(choices)
463
+ }
464
+ }
package/lib/local.sesi CHANGED
@@ -1,53 +1,53 @@
1
- export fn generateLicense(name: string, year: string, license: string) -> string {
2
- let licensePlaceholder = ""
3
- if license == "MIT" { licensePlaceholder = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n" }
4
- if license == "Apache-2.0" { licensePlaceholder = "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n" }
5
- if license == "GPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
6
- if license == "BSD-3-Clause" { licensePlaceholder = "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n" }
7
- if license == "MPL-2.0" { licensePlaceholder = "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. \n" }
8
- if license == "AGPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
9
- if license == "LGPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
10
- if license == "EPL-2.0" { licensePlaceholder = "This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/. \n"
11
- } else if license == "Unlicense" { licensePlaceholder = "This is free and unencumbered software released into the public domain.\n"
12
- } else if license == "CC0-1.0" { licensePlaceholder = "The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.\n"
13
- } else if license == "Proprietary" { licensePlaceholder = "All rights reserved. This software is proprietary and confidential. Unauthorized copying of this file, via any medium is strictly prohibited.\n"
14
- } else if license == "" { licensePlaceholder = "No license specified. All rights reserved.\n" }
15
- prompt licenseText {"# "license" License
16
-
17
- Copyright (c) " year " " name "
18
-
19
- "licensePlaceholder"
20
- (if applicable, include the full text of the license here)
21
- "}
22
- return licenseText
23
- }
24
-
25
- fn generateReadMe(title: string, description: string, body: string, installation: string, usage: string) -> string {
26
- prompt contents {"# "title"
27
- "description"
28
- ----
29
-
30
- ## Installation
31
-
32
- ```bash
33
- " installation "
34
- ```
35
-
36
- " body "
37
- ----
38
-
39
- ## Usage
40
-
41
- ```bash
42
- " usage "
43
- ```
44
- ----
45
- "}
46
- return contents
47
- }
48
-
49
- export fn generateReadMeWithLicense(title: string, description: string, body: string, installation: string, usage: string, license: string, name: string, year: string) -> string {
50
- let licenseText = generateLicense(name, year, license)
51
- let readme = generateReadMe(title, description, body, installation, usage + "\n" + licenseText + "----")
52
- return readme
1
+ export fn generateLicense(name: string, year: string, license: string) -> string {
2
+ let licensePlaceholder = ""
3
+ if license == "MIT" { licensePlaceholder = "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n" }
4
+ if license == "Apache-2.0" { licensePlaceholder = "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n" }
5
+ if license == "GPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
6
+ if license == "BSD-3-Clause" { licensePlaceholder = "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n" }
7
+ if license == "MPL-2.0" { licensePlaceholder = "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. \n" }
8
+ if license == "AGPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
9
+ if license == "LGPL-3.0" { licensePlaceholder = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n" }
10
+ if license == "EPL-2.0" { licensePlaceholder = "This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/. \n"
11
+ } else if license == "Unlicense" { licensePlaceholder = "This is free and unencumbered software released into the public domain.\n"
12
+ } else if license == "CC0-1.0" { licensePlaceholder = "The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.\n"
13
+ } else if license == "Proprietary" { licensePlaceholder = "All rights reserved. This software is proprietary and confidential. Unauthorized copying of this file, via any medium is strictly prohibited.\n"
14
+ } else if license == "" { licensePlaceholder = "No license specified. All rights reserved.\n" }
15
+ prompt licenseText {"# "license" License
16
+
17
+ Copyright (c) " year " " name "
18
+
19
+ "licensePlaceholder"
20
+ (if applicable, include the full text of the license here)
21
+ "}
22
+ return licenseText
23
+ }
24
+
25
+ fn generateReadMe(title: string, description: string, body: string, installation: string, usage: string) -> string {
26
+ prompt contents {"# "title"
27
+ "description"
28
+ ----
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ " installation "
34
+ ```
35
+
36
+ " body "
37
+ ----
38
+
39
+ ## Usage
40
+
41
+ ```bash
42
+ " usage "
43
+ ```
44
+ ----
45
+ "}
46
+ return contents
47
+ }
48
+
49
+ export fn generateReadMeWithLicense(title: string, description: string, body: string, installation: string, usage: string, license: string, name: string, year: string) -> string {
50
+ let licenseText = generateLicense(name, year, license)
51
+ let readme = generateReadMe(title, description, body, installation, usage + "\n" + licenseText + "----")
52
+ return readme
53
53
  }
package/lib/term.sesi CHANGED
@@ -1,5 +1,5 @@
1
- allow "std/terminal" in as Term
2
- export fn info(msg: string) { let text = "ℹ️ " + msg; show text | Term.color("cyan") | Term.style("bold") }
3
- export fn success(msg: string) { let text = "✔ " + msg; show text | Term.color("green") | Term.style("bold") }
4
- export fn warning(msg: string) { let text = "⚠️ " + msg; show text | Term.color("yellow") | Term.style("bold") }
1
+ allow "std/terminal" in as Term
2
+ export fn info(msg: string) { let text = "ℹ️ " + msg; show text | Term.color("cyan") | Term.style("bold") }
3
+ export fn success(msg: string) { let text = "✔ " + msg; show text | Term.color("green") | Term.style("bold") }
4
+ export fn warning(msg: string) { let text = "⚠️ " + msg; show text | Term.color("yellow") | Term.style("bold") }
5
5
  export fn error(msg: string) { let text = "✖ " + msg; show text | Term.color("red") | Term.style("bold") }
package/lib/utils.sesi CHANGED
@@ -1,27 +1,29 @@
1
- /** Create a fresh test directory using Sesi filesystem functions. */
2
- export fn temporary_directory() {
3
- let base = $TMPDIR || $TEMP || $TMP || "/tmp"
4
- fn create_directory() {
5
- let path = base + "/scaffold-sesi-" + str(floor(random() * 1000000000)) + "-" + str(floor(random() * 1000000000))
6
- if exists(path) { raise_error("TestSetupError", "Temporary path already exists.") }
7
- if !make_dir(path) { raise_error("TestSetupError", "Unable to create temporary directory.") }
8
- return path
9
- }
10
- return retry(create_directory, {max_retries: 9, initial_delay: 25, backoff_factor: 1})
11
- }
12
-
13
- /** Quote a test argument for the shell used by Sesi's run builtin. */
14
- export fn quote(value) {
15
- if $OS == "Windows_NT" { return "\"" + str(value) + "\"" }
16
- return "'" + swap(str(value), "'", "'\"'\"'") + "'"
17
- }
18
-
19
- /** Read a test artifact, retrying transient filesystem failures. */
20
- export fn read_artifact(path) {
21
- fn read_once() {
22
- let content = read_file(path)
23
- if content == null { raise_error("TestError", "Cannot read artifact: " + path) }
24
- return content
25
- }
26
- return retry(read_once, {max_retries: 2, initial_delay: 50, backoff_factor: 1})
27
- }
1
+ allow "src/os" in as OS
2
+ /** Create a fresh test directory using Sesi filesystem functions. */
3
+ export fn temporary_directory() {
4
+ let base = OS.temp_dir()
5
+ fn create_directory() {
6
+ let path = base + "/scaffold-sesi-" + str(floor(random() * 1000000000)) + "-" + str(floor(random() * 1000000000))
7
+ if exists(path) { raise_error("TestSetupError", "Temporary path already exists.") }
8
+ if !make_dir(path) { raise_error("TestSetupError", "Unable to create temporary directory.") }
9
+ return path
10
+ }
11
+ return retry(create_directory, {max_retries: 9, initial_delay: 25, backoff_factor: 1})
12
+ }
13
+
14
+ /** Quote a test argument for the shell used by Sesi's run builtin. */
15
+ export fn quote(value) {
16
+ if OS.platform == "Windows_NT" { return "\"" + str(value) + "\"" }
17
+ return "'" + swap(str(value), "'", "'\"'\"'") + "'"
18
+ }
19
+
20
+ /** Read a test artifact, retrying transient filesystem failures. */
21
+ export fn read_artifact(path) {
22
+ fn read_once() {
23
+ let content = ""
24
+ try { content = read_file(path) }
25
+ catch (err) { raise_error("TestError", "Cannot read artifact: " + path + ": " + str(err)) }
26
+ return content
27
+ }
28
+ return retry(read_once, {max_retries: 2, initial_delay: 50, backoff_factor: 1})
29
+ }