@surfaice/cli 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 surfaiceai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @surfaice/cli
2
+
3
+ CLI tool for managing Surfaice UI manifests — export, check drift, and diff changes.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @surfaice/cli
9
+ # or use without installing:
10
+ npx @surfaice/cli
11
+ ```
12
+
13
+ ## Commands
14
+
15
+ ### `surfaice export`
16
+ Fetch routes from a running app and save `.surfaice.md` files.
17
+
18
+ ```bash
19
+ surfaice export -u http://localhost:3000 -r /settings /dashboard -o ./surfaice/
20
+ ```
21
+
22
+ ### `surfaice check`
23
+ Compare committed `.surfaice.md` files against the live app. Exit code 1 on drift — CI-ready.
24
+
25
+ ```bash
26
+ surfaice check -u http://localhost:3000 -d ./surfaice/
27
+ # ✅ /settings — 6 elements match
28
+ # ❌ /dashboard — DRIFT: 1 added, 1 changed
29
+ ```
30
+
31
+ ### `surfaice diff`
32
+ Show human-readable or JSON diff between committed and live.
33
+
34
+ ```bash
35
+ surfaice diff -u http://localhost:3000 -d ./surfaice/
36
+ surfaice diff -u http://localhost:3000 -d ./surfaice/ --json
37
+ ```
38
+
39
+ ## CI Integration
40
+
41
+ ```yaml
42
+ # .github/workflows/surfaice.yml
43
+ - name: Check for UI drift
44
+ run: surfaice check -u ${{ env.APP_URL }} -d ./surfaice/
45
+ ```
@@ -0,0 +1,11 @@
1
+ export interface CheckOptions {
2
+ /** Directory containing committed .surfaice.md files */
3
+ dir: string;
4
+ /** Base URL of the running app */
5
+ baseUrl: string;
6
+ }
7
+ /**
8
+ * Compare committed .surfaice.md files against the live app.
9
+ * Returns 0 on success (no drift), 1 on any failures or drift.
10
+ */
11
+ export declare function checkCommand(options: CheckOptions): Promise<number>;
@@ -0,0 +1,51 @@
1
+ import { readFileSync, readdirSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { parse } from '@surfaice/format';
4
+ import { diff } from '@surfaice/differ';
5
+ /**
6
+ * Compare committed .surfaice.md files against the live app.
7
+ * Returns 0 on success (no drift), 1 on any failures or drift.
8
+ */
9
+ export async function checkCommand(options) {
10
+ const files = readdirSync(options.dir)
11
+ .filter((f) => f.endsWith('.surfaice.md'));
12
+ let failures = 0;
13
+ for (const file of files) {
14
+ const committed = readFileSync(join(options.dir, file), 'utf-8');
15
+ const expected = parse(committed);
16
+ const route = expected.route;
17
+ let response;
18
+ try {
19
+ response = await fetch(new URL(route, options.baseUrl).toString(), {
20
+ headers: { 'Accept': 'text/surfaice' },
21
+ });
22
+ }
23
+ catch (err) {
24
+ console.error(`❌ ${route} — Network error: ${String(err)}`);
25
+ failures++;
26
+ continue;
27
+ }
28
+ if (!response.ok) {
29
+ console.error(`❌ ${route} — ${response.status} ${response.statusText}`);
30
+ failures++;
31
+ continue;
32
+ }
33
+ const live = parse(await response.text());
34
+ const result = diff(expected, live);
35
+ if (result.status === 'match') {
36
+ const elementCount = expected.sections.reduce((n, s) => n + s.elements.length, 0);
37
+ console.log(`✅ ${route} — ${elementCount} elements match`);
38
+ }
39
+ else {
40
+ console.log(`❌ ${route} — DRIFT: ${result.summary}`);
41
+ for (const a of result.added)
42
+ console.log(` + [${a.id}] ${a.type} "${a.label}"`);
43
+ for (const r of result.removed)
44
+ console.log(` - [${r.id}] ${r.type} "${r.label}"`);
45
+ for (const c of result.changed)
46
+ console.log(` ~ [${c.id}] ${c.field}: "${c.expected}" → "${c.actual}"`);
47
+ failures++;
48
+ }
49
+ }
50
+ return failures > 0 ? 1 : 0;
51
+ }
@@ -0,0 +1,15 @@
1
+ import type { SurfaiceDiff } from '@surfaice/differ';
2
+ export interface DiffOptions {
3
+ dir: string;
4
+ baseUrl: string;
5
+ /** Output as JSON instead of human-readable text */
6
+ json?: boolean;
7
+ }
8
+ export interface DiffResult extends SurfaiceDiff {
9
+ file: string;
10
+ }
11
+ /**
12
+ * Show structural diff between committed .surfaice.md files and the live app.
13
+ * Returns array of diff results (one per file).
14
+ */
15
+ export declare function diffCommand(options: DiffOptions): Promise<DiffResult[]>;
@@ -0,0 +1,50 @@
1
+ import { readFileSync, readdirSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { parse } from '@surfaice/format';
4
+ import { diff } from '@surfaice/differ';
5
+ /**
6
+ * Show structural diff between committed .surfaice.md files and the live app.
7
+ * Returns array of diff results (one per file).
8
+ */
9
+ export async function diffCommand(options) {
10
+ const files = readdirSync(options.dir)
11
+ .filter((f) => f.endsWith('.surfaice.md'));
12
+ const results = [];
13
+ for (const file of files) {
14
+ const committed = readFileSync(join(options.dir, file), 'utf-8');
15
+ const expected = parse(committed);
16
+ const route = expected.route;
17
+ let response;
18
+ try {
19
+ response = await fetch(new URL(route, options.baseUrl).toString(), {
20
+ headers: { 'Accept': 'text/surfaice' },
21
+ });
22
+ }
23
+ catch (err) {
24
+ console.error(`❌ ${route} — Network error: ${String(err)}`);
25
+ continue;
26
+ }
27
+ if (!response.ok) {
28
+ console.error(`❌ ${route} — ${response.status} ${response.statusText}`);
29
+ continue;
30
+ }
31
+ const live = parse(await response.text());
32
+ const result = diff(expected, live);
33
+ results.push({ ...result, file });
34
+ if (options.json)
35
+ continue; // collect silently for JSON output
36
+ // Human-readable output
37
+ const icon = result.status === 'match' ? '✅' : '❌';
38
+ console.log(`${icon} ${route} — ${result.summary}`);
39
+ for (const a of result.added)
40
+ console.log(` + [${a.id}] ${a.type} "${a.label}" (${a.section})`);
41
+ for (const r of result.removed)
42
+ console.log(` - [${r.id}] ${r.type} "${r.label}" (${r.section})`);
43
+ for (const c of result.changed)
44
+ console.log(` ~ [${c.id}].${c.field}: "${c.expected}" → "${c.actual}"`);
45
+ }
46
+ if (options.json) {
47
+ console.log(JSON.stringify(results, null, 2));
48
+ }
49
+ return results;
50
+ }
@@ -0,0 +1,11 @@
1
+ export interface ExportOptions {
2
+ baseUrl: string;
3
+ routes: string[];
4
+ /** Output directory. Default: 'surfaice/' */
5
+ outDir: string;
6
+ }
7
+ /**
8
+ * Fetch each route with Accept: text/surfaice and write .surfaice.md files.
9
+ */
10
+ export declare function exportCommand(options: ExportOptions): Promise<void>;
11
+ export declare function routeToFilename(route: string): string;
@@ -0,0 +1,36 @@
1
+ import { writeFileSync, mkdirSync } from 'fs';
2
+ import { join, dirname } from 'path';
3
+ /**
4
+ * Fetch each route with Accept: text/surfaice and write .surfaice.md files.
5
+ */
6
+ export async function exportCommand(options) {
7
+ mkdirSync(options.outDir, { recursive: true });
8
+ for (const route of options.routes) {
9
+ const url = new URL(route, options.baseUrl).toString();
10
+ let response;
11
+ try {
12
+ response = await fetch(url, {
13
+ headers: { 'Accept': 'text/surfaice' },
14
+ });
15
+ }
16
+ catch (err) {
17
+ console.error(`❌ ${route} — Network error: ${String(err)}`);
18
+ continue;
19
+ }
20
+ if (!response.ok) {
21
+ console.error(`❌ ${route} — ${response.status} ${response.statusText}`);
22
+ continue;
23
+ }
24
+ const markdown = await response.text();
25
+ const filename = routeToFilename(route);
26
+ const filepath = join(options.outDir, filename);
27
+ mkdirSync(dirname(filepath), { recursive: true });
28
+ writeFileSync(filepath, markdown);
29
+ console.log(`✅ ${route} → ${filepath}`);
30
+ }
31
+ }
32
+ export function routeToFilename(route) {
33
+ if (route === '/')
34
+ return 'index.surfaice.md';
35
+ return `${route.slice(1).replace(/\//g, '-')}.surfaice.md`;
36
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { exportCommand } from './commands/export.js';
4
+ import { checkCommand } from './commands/check.js';
5
+ import { diffCommand } from './commands/diff.js';
6
+ const program = new Command()
7
+ .name('surfaice')
8
+ .description('Surfaice CLI — manage UI manifests')
9
+ .version('0.0.1');
10
+ program
11
+ .command('export')
12
+ .description('Export .surfaice.md files from a running app')
13
+ .requiredOption('-u, --url <url>', 'Base URL of the running app')
14
+ .option('-r, --routes <routes...>', 'Routes to export', ['/'])
15
+ .option('-o, --out <dir>', 'Output directory', 'surfaice/')
16
+ .action(async (opts) => {
17
+ await exportCommand({ baseUrl: opts.url, routes: opts.routes, outDir: opts.out });
18
+ });
19
+ program
20
+ .command('check')
21
+ .description('Check committed .surfaice.md files against live app')
22
+ .requiredOption('-u, --url <url>', 'Base URL of the running app')
23
+ .option('-d, --dir <dir>', 'Directory with .surfaice.md files', 'surfaice/')
24
+ .action(async (opts) => {
25
+ const exitCode = await checkCommand({ dir: opts.dir, baseUrl: opts.url });
26
+ process.exit(exitCode);
27
+ });
28
+ program
29
+ .command('diff')
30
+ .description('Show drift between committed and live UI')
31
+ .requiredOption('-u, --url <url>', 'Base URL of the running app')
32
+ .option('-d, --dir <dir>', 'Directory with .surfaice.md files', 'surfaice/')
33
+ .option('--json', 'Output as JSON', false)
34
+ .action(async (opts) => {
35
+ await diffCommand({ dir: opts.dir, baseUrl: opts.url, json: opts.json });
36
+ });
37
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@surfaice/cli",
3
+ "version": "0.0.1",
4
+ "description": "Surfaice CLI — export, check, and diff UI manifests",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "surfaice": "./dist/index.js"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/surfaiceai/surfaice",
20
+ "directory": "packages/cli"
21
+ },
22
+ "dependencies": {
23
+ "commander": "^12.0.0",
24
+ "@surfaice/differ": "0.0.1",
25
+ "@surfaice/format": "0.0.1"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^25.5.0",
29
+ "typescript": "^5.5.0",
30
+ "vitest": "^2.0.0"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "README.md"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "registry": "https://registry.npmjs.org"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc",
42
+ "test": "vitest run",
43
+ "dev": "tsc --watch"
44
+ }
45
+ }