@stagepass/cli 2.0.0 → 2.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 (42) hide show
  1. package/README.md +87 -7
  2. package/TESTING-macos.md +58 -0
  3. package/bin/index.js +2 -2
  4. package/package.json +3 -1
  5. package/src/cli.js +204 -0
  6. package/src/commands/autostart.js +85 -0
  7. package/src/commands/certs.js +185 -0
  8. package/src/commands/daemon.js +126 -0
  9. package/src/commands/doctor.js +57 -0
  10. package/src/commands/new.js +455 -0
  11. package/src/commands/npm-run.js +84 -0
  12. package/src/commands/stop.js +15 -0
  13. package/src/commands/upgrade.js +276 -0
  14. package/src/lib/ai-guide.js +161 -0
  15. package/src/lib/autostart.js +360 -0
  16. package/src/lib/cdn-snippets.js +27 -0
  17. package/src/lib/certs.js +476 -0
  18. package/src/lib/doctor-site.js +89 -0
  19. package/src/lib/doctor.js +521 -0
  20. package/src/lib/exec.js +71 -0
  21. package/src/lib/paths.js +58 -0
  22. package/src/lib/platform.js +47 -0
  23. package/src/lib/project-modules.js +98 -0
  24. package/src/lib/project-name.js +47 -0
  25. package/src/lib/project-sync.js +394 -0
  26. package/src/lib/remote-url.js +63 -0
  27. package/src/lib/scaffold.js +212 -0
  28. package/src/lib/site-detect.js +242 -0
  29. package/src/lib/snippets.js +94 -0
  30. package/src/lib/spawn.js +30 -0
  31. package/src/lib/versions.js +27 -0
  32. package/templates/project/AGENTS.md.tmpl +39 -0
  33. package/templates/project/README.md.tmpl +44 -0
  34. package/templates/project/gitignore +7 -0
  35. package/templates/project/jsconfig.json.tmpl +14 -0
  36. package/templates/project/scripts/build.mjs +110 -0
  37. package/templates/project/src/main.js.tmpl +29 -0
  38. package/templates/project/src/main.ts.tmpl +29 -0
  39. package/templates/project/src/styles.css.tmpl +8 -0
  40. package/templates/project/src/styles.scss.tmpl +8 -0
  41. package/templates/project/stagepass.json.tmpl +8 -0
  42. package/templates/project/tsconfig.json.tmpl +13 -0
@@ -0,0 +1,7 @@
1
+ node_modules/
2
+ dist/
3
+ .DS_Store
4
+ *.log
5
+ .env
6
+ .env.*
7
+ !.env.example
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2018",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "checkJs": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "skipLibCheck": true,
10
+ "lib": ["ES2018", "DOM"],
11
+ "types": {{TYPES_JSON}}
12
+ },
13
+ "include": ["src/**/*.js"]
14
+ }
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Stagepass project build: esbuild (+ optional sass) → content-hashed dist files + manifest.json.
4
+ * Also writes stable dist/main.js and dist/styles.css copies for local Stagepass paths.
5
+ */
6
+ import { createHash } from 'node:crypto';
7
+ import { watch as fsWatch, promises as fs } from 'node:fs';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ import * as esbuild from 'esbuild';
11
+
12
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
13
+ const root = path.join(__dirname, '..');
14
+ const distDir = path.join(root, 'dist');
15
+ const watchMode = process.argv.includes('--watch');
16
+
17
+ const ENTRY_JS = process.env.STAGEPASS_ENTRY_JS || '{{ENTRY_JS}}';
18
+ const ENTRY_CSS = process.env.STAGEPASS_ENTRY_CSS || '{{ENTRY_CSS}}';
19
+ const USE_SASS = (process.env.STAGEPASS_USE_SASS || '{{USE_SASS}}') === 'true';
20
+
21
+ async function ensureDist() {
22
+ await fs.mkdir(distDir, { recursive: true });
23
+ }
24
+
25
+ function hashContent(buf) {
26
+ return createHash('sha256').update(buf).digest('hex').slice(0, 8);
27
+ }
28
+
29
+ async function writeHashed(stableName, contents, encoding = undefined) {
30
+ const buf = Buffer.isBuffer(contents)
31
+ ? contents
32
+ : Buffer.from(contents, encoding || 'utf8');
33
+ const hash = hashContent(buf);
34
+ const ext = path.extname(stableName);
35
+ const base = path.basename(stableName, ext);
36
+ const hashedName = `${base}.${hash}${ext}`;
37
+ await fs.writeFile(path.join(distDir, hashedName), buf);
38
+ await fs.writeFile(path.join(distDir, stableName), buf);
39
+ return hashedName;
40
+ }
41
+
42
+ async function buildJs() {
43
+ const entry = path.join(root, ENTRY_JS);
44
+ const result = await esbuild.build({
45
+ entryPoints: [entry],
46
+ bundle: true,
47
+ write: false,
48
+ format: 'iife',
49
+ platform: 'browser',
50
+ target: ['es2018'],
51
+ sourcemap: false,
52
+ logLevel: 'warning',
53
+ });
54
+ const out = result.outputFiles[0];
55
+ return writeHashed('main.js', out.contents);
56
+ }
57
+
58
+ async function buildCss() {
59
+ const entry = path.join(root, ENTRY_CSS);
60
+ let css;
61
+ if (USE_SASS) {
62
+ const sass = await import('sass');
63
+ const compiled = sass.compile(entry, { style: 'compressed' });
64
+ css = compiled.css;
65
+ } else {
66
+ css = await fs.readFile(entry, 'utf8');
67
+ }
68
+ return writeHashed('styles.css', css, 'utf8');
69
+ }
70
+
71
+ async function buildOnce() {
72
+ await ensureDist();
73
+ const mainFile = await buildJs();
74
+ const stylesFile = await buildCss();
75
+ const manifest = {
76
+ 'main.js': mainFile,
77
+ 'styles.css': stylesFile,
78
+ };
79
+ await fs.writeFile(
80
+ path.join(distDir, 'manifest.json'),
81
+ `${JSON.stringify(manifest, null, 2)}\n`,
82
+ 'utf8'
83
+ );
84
+ return manifest;
85
+ }
86
+
87
+ const manifest = await buildOnce();
88
+ console.log('[stagepass] build ok', manifest);
89
+
90
+ if (watchMode) {
91
+ let pending = false;
92
+ const rebuild = async () => {
93
+ if (pending) return;
94
+ pending = true;
95
+ try {
96
+ const next = await buildOnce();
97
+ console.log('[stagepass] rebuild ok', next);
98
+ } catch (err) {
99
+ console.error('[stagepass] rebuild failed', err);
100
+ } finally {
101
+ pending = false;
102
+ }
103
+ };
104
+ for (const rel of [ENTRY_JS, ENTRY_CSS]) {
105
+ fsWatch(path.join(root, rel), () => {
106
+ rebuild().catch(() => {});
107
+ });
108
+ }
109
+ console.log('[stagepass] watching…');
110
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Webflow-safe entry: runs once, waits for DOM and window.Webflow when present.
3
+ * No globals leaked; no eval.
4
+ */
5
+ (() => {
6
+ const run = () => {
7
+ // Your project code here.
8
+ // Prefer `sp` when Stagepass loader is present (session-aware logging, vars, etc.).
9
+ const sp = window.sp;
10
+ if (sp && typeof sp.log === 'function') {
11
+ sp.log('{{NAME}}: ready');
12
+ }
13
+ };
14
+
15
+ const start = () => {
16
+ const w = window;
17
+ if (w.Webflow && typeof w.Webflow.push === 'function') {
18
+ w.Webflow.push(run);
19
+ return;
20
+ }
21
+ run();
22
+ };
23
+
24
+ if (document.readyState === 'loading') {
25
+ document.addEventListener('DOMContentLoaded', start, { once: true });
26
+ } else {
27
+ start();
28
+ }
29
+ })();
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Webflow-safe entry: runs once, waits for DOM and window.Webflow when present.
3
+ * No globals leaked; no eval.
4
+ */
5
+ (() => {
6
+ const run = (): void => {
7
+ // Your project code here.
8
+ // Prefer `sp` when Stagepass loader is present (session-aware logging, vars, etc.).
9
+ const sp = (window as Window & { sp?: { log?: (...args: unknown[]) => void } }).sp;
10
+ sp?.log?.('{{NAME}}: ready');
11
+ };
12
+
13
+ const start = (): void => {
14
+ const w = window as Window & {
15
+ Webflow?: { push?: (fn: () => void) => void };
16
+ };
17
+ if (w.Webflow && typeof w.Webflow.push === 'function') {
18
+ w.Webflow.push(run);
19
+ return;
20
+ }
21
+ run();
22
+ };
23
+
24
+ if (document.readyState === 'loading') {
25
+ document.addEventListener('DOMContentLoaded', start, { once: true });
26
+ } else {
27
+ start();
28
+ }
29
+ })();
@@ -0,0 +1,8 @@
1
+ /* {{NAME}} styles */
2
+ :root {
3
+ --sp-project: '{{NAME}}';
4
+ }
5
+
6
+ .sp-{{NAME}} {
7
+ /* Add project styles here. */
8
+ }
@@ -0,0 +1,8 @@
1
+ // {{NAME}} styles
2
+ :root {
3
+ --sp-project: '{{NAME}}';
4
+ }
5
+
6
+ .sp-{{NAME}} {
7
+ // Add project styles here.
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "{{NAME}}",
3
+ "domain": "{{NAME}}.sp",
4
+ "lang": "{{LANG}}",
5
+ "styles": "{{STYLES}}",
6
+ "modules": {{MODULES_JSON}},{{ORIGIN_LINE}}
7
+ "version": 1
8
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2018",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "noEmit": true,
8
+ "skipLibCheck": true,
9
+ "lib": ["ES2018", "DOM"],
10
+ "types": {{TYPES_JSON}}
11
+ },
12
+ "include": ["src/**/*.ts"]
13
+ }