@stagepass/cli 2.2.6 → 2.3.0-beta.1
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 +61 -13
- package/TESTING-macos.md +35 -8
- package/bin/index.js +4 -1
- package/package.json +9 -8
- package/src/cli.js +62 -7
- package/src/commands/certs.js +375 -19
- package/src/commands/daemon.js +75 -7
- package/src/commands/dev.js +419 -0
- package/src/commands/link.js +66 -25
- package/src/commands/new.js +397 -41
- package/src/commands/npm-run.js +8 -0
- package/src/commands/reload.js +2 -2
- package/src/commands/setup.js +5 -5
- package/src/commands/start.js +386 -83
- package/src/commands/stop.js +50 -31
- package/src/commands/unlink.js +8 -6
- package/src/commands/upgrade.js +51 -12
- package/src/lib/apply-site-block.js +48 -0
- package/src/lib/autostart.js +300 -3
- package/src/lib/caddyfile.js +72 -13
- package/src/lib/cdn-snippets.js +145 -3
- package/src/lib/certs.js +334 -47
- package/src/lib/dev-port.js +45 -0
- package/src/lib/doctor-site.js +61 -5
- package/src/lib/doctor.js +48 -4
- package/src/lib/ensure-running.js +89 -0
- package/src/lib/exec.js +72 -24
- package/src/lib/live-server.js +484 -0
- package/src/lib/node-engine.js +55 -0
- package/src/lib/notify.js +62 -0
- package/src/lib/origins.js +27 -5
- package/src/lib/package-versions.js +9 -0
- package/src/lib/paths.js +18 -0
- package/src/lib/php-fpm.js +33 -0
- package/src/lib/project-sync.js +165 -20
- package/src/lib/projects.js +137 -7
- package/src/lib/prompts.js +19 -0
- package/src/lib/registry.js +27 -6
- package/src/lib/scaffold.js +288 -11
- package/src/lib/site-detect.js +78 -25
- package/src/lib/snippets.js +14 -11
- package/src/lib/spinner.js +60 -0
- package/src/lib/versions.js +20 -8
- package/templates/project/AGENTS.md.tmpl +4 -3
- package/templates/project/README.md.tmpl +35 -6
- package/templates/project/api/README.md.tmpl +7 -0
- package/templates/project/examples/php/README.md.tmpl +18 -0
- package/templates/project/examples/php/form.php +105 -0
- package/templates/project/examples/php/proxy.php +171 -0
- package/templates/project/scripts/build.mjs +200 -37
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Stagepass project build: esbuild (+ optional sass) → content-hashed dist files + manifest.json.
|
|
4
4
|
* Also writes stable dist/main.js and dist/styles.css copies for local Stagepass paths.
|
|
5
|
+
* Manifest entries include Subresource Integrity (sha384) for production Webflow tags.
|
|
6
|
+
*
|
|
7
|
+
* Watch mode rebuilds only the affected part (JS entry/imports → JS, CSS entry → CSS)
|
|
8
|
+
* and writes a dist file only when its bytes changed.
|
|
5
9
|
*/
|
|
6
10
|
import { createHash } from 'node:crypto';
|
|
7
11
|
import { watch as fsWatch, promises as fs } from 'node:fs';
|
|
@@ -18,6 +22,12 @@ const ENTRY_JS = process.env.STAGEPASS_ENTRY_JS || '{{ENTRY_JS}}';
|
|
|
18
22
|
const ENTRY_CSS = process.env.STAGEPASS_ENTRY_CSS || '{{ENTRY_CSS}}';
|
|
19
23
|
const USE_SASS = (process.env.STAGEPASS_USE_SASS || '{{USE_SASS}}') === 'true';
|
|
20
24
|
|
|
25
|
+
/** @type {{ 'main.js': { file: string, integrity: string } | null, 'styles.css': { file: string, integrity: string } | null }} */
|
|
26
|
+
const manifestState = {
|
|
27
|
+
'main.js': null,
|
|
28
|
+
'styles.css': null,
|
|
29
|
+
};
|
|
30
|
+
|
|
21
31
|
async function ensureDist() {
|
|
22
32
|
await fs.mkdir(distDir, { recursive: true });
|
|
23
33
|
}
|
|
@@ -26,6 +36,32 @@ function hashContent(buf) {
|
|
|
26
36
|
return createHash('sha256').update(buf).digest('hex').slice(0, 8);
|
|
27
37
|
}
|
|
28
38
|
|
|
39
|
+
function sriSha384(buf) {
|
|
40
|
+
return `sha384-${createHash('sha384').update(buf).digest('base64')}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Write only when contents differ from the existing file (preserves mtime when unchanged).
|
|
45
|
+
* @param {string} filePath
|
|
46
|
+
* @param {Buffer} buf
|
|
47
|
+
* @returns {Promise<boolean>} true when written
|
|
48
|
+
*/
|
|
49
|
+
async function writeIfChanged(filePath, buf) {
|
|
50
|
+
try {
|
|
51
|
+
const existing = await fs.readFile(filePath);
|
|
52
|
+
if (existing.equals(buf)) return false;
|
|
53
|
+
} catch {
|
|
54
|
+
/* missing or unreadable → write */
|
|
55
|
+
}
|
|
56
|
+
await fs.writeFile(filePath, buf);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} stableName
|
|
62
|
+
* @param {Buffer|string} contents
|
|
63
|
+
* @param {BufferEncoding} [encoding]
|
|
64
|
+
*/
|
|
29
65
|
async function writeHashed(stableName, contents, encoding = undefined) {
|
|
30
66
|
const buf = Buffer.isBuffer(contents)
|
|
31
67
|
? contents
|
|
@@ -34,15 +70,30 @@ async function writeHashed(stableName, contents, encoding = undefined) {
|
|
|
34
70
|
const ext = path.extname(stableName);
|
|
35
71
|
const base = path.basename(stableName, ext);
|
|
36
72
|
const hashedName = `${base}.${hash}${ext}`;
|
|
37
|
-
await
|
|
38
|
-
await
|
|
39
|
-
return
|
|
73
|
+
await writeIfChanged(path.join(distDir, hashedName), buf);
|
|
74
|
+
await writeIfChanged(path.join(distDir, stableName), buf);
|
|
75
|
+
return {
|
|
76
|
+
file: hashedName,
|
|
77
|
+
integrity: sriSha384(buf),
|
|
78
|
+
};
|
|
40
79
|
}
|
|
41
80
|
|
|
42
|
-
async function
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
81
|
+
async function writeManifest() {
|
|
82
|
+
if (!manifestState['main.js'] || !manifestState['styles.css']) return;
|
|
83
|
+
const text = `${JSON.stringify(
|
|
84
|
+
{
|
|
85
|
+
'main.js': manifestState['main.js'],
|
|
86
|
+
'styles.css': manifestState['styles.css'],
|
|
87
|
+
},
|
|
88
|
+
null,
|
|
89
|
+
2
|
|
90
|
+
)}\n`;
|
|
91
|
+
await writeIfChanged(path.join(distDir, 'manifest.json'), Buffer.from(text, 'utf8'));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function jsBuildOptions() {
|
|
95
|
+
return {
|
|
96
|
+
entryPoints: [path.join(root, ENTRY_JS)],
|
|
46
97
|
bundle: true,
|
|
47
98
|
write: false,
|
|
48
99
|
format: 'iife',
|
|
@@ -50,9 +101,22 @@ async function buildJs() {
|
|
|
50
101
|
target: ['es2018'],
|
|
51
102
|
sourcemap: false,
|
|
52
103
|
logLevel: 'warning',
|
|
53
|
-
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {Buffer} contents
|
|
109
|
+
*/
|
|
110
|
+
async function applyJsOutput(contents) {
|
|
111
|
+
manifestState['main.js'] = await writeHashed('main.js', contents);
|
|
112
|
+
await writeManifest();
|
|
113
|
+
return manifestState['main.js'];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function buildJsOnce() {
|
|
117
|
+
const result = await esbuild.build(jsBuildOptions());
|
|
54
118
|
const out = result.outputFiles[0];
|
|
55
|
-
return
|
|
119
|
+
return applyJsOutput(out.contents);
|
|
56
120
|
}
|
|
57
121
|
|
|
58
122
|
async function buildCss() {
|
|
@@ -65,46 +129,145 @@ async function buildCss() {
|
|
|
65
129
|
} else {
|
|
66
130
|
css = await fs.readFile(entry, 'utf8');
|
|
67
131
|
}
|
|
68
|
-
|
|
132
|
+
manifestState['styles.css'] = await writeHashed('styles.css', css, 'utf8');
|
|
133
|
+
await writeManifest();
|
|
134
|
+
return manifestState['styles.css'];
|
|
69
135
|
}
|
|
70
136
|
|
|
71
137
|
async function buildOnce() {
|
|
72
138
|
await ensureDist();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'main.js':
|
|
77
|
-
'styles.css':
|
|
139
|
+
await buildJsOnce();
|
|
140
|
+
await buildCss();
|
|
141
|
+
return {
|
|
142
|
+
'main.js': manifestState['main.js'],
|
|
143
|
+
'styles.css': manifestState['styles.css'],
|
|
78
144
|
};
|
|
79
|
-
await fs.writeFile(
|
|
80
|
-
path.join(distDir, 'manifest.json'),
|
|
81
|
-
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
82
|
-
'utf8'
|
|
83
|
-
);
|
|
84
|
-
return manifest;
|
|
85
145
|
}
|
|
86
146
|
|
|
87
|
-
|
|
88
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Serialize async rebuild work so overlapping esbuild / CSS events stay ordered.
|
|
149
|
+
* @type {Promise<void>}
|
|
150
|
+
*/
|
|
151
|
+
let chain = Promise.resolve();
|
|
152
|
+
function enqueue(label, fn) {
|
|
153
|
+
chain = chain
|
|
154
|
+
.then(async () => {
|
|
155
|
+
try {
|
|
156
|
+
const next = await fn();
|
|
157
|
+
console.log(`[stagepass] rebuild ${label} ok`, next);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.error(`[stagepass] rebuild ${label} failed`, err);
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
.catch(() => {});
|
|
163
|
+
return chain;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!watchMode) {
|
|
167
|
+
const manifest = await buildOnce();
|
|
168
|
+
console.log('[stagepass] build ok', manifest);
|
|
169
|
+
} else {
|
|
170
|
+
await ensureDist();
|
|
171
|
+
|
|
172
|
+
/** Skip the first onEnd from context.watch (we seed via rebuild below). */
|
|
173
|
+
let jsWatchReady = false;
|
|
174
|
+
/** @type {import('esbuild').BuildContext|null} */
|
|
175
|
+
let ctx = null;
|
|
176
|
+
/** @type {import('node:fs').FSWatcher|null} */
|
|
177
|
+
let cssWatcher = null;
|
|
178
|
+
let shuttingDown = false;
|
|
89
179
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (pending) return;
|
|
94
|
-
pending = true;
|
|
180
|
+
async function shutdown(code = 0) {
|
|
181
|
+
if (shuttingDown) return;
|
|
182
|
+
shuttingDown = true;
|
|
95
183
|
try {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
console.error('[stagepass] rebuild failed', err);
|
|
100
|
-
} finally {
|
|
101
|
-
pending = false;
|
|
184
|
+
cssWatcher?.close();
|
|
185
|
+
} catch {
|
|
186
|
+
/* ignore */
|
|
102
187
|
}
|
|
188
|
+
cssWatcher = null;
|
|
189
|
+
try {
|
|
190
|
+
if (ctx) await ctx.dispose();
|
|
191
|
+
} catch {
|
|
192
|
+
/* ignore */
|
|
193
|
+
}
|
|
194
|
+
ctx = null;
|
|
195
|
+
// Allow pending enqueue work to settle briefly, then exit hard.
|
|
196
|
+
await Promise.race([chain, new Promise((r) => setTimeout(r, 500))]);
|
|
197
|
+
process.exit(code);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
for (const signal of ['SIGTERM', 'SIGINT']) {
|
|
201
|
+
process.on(signal, () => {
|
|
202
|
+
void shutdown(0);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
ctx = await esbuild.context({
|
|
207
|
+
...jsBuildOptions(),
|
|
208
|
+
plugins: [
|
|
209
|
+
{
|
|
210
|
+
name: 'stagepass-js-watch',
|
|
211
|
+
setup(build) {
|
|
212
|
+
build.onEnd((result) => {
|
|
213
|
+
if (!jsWatchReady || shuttingDown) return;
|
|
214
|
+
if (result.errors.length > 0) {
|
|
215
|
+
console.error('[stagepass] rebuild js failed');
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const out = result.outputFiles && result.outputFiles[0];
|
|
219
|
+
if (!out) {
|
|
220
|
+
enqueue('full', buildOnce);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const contents = Buffer.from(out.contents);
|
|
224
|
+
enqueue('js', () => applyJsOutput(contents));
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// Initial full build (JS via context.rebuild so the graph is warm for watch).
|
|
232
|
+
const initial = await ctx.rebuild();
|
|
233
|
+
if (initial.errors.length > 0 || !initial.outputFiles?.[0]) {
|
|
234
|
+
await shutdown(1);
|
|
235
|
+
throw new Error('[stagepass] initial js build failed');
|
|
236
|
+
}
|
|
237
|
+
await applyJsOutput(initial.outputFiles[0].contents);
|
|
238
|
+
await buildCss();
|
|
239
|
+
console.log('[stagepass] build ok', {
|
|
240
|
+
'main.js': manifestState['main.js'],
|
|
241
|
+
'styles.css': manifestState['styles.css'],
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
jsWatchReady = true;
|
|
245
|
+
await ctx.watch();
|
|
246
|
+
|
|
247
|
+
let cssPending = false;
|
|
248
|
+
const scheduleCss = () => {
|
|
249
|
+
if (cssPending || shuttingDown) return;
|
|
250
|
+
cssPending = true;
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
cssPending = false;
|
|
253
|
+
if (shuttingDown) return;
|
|
254
|
+
enqueue('css', async () => {
|
|
255
|
+
await buildCss();
|
|
256
|
+
return manifestState['styles.css'];
|
|
257
|
+
});
|
|
258
|
+
}, 40);
|
|
103
259
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
cssWatcher = fsWatch(path.join(root, ENTRY_CSS), () => {
|
|
263
|
+
scheduleCss();
|
|
264
|
+
});
|
|
265
|
+
} catch (err) {
|
|
266
|
+
console.error('[stagepass] css watch failed; falling back to full rebuilds', err);
|
|
267
|
+
cssWatcher = fsWatch(path.join(root, ENTRY_CSS), () => {
|
|
268
|
+
enqueue('full', buildOnce);
|
|
107
269
|
});
|
|
108
270
|
}
|
|
271
|
+
|
|
109
272
|
console.log('[stagepass] watching…');
|
|
110
273
|
}
|