@sigx/cli 0.2.8 → 0.3.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 +8 -59
- package/dist/cli.js +59 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +48 -413
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/scaffold.js +165 -0
- package/dist/commands/scaffold.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/plugin.d.ts +56 -0
- package/dist/plugin.js.map +1 -1
- package/dist/shell/index.d.ts +23 -0
- package/dist/shell/index.js +503 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/templates/lynx/package.json +1 -1
- package/dist/templates/lynx/src/lynx-env.d.ts +1 -0
- package/dist/templates/lynx/src/main.tsx +2 -2
- package/dist/templates/lynx-daisyui/package.json +1 -1
- package/dist/templates/lynx-daisyui/src/lynx-env.d.ts +1 -0
- package/dist/templates/lynx-daisyui/src/main.tsx +2 -2
- package/dist/templates/lynx-tailwind/package.json +1 -1
- package/dist/templates/lynx-tailwind/src/lynx-env.d.ts +1 -0
- package/dist/templates/lynx-tailwind/src/main.tsx +2 -2
- package/dist/templates/ssg/package.json +1 -1
- package/dist/templates/ssg-daisyui/package.json +1 -1
- package/dist/templates/ssg-tailwind/package.json +1 -1
- package/package.json +7 -3
- package/templates/lynx/package.json +1 -1
- package/templates/lynx/src/lynx-env.d.ts +1 -0
- package/templates/lynx/src/main.tsx +2 -2
- package/templates/lynx-daisyui/package.json +1 -1
- package/templates/lynx-daisyui/src/lynx-env.d.ts +1 -0
- package/templates/lynx-daisyui/src/main.tsx +2 -2
- package/templates/lynx-tailwind/package.json +1 -1
- package/templates/lynx-tailwind/src/lynx-env.d.ts +1 -0
- package/templates/lynx-tailwind/src/main.tsx +2 -2
- package/templates/ssg/package.json +1 -1
- package/templates/ssg-daisyui/package.json +1 -1
- package/templates/ssg-tailwind/package.json +1 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "fs";
|
|
2
|
+
import { dirname, join, resolve } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
//#region src/commands/scaffold.ts
|
|
5
|
+
/**
|
|
6
|
+
* Pure scaffolding helpers shared by the interactive and headless `create`
|
|
7
|
+
* paths — template copy with `{{projectName}}` substitution, gitignore
|
|
8
|
+
* rename, binary-safe asset copy, and workspace dependency patching.
|
|
9
|
+
*/
|
|
10
|
+
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
var projectTypeOptions = [
|
|
12
|
+
{
|
|
13
|
+
value: "basic",
|
|
14
|
+
label: "Basic SPA",
|
|
15
|
+
description: "Simple single-page application (web)"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
value: "ssr",
|
|
19
|
+
label: "SSR",
|
|
20
|
+
description: "Server-side rendering with Express (web)"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
value: "ssg",
|
|
24
|
+
label: "SSG",
|
|
25
|
+
description: "Static site with file-based routing & MDX (web)"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: "lynx",
|
|
29
|
+
label: "Lynx",
|
|
30
|
+
description: "Native mobile app with Lynx runtime"
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
var webStylingOptions = [
|
|
34
|
+
{
|
|
35
|
+
value: "none",
|
|
36
|
+
label: "None",
|
|
37
|
+
description: "No CSS framework"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
value: "tailwind",
|
|
41
|
+
label: "Tailwind CSS",
|
|
42
|
+
description: "Utility-first CSS framework"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
value: "daisyui",
|
|
46
|
+
label: "Tailwind + Daisy UI",
|
|
47
|
+
description: "Tailwind with component library"
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
var lynxStylingOptions = [
|
|
51
|
+
{
|
|
52
|
+
value: "none",
|
|
53
|
+
label: "None",
|
|
54
|
+
description: "No CSS framework"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
value: "tailwind",
|
|
58
|
+
label: "Tailwind CSS",
|
|
59
|
+
description: "Tailwind with Lynx preset"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
value: "daisyui",
|
|
63
|
+
label: "Tailwind + Daisy UI",
|
|
64
|
+
description: "Lynx + @sigx/lynx-daisyui components"
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
var TEXT_EXTS = new Set([
|
|
68
|
+
"ts",
|
|
69
|
+
"tsx",
|
|
70
|
+
"js",
|
|
71
|
+
"jsx",
|
|
72
|
+
"mjs",
|
|
73
|
+
"cjs",
|
|
74
|
+
"mts",
|
|
75
|
+
"cts",
|
|
76
|
+
"json",
|
|
77
|
+
"json5",
|
|
78
|
+
"jsonc",
|
|
79
|
+
"md",
|
|
80
|
+
"mdx",
|
|
81
|
+
"txt",
|
|
82
|
+
"html",
|
|
83
|
+
"htm",
|
|
84
|
+
"css",
|
|
85
|
+
"scss",
|
|
86
|
+
"sass",
|
|
87
|
+
"less",
|
|
88
|
+
"yml",
|
|
89
|
+
"yaml",
|
|
90
|
+
"toml",
|
|
91
|
+
"xml",
|
|
92
|
+
"svg",
|
|
93
|
+
"gitignore",
|
|
94
|
+
"gitattributes",
|
|
95
|
+
"editorconfig",
|
|
96
|
+
"npmrc",
|
|
97
|
+
"nvmrc",
|
|
98
|
+
"env"
|
|
99
|
+
]);
|
|
100
|
+
function isTextExtension(filename) {
|
|
101
|
+
const ext = filename.startsWith(".") ? filename.slice(1).toLowerCase() : filename.split(".").pop()?.toLowerCase() ?? "";
|
|
102
|
+
return TEXT_EXTS.has(ext);
|
|
103
|
+
}
|
|
104
|
+
function copyDirectory(src, dest, projectName) {
|
|
105
|
+
if (!existsSync(dest)) mkdirSync(dest, { recursive: true });
|
|
106
|
+
const entries = readdirSync(src);
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const srcPath = join(src, entry);
|
|
109
|
+
const destPath = join(dest, entry === "gitignore" ? ".gitignore" : entry);
|
|
110
|
+
if (statSync(srcPath).isDirectory()) copyDirectory(srcPath, destPath, projectName);
|
|
111
|
+
else if (isTextExtension(entry)) {
|
|
112
|
+
let content = readFileSync(srcPath, "utf-8");
|
|
113
|
+
content = content.replace(/\{\{projectName\}\}/g, projectName);
|
|
114
|
+
writeFileSync(destPath, content);
|
|
115
|
+
} else writeFileSync(destPath, readFileSync(srcPath));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Detect if the target directory is inside a pnpm workspace that includes @sigx packages.
|
|
120
|
+
* If so, rewrite @sigx/* dependency versions to workspace:* in package.json.
|
|
121
|
+
*/
|
|
122
|
+
function patchWorkspaceDeps(targetDir) {
|
|
123
|
+
const pkgPath = join(targetDir, "package.json");
|
|
124
|
+
if (!existsSync(pkgPath)) return;
|
|
125
|
+
let dir = dirname(targetDir);
|
|
126
|
+
let isWorkspace = false;
|
|
127
|
+
for (let i = 0; i < 10; i++) {
|
|
128
|
+
if (existsSync(join(dir, "pnpm-workspace.yaml"))) {
|
|
129
|
+
isWorkspace = true;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
const parent = dirname(dir);
|
|
133
|
+
if (parent === dir) break;
|
|
134
|
+
dir = parent;
|
|
135
|
+
}
|
|
136
|
+
if (!isWorkspace) return;
|
|
137
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
138
|
+
for (const section of ["dependencies", "devDependencies"]) {
|
|
139
|
+
if (!pkg[section]) continue;
|
|
140
|
+
for (const dep of Object.keys(pkg[section])) if (dep.startsWith("@sigx/")) pkg[section][dep] = "workspace:*";
|
|
141
|
+
}
|
|
142
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + "\n");
|
|
143
|
+
}
|
|
144
|
+
function scaffoldProject(opts) {
|
|
145
|
+
const targetDir = resolve(process.cwd(), opts.projectName);
|
|
146
|
+
let templateName;
|
|
147
|
+
if (opts.projectType === "lynx") templateName = opts.styling !== "none" ? `lynx-${opts.styling}` : "lynx";
|
|
148
|
+
else templateName = opts.styling !== "none" ? `${opts.projectType}-${opts.styling}` : opts.projectType;
|
|
149
|
+
const templateDir = resolve(__dirname, "..", "templates", templateName);
|
|
150
|
+
if (existsSync(targetDir)) return {
|
|
151
|
+
ok: false,
|
|
152
|
+
error: `Directory "${opts.projectName}" already exists!`
|
|
153
|
+
};
|
|
154
|
+
if (!existsSync(templateDir)) return {
|
|
155
|
+
ok: false,
|
|
156
|
+
error: `Template "${templateName}" not found at ${templateDir}`
|
|
157
|
+
};
|
|
158
|
+
copyDirectory(templateDir, targetDir, opts.projectName);
|
|
159
|
+
patchWorkspaceDeps(targetDir);
|
|
160
|
+
return { ok: true };
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
export { copyDirectory, isTextExtension, lynxStylingOptions, patchWorkspaceDeps, projectTypeOptions, scaffoldProject, webStylingOptions };
|
|
164
|
+
|
|
165
|
+
//# sourceMappingURL=scaffold.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffold.js","names":[],"sources":["../../src/commands/scaffold.ts"],"sourcesContent":["/**\n * Pure scaffolding helpers shared by the interactive and headless `create`\n * paths — template copy with `{{projectName}}` substitution, gitignore\n * rename, binary-safe asset copy, and workspace dependency patching.\n */\nimport { existsSync, mkdirSync, readdirSync, statSync, writeFileSync, readFileSync } from 'fs';\nimport { dirname, resolve, join } from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type ProjectType = 'basic' | 'ssr' | 'ssg' | 'lynx';\nexport type Styling = 'none' | 'tailwind' | 'daisyui';\n\nexport const projectTypeOptions = [\n { value: 'basic' as ProjectType, label: 'Basic SPA', description: 'Simple single-page application (web)' },\n { value: 'ssr' as ProjectType, label: 'SSR', description: 'Server-side rendering with Express (web)' },\n { value: 'ssg' as ProjectType, label: 'SSG', description: 'Static site with file-based routing & MDX (web)' },\n { value: 'lynx' as ProjectType, label: 'Lynx', description: 'Native mobile app with Lynx runtime' },\n];\n\nexport const webStylingOptions = [\n { value: 'none' as Styling, label: 'None', description: 'No CSS framework' },\n { value: 'tailwind' as Styling, label: 'Tailwind CSS', description: 'Utility-first CSS framework' },\n { value: 'daisyui' as Styling, label: 'Tailwind + Daisy UI', description: 'Tailwind with component library' },\n];\n\nexport const lynxStylingOptions = [\n { value: 'none' as Styling, label: 'None', description: 'No CSS framework' },\n { value: 'tailwind' as Styling, label: 'Tailwind CSS', description: 'Tailwind with Lynx preset' },\n { value: 'daisyui' as Styling, label: 'Tailwind + Daisy UI', description: 'Lynx + @sigx/lynx-daisyui components' },\n];\n\nconst TEXT_EXTS = new Set([\n 'ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs', 'mts', 'cts',\n 'json', 'json5', 'jsonc',\n 'md', 'mdx', 'txt',\n 'html', 'htm', 'css', 'scss', 'sass', 'less',\n 'yml', 'yaml', 'toml', 'xml', 'svg',\n 'gitignore', 'gitattributes', 'editorconfig', 'npmrc', 'nvmrc', 'env',\n]);\n\nexport function isTextExtension(filename: string): boolean {\n // Dotfiles: name after leading dot (.gitignore → \"gitignore\").\n const ext = filename.startsWith('.')\n ? filename.slice(1).toLowerCase()\n : filename.split('.').pop()?.toLowerCase() ?? '';\n return TEXT_EXTS.has(ext);\n}\n\nexport function copyDirectory(src: string, dest: string, projectName: string) {\n if (!existsSync(dest)) {\n mkdirSync(dest, { recursive: true });\n }\n\n const entries = readdirSync(src);\n for (const entry of entries) {\n const srcPath = join(src, entry);\n // Templates ship `gitignore` (no leading dot) because npm strips\n // `.gitignore` from the published tarball. Rename on copy so the\n // generated project has a real `.gitignore`.\n const destName = entry === 'gitignore' ? '.gitignore' : entry;\n const destPath = join(dest, destName);\n const stat = statSync(srcPath);\n\n if (stat.isDirectory()) {\n copyDirectory(srcPath, destPath, projectName);\n } else if (isTextExtension(entry)) {\n let content = readFileSync(srcPath, 'utf-8');\n content = content.replace(/\\{\\{projectName\\}\\}/g, projectName);\n writeFileSync(destPath, content);\n } else {\n // Binary asset — copy bytes verbatim. Reading as UTF-8 would corrupt\n // non-ASCII bytes (e.g. PNG magic 0x89 → U+FFFD).\n writeFileSync(destPath, readFileSync(srcPath));\n }\n }\n}\n\n/**\n * Detect if the target directory is inside a pnpm workspace that includes @sigx packages.\n * If so, rewrite @sigx/* dependency versions to workspace:* in package.json.\n */\nexport function patchWorkspaceDeps(targetDir: string) {\n const pkgPath = join(targetDir, 'package.json');\n if (!existsSync(pkgPath)) return;\n\n // Walk up to find pnpm-workspace.yaml\n let dir = dirname(targetDir);\n let isWorkspace = false;\n for (let i = 0; i < 10; i++) {\n if (existsSync(join(dir, 'pnpm-workspace.yaml'))) {\n isWorkspace = true;\n break;\n }\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n if (!isWorkspace) return;\n\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n for (const section of ['dependencies', 'devDependencies'] as const) {\n if (!pkg[section]) continue;\n for (const dep of Object.keys(pkg[section])) {\n if (dep.startsWith('@sigx/')) {\n pkg[section][dep] = 'workspace:*';\n }\n }\n }\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + '\\n');\n}\n\nexport function scaffoldProject(opts: {\n projectName: string;\n projectType: ProjectType;\n styling: Styling;\n}): { ok: true } | { ok: false; error: string } {\n const targetDir = resolve(process.cwd(), opts.projectName);\n let templateName: string;\n if (opts.projectType === 'lynx') {\n templateName = opts.styling !== 'none' ? `lynx-${opts.styling}` : 'lynx';\n } else {\n templateName = opts.styling !== 'none' ? `${opts.projectType}-${opts.styling}` : opts.projectType;\n }\n const templateDir = resolve(__dirname, '..', 'templates', templateName);\n if (existsSync(targetDir)) return { ok: false, error: `Directory \"${opts.projectName}\" already exists!` };\n if (!existsSync(templateDir)) return { ok: false, error: `Template \"${templateName}\" not found at ${templateDir}` };\n copyDirectory(templateDir, targetDir, opts.projectName);\n patchWorkspaceDeps(targetDir);\n return { ok: true };\n}\n"],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { definePlugin } from './plugin.js';
|
|
2
|
-
export type { SigxPlugin, PluginCommand, CommandContext, ArgDef, Logger } from './plugin.js';
|
|
2
|
+
export type { SigxPlugin, PluginCommand, CommandContext, ArgDef, Logger, ShellNode, StatusItem, ShellTab, SlashCommand, Shortcut, ShellLogStore, ShellHandle, TuiContribution } from './plugin.js';
|
package/dist/plugin.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export interface CommandContext {
|
|
|
7
7
|
cwd: string;
|
|
8
8
|
args: Record<string, unknown>;
|
|
9
9
|
logger: Logger;
|
|
10
|
+
/** All plugins discovered for this project (for runShell({ plugins })). */
|
|
11
|
+
plugins?: SigxPlugin[];
|
|
12
|
+
/** The running CLI binary's version — for plugin feature detection. */
|
|
13
|
+
cliVersion?: string;
|
|
10
14
|
}
|
|
11
15
|
export interface Logger {
|
|
12
16
|
log: (msg: string) => void;
|
|
@@ -18,9 +22,61 @@ export interface PluginCommand {
|
|
|
18
22
|
args?: Record<string, ArgDef>;
|
|
19
23
|
run: (ctx: CommandContext) => Promise<void>;
|
|
20
24
|
}
|
|
25
|
+
/** Opaque renderable returned by a tab's render() — author with JSX. */
|
|
26
|
+
export type ShellNode = unknown;
|
|
27
|
+
export interface StatusItem {
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
/** Theme token, e.g. 'success' | 'warn' | 'danger' | 'dim' | 'accent' */
|
|
31
|
+
tone?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ShellTab {
|
|
34
|
+
id: string;
|
|
35
|
+
label: string;
|
|
36
|
+
render: () => ShellNode;
|
|
37
|
+
}
|
|
38
|
+
export interface SlashCommand {
|
|
39
|
+
/** Includes the leading slash, e.g. '/reload'. */
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
run: (shell: ShellHandle) => void | Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export interface Shortcut {
|
|
45
|
+
/** Single key, active only while the command input is empty. */
|
|
46
|
+
key: string;
|
|
47
|
+
label: string;
|
|
48
|
+
run: (shell: ShellHandle) => void | Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export interface ShellLogStore {
|
|
51
|
+
push: (chunk: string) => void;
|
|
52
|
+
}
|
|
53
|
+
export interface ShellHandle {
|
|
54
|
+
isInteractive: boolean;
|
|
55
|
+
say: (text?: string) => void;
|
|
56
|
+
store: ShellLogStore;
|
|
57
|
+
setStatus: (items: StatusItem[]) => void;
|
|
58
|
+
switchTab: (id: string) => void;
|
|
59
|
+
pushView: (id: string) => void;
|
|
60
|
+
popView: () => void;
|
|
61
|
+
/** Register teardown (runs on exit()/Ctrl+C/SIGTERM/SIGHUP/SIGINT,
|
|
62
|
+
* after the host's onExit, most-recent-first). Returns unsubscribe. */
|
|
63
|
+
onExit: (cb: () => void | Promise<void>) => () => void;
|
|
64
|
+
exit: (code?: number) => void;
|
|
65
|
+
}
|
|
66
|
+
export interface TuiContribution {
|
|
67
|
+
tabs?: ShellTab[];
|
|
68
|
+
commands?: SlashCommand[];
|
|
69
|
+
shortcuts?: Shortcut[];
|
|
70
|
+
status?: () => StatusItem[];
|
|
71
|
+
/** Called once when the hosting shell comes up; a returned function is
|
|
72
|
+
* registered as teardown. Start servers/watchers here. */
|
|
73
|
+
setup?: (shell: ShellHandle) => void | (() => void | Promise<void>) | Promise<void | (() => void | Promise<void>)>;
|
|
74
|
+
}
|
|
21
75
|
export interface SigxPlugin {
|
|
22
76
|
name: string;
|
|
23
77
|
detect: (cwd: string) => boolean;
|
|
24
78
|
commands: Record<string, PluginCommand>;
|
|
79
|
+
/** Optional TUI contributions merged into any plugin-hosted shell. */
|
|
80
|
+
tui?: TuiContribution;
|
|
25
81
|
}
|
|
26
82
|
export declare function definePlugin(plugin: SigxPlugin): SigxPlugin;
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Plugin interface for the sigx CLI.\n *\n * Packages that want to extend the CLI declare a `\"sigx-cli\"` field\n * in their package.json pointing to a module that default-exports\n * a SigxPlugin created with `definePlugin()`.\n */\n\nexport interface ArgDef {\n type: 'string' | 'boolean';\n description?: string;\n default?: string | boolean;\n}\n\nexport interface CommandContext {\n cwd: string;\n args: Record<string, unknown>;\n logger: Logger;\n}\n\nexport interface Logger {\n log: (msg: string) => void;\n warn: (msg: string) => void;\n error: (msg: string) => void;\n}\n\nexport interface PluginCommand {\n description: string;\n args?: Record<string, ArgDef>;\n run: (ctx: CommandContext) => Promise<void>;\n}\n\nexport interface SigxPlugin {\n /** Unique plugin name (e.g. 'ssg', 'lynx') */\n name: string;\n /** Return true if this plugin handles the current project */\n detect: (cwd: string) => boolean;\n /** Commands this plugin provides */\n commands: Record<string, PluginCommand>;\n}\n\n/**\n * Define a sigx CLI plugin. Identity function for type safety.\n */\nexport function definePlugin(plugin: SigxPlugin): SigxPlugin {\n return plugin;\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Plugin interface for the sigx CLI.\n *\n * Packages that want to extend the CLI declare a `\"sigx-cli\"` field\n * in their package.json pointing to a module that default-exports\n * a SigxPlugin created with `definePlugin()`.\n *\n * This module is deliberately dependency-free: plugins import it via\n * `@sigx/cli/plugin` without pulling the TUI stack. The TUI types below\n * (`ShellTab`, `ShellHandle`, …) are structural contracts consumed by\n * `runShell` from `@sigx/cli/shell`.\n */\n\nexport interface ArgDef {\n type: 'string' | 'boolean';\n description?: string;\n default?: string | boolean;\n}\n\nexport interface CommandContext {\n cwd: string;\n args: Record<string, unknown>;\n logger: Logger;\n /**\n * All plugins discovered for this project — lets a shell-hosting command\n * (e.g. lynx `dev`) merge peer plugins' TUI contributions via\n * `runShell({ plugins })` from `@sigx/cli/shell`.\n */\n plugins?: SigxPlugin[];\n /** The running CLI binary's version — for plugin feature detection. */\n cliVersion?: string;\n}\n\nexport interface Logger {\n log: (msg: string) => void;\n warn: (msg: string) => void;\n error: (msg: string) => void;\n}\n\nexport interface PluginCommand {\n description: string;\n args?: Record<string, ArgDef>;\n run: (ctx: CommandContext) => Promise<void>;\n}\n\n/**\n * Opaque renderable returned by a tab's `render()`. Author it with JSX\n * (`@jsxImportSource @sigx/terminal`); typed as `unknown` so this module\n * stays dependency-free — the shell passes it straight to the renderer.\n */\nexport type ShellNode = unknown;\n\n/** One entry in the shell's status line. `tone` is a theme token. */\nexport interface StatusItem {\n label: string;\n value: string;\n /** e.g. 'success' | 'warn' | 'danger' | 'dim' | 'accent' */\n tone?: string;\n}\n\n/** A tab in the shell's tab strip. */\nexport interface ShellTab {\n id: string;\n label: string;\n render: () => ShellNode;\n}\n\n/** A `/command` offered in the shell input's intellisense. */\nexport interface SlashCommand {\n /** Includes the leading slash, e.g. '/reload'. */\n name: string;\n description: string;\n run: (shell: ShellHandle) => void | Promise<void>;\n}\n\n/** A single-key shortcut, active only while the command input is empty. */\nexport interface Shortcut {\n key: string;\n label: string;\n run: (shell: ShellHandle) => void | Promise<void>;\n}\n\n/** Structural subset of @sigx/terminal's LogStore — keeps this module dep-free. */\nexport interface ShellLogStore {\n push: (chunk: string) => void;\n}\n\n/**\n * Handle to a running shell, passed to slash commands, shortcuts, and the\n * host's onReady. In non-TTY environments (`isInteractive: false`) the shell\n * never mounts: `say` writes plain lines, the store streams through, and the\n * navigation methods are no-ops — callers keep a single code path.\n */\nexport interface ShellHandle {\n isInteractive: boolean;\n /** Print a permanent transcript line above the live region. */\n say: (text?: string) => void;\n /** The main streaming log store (feeds the host's Logs tab). */\n store: ShellLogStore;\n setStatus: (items: StatusItem[]) => void;\n switchTab: (id: string) => void;\n pushView: (id: string) => void;\n popView: () => void;\n /**\n * Register teardown to run BEFORE the process exits — on `exit()`,\n * Ctrl+C/q, and external SIGTERM/SIGHUP/SIGINT. Subscribers run after\n * the host's onExit, most-recently-registered first. Returns an\n * unsubscribe. Use this for servers, watchers, locks.\n */\n onExit: (cb: () => void | Promise<void>) => () => void;\n exit: (code?: number) => void;\n}\n\n/**\n * TUI contributions a plugin offers to whichever plugin hosts the shell:\n * tabs, slash commands, shortcuts, and status-line items.\n */\nexport interface TuiContribution {\n tabs?: ShellTab[];\n commands?: SlashCommand[];\n shortcuts?: Shortcut[];\n status?: () => StatusItem[];\n /**\n * Lifecycle: called once when the hosting shell comes up (interactive or\n * plain). Start servers/watchers here; an optionally returned function is\n * registered as teardown (equivalent to `shell.onExit(fn)`).\n */\n setup?: (shell: ShellHandle) => void | (() => void | Promise<void>) | Promise<void | (() => void | Promise<void>)>;\n}\n\nexport interface SigxPlugin {\n /** Unique plugin name (e.g. 'ssg', 'lynx') */\n name: string;\n /** Return true if this plugin handles the current project */\n detect: (cwd: string) => boolean;\n /** Commands this plugin provides */\n commands: Record<string, PluginCommand>;\n /** Optional TUI contributions merged into any plugin-hosted shell. */\n tui?: TuiContribution;\n}\n\n/**\n * Define a sigx CLI plugin. Identity function for type safety.\n */\nexport function definePlugin(plugin: SigxPlugin): SigxPlugin {\n return plugin;\n}\n"],"mappings":";;;;AAgJA,SAAgB,aAAa,QAAgC;CACzD,OAAO"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SigxPlugin, ShellTab, SlashCommand, Shortcut, StatusItem, ShellHandle, TuiContribution, Logger } from '../plugin.js';
|
|
2
|
+
export type { ShellTab, SlashCommand, Shortcut, StatusItem, ShellHandle, TuiContribution } from '../plugin.js';
|
|
3
|
+
export interface ShellConfig {
|
|
4
|
+
/** 'fullscreen': alt-screen dashboard (title bar, tabs, palette);
|
|
5
|
+
* 'inline' (default): transcript shape with bottom-anchored input. */
|
|
6
|
+
mode?: 'inline' | 'fullscreen';
|
|
7
|
+
/** Design theme (themed canvas in fullscreen). Default 'obsidian'. */
|
|
8
|
+
theme?: string;
|
|
9
|
+
title: string;
|
|
10
|
+
version?: string;
|
|
11
|
+
logo?: { rows: string[]; palette: Record<string, string> };
|
|
12
|
+
tabs: ShellTab[];
|
|
13
|
+
commands?: SlashCommand[];
|
|
14
|
+
shortcuts?: Shortcut[];
|
|
15
|
+
status?: () => StatusItem[];
|
|
16
|
+
plugins?: SigxPlugin[];
|
|
17
|
+
onReady?: (shell: ShellHandle) => void | Promise<void>;
|
|
18
|
+
onExit?: () => void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function runShell(config: ShellConfig, opts?: { interactive?: boolean }): Promise<ShellHandle>;
|
|
21
|
+
export declare function createShellLogger(shell: ShellHandle): Logger;
|
|
22
|
+
export declare function collectTuiContributions(plugins: SigxPlugin[]): TuiContribution[];
|
|
23
|
+
export declare function mergeShellConfig(config: ShellConfig, contributions: TuiContribution[], logger?: Logger): ShellConfig;
|