@cccarv82/freya 1.0.7 → 1.0.8
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/cli/web.js +38 -8
- package/package.json +1 -1
package/cli/web.js
CHANGED
|
@@ -13,6 +13,11 @@ function guessNpxCmd() {
|
|
|
13
13
|
return process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
function guessNpxYesFlag() {
|
|
17
|
+
// npx supports --yes/-y on modern npm; use -y for broad compatibility
|
|
18
|
+
return '-y';
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
function guessOpenCmd() {
|
|
17
22
|
// Minimal cross-platform opener without extra deps
|
|
18
23
|
if (process.platform === 'win32') return { cmd: 'cmd', args: ['/c', 'start', ''] };
|
|
@@ -62,6 +67,26 @@ function safeJson(res, code, obj) {
|
|
|
62
67
|
res.end(body);
|
|
63
68
|
}
|
|
64
69
|
|
|
70
|
+
function looksLikeFreyaWorkspace(dir) {
|
|
71
|
+
// minimal check: has scripts/validate-data.js and data/
|
|
72
|
+
return (
|
|
73
|
+
exists(path.join(dir, 'package.json')) &&
|
|
74
|
+
exists(path.join(dir, 'scripts')) &&
|
|
75
|
+
exists(path.join(dir, 'data'))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function normalizeWorkspaceDir(inputDir) {
|
|
80
|
+
const d = path.resolve(process.cwd(), inputDir);
|
|
81
|
+
if (looksLikeFreyaWorkspace(d)) return d;
|
|
82
|
+
|
|
83
|
+
// Common case: user picked parent folder that contains ./freya
|
|
84
|
+
const child = path.join(d, 'freya');
|
|
85
|
+
if (looksLikeFreyaWorkspace(child)) return child;
|
|
86
|
+
|
|
87
|
+
return d;
|
|
88
|
+
}
|
|
89
|
+
|
|
65
90
|
function readBody(req) {
|
|
66
91
|
return new Promise((resolve, reject) => {
|
|
67
92
|
const chunks = [];
|
|
@@ -1007,7 +1032,8 @@ async function cmdWeb({ port, dir, open, dev }) {
|
|
|
1007
1032
|
const raw = await readBody(req);
|
|
1008
1033
|
const payload = raw ? JSON.parse(raw) : {};
|
|
1009
1034
|
|
|
1010
|
-
const
|
|
1035
|
+
const requestedDir = payload.dir || dir || './freya';
|
|
1036
|
+
const workspaceDir = normalizeWorkspaceDir(requestedDir);
|
|
1011
1037
|
|
|
1012
1038
|
if (req.url === '/api/pick-dir') {
|
|
1013
1039
|
const picked = await pickDirectoryNative();
|
|
@@ -1016,27 +1042,31 @@ async function cmdWeb({ port, dir, open, dev }) {
|
|
|
1016
1042
|
|
|
1017
1043
|
if (req.url === '/api/init') {
|
|
1018
1044
|
const pkg = '@cccarv82/freya';
|
|
1019
|
-
const r = await run(guessNpxCmd(), [pkg, 'init', workspaceDir], process.cwd());
|
|
1020
|
-
|
|
1045
|
+
const r = await run(guessNpxCmd(), [guessNpxYesFlag(), pkg, 'init', workspaceDir], process.cwd());
|
|
1046
|
+
const output = (r.stdout + r.stderr).trim();
|
|
1047
|
+
return safeJson(res, r.code === 0 ? 200 : 400, r.code === 0 ? { output } : { error: output || 'init failed', output });
|
|
1021
1048
|
}
|
|
1022
1049
|
|
|
1023
1050
|
if (req.url === '/api/update') {
|
|
1024
1051
|
const pkg = '@cccarv82/freya';
|
|
1025
1052
|
fs.mkdirSync(workspaceDir, { recursive: true });
|
|
1026
|
-
const r = await run(guessNpxCmd(), [pkg, 'init', '--here'], workspaceDir);
|
|
1027
|
-
|
|
1053
|
+
const r = await run(guessNpxCmd(), [guessNpxYesFlag(), pkg, 'init', '--here'], workspaceDir);
|
|
1054
|
+
const output = (r.stdout + r.stderr).trim();
|
|
1055
|
+
return safeJson(res, r.code === 0 ? 200 : 400, r.code === 0 ? { output } : { error: output || 'update failed', output });
|
|
1028
1056
|
}
|
|
1029
1057
|
|
|
1030
1058
|
const npmCmd = guessNpmCmd();
|
|
1031
1059
|
|
|
1032
1060
|
if (req.url === '/api/health') {
|
|
1033
1061
|
const r = await run(npmCmd, ['run', 'health'], workspaceDir);
|
|
1034
|
-
|
|
1062
|
+
const output = (r.stdout + r.stderr).trim();
|
|
1063
|
+
return safeJson(res, r.code === 0 ? 200 : 400, r.code === 0 ? { output } : { error: output || 'health failed', output });
|
|
1035
1064
|
}
|
|
1036
1065
|
|
|
1037
1066
|
if (req.url === '/api/migrate') {
|
|
1038
1067
|
const r = await run(npmCmd, ['run', 'migrate'], workspaceDir);
|
|
1039
|
-
|
|
1068
|
+
const output = (r.stdout + r.stderr).trim();
|
|
1069
|
+
return safeJson(res, r.code === 0 ? 200 : 400, r.code === 0 ? { output } : { error: output || 'migrate failed', output });
|
|
1040
1070
|
}
|
|
1041
1071
|
|
|
1042
1072
|
if (req.url === '/api/report') {
|
|
@@ -1060,7 +1090,7 @@ async function cmdWeb({ port, dir, open, dev }) {
|
|
|
1060
1090
|
// Prefer showing the actual report content when available.
|
|
1061
1091
|
const output = reportText ? reportText : out;
|
|
1062
1092
|
|
|
1063
|
-
return safeJson(res, r.code === 0 ? 200 : 400, { output, reportPath, reportText });
|
|
1093
|
+
return safeJson(res, r.code === 0 ? 200 : 400, r.code === 0 ? { output, reportPath, reportText } : { error: output || 'report failed', output, reportPath, reportText });
|
|
1064
1094
|
}
|
|
1065
1095
|
|
|
1066
1096
|
if (req.url === '/api/publish') {
|