dealsystem 0.0.1 → 0.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.
- package/README.md +64 -2
- package/dist/api/errors.d.ts +25 -0
- package/dist/api/errors.js +38 -0
- package/dist/api/http.d.ts +56 -0
- package/dist/api/http.js +406 -0
- package/dist/api/legal.d.ts +9 -0
- package/dist/api/legal.js +20 -0
- package/dist/api/oauth.d.ts +35 -0
- package/dist/api/oauth.js +113 -0
- package/dist/api/types.d.ts +142 -0
- package/dist/api/types.js +9 -0
- package/dist/auth/credentials.d.ts +28 -0
- package/dist/auth/credentials.js +96 -0
- package/dist/auth/session.d.ts +10 -0
- package/dist/auth/session.js +46 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +4 -0
- package/dist/check/allowlist.d.ts +9 -0
- package/dist/check/allowlist.js +74 -0
- package/dist/check/catalog.d.ts +6 -0
- package/dist/check/catalog.js +410 -0
- package/dist/check/context.d.ts +79 -0
- package/dist/check/context.js +230 -0
- package/dist/check/fileset.d.ts +19 -0
- package/dist/check/fileset.js +91 -0
- package/dist/check/format.d.ts +25 -0
- package/dist/check/format.js +79 -0
- package/dist/check/index.d.ts +8 -0
- package/dist/check/index.js +9 -0
- package/dist/check/rule.d.ts +15 -0
- package/dist/check/rule.js +6 -0
- package/dist/check/rules/a11y.d.ts +3 -0
- package/dist/check/rules/a11y.js +433 -0
- package/dist/check/rules/privacy.d.ts +9 -0
- package/dist/check/rules/privacy.js +437 -0
- package/dist/check/rules/quality.d.ts +11 -0
- package/dist/check/rules/quality.js +451 -0
- package/dist/check/rules/schedule.d.ts +2 -0
- package/dist/check/rules/schedule.js +30 -0
- package/dist/check/rules/security.d.ts +18 -0
- package/dist/check/rules/security.js +744 -0
- package/dist/check/rules/structure.d.ts +2 -0
- package/dist/check/rules/structure.js +399 -0
- package/dist/check/run.d.ts +15 -0
- package/dist/check/run.js +147 -0
- package/dist/check/sdk.d.ts +56 -0
- package/dist/check/sdk.js +58 -0
- package/dist/check/types.d.ts +116 -0
- package/dist/check/types.js +2 -0
- package/dist/check/util/code.d.ts +19 -0
- package/dist/check/util/code.js +113 -0
- package/dist/check/util/color.d.ts +10 -0
- package/dist/check/util/color.js +53 -0
- package/dist/check/util/csp.d.ts +71 -0
- package/dist/check/util/csp.js +229 -0
- package/dist/check/util/html.d.ts +31 -0
- package/dist/check/util/html.js +65 -0
- package/dist/check/util/lines.d.ts +1 -0
- package/dist/check/util/lines.js +2 -0
- package/dist/check/util/literal.d.ts +1 -0
- package/dist/check/util/literal.js +3 -0
- package/dist/check/util/svelte.d.ts +42 -0
- package/dist/check/util/svelte.js +109 -0
- package/dist/cli/context.d.ts +40 -0
- package/dist/cli/context.js +107 -0
- package/dist/cli/io.d.ts +26 -0
- package/dist/cli/io.js +68 -0
- package/dist/cli/main.d.ts +24 -0
- package/dist/cli/main.js +269 -0
- package/dist/commands/check.d.ts +4 -0
- package/dist/commands/check.js +54 -0
- package/dist/commands/deploy.d.ts +20 -0
- package/dist/commands/deploy.js +315 -0
- package/dist/commands/dev.d.ts +29 -0
- package/dist/commands/dev.js +149 -0
- package/dist/commands/image.d.ts +12 -0
- package/dist/commands/image.js +291 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.js +116 -0
- package/dist/commands/pull.d.ts +12 -0
- package/dist/commands/pull.js +178 -0
- package/dist/commands/site.d.ts +9 -0
- package/dist/commands/site.js +84 -0
- package/dist/commands/sync.d.ts +2 -0
- package/dist/commands/sync.js +126 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/project/agentFiles.d.ts +17 -0
- package/dist/project/agentFiles.js +156 -0
- package/dist/project/agentsBlock.d.ts +2 -0
- package/dist/project/agentsBlock.js +14 -0
- package/dist/project/siteConfig.d.ts +5 -0
- package/dist/project/siteConfig.js +35 -0
- package/dist/project/snapshot.d.ts +21 -0
- package/dist/project/snapshot.js +125 -0
- package/dist/project/svelteConfig.d.ts +4 -0
- package/dist/project/svelteConfig.js +74 -0
- package/dist/project/tar.d.ts +8 -0
- package/dist/project/tar.js +89 -0
- package/dist/project/untar.d.ts +27 -0
- package/dist/project/untar.js +232 -0
- package/dist/project/uploadFiles.d.ts +17 -0
- package/dist/project/uploadFiles.js +55 -0
- package/package.json +63 -7
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Kleiner HTML-Baum für die Ausgabe-Regeln. Liest gebautes HTML, führt nichts aus.
|
|
2
|
+
import { Parser } from 'htmlparser2';
|
|
3
|
+
import { LineIndex } from './lines.js';
|
|
4
|
+
export function isElement(node) {
|
|
5
|
+
return 'tag' in node;
|
|
6
|
+
}
|
|
7
|
+
export function parseHtml(html) {
|
|
8
|
+
const root = { tag: '#root', attrs: {}, children: [], parent: null, start: 0 };
|
|
9
|
+
const elements = [];
|
|
10
|
+
let current = root;
|
|
11
|
+
const parser = new Parser({
|
|
12
|
+
onopentag(name, attrs) {
|
|
13
|
+
const el = { tag: name, attrs, children: [], parent: current, start: parser.startIndex };
|
|
14
|
+
current.children.push(el);
|
|
15
|
+
elements.push(el);
|
|
16
|
+
current = el;
|
|
17
|
+
},
|
|
18
|
+
ontext(text) {
|
|
19
|
+
current.children.push({ text, parent: current, start: parser.startIndex });
|
|
20
|
+
},
|
|
21
|
+
onclosetag() {
|
|
22
|
+
current = current.parent ?? root;
|
|
23
|
+
},
|
|
24
|
+
}, { decodeEntities: true, lowerCaseTags: true, lowerCaseAttributeNames: true, recognizeSelfClosing: true });
|
|
25
|
+
parser.write(html);
|
|
26
|
+
parser.end();
|
|
27
|
+
return { root, lines: new LineIndex(html), elements };
|
|
28
|
+
}
|
|
29
|
+
/** Sichtbarer Text eines Elements (ohne `script`, `style`, `template`). */
|
|
30
|
+
export function textContent(el) {
|
|
31
|
+
let out = '';
|
|
32
|
+
for (const child of el.children) {
|
|
33
|
+
if (isElement(child)) {
|
|
34
|
+
if (child.tag === 'script' || child.tag === 'style' || child.tag === 'template')
|
|
35
|
+
continue;
|
|
36
|
+
out += textContent(child);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
out += child.text;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
export function ancestors(el) {
|
|
45
|
+
const out = [];
|
|
46
|
+
let p = el.parent;
|
|
47
|
+
while (p && p.tag !== '#root') {
|
|
48
|
+
out.push(p);
|
|
49
|
+
p = p.parent;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** Element oder ein Vorfahre ist für Hilfstechnik versteckt. */
|
|
54
|
+
export function isHidden(el) {
|
|
55
|
+
for (const node of [el, ...ancestors(el)]) {
|
|
56
|
+
if (node.attrs['aria-hidden'] === 'true' || 'hidden' in node.attrs || 'inert' in node.attrs)
|
|
57
|
+
return true;
|
|
58
|
+
if (node.tag === 'template' || node.tag === 'noscript')
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
export function lineOf(doc, el) {
|
|
64
|
+
return doc.lines.at(el.start).line;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LineIndex, type Position } from '@dealsystem/site/config/static';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { evaluate, findKeyLine, isOpaque, isPlainObject, parseModule, type LiteralValue, type Opaque, type ParsedModule, } from '@dealsystem/site/config/static';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// Statischer Leser für Konfigurationsdateien. Liegt seit Regelsatz 3 im SDK (`@dealsystem/site/config/static`),
|
|
2
|
+
// weil `dealsystemCsp()` in svelte.config.js dieselbe Konfiguration lesen muss wie `check`.
|
|
3
|
+
export { evaluate, findKeyLine, isOpaque, isPlainObject, parseModule, } from '@dealsystem/site/config/static';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LineIndex } from './lines.js';
|
|
2
|
+
export interface SvelteAttr {
|
|
3
|
+
name: string;
|
|
4
|
+
/** `attribute` (`alt="…"`), `spread` (`{...props}`), `directive` (`bind:`, `on:`, `class:` …). */
|
|
5
|
+
kind: 'attribute' | 'spread' | 'directive';
|
|
6
|
+
/** Fester Wert; `true` bei Attribut ohne Wert; `null`, wenn der Wert ein Ausdruck ist. */
|
|
7
|
+
value: string | true | null;
|
|
8
|
+
start: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SvelteElement {
|
|
11
|
+
kind: 'element' | 'component';
|
|
12
|
+
name: string;
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
attributes: SvelteAttr[];
|
|
16
|
+
/** Namen der umschließenden Elemente und Komponenten, außen zuerst. */
|
|
17
|
+
ancestors: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface SvelteText {
|
|
20
|
+
data: string;
|
|
21
|
+
start: number;
|
|
22
|
+
ancestors: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface ParsedSvelte {
|
|
25
|
+
lines: LineIndex;
|
|
26
|
+
elements: SvelteElement[];
|
|
27
|
+
/** `{@html …}` */
|
|
28
|
+
htmlTags: {
|
|
29
|
+
start: number;
|
|
30
|
+
ancestors: string[];
|
|
31
|
+
}[];
|
|
32
|
+
texts: SvelteText[];
|
|
33
|
+
/** Inhalt der `<style>`-Blöcke mit Start-Offset. */
|
|
34
|
+
styles: {
|
|
35
|
+
content: string;
|
|
36
|
+
start: number;
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
/** Liefert `null`, wenn die Datei nicht parst (dann scheitert ohnehin der Build, BLD-001). */
|
|
40
|
+
export declare function parseSvelte(code: string): ParsedSvelte | null;
|
|
41
|
+
export declare function getAttr(el: SvelteElement, name: string): SvelteAttr | undefined;
|
|
42
|
+
export declare function hasSpread(el: SvelteElement): boolean;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Liest Svelte-Komponenten über den Svelte-Parser (kein Kompilieren, kein Ausführen).
|
|
2
|
+
import { parse } from 'svelte/compiler';
|
|
3
|
+
import { LineIndex } from './lines.js';
|
|
4
|
+
const ELEMENT_TYPES = new Set([
|
|
5
|
+
'RegularElement',
|
|
6
|
+
'SvelteElement',
|
|
7
|
+
'SlotElement',
|
|
8
|
+
'TitleElement',
|
|
9
|
+
'SvelteHead',
|
|
10
|
+
'SvelteBody',
|
|
11
|
+
'SvelteWindow',
|
|
12
|
+
'SvelteDocument',
|
|
13
|
+
'SvelteFragment',
|
|
14
|
+
'SvelteBoundary',
|
|
15
|
+
]);
|
|
16
|
+
function attrValue(value) {
|
|
17
|
+
if (value === true)
|
|
18
|
+
return true;
|
|
19
|
+
const parts = Array.isArray(value) ? value : [value];
|
|
20
|
+
let out = '';
|
|
21
|
+
for (const part of parts) {
|
|
22
|
+
if (part?.type === 'Text')
|
|
23
|
+
out += String(part.data ?? '');
|
|
24
|
+
else
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function toAttrs(list) {
|
|
30
|
+
if (!Array.isArray(list))
|
|
31
|
+
return [];
|
|
32
|
+
return list.map((a) => {
|
|
33
|
+
if (a.type === 'Attribute') {
|
|
34
|
+
return { name: String(a.name), kind: 'attribute', value: attrValue(a.value), start: a.start ?? 0 };
|
|
35
|
+
}
|
|
36
|
+
if (a.type === 'SpreadAttribute')
|
|
37
|
+
return { name: '...', kind: 'spread', value: null, start: a.start ?? 0 };
|
|
38
|
+
return { name: String(a.name ?? a.type), kind: 'directive', value: null, start: a.start ?? 0 };
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Liefert `null`, wenn die Datei nicht parst (dann scheitert ohnehin der Build, BLD-001). */
|
|
42
|
+
export function parseSvelte(code) {
|
|
43
|
+
let ast;
|
|
44
|
+
try {
|
|
45
|
+
ast = parse(code, { modern: true });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const result = {
|
|
51
|
+
lines: new LineIndex(code),
|
|
52
|
+
elements: [],
|
|
53
|
+
htmlTags: [],
|
|
54
|
+
texts: [],
|
|
55
|
+
styles: [],
|
|
56
|
+
};
|
|
57
|
+
const seen = new Set();
|
|
58
|
+
const visit = (node, ancestors) => {
|
|
59
|
+
if (!node || typeof node !== 'object' || seen.has(node))
|
|
60
|
+
return;
|
|
61
|
+
seen.add(node);
|
|
62
|
+
if (Array.isArray(node)) {
|
|
63
|
+
for (const child of node)
|
|
64
|
+
visit(child, ancestors);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const n = node;
|
|
68
|
+
let inner = ancestors;
|
|
69
|
+
if (n.type === 'Component' || ELEMENT_TYPES.has(n.type ?? '')) {
|
|
70
|
+
const name = n.type === 'SvelteHead' ? 'svelte:head' : String(n.name ?? n.type);
|
|
71
|
+
result.elements.push({
|
|
72
|
+
kind: n.type === 'Component' ? 'component' : 'element',
|
|
73
|
+
name,
|
|
74
|
+
start: n.start ?? 0,
|
|
75
|
+
end: n.end ?? 0,
|
|
76
|
+
attributes: toAttrs(n.attributes),
|
|
77
|
+
ancestors,
|
|
78
|
+
});
|
|
79
|
+
inner = [...ancestors, name];
|
|
80
|
+
}
|
|
81
|
+
else if (n.type === 'HtmlTag') {
|
|
82
|
+
result.htmlTags.push({ start: n.start ?? 0, ancestors });
|
|
83
|
+
}
|
|
84
|
+
else if (n.type === 'Text' && typeof n.data === 'string') {
|
|
85
|
+
result.texts.push({ data: n.data, start: n.start ?? 0, ancestors });
|
|
86
|
+
}
|
|
87
|
+
else if (n.type === 'StyleSheet') {
|
|
88
|
+
const content = n.content;
|
|
89
|
+
if (content?.styles !== undefined)
|
|
90
|
+
result.styles.push({ content: content.styles, start: content.start ?? 0 });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
for (const [key, value] of Object.entries(n)) {
|
|
94
|
+
if (key === 'attributes' || key === 'metadata')
|
|
95
|
+
continue;
|
|
96
|
+
if (value && typeof value === 'object')
|
|
97
|
+
visit(value, inner);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
visit(ast.fragment, []);
|
|
101
|
+
visit(ast.css, []);
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
export function getAttr(el, name) {
|
|
105
|
+
return el.attributes.find((a) => a.name === name);
|
|
106
|
+
}
|
|
107
|
+
export function hasSpread(el) {
|
|
108
|
+
return el.attributes.some((a) => a.kind === 'spread');
|
|
109
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ExitCode } from '../api/errors.js';
|
|
2
|
+
import type { DeployApi } from '../api/types.js';
|
|
3
|
+
import { CredentialStore } from '../auth/credentials.js';
|
|
4
|
+
import type { CliIO } from './io.js';
|
|
5
|
+
export declare const DEFAULT_API_URL = "https://app.dealsystem.io";
|
|
6
|
+
export type OptionValues = Record<string, string | boolean | undefined>;
|
|
7
|
+
export interface CommandResult {
|
|
8
|
+
exitCode: ExitCode;
|
|
9
|
+
/** Inhalt von `data` in der JSON-Ausgabe. */
|
|
10
|
+
data: unknown;
|
|
11
|
+
/** Textausgabe für Menschen und Agenten ohne `--json`. */
|
|
12
|
+
text: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class CommandContext {
|
|
15
|
+
readonly io: CliIO;
|
|
16
|
+
readonly command: string;
|
|
17
|
+
readonly options: OptionValues;
|
|
18
|
+
readonly positionals: string[];
|
|
19
|
+
private readonly apiFactory?;
|
|
20
|
+
readonly apiUrl: string;
|
|
21
|
+
readonly projectDir: string;
|
|
22
|
+
readonly json: boolean;
|
|
23
|
+
readonly store: CredentialStore;
|
|
24
|
+
private apiInstance;
|
|
25
|
+
constructor(io: CliIO, command: string, options: OptionValues, positionals: string[], apiFactory?: ((ctx: CommandContext) => DeployApi) | undefined);
|
|
26
|
+
str(name: string): string | undefined;
|
|
27
|
+
flag(name: string): boolean;
|
|
28
|
+
/** Fortschritt auf stderr; stdout bleibt dem Ergebnis vorbehalten (wichtig für `--json`). */
|
|
29
|
+
progress(message: string): void;
|
|
30
|
+
api(): DeployApi;
|
|
31
|
+
path(rel: string): string;
|
|
32
|
+
readProjectFile(rel: string): string | null;
|
|
33
|
+
/** `--site` oder `siteId` aus dealsystem.config.ts. */
|
|
34
|
+
siteId(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Bestätigung für folgenreiche Schritte (Live schalten, Rollback). Agenten laufen ohne Terminal: sie
|
|
37
|
+
* müssen den Nutzer fragen und dann `--confirm` übergeben, wie `confirmedByUser` im MCP-Werkzeug.
|
|
38
|
+
*/
|
|
39
|
+
confirm(question: string, retryCommand: string, data?: unknown): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Gemeinsamer Zustand eines Befehls: Optionen, Projektordner, API, Fortschrittsmeldungen.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { CliError, EXIT } from '../api/errors.js';
|
|
5
|
+
import { HttpDeployApi } from '../api/http.js';
|
|
6
|
+
import { CredentialStore } from '../auth/credentials.js';
|
|
7
|
+
import { createTokenProvider } from '../auth/session.js';
|
|
8
|
+
import { readSiteConfig, SITE_CONFIG_FILE } from '../project/siteConfig.js';
|
|
9
|
+
export const DEFAULT_API_URL = 'https://app.dealsystem.io';
|
|
10
|
+
export class CommandContext {
|
|
11
|
+
io;
|
|
12
|
+
command;
|
|
13
|
+
options;
|
|
14
|
+
positionals;
|
|
15
|
+
apiFactory;
|
|
16
|
+
apiUrl;
|
|
17
|
+
projectDir;
|
|
18
|
+
json;
|
|
19
|
+
store;
|
|
20
|
+
apiInstance;
|
|
21
|
+
constructor(io, command, options, positionals, apiFactory) {
|
|
22
|
+
this.io = io;
|
|
23
|
+
this.command = command;
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.positionals = positionals;
|
|
26
|
+
this.apiFactory = apiFactory;
|
|
27
|
+
const apiUrl = (this.str('api-url') ?? io.env.DEALSYSTEM_API_URL ?? DEFAULT_API_URL).replace(/\/+$/, '');
|
|
28
|
+
try {
|
|
29
|
+
const u = new URL(apiUrl);
|
|
30
|
+
if (u.protocol !== 'https:' && !['localhost', '127.0.0.1', '[::1]'].includes(u.hostname)) {
|
|
31
|
+
throw new Error('https');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throw new CliError('invalid_api_url', `\`${apiUrl}\` ist keine gültige API-Adresse.`, 'Nutze https (z. B. `https://app.dealsystem.io`); http nur für localhost.', EXIT.usage);
|
|
36
|
+
}
|
|
37
|
+
this.apiUrl = apiUrl;
|
|
38
|
+
const dir = this.str('dir');
|
|
39
|
+
this.projectDir = dir ? (isAbsolute(dir) ? dir : resolve(io.cwd, dir)) : io.cwd;
|
|
40
|
+
this.json = this.options.json === true;
|
|
41
|
+
this.store = new CredentialStore(io.env);
|
|
42
|
+
}
|
|
43
|
+
str(name) {
|
|
44
|
+
const v = this.options[name];
|
|
45
|
+
return typeof v === 'string' ? v : undefined;
|
|
46
|
+
}
|
|
47
|
+
flag(name) {
|
|
48
|
+
return this.options[name] === true;
|
|
49
|
+
}
|
|
50
|
+
/** Fortschritt auf stderr; stdout bleibt dem Ergebnis vorbehalten (wichtig für `--json`). */
|
|
51
|
+
progress(message) {
|
|
52
|
+
if (this.flag('quiet'))
|
|
53
|
+
return;
|
|
54
|
+
this.io.stderr(message);
|
|
55
|
+
}
|
|
56
|
+
api() {
|
|
57
|
+
this.apiInstance ??= this.apiFactory
|
|
58
|
+
? this.apiFactory(this)
|
|
59
|
+
: new HttpDeployApi(this.apiUrl, createTokenProvider({
|
|
60
|
+
apiUrl: this.apiUrl,
|
|
61
|
+
env: this.io.env,
|
|
62
|
+
store: this.store,
|
|
63
|
+
fetch: this.io.fetch,
|
|
64
|
+
now: () => this.io.now(),
|
|
65
|
+
}), this.io.fetch);
|
|
66
|
+
return this.apiInstance;
|
|
67
|
+
}
|
|
68
|
+
path(rel) {
|
|
69
|
+
return join(this.projectDir, ...rel.split('/'));
|
|
70
|
+
}
|
|
71
|
+
readProjectFile(rel) {
|
|
72
|
+
try {
|
|
73
|
+
return readFileSync(this.path(rel), 'utf8');
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** `--site` oder `siteId` aus dealsystem.config.ts. */
|
|
80
|
+
siteId() {
|
|
81
|
+
const fromFlag = this.str('site');
|
|
82
|
+
if (fromFlag)
|
|
83
|
+
return fromFlag;
|
|
84
|
+
const config = readSiteConfig(this.readProjectFile(SITE_CONFIG_FILE));
|
|
85
|
+
const id = config.data?.siteId;
|
|
86
|
+
if (id)
|
|
87
|
+
return id;
|
|
88
|
+
throw new CliError('no_site', config.exists
|
|
89
|
+
? `In ${SITE_CONFIG_FILE} ist keine gültige \`siteId\` eingetragen.`
|
|
90
|
+
: `${SITE_CONFIG_FILE} fehlt in ${this.projectDir}.`, 'Führe `npx dealsystem init` im Projektordner aus.', EXIT.usage);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Bestätigung für folgenreiche Schritte (Live schalten, Rollback). Agenten laufen ohne Terminal: sie
|
|
94
|
+
* müssen den Nutzer fragen und dann `--confirm` übergeben, wie `confirmedByUser` im MCP-Werkzeug.
|
|
95
|
+
*/
|
|
96
|
+
async confirm(question, retryCommand, data) {
|
|
97
|
+
if (this.flag('confirm'))
|
|
98
|
+
return;
|
|
99
|
+
if (this.io.isInteractive && !this.json) {
|
|
100
|
+
const answer = (await this.io.prompt(`${question} [j/N] `)).trim().toLowerCase();
|
|
101
|
+
if (answer === 'j' || answer === 'ja' || answer === 'y' || answer === 'yes')
|
|
102
|
+
return;
|
|
103
|
+
throw new CliError('not_confirmed', 'Abgebrochen, nichts wurde live geschaltet.', 'Nichts zu tun.', EXIT.usage, data);
|
|
104
|
+
}
|
|
105
|
+
throw new CliError('confirmation_required', `${question} Dafür braucht es die ausdrückliche Zustimmung des Nutzers.`, `Frage den Nutzer genau das. Nur wenn er zustimmt: \`${retryCommand} --confirm\`.`, EXIT.usage, data);
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/cli/io.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FetchLike } from '../api/http.js';
|
|
2
|
+
/** Ergebnis eines Prozesses: Exit-Code (`null` bei Abbruch durch ein Signal) und die Ausgabe von stdout und stderr. */
|
|
3
|
+
export interface ProcessResult {
|
|
4
|
+
exitCode: number | null;
|
|
5
|
+
output: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CliIO {
|
|
8
|
+
cwd: string;
|
|
9
|
+
env: NodeJS.ProcessEnv;
|
|
10
|
+
stdout(text: string): void;
|
|
11
|
+
stderr(text: string): void;
|
|
12
|
+
/** Mensch am Terminal (stdin und stdout sind TTY). Agenten laufen ohne. */
|
|
13
|
+
isInteractive: boolean;
|
|
14
|
+
prompt(question: string): Promise<string>;
|
|
15
|
+
/** Öffnet die Adresse im Standard-Browser. `false`, wenn das nicht ging. */
|
|
16
|
+
openBrowser(url: string): Promise<boolean>;
|
|
17
|
+
fetch: FetchLike;
|
|
18
|
+
now(): Date;
|
|
19
|
+
sleep(ms: number): Promise<void>;
|
|
20
|
+
/** Startet einen Prozess ohne Shell (z. B. den lokalen Build vor dem Hochladen) und sammelt seine Ausgabe. */
|
|
21
|
+
run(command: string, args: string[], options: {
|
|
22
|
+
cwd: string;
|
|
23
|
+
env: NodeJS.ProcessEnv;
|
|
24
|
+
}): Promise<ProcessResult>;
|
|
25
|
+
}
|
|
26
|
+
export declare function nodeIO(): CliIO;
|
package/dist/cli/io.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Alles, was die CLI von außen braucht. Tests ersetzen es; `nodeIO()` ist die echte Umgebung.
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { createInterface } from 'node:readline/promises';
|
|
4
|
+
/** So viel Ausgabe eines Prozesses bleibt höchstens im Speicher (das Ende zählt). */
|
|
5
|
+
const MAX_PROCESS_OUTPUT = 256 * 1024;
|
|
6
|
+
function browserCommand(url) {
|
|
7
|
+
if (process.platform === 'darwin')
|
|
8
|
+
return ['open', [url]];
|
|
9
|
+
if (process.platform === 'win32')
|
|
10
|
+
return ['cmd', ['/c', 'start', '""', url]];
|
|
11
|
+
return ['xdg-open', [url]];
|
|
12
|
+
}
|
|
13
|
+
export function nodeIO() {
|
|
14
|
+
return {
|
|
15
|
+
cwd: process.cwd(),
|
|
16
|
+
env: process.env,
|
|
17
|
+
stdout: (text) => process.stdout.write(text.endsWith('\n') ? text : `${text}\n`),
|
|
18
|
+
stderr: (text) => process.stderr.write(text.endsWith('\n') ? text : `${text}\n`),
|
|
19
|
+
isInteractive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
20
|
+
async prompt(question) {
|
|
21
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
22
|
+
try {
|
|
23
|
+
return await rl.question(question);
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
rl.close();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
openBrowser(url) {
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
try {
|
|
32
|
+
const [cmd, args] = browserCommand(url);
|
|
33
|
+
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
34
|
+
child.on('error', () => resolve(false));
|
|
35
|
+
child.on('spawn', () => {
|
|
36
|
+
child.unref();
|
|
37
|
+
resolve(true);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
resolve(false);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
fetch: (input, init) => fetch(input, init),
|
|
46
|
+
now: () => new Date(),
|
|
47
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
48
|
+
run(command, args, options) {
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
let output = '';
|
|
51
|
+
const append = (chunk) => {
|
|
52
|
+
output += chunk.toString('utf8');
|
|
53
|
+
if (output.length > MAX_PROCESS_OUTPUT)
|
|
54
|
+
output = output.slice(-MAX_PROCESS_OUTPUT);
|
|
55
|
+
};
|
|
56
|
+
const child = spawn(command, args, {
|
|
57
|
+
cwd: options.cwd,
|
|
58
|
+
env: options.env,
|
|
59
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
60
|
+
});
|
|
61
|
+
child.stdout.on('data', append);
|
|
62
|
+
child.stderr.on('data', append);
|
|
63
|
+
child.on('error', (error) => resolve({ exitCode: null, output: `${output}\n${error.message}` }));
|
|
64
|
+
child.on('close', (code) => resolve({ exitCode: code, output }));
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ParseArgsConfig } from 'node:util';
|
|
2
|
+
import { type ExitCode } from '../api/errors.js';
|
|
3
|
+
import type { DeployApi } from '../api/types.js';
|
|
4
|
+
import { CommandContext, type CommandResult } from './context.js';
|
|
5
|
+
import type { CliIO } from './io.js';
|
|
6
|
+
type Options = NonNullable<ParseArgsConfig['options']>;
|
|
7
|
+
interface CommandDef {
|
|
8
|
+
summary: string;
|
|
9
|
+
usage: string;
|
|
10
|
+
options: Options;
|
|
11
|
+
flags: string[];
|
|
12
|
+
run: (ctx: CommandContext) => Promise<CommandResult>;
|
|
13
|
+
positionals?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const COMMANDS: Record<string, CommandDef>;
|
|
16
|
+
export declare function cliVersion(): string;
|
|
17
|
+
export declare function helpText(command?: string): string;
|
|
18
|
+
export interface RunOptions {
|
|
19
|
+
/** Für Tests: eigene API statt HTTP. */
|
|
20
|
+
apiFactory?: (ctx: CommandContext) => DeployApi;
|
|
21
|
+
}
|
|
22
|
+
/** Führt die CLI aus und liefert den Exit-Code. Wirft nie. */
|
|
23
|
+
export declare function run(argv: string[], io: CliIO, options?: RunOptions): Promise<ExitCode>;
|
|
24
|
+
export {};
|