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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Misterscan
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Misterscan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,216 +1,216 @@
1
- # Sesi Project Scaffolder
2
-
3
- A project generator that creates a structured Sesi application with starter scripts, environment configuration, linting and testing utilities, documentation, and a license.
4
-
5
- # IMPORTANT:
6
- - **Before proceeding, inspect your environment and ensure `sesi` is installed.**
7
- - **Check with `sesi version` to verify sesi is available.**
8
- - **Inspect this README and repository for usage details.**
9
- - **After scaffolding, check the created files and structure. Work from there.**
10
-
11
- ## Features
12
-
13
- - Creates a project directory with `src/`, `lib/`, `tests/`, and `docs/`.
14
- - Generates an editable entry point and a central module interface.
15
- - Copies and adapts an existing linting script.
16
- - Includes a testing utility. Use these imports in your tests, no need to create them manually.
17
- - Generates a README and license using local helper functions.
18
- - Copies selected environment settings into a project-local `.env` file. If missing, defaults are used.
19
- - Supports a standard projects directory or a sandbox-oriented directory.
20
- - Rejects project names containing path separators and prevents overwriting an existing project directory.
21
-
22
- ## Prerequisites
23
-
24
- The generator expects:
25
-
26
- - The `sesi` command to be available.
27
-
28
- ## npm CLI
29
-
30
- ```sh
31
- npm install -g @misterscan/sesi
32
- npx scaffold-sesi "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox"
33
- # If working locally
34
- npm link # If this is a local development setup, may return an error if already linked. This is expected behavior.
35
- scaffold-sesi "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox"
36
- ```
37
-
38
- Run `scaffold-sesi` without arguments for the existing interactive setup. A project name starts generation directly; `--run` is also supported. Use `--template` to select a starter; omitting it preserves the generic starter and existing prompts and destination choices.
39
-
40
- ## Project Templates
41
-
42
- ```sh
43
- scaffold-sesi "my-web" "A web app" Misterscan MIT 2026 sandbox --template web
44
- scaffold-sesi --template cli "my-cli" "A CLI app" Misterscan MIT 2026 sandbox
45
- sesi -l main.sesi --run "my-api" "An API" Misterscan MIT 2026 sandbox --template api
46
- ```
47
-
48
- | Template | Generated application |
49
- |---|---|
50
- | `basic` (default) | Generic editable Sesi entry point and shared project utilities |
51
- | `web` | Sesi HTTP server, editable HTML/CSS, form handling, and a Base64 JSON theme cookie |
52
- | `cli` | Greeting command with `greet [name]`, `--help`, and `--version` |
53
- | `api` | `std/api` application with `/health`, `/hello`, `/docs`, and `/openapi.json` |
54
-
55
- The `--template basic|web|cli|api` option works before or after positional arguments. Missing values, unknown template names, and duplicate options fail before prompting or creating a project.
56
-
57
- The web starter follows the Margin client pattern: Sesi renders standard HTML forms and handles browser preferences on the server, without application JavaScript. `std/base64` encodes JSON in an `HttpOnly; SameSite=Lax` cookie. Invalid cookie state defaults to the light theme. HTML and CSS remain readable files under `src/`.
58
-
59
- Web and API projects start with `npm start` or `sesi -l main.sesi`; native HTTP serving requires `-l`. Both default to port 8080, configurable through `PORT` or `config.sesi`. CLI projects support `npm start -- greet Alice` or `sesi main.sesi greet Alice`.
60
-
61
- Templates live under `templates/`. Each template module exports `build(context)` and returns `directories`, a `files` map, package `scripts` overrides, and `readme` content. Readable assets live in the corresponding template directory. Configuration, licensing, linting, test utilities, and output generation are shared.
62
-
63
- ## Scaffolder Verification
64
-
65
- Run `npm test` to run the Sesi suites in `tests/` using the existing `src/test.sesi` utilities.
66
-
67
- ## Usage
68
-
69
- ### Display Help
70
-
71
- ```sh
72
- sesi main.sesi --help
73
- ```
74
-
75
- Running the generator without arguments also displays help.
76
-
77
- ### Create a Project
78
-
79
- ```sh
80
- sesi -l main.sesi --run "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox" --template basic
81
- ```
82
-
83
- Missing values are requested interactively.
84
-
85
- | Setting | Default |
86
- |---|---|
87
- | Project name | `my-sesi-app` |
88
- | Description | `An app built with Sesi.` |
89
- | Author | `Unknown` |
90
- | License | `MIT` |
91
- | Year | `2026` |
92
- | Sandbox selection | `agent-sandbox` |
93
-
94
- The project-name expression includes lowercasing, whitespace trimming, and replacement of spaces with hyphens.
95
-
96
-
97
- ## Project Location
98
-
99
- Selecting `n` places the project under:
100
-
101
- ```text
102
- $HOME/Documents/Projects/<project-name>/
103
- ```
104
-
105
- Recognized sandbox selections include `y`, `agent-sandbox`, `agent`, `sandbox`, `ai-agent`, `ai`, and `ai-sandbox`. These place the project under:
106
-
107
- ```text
108
- <working-directory>/Sandbox/Projects/<project-name>/
109
- ```
110
-
111
- > The sandbox option changes the destination directory only. This script does not establish process isolation, filesystem restrictions, or an AI-agent security boundary.
112
-
113
- ## Generated Structure
114
-
115
- ```text
116
- my-app/
117
- ├── src/
118
- ├── lib/
119
- ├── tests/
120
- ├── docs/
121
- ├── .env
122
- ├── .gitignore
123
- ├── main.sesi
124
- ├── config.sesi
125
- ├── check.sesi
126
- ├── test.sesi
127
- ├── README.md
128
- ├── LICENSE
129
- └── package.json
130
- ```
131
-
132
- ### Key Files
133
-
134
- | File | Purpose |
135
- |---|---|
136
- | `main.sesi` | Project entry point with configuration, functions, and execution sections |
137
- | `config.sesi` | Shared configuration, including the server port |
138
- | `check.sesi` | Checks Sesi files directly inside `.`, `lib/`, `src/`, and `tests/` |
139
- | `test.sesi` | Test discovery and execution |
140
- | `lib/lint.sesi` | Adapted linting script |
141
- | `lib/test.sesi` | Copied testing utility |
142
- | `.env` | Generated environment settings |
143
- | `README.md` | Project documentation |
144
- | `LICENSE` | Generated license text |
145
- | `package.json` | Project metadata and command shortcuts |
146
-
147
- ### Starter Entry Point
148
-
149
- ```sesi
150
- /**
151
- Project entry point.
152
-
153
- Run: `sesi main.sesi`
154
- */
155
-
156
- allow "src/" in as *
157
- allow "config" in with {global}
158
-
159
- // Functions
160
- // Define named functions here (if applicable).
161
-
162
- // Execution
163
- try {
164
- // Write top-level project logic here.
165
- // ...
166
- } catch (e) { show e }
167
- ```
168
-
169
- ## Environment Configuration
170
-
171
- The generator reads the current environment and writes these settings to `.env`:
172
-
173
- | Variable | Fallback |
174
- |---|---|
175
- | `GEMINI_API_KEY` | Empty string |
176
- | `OPENAI_API_KEY` | Empty string |
177
- | `SESI_PASSWORD` | Empty string |
178
- | `SESI_SAFE_MODE` | `true` |
179
- | `SESI_LOCAL_FS` | `false` |
180
-
181
- Values are serialized with `to_json()` before being written.
182
-
183
- **Security:** API keys and passwords are copied into a plaintext file. Although the generated `.gitignore` excludes `.env`, avoid sharing it or including it in public artifacts. This generator writes the configuration file; it does not explicitly load it into the generated application.
184
-
185
- ## Development Commands
186
-
187
- Run these commands from the generated project directory:
188
-
189
- ```sh
190
- # Run the application
191
- npm start
192
-
193
- # Quick scaffold
194
- npm run scaffold
195
-
196
- # Run sandbox
197
- npm run sandbox
198
-
199
- # Check sesi files
200
- npm run check
201
-
202
- # Run the generated linter
203
- npm run lint
204
- ```
205
-
206
- The generated `package.json` also defines `eval`, `help`, `encrypt`, and `decrypt` scripts.
207
-
208
- ## Linter Adaptations
209
-
210
- The generator modifies the existing lint template to:
211
-
212
- - Target `.`, `src`, `lib`, and `tests`.
213
- - Discover exported names from top-level local wildcard imports without executing imported modules.
214
- - Recognize those imported names during scope auditing.
215
-
216
- These modifications use exact string replacements, so changes to the source lint template may require corresponding updates to the generator.
1
+ # Sesi Project Scaffolder
2
+
3
+ A project generator that creates a structured Sesi application with starter scripts, environment configuration, linting and testing utilities, documentation, and a license.
4
+
5
+ # IMPORTANT:
6
+ - **Before proceeding, inspect your environment and ensure `sesi` is installed.**
7
+ - **Check with `sesi version` to verify sesi is available.**
8
+ - **Inspect this README and repository for usage details.**
9
+ - **After scaffolding, check the created files and structure. Work from there.**
10
+
11
+ ## Features
12
+
13
+ - Creates a project directory with `src/`, `lib/`, `tests/`, and `docs/`.
14
+ - Generates an editable entry point and a central module interface.
15
+ - Copies and adapts an existing linting script.
16
+ - Includes a testing utility. Use these imports in your tests, no need to create them manually.
17
+ - Generates a README and license using local helper functions.
18
+ - Copies selected environment settings into a project-local `.env` file. If missing, defaults are used.
19
+ - Supports a standard projects directory or a sandbox-oriented directory.
20
+ - Rejects project names containing path separators and prevents overwriting an existing project directory.
21
+
22
+ ## Prerequisites
23
+
24
+ The generator expects:
25
+
26
+ - The `sesi` command to be available.
27
+
28
+ ## npm CLI
29
+
30
+ ```sh
31
+ npm install -g @misterscan/sesi
32
+ npx scaffold-sesi "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox"
33
+ # If working locally
34
+ npm link # If this is a local development setup, may return an error if already linked. This is expected behavior.
35
+ scaffold-sesi "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox"
36
+ ```
37
+
38
+ Run `scaffold-sesi` without arguments for the existing interactive setup. A project name starts generation directly; `--run` is also supported. Use `--template` to select a starter; omitting it preserves the generic starter and existing prompts and destination choices.
39
+
40
+ ## Project Templates
41
+
42
+ ```sh
43
+ scaffold-sesi "my-web" "A web app" Misterscan MIT 2026 sandbox --template web
44
+ scaffold-sesi --template cli "my-cli" "A CLI app" Misterscan MIT 2026 sandbox
45
+ sesi -l main.sesi --run "my-api" "An API" Misterscan MIT 2026 sandbox --template api
46
+ ```
47
+
48
+ | Template | Generated application |
49
+ |---|---|
50
+ | `basic` (default) | Generic editable Sesi entry point and shared project utilities |
51
+ | `web` | Sesi HTTP server, editable HTML/CSS, form handling, and a Base64 JSON theme cookie |
52
+ | `cli` | Greeting command with `greet [name]`, `--help`, and `--version` |
53
+ | `api` | `std/api` application with `/health`, `/hello`, `/docs`, and `/openapi.json` |
54
+
55
+ The `--template basic|web|cli|api` option works before or after positional arguments. Missing values, unknown template names, and duplicate options fail before prompting or creating a project.
56
+
57
+ The web starter follows the Margin client pattern: Sesi renders standard HTML forms and handles browser preferences on the server, without application JavaScript. `std/base64` encodes JSON in an `HttpOnly; SameSite=Lax` cookie. Invalid cookie state defaults to the light theme. HTML and CSS remain readable files under `src/`.
58
+
59
+ Web and API projects start with `npm start` or `sesi -l main.sesi`; native HTTP serving requires `-l`. Both default to port 8080, configurable through `PORT` or `config.sesi`. CLI projects support `npm start -- greet Alice` or `sesi main.sesi greet Alice`.
60
+
61
+ Templates live under `templates/`. Each template module exports `build(context)` and returns `directories`, a `files` map, package `scripts` overrides, and `readme` content. Readable assets live in the corresponding template directory. Configuration, licensing, linting, test utilities, and output generation are shared.
62
+
63
+ ## Scaffolder Verification
64
+
65
+ Run `npm test` to run the Sesi suites in `tests/` using the existing `src/test.sesi` utilities.
66
+
67
+ ## Usage
68
+
69
+ ### Display Help
70
+
71
+ ```sh
72
+ sesi main.sesi --help
73
+ ```
74
+
75
+ Running the generator without arguments also displays help.
76
+
77
+ ### Create a Project
78
+
79
+ ```sh
80
+ sesi -l main.sesi --run "my-app" "An app built with Sesi." "Your Name" "MIT" "2026" "agent-sandbox" --template basic
81
+ ```
82
+
83
+ Missing values are requested interactively.
84
+
85
+ | Setting | Default |
86
+ |---|---|
87
+ | Project name | `my-sesi-app` |
88
+ | Description | `An app built with Sesi.` |
89
+ | Author | `Unknown` |
90
+ | License | `MIT` |
91
+ | Year | `2026` |
92
+ | Sandbox selection | `agent-sandbox` |
93
+
94
+ The project-name expression includes lowercasing, whitespace trimming, and replacement of spaces with hyphens.
95
+
96
+
97
+ ## Project Location
98
+
99
+ Selecting `n` places the project under:
100
+
101
+ ```text
102
+ $HOME/Documents/Projects/<project-name>/
103
+ ```
104
+
105
+ Recognized sandbox selections include `y`, `agent-sandbox`, `agent`, `sandbox`, `ai-agent`, `ai`, and `ai-sandbox`. These place the project under:
106
+
107
+ ```text
108
+ <working-directory>/Sandbox/Projects/<project-name>/
109
+ ```
110
+
111
+ > The sandbox option changes the destination directory only. This script does not establish process isolation, filesystem restrictions, or an AI-agent security boundary.
112
+
113
+ ## Generated Structure
114
+
115
+ ```text
116
+ my-app/
117
+ ├── src/
118
+ ├── lib/
119
+ ├── tests/
120
+ ├── docs/
121
+ ├── .env
122
+ ├── .gitignore
123
+ ├── main.sesi
124
+ ├── config.sesi
125
+ ├── check.sesi
126
+ ├── test.sesi
127
+ ├── README.md
128
+ ├── LICENSE
129
+ └── package.json
130
+ ```
131
+
132
+ ### Key Files
133
+
134
+ | File | Purpose |
135
+ |---|---|
136
+ | `main.sesi` | Project entry point with configuration, functions, and execution sections |
137
+ | `config.sesi` | Shared configuration, including the server port |
138
+ | `check.sesi` | Checks Sesi files directly inside `.`, `lib/`, `src/`, and `tests/` |
139
+ | `test.sesi` | Test discovery and execution |
140
+ | `lib/lint.sesi` | Adapted linting script |
141
+ | `lib/test.sesi` | Copied testing utility |
142
+ | `.env` | Generated environment settings |
143
+ | `README.md` | Project documentation |
144
+ | `LICENSE` | Generated license text |
145
+ | `package.json` | Project metadata and command shortcuts |
146
+
147
+ ### Starter Entry Point
148
+
149
+ ```sesi
150
+ /**
151
+ Project entry point.
152
+
153
+ Run: `sesi main.sesi`
154
+ */
155
+
156
+ allow "src/" in as *
157
+ allow "config" in with {global}
158
+
159
+ // Functions
160
+ // Define named functions here (if applicable).
161
+
162
+ // Execution
163
+ try {
164
+ // Write top-level project logic here.
165
+ // ...
166
+ } catch (e) { show e }
167
+ ```
168
+
169
+ ## Environment Configuration
170
+
171
+ The generator reads the current environment and writes these settings to `.env`:
172
+
173
+ | Variable | Fallback |
174
+ |---|---|
175
+ | `GEMINI_API_KEY` | Empty string |
176
+ | `OPENAI_API_KEY` | Empty string |
177
+ | `SESI_PASSWORD` | Empty string |
178
+ | `SESI_SAFE_MODE` | `true` |
179
+ | `SESI_LOCAL_FS` | `false` |
180
+
181
+ Values are serialized with `to_json()` before being written.
182
+
183
+ **Security:** API keys and passwords are copied into a plaintext file. Although the generated `.gitignore` excludes `.env`, avoid sharing it or including it in public artifacts. This generator writes the configuration file; it does not explicitly load it into the generated application.
184
+
185
+ ## Development Commands
186
+
187
+ Run these commands from the generated project directory:
188
+
189
+ ```sh
190
+ # Run the application
191
+ npm start
192
+
193
+ # Quick scaffold
194
+ npm run scaffold
195
+
196
+ # Run sandbox
197
+ npm run sandbox
198
+
199
+ # Check sesi files
200
+ npm run check
201
+
202
+ # Run the generated linter
203
+ npm run lint
204
+ ```
205
+
206
+ The generated `package.json` also defines `eval`, `help`, `encrypt`, and `decrypt` scripts.
207
+
208
+ ## Linter Adaptations
209
+
210
+ The generator modifies the existing lint template to:
211
+
212
+ - Target `.`, `src`, `lib`, and `tests`.
213
+ - Discover exported names from top-level local wildcard imports without executing imported modules.
214
+ - Recognize those imported names during scope auditing.
215
+
216
+ These modifications use exact string replacements, so changes to the source lint template may require corresponding updates to the generator.
@@ -1,48 +1,48 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const { existsSync } = require('node:fs');
5
- const path = require('node:path');
6
- const { spawnSync } = require('node:child_process');
7
-
8
- function findNpmSesi() {
9
- for (const entry of (process.env.PATH ?? '').split(path.delimiter).filter(Boolean)) {
10
- const directory = entry.replace(/^"|"$/g, '');
11
- const modules = path.basename(directory) === '.bin'
12
- ? path.dirname(directory)
13
- : path.join(directory, 'node_modules');
14
- const script = path.join(modules, '@misterscan', 'sesi', 'bin', 'sesi.js');
15
- if (existsSync(script)) return script;
16
- }
17
- }
18
-
19
- // Keep all prompting and project generation in the existing Sesi script.
20
- const args = process.argv.slice(2);
21
- const version = require('../package.json').version;
22
- if (args.includes('--version') || args.includes('-v')) {
23
- console.log(version);
24
- process.exit(0);
25
- }
26
- if (args.length === 0 || !args[0].startsWith('-') || args[0] === '--template') args.unshift('--run');
27
- const sesiArgs = [
28
- '-l', path.resolve(__dirname, '../main.sesi'), ...args
29
- ];
30
- const options = {
31
- cwd: path.resolve(__dirname, '..'),
32
- env: { ...process.env, PWD: process.cwd() },
33
- stdio: 'inherit'
34
- };
35
- const isWindows = process.platform === 'win32';
36
- let result = spawnSync(isWindows ? 'sesi.exe' : 'sesi', sesiArgs, options);
37
- if (isWindows && result.error?.code === 'ENOENT') {
38
- // Run npm's JavaScript entry point directly so arguments never pass through cmd.exe.
39
- const script = findNpmSesi();
40
- if (script) result = spawnSync(process.execPath, [script, ...sesiArgs], options);
41
- }
42
-
43
- if (result.error) {
44
- console.error(result.error.code === 'ENOENT'
45
- ? 'scaffold-sesi requires Sesi on PATH. Install it with: npm install -g @misterscan/sesi'
46
- : result.error.message);
47
- }
48
- process.exitCode = result.status ?? 1;
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const { existsSync } = require('node:fs');
5
+ const path = require('node:path');
6
+ const { spawnSync } = require('node:child_process');
7
+
8
+ function findNpmSesi() {
9
+ for (const entry of (process.env.PATH ?? '').split(path.delimiter).filter(Boolean)) {
10
+ const directory = entry.replace(/^"|"$/g, '');
11
+ const modules = path.basename(directory) === '.bin'
12
+ ? path.dirname(directory)
13
+ : path.join(directory, 'node_modules');
14
+ const script = path.join(modules, '@misterscan', 'sesi', 'bin', 'sesi.js');
15
+ if (existsSync(script)) return script;
16
+ }
17
+ }
18
+
19
+ // Keep all prompting and project generation in the existing Sesi script.
20
+ const args = process.argv.slice(2);
21
+ const version = require('../package.json').version;
22
+ if (args.includes('--version') || args.includes('-v')) {
23
+ console.log(version);
24
+ process.exit(0);
25
+ }
26
+ if (args.length === 0 || !args[0].startsWith('-') || args[0] === '--template') args.unshift('--run');
27
+ const sesiArgs = [
28
+ '-l', path.resolve(__dirname, '../main.sesi'), ...args
29
+ ];
30
+ const options = {
31
+ cwd: path.resolve(__dirname, '..'),
32
+ env: { ...process.env, PWD: process.cwd() },
33
+ stdio: 'inherit'
34
+ };
35
+ const isWindows = process.platform === 'win32';
36
+ let result = spawnSync(isWindows ? 'sesi.exe' : 'sesi', sesiArgs, options);
37
+ if (isWindows && result.error?.code === 'ENOENT') {
38
+ // Run npm's JavaScript entry point directly so arguments never pass through cmd.exe.
39
+ const script = findNpmSesi();
40
+ if (script) result = spawnSync(process.execPath, [script, ...sesiArgs], options);
41
+ }
42
+
43
+ if (result.error) {
44
+ console.error(result.error.code === 'ENOENT'
45
+ ? 'scaffold-sesi requires Sesi on PATH. Install it with: npm install -g @misterscan/sesi'
46
+ : result.error.message);
47
+ }
48
+ process.exitCode = result.status ?? 1;