@chemx/starter-kit 26.9.16-41 → 26.9.17-1100
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 +181 -2
- package/assets/chemx-starter-kit-logo.gif +0 -0
- package/blueprints/_view-template.scss +24 -0
- package/blueprints/atoms/a-button.vue +43 -0
- package/blueprints/molecule-capsule/_m-sample-card.scss +75 -0
- package/blueprints/molecule-capsule/index.ts +2 -0
- package/blueprints/molecule-capsule/m-chemx-badge/_m-chemx-badge.scss +76 -0
- package/blueprints/molecule-capsule/m-chemx-badge/index.ts +3 -0
- package/blueprints/molecule-capsule/m-chemx-badge/m-chemx-badge.spec.ts +74 -0
- package/blueprints/molecule-capsule/m-chemx-badge/m-chemx-badge.tsx +39 -0
- package/blueprints/molecule-capsule/m-chemx-badge/m-chemx-badge.vue +42 -0
- package/blueprints/molecule-capsule/m-chemx-badge/types.d.ts +12 -0
- package/blueprints/molecule-capsule/m-sample-card.spec.ts +74 -0
- package/blueprints/molecule-capsule/m-sample-card.tsx +72 -0
- package/blueprints/molecule-capsule/m-tab-button/_m-tab-button.scss +49 -0
- package/blueprints/molecule-capsule/m-tab-button/index.ts +3 -0
- package/blueprints/molecule-capsule/m-tab-button/m-tab-button.controller.ts +40 -0
- package/blueprints/molecule-capsule/m-tab-button/m-tab-button.spec.ts +40 -0
- package/blueprints/molecule-capsule/m-tab-button/m-tab-button.vue +38 -0
- package/blueprints/molecule-capsule/m-tab-button/types.d.ts +14 -0
- package/blueprints/molecule-capsule/types.d.ts +12 -0
- package/blueprints/shims-vue.d.ts +4 -0
- package/blueprints/view-template.tsx +20 -0
- package/blueprints/workflows/chemx-audit.yml +79 -0
- package/cli/audit/ast-visitors.js +73 -0
- package/cli/audit/autofix.js +4 -5
- package/cli/audit/extended-visitors.js +243 -0
- package/cli/audit/pattern-detector.js +90 -3
- package/cli/audit/pattern-detector.spec.js +36 -1
- package/cli/audit/prompts.js +10 -12
- package/cli/audit/reporter-utils.js +13 -22
- package/cli/audit/roadmap.js +5 -20
- package/cli/audit/rules-predicates.js +3 -2
- package/cli/audit/rules-registry.js +25 -0
- package/cli/audit/rules.js +4 -0
- package/cli/audit/rules.spec.js +205 -0
- package/cli/audit-preflight-git.js +54 -0
- package/cli/audit-preflight-scope.js +87 -0
- package/cli/audit-preflight.d.ts +16 -0
- package/cli/audit-preflight.js +85 -0
- package/cli/audit-preflight.spec.js +115 -0
- package/cli/audit.js +48 -22
- package/cli/build/detector.js +40 -23
- package/cli/build/detector.spec.js +81 -0
- package/cli/build.d.ts +2 -1
- package/cli/build.js +16 -12
- package/cli/columnar.d.ts +14 -0
- package/cli/columnar.js +52 -0
- package/cli/columnar.spec.js +49 -0
- package/cli/generator-templates/controller.js +36 -0
- package/cli/generator-templates/hooks.js +60 -0
- package/cli/generator-templates/naming.js +14 -0
- package/cli/generator-templates/react.js +63 -0
- package/cli/generator-templates/specs.js +38 -0
- package/cli/generator-templates/styles.js +64 -0
- package/cli/generator-templates/svelte.js +66 -0
- package/cli/generator-templates/types.js +29 -0
- package/cli/generator-templates/views.js +76 -0
- package/cli/generator-templates/vue.js +62 -0
- package/cli/generator-templates.d.ts +35 -0
- package/cli/generator-templates.js +28 -480
- package/cli/generator-templates.spec.js +108 -0
- package/cli/generator.js +2 -2
- package/cli/generator.spec.js +61 -1
- package/cli/help.js +38 -4
- package/cli/index.js +112 -14
- package/cli/installer-templates.js +67 -13
- package/cli/installer.d.ts +2 -0
- package/cli/installer.js +48 -21
- package/cli/installer.spec.js +72 -0
- package/cli/license.js +22 -1
- package/cli/mcp/antigravity.js +59 -0
- package/cli/mcp/index.js +2 -1
- package/cli/mcp/installer.js +54 -22
- package/cli/mcp/installer.spec.js +24 -1
- package/cli/mcp/manifests.js +332 -0
- package/cli/mcp/prompts.js +28 -0
- package/cli/mcp/resources.js +175 -64
- package/cli/mcp/server.js +51 -5
- package/cli/mcp/server.spec.js +247 -1
- package/cli/mcp/tools.js +386 -194
- package/cli/mcp/types.d.ts +37 -0
- package/cli/navigator-actions.js +23 -10
- package/cli/navigator-banner-helpers.js +33 -0
- package/cli/navigator-banner.js +19 -38
- package/cli/navigator-banner.spec.js +68 -0
- package/cli/navigator-guide.js +73 -0
- package/cli/navigator-menu.js +20 -0
- package/cli/navigator.js +1 -0
- package/cli/patcher.d.ts +73 -0
- package/cli/patcher.js +249 -4
- package/cli/patcher.spec.js +148 -0
- package/cli/postinstall.js +27 -0
- package/cli/project-detector.js +20 -2
- package/cli/project-detector.spec.js +19 -0
- package/cli/reader.js +18 -4
- package/cli/scaffold.js +26 -4
- package/cli/search-commands.js +10 -8
- package/cli/search-queries.js +8 -3
- package/cli/search-schema.js +5 -0
- package/cli/search.d.ts +16 -0
- package/cli/search.js +103 -11
- package/cli/silence-warnings.js +17 -0
- package/cli/team/index.js +30 -0
- package/cli/team/team-adversarial-locks.spec.js +105 -0
- package/cli/team/team-adversarial-telemetry.spec.js +93 -0
- package/cli/team/team-commands.js +199 -0
- package/cli/team/team-db-agents.js +79 -0
- package/cli/team/team-db-feed.js +84 -0
- package/cli/team/team-db-lock-promotion.js +91 -0
- package/cli/team/team-db-locks.js +94 -0
- package/cli/team/team-db-task-helpers.js +94 -0
- package/cli/team/team-db-tasks.js +90 -0
- package/cli/team/team-db.js +93 -0
- package/cli/team/team-format.js +80 -0
- package/cli/team/team-lock-concurrency.spec.js +182 -0
- package/cli/team/team-schema.js +74 -0
- package/cli/team/team-telemetry.js +104 -0
- package/cli/team/team-triage.js +88 -0
- package/cli/team/team.spec.js +344 -0
- package/cli/terminal.js +36 -1
- package/cli/ui-actions-helpers.js +66 -0
- package/cli/ui-actions.js +85 -0
- package/cli/ui-attention.js +74 -0
- package/cli/ui-client-api.js +49 -0
- package/cli/ui-client-cert.js +27 -0
- package/cli/ui-client-script.js +83 -0
- package/cli/ui-db-studio.js +79 -0
- package/cli/ui-handlers.js +95 -0
- package/cli/ui-html.js +35 -0
- package/cli/ui-server-routes.js +63 -0
- package/cli/ui-server.js +75 -0
- package/cli/ui-styles.js +34 -0
- package/cli/ui-template-views.js +63 -0
- package/cli/ui-template.js +91 -0
- package/cli/ui.spec.js +305 -0
- package/cli/verify.js +367 -0
- package/cli/verify.spec.js +98 -0
- package/docs/CHANGELOG.md +10 -0
- package/package.json +13 -15
- package/scripts/postinstall.mjs +27 -0
- package/scripts/pre-commit.sh +135 -0
- package/scripts/publish-both.mjs +108 -0
- package/cli/mcp.js +0 -326
package/cli/build/detector.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
const findFileUpward = (fileName, startDir) => {
|
|
4
|
+
export const findFileUpward = (fileName, startDir) => {
|
|
5
5
|
let currentDir = path.resolve(startDir);
|
|
6
6
|
while (true) {
|
|
7
7
|
const candidate = path.join(currentDir, fileName);
|
|
@@ -13,18 +13,17 @@ const findFileUpward = (fileName, startDir) => {
|
|
|
13
13
|
return null;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
return 'npm';
|
|
16
|
+
export const findProjectRoot = (startDir = process.cwd()) => {
|
|
17
|
+
const pkgFile = findFileUpward('package.json', startDir);
|
|
18
|
+
if (pkgFile) return path.dirname(pkgFile);
|
|
19
|
+
const chemxDir = findFileUpward('.chemx', startDir);
|
|
20
|
+
if (chemxDir) return path.dirname(chemxDir);
|
|
21
|
+
const cardVault = '/home/xopher/www/elysium/apps/my-card-vault';
|
|
22
|
+
if (fs.existsSync(cardVault)) return cardVault;
|
|
23
|
+
return startDir;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
const loadLocalPackageJson = (cwd) => {
|
|
26
|
+
export const loadLocalPackageJson = (cwd) => {
|
|
28
27
|
const pkgPath = path.join(cwd, 'package.json');
|
|
29
28
|
if (!fs.existsSync(pkgPath)) return null;
|
|
30
29
|
try {
|
|
@@ -34,6 +33,31 @@ const loadLocalPackageJson = (cwd) => {
|
|
|
34
33
|
}
|
|
35
34
|
};
|
|
36
35
|
|
|
36
|
+
export const resolvePackageManager = (cwd) => {
|
|
37
|
+
const pkg = loadLocalPackageJson(cwd);
|
|
38
|
+
if (pkg && typeof pkg.packageManager === 'string') {
|
|
39
|
+
const pmField = pkg.packageManager.toLowerCase();
|
|
40
|
+
if (pmField.startsWith('pnpm')) return 'pnpm';
|
|
41
|
+
if (pmField.startsWith('bun')) return 'bun';
|
|
42
|
+
if (pmField.startsWith('yarn')) return 'yarn';
|
|
43
|
+
if (pmField.startsWith('npm')) return 'npm';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let currentDir = path.resolve(cwd);
|
|
47
|
+
while (true) {
|
|
48
|
+
if (fs.existsSync(path.join(currentDir, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
49
|
+
if (fs.existsSync(path.join(currentDir, 'bun.lockb')) || fs.existsSync(path.join(currentDir, 'bun.lock'))) return 'bun';
|
|
50
|
+
if (fs.existsSync(path.join(currentDir, 'yarn.lock'))) return 'yarn';
|
|
51
|
+
if (fs.existsSync(path.join(currentDir, 'package-lock.json'))) return 'npm';
|
|
52
|
+
|
|
53
|
+
const parent = path.dirname(currentDir);
|
|
54
|
+
if (parent === currentDir) break;
|
|
55
|
+
currentDir = parent;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return 'npm';
|
|
59
|
+
};
|
|
60
|
+
|
|
37
61
|
export const detectProjectBuildCommand = (customCmd, cwd = process.cwd()) => {
|
|
38
62
|
const hasCustomCommand = Boolean(customCmd && customCmd.trim().length > 0);
|
|
39
63
|
if (hasCustomCommand) return customCmd.trim();
|
|
@@ -42,18 +66,11 @@ export const detectProjectBuildCommand = (customCmd, cwd = process.cwd()) => {
|
|
|
42
66
|
const pkg = loadLocalPackageJson(cwd);
|
|
43
67
|
const scripts = (pkg && pkg.scripts) || {};
|
|
44
68
|
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return pm === 'yarn' ? 'yarn build' : `${pm} run build`;
|
|
51
|
-
}
|
|
52
|
-
if (hasBuildPublicScript) {
|
|
53
|
-
return pm === 'yarn' ? 'yarn build:public' : `${pm} run build:public`;
|
|
54
|
-
}
|
|
55
|
-
if (hasBuildProdScript) {
|
|
56
|
-
return pm === 'yarn' ? 'yarn build:prod' : `${pm} run build:prod`;
|
|
69
|
+
const scriptCandidates = ['build', 'build:prod', 'build:public', 'bundle'];
|
|
70
|
+
for (const scriptName of scriptCandidates) {
|
|
71
|
+
if (scripts[scriptName]) {
|
|
72
|
+
return pm === 'yarn' ? `yarn ${scriptName}` : `${pm} run ${scriptName}`;
|
|
73
|
+
}
|
|
57
74
|
}
|
|
58
75
|
|
|
59
76
|
const hasViteConfig = fs.existsSync(path.join(cwd, 'vite.config.js')) ||
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
findFileUpward,
|
|
7
|
+
resolvePackageManager,
|
|
8
|
+
detectProjectBuildCommand
|
|
9
|
+
} from './detector.js';
|
|
10
|
+
|
|
11
|
+
test('detector: resolvePackageManager detects packageManager field in package.json', () => {
|
|
12
|
+
const tmpDir = path.resolve(process.cwd(), 'scratch/test-detector-pm-field');
|
|
13
|
+
if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
14
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
15
|
+
|
|
16
|
+
fs.writeFileSync(
|
|
17
|
+
path.join(tmpDir, 'package.json'),
|
|
18
|
+
JSON.stringify({ name: 'test-app', packageManager: 'pnpm@9.1.0' }),
|
|
19
|
+
'utf-8'
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const pm = resolvePackageManager(tmpDir);
|
|
23
|
+
assert.strictEqual(pm, 'pnpm');
|
|
24
|
+
|
|
25
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('detector: resolvePackageManager detects upward lockfiles', () => {
|
|
29
|
+
const tmpDir = path.resolve(process.cwd(), 'scratch/test-detector-lockfile');
|
|
30
|
+
const subDir = path.join(tmpDir, 'apps/sub-app');
|
|
31
|
+
if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
32
|
+
fs.mkdirSync(subDir, { recursive: true });
|
|
33
|
+
|
|
34
|
+
fs.writeFileSync(path.join(tmpDir, 'bun.lockb'), '', 'utf-8');
|
|
35
|
+
fs.writeFileSync(path.join(subDir, 'package.json'), JSON.stringify({ name: 'sub-app' }), 'utf-8');
|
|
36
|
+
|
|
37
|
+
const pm = resolvePackageManager(subDir);
|
|
38
|
+
assert.strictEqual(pm, 'bun');
|
|
39
|
+
|
|
40
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('detector: detectProjectBuildCommand uses custom command verbatim', () => {
|
|
44
|
+
const cmd = detectProjectBuildCommand('vite build --mode production');
|
|
45
|
+
assert.strictEqual(cmd, 'vite build --mode production');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('detector: detectProjectBuildCommand auto-detects from package.json scripts.build', () => {
|
|
49
|
+
const tmpDir = path.resolve(process.cwd(), 'scratch/test-detector-build-script');
|
|
50
|
+
if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
51
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
52
|
+
|
|
53
|
+
fs.writeFileSync(
|
|
54
|
+
path.join(tmpDir, 'package.json'),
|
|
55
|
+
JSON.stringify({
|
|
56
|
+
name: 'test-app',
|
|
57
|
+
packageManager: 'pnpm@9.0.0',
|
|
58
|
+
scripts: { build: 'vue-tsc --noEmit && vite build' }
|
|
59
|
+
}),
|
|
60
|
+
'utf-8'
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const cmd = detectProjectBuildCommand(null, tmpDir);
|
|
64
|
+
assert.strictEqual(cmd, 'pnpm run build');
|
|
65
|
+
|
|
66
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('detector: detectProjectBuildCommand falls back to vite when vite.config exists', () => {
|
|
70
|
+
const tmpDir = path.resolve(process.cwd(), 'scratch/test-detector-vite-fallback');
|
|
71
|
+
if (fs.existsSync(tmpDir)) fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
72
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
73
|
+
|
|
74
|
+
fs.writeFileSync(path.join(tmpDir, 'package.json'), JSON.stringify({ name: 'test-app' }), 'utf-8');
|
|
75
|
+
fs.writeFileSync(path.join(tmpDir, 'vite.config.ts'), 'export default {}', 'utf-8');
|
|
76
|
+
|
|
77
|
+
const cmd = detectProjectBuildCommand('', tmpDir);
|
|
78
|
+
assert.strictEqual(cmd, 'npx vite build');
|
|
79
|
+
|
|
80
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
81
|
+
});
|
package/cli/build.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { BuildAuditReport, BuildOptions } from './build/types.js';
|
|
|
2
2
|
|
|
3
3
|
export function runBuildAudit(
|
|
4
4
|
rawArgs?: readonly string[],
|
|
5
|
-
isCli?: boolean
|
|
5
|
+
isCli?: boolean,
|
|
6
|
+
options?: { readonly print?: boolean; readonly silent?: boolean }
|
|
6
7
|
): Promise<BuildAuditReport>;
|
|
7
8
|
|
|
8
9
|
export {
|
package/cli/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { detectProjectBuildCommand } from './build/detector.js';
|
|
1
|
+
import { detectProjectBuildCommand, findProjectRoot } from './build/detector.js';
|
|
2
2
|
import { executeBuild } from './build/executor.js';
|
|
3
3
|
import { parseBuildOutput } from './build/parser.js';
|
|
4
4
|
import { groupBuildDiagnostics } from './build/grouper.js';
|
|
@@ -20,32 +20,36 @@ const parseCommandFromArgs = (args) => {
|
|
|
20
20
|
return candidate ? candidate.trim() : null;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export const runBuildAudit = async (rawArgs = [], isCli = false) => {
|
|
24
|
-
const isJson = rawArgs.includes('--json');
|
|
25
|
-
const isSilent = rawArgs.includes('--silent');
|
|
26
|
-
const isRaw = rawArgs.includes('--raw');
|
|
27
|
-
const isSummary = rawArgs.includes('--summary');
|
|
23
|
+
export const runBuildAudit = async (rawArgs = [], isCli = false, options = {}) => {
|
|
24
|
+
const isJson = rawArgs.includes('--json') || options.json === true;
|
|
25
|
+
const isSilent = rawArgs.includes('--silent') || options.silent === true;
|
|
26
|
+
const isRaw = rawArgs.includes('--raw') || options.raw === true;
|
|
27
|
+
const isSummary = rawArgs.includes('--summary') || options.summary === true;
|
|
28
|
+
const shouldPrint = options.print !== false;
|
|
29
|
+
const cwd = findProjectRoot(options.cwd || process.cwd());
|
|
28
30
|
|
|
29
|
-
const customCommand = parseCommandFromArgs(rawArgs);
|
|
30
|
-
const command = detectProjectBuildCommand(customCommand,
|
|
31
|
+
const customCommand = parseCommandFromArgs(rawArgs) || options.command;
|
|
32
|
+
const command = detectProjectBuildCommand(customCommand, cwd);
|
|
31
33
|
|
|
32
|
-
const shouldPrintStart = !isJson && !isSilent && !isRaw;
|
|
34
|
+
const shouldPrintStart = shouldPrint && !isJson && !isSilent && !isRaw;
|
|
33
35
|
if (shouldPrintStart) {
|
|
34
36
|
process.stdout.write(`${ANSI.CYAN}Auditing build:${ANSI.RESET} ${ANSI.DIM}${command}${ANSI.RESET}\n`);
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
const executionResult = await executeBuild(command,
|
|
39
|
+
const executionResult = await executeBuild(command, cwd, { raw: isRaw });
|
|
38
40
|
const rawDiagnostics = parseBuildOutput(executionResult.stdout, executionResult.stderr);
|
|
39
41
|
const report = groupBuildDiagnostics(rawDiagnostics, executionResult);
|
|
40
42
|
|
|
41
43
|
if (isJson) {
|
|
42
|
-
|
|
44
|
+
if (shouldPrint) {
|
|
45
|
+
process.stdout.write(formatJsonBuildReport(report) + '\n');
|
|
46
|
+
}
|
|
43
47
|
if (isCli) process.exit(report.exitCode);
|
|
44
48
|
return report;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
const terminalOutput = formatTerminalBuildReport(report, { silent: isSilent, summary: isSummary });
|
|
48
|
-
if (terminalOutput) {
|
|
52
|
+
if (terminalOutput && shouldPrint) {
|
|
49
53
|
process.stdout.write(terminalOutput);
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ColumnarData<T = any> {
|
|
2
|
+
readonly cols: readonly string[];
|
|
3
|
+
readonly rows: readonly T[][];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export declare function toColumnar<T extends Record<string, any>>(
|
|
7
|
+
items?: readonly T[],
|
|
8
|
+
cols?: readonly string[],
|
|
9
|
+
accessors?: Record<string, (item: T) => any>
|
|
10
|
+
): ColumnarData;
|
|
11
|
+
|
|
12
|
+
export declare function fromColumnar<T extends Record<string, any>>(
|
|
13
|
+
columnar?: ColumnarData
|
|
14
|
+
): readonly T[];
|
package/cli/columnar.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chemical X Protocol: Columnar Serialization Utility
|
|
3
|
+
* Converts object collections into compact single-schema matrices
|
|
4
|
+
* to eliminate repeated dictionary keys and slash token consumption.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Transforms an array of objects into a single-schema columnar structure.
|
|
9
|
+
*
|
|
10
|
+
* @param {readonly object[]} items Array of record objects.
|
|
11
|
+
* @param {readonly string[]} cols Column names to extract.
|
|
12
|
+
* @param {Record<string, (item: any) => any>} [accessors={}] Optional field transformers.
|
|
13
|
+
* @returns {{ cols: readonly string[], rows: readonly any[][] }}
|
|
14
|
+
*/
|
|
15
|
+
export const toColumnar = (items = [], cols = [], accessors = {}) => {
|
|
16
|
+
if (!items || items.length === 0) {
|
|
17
|
+
return { cols, rows: [] };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const rows = items.map((item) => {
|
|
21
|
+
return cols.map((col) => {
|
|
22
|
+
const accessor = accessors[col];
|
|
23
|
+
if (typeof accessor === 'function') {
|
|
24
|
+
return accessor(item);
|
|
25
|
+
}
|
|
26
|
+
return item[col];
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return { cols, rows };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Reconstructs an array of objects from a columnar structure.
|
|
35
|
+
*
|
|
36
|
+
* @param {{ cols: readonly string[], rows: readonly any[][] }} columnar
|
|
37
|
+
* @returns {readonly Record<string, any>[]}
|
|
38
|
+
*/
|
|
39
|
+
export const fromColumnar = (columnar) => {
|
|
40
|
+
if (!columnar || !columnar.cols || !columnar.rows) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { cols, rows } = columnar;
|
|
45
|
+
return rows.map((row) => {
|
|
46
|
+
const obj = {};
|
|
47
|
+
cols.forEach((col, idx) => {
|
|
48
|
+
obj[col] = row[idx];
|
|
49
|
+
});
|
|
50
|
+
return obj;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { toColumnar, fromColumnar } from './columnar.js';
|
|
4
|
+
|
|
5
|
+
test('toColumnar: converts array of objects into cols and rows', () => {
|
|
6
|
+
const items = [
|
|
7
|
+
{ file: 'src/a.ts', tier: 'atom', lines: 40 },
|
|
8
|
+
{ file: 'src/b.ts', tier: 'molecule', lines: 75 }
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const result = toColumnar(items, ['file', 'tier', 'lines']);
|
|
12
|
+
|
|
13
|
+
assert.deepStrictEqual(result.cols, ['file', 'tier', 'lines']);
|
|
14
|
+
assert.strictEqual(result.rows.length, 2);
|
|
15
|
+
assert.deepStrictEqual(result.rows[0], ['src/a.ts', 'atom', 40]);
|
|
16
|
+
assert.deepStrictEqual(result.rows[1], ['src/b.ts', 'molecule', 75]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('toColumnar: handles empty or missing arrays cleanly', () => {
|
|
20
|
+
assert.deepStrictEqual(toColumnar([], ['file', 'tier']), { cols: ['file', 'tier'], rows: [] });
|
|
21
|
+
assert.deepStrictEqual(toColumnar(null, ['file']), { cols: ['file'], rows: [] });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('toColumnar: supports custom accessor functions for nested fields', () => {
|
|
25
|
+
const items = [
|
|
26
|
+
{ file: 'src/card.vue', symbols: [{ name: 'UserCard' }, { name: 'CardBadge' }] }
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const result = toColumnar(items, ['file', 'symbols'], {
|
|
30
|
+
symbols: (item) => item.symbols.map((s) => s.name)
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
assert.deepStrictEqual(result.rows[0], ['src/card.vue', ['UserCard', 'CardBadge']]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('fromColumnar: reconstructs array of objects from columnar data', () => {
|
|
37
|
+
const columnar = {
|
|
38
|
+
cols: ['file', 'tier', 'lines'],
|
|
39
|
+
rows: [
|
|
40
|
+
['src/a.ts', 'atom', 40],
|
|
41
|
+
['src/b.ts', 'molecule', 75]
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const items = fromColumnar(columnar);
|
|
46
|
+
assert.strictEqual(items.length, 2);
|
|
47
|
+
assert.deepStrictEqual(items[0], { file: 'src/a.ts', tier: 'atom', lines: 40 });
|
|
48
|
+
assert.deepStrictEqual(items[1], { file: 'src/b.ts', tier: 'molecule', lines: 75 });
|
|
49
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const buildController = (name, pascalName) => `import { useState, useMemo } from 'react';
|
|
2
|
+
import type { ${pascalName}State, ${pascalName}Descriptor } from './types';
|
|
3
|
+
|
|
4
|
+
interface ControllerOptions {
|
|
5
|
+
readonly initialState?: ${pascalName}State;
|
|
6
|
+
readonly onAction?: () => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const use${pascalName}Controller = (options: ControllerOptions = {}) => {
|
|
10
|
+
const [state, setState] = useState<${pascalName}State>(
|
|
11
|
+
options.initialState || { status: 'idle' }
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const isIdle = state.status === 'idle';
|
|
15
|
+
const isPending = state.status === 'loading';
|
|
16
|
+
const canProceed = isIdle && !isPending;
|
|
17
|
+
|
|
18
|
+
const descriptor: ${pascalName}Descriptor = useMemo(() => {
|
|
19
|
+
if (state.status === 'loading') {
|
|
20
|
+
return { text: 'Loading...', className: '${name}__badge ${name}__badge--pending' };
|
|
21
|
+
}
|
|
22
|
+
if (state.status === 'active') {
|
|
23
|
+
return { text: 'Active', className: '${name}__badge ${name}__badge--active' };
|
|
24
|
+
}
|
|
25
|
+
return { text: 'Ready', className: '${name}__badge ${name}__badge--ready' };
|
|
26
|
+
}, [state.status]);
|
|
27
|
+
|
|
28
|
+
const handleAction = () => {
|
|
29
|
+
if (!canProceed) return;
|
|
30
|
+
setState({ status: 'active', activeId: 'item-1' });
|
|
31
|
+
options.onAction?.();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return { state, canProceed, descriptor, handleAction };
|
|
35
|
+
};
|
|
36
|
+
`;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const buildHook = (name, camelName, pascalName) => `import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import type { ${pascalName}HookOptions, ${pascalName}HookReturn } from './types';
|
|
3
|
+
|
|
4
|
+
export const ${camelName} = (options: ${pascalName}HookOptions = {}): ${pascalName}HookReturn => {
|
|
5
|
+
const [data, setData] = useState<string | null>(null);
|
|
6
|
+
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
7
|
+
const [error, setError] = useState<string | null>(null);
|
|
8
|
+
|
|
9
|
+
const execute = useCallback(async () => {
|
|
10
|
+
setIsLoading(true);
|
|
11
|
+
setError(null);
|
|
12
|
+
try {
|
|
13
|
+
setData('ready');
|
|
14
|
+
options.onSuccess?.();
|
|
15
|
+
} catch (err) {
|
|
16
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
17
|
+
setError(message);
|
|
18
|
+
} finally {
|
|
19
|
+
setIsLoading(false);
|
|
20
|
+
}
|
|
21
|
+
}, [options]);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (options.immediate) {
|
|
25
|
+
execute();
|
|
26
|
+
}
|
|
27
|
+
}, [options.immediate, execute]);
|
|
28
|
+
|
|
29
|
+
return { data, isLoading, error, execute };
|
|
30
|
+
};
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export const buildHookOptionsType = (pascalName) => `export interface ${pascalName}HookOptions {
|
|
34
|
+
readonly immediate?: boolean;
|
|
35
|
+
readonly onSuccess?: () => void;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const buildHookReturnType = (pascalName) => `export interface ${pascalName}HookReturn {
|
|
40
|
+
readonly data: string | null;
|
|
41
|
+
readonly isLoading: boolean;
|
|
42
|
+
readonly error: string | null;
|
|
43
|
+
readonly execute: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
export const buildHookIndex = (name, camelName) => `export { ${camelName} } from './${name}';
|
|
48
|
+
export type * from './types';
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
export const buildHookSpec = (name, camelName) => `import { describe, it } from 'node:test';
|
|
52
|
+
import assert from 'node:assert/strict';
|
|
53
|
+
import { ${camelName} } from './${name}.ts';
|
|
54
|
+
|
|
55
|
+
describe('${camelName} Hook Composable', () => {
|
|
56
|
+
it('exports pure hook function', () => {
|
|
57
|
+
assert.equal(typeof ${camelName}, 'function');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const toPascalCase = (str) =>
|
|
2
|
+
str
|
|
3
|
+
.replace(/^(?:[a-z]|use|v)-/, '')
|
|
4
|
+
.split('-')
|
|
5
|
+
.map((p) => p.charAt(0).toUpperCase() + p.slice(1))
|
|
6
|
+
.join('');
|
|
7
|
+
|
|
8
|
+
export const toCamelCase = (str) => {
|
|
9
|
+
const p = toPascalCase(str);
|
|
10
|
+
if (str.startsWith('use-') || str.startsWith('use')) {
|
|
11
|
+
return `use${p}`;
|
|
12
|
+
}
|
|
13
|
+
return p.charAt(0).toLowerCase() + p.slice(1);
|
|
14
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const buildReactComponent = (name, pascalName, options = {}) => {
|
|
2
|
+
const atomsPackage = options.atomsPackage || null;
|
|
3
|
+
const hasController = options.hasController !== false;
|
|
4
|
+
const atomImport = atomsPackage ? `import { AtomButton } from '${atomsPackage}';\n` : '';
|
|
5
|
+
const actionButton = atomsPackage
|
|
6
|
+
? ` <AtomButton
|
|
7
|
+
disabled={!canProceed}
|
|
8
|
+
onClick={handleAction}
|
|
9
|
+
>
|
|
10
|
+
{variant}
|
|
11
|
+
</AtomButton>`
|
|
12
|
+
: ` <button
|
|
13
|
+
type="button"
|
|
14
|
+
className="${name}__action"
|
|
15
|
+
disabled={!canProceed}
|
|
16
|
+
onClick={handleAction}
|
|
17
|
+
>
|
|
18
|
+
{variant}
|
|
19
|
+
</button>`;
|
|
20
|
+
|
|
21
|
+
const controllerImport = hasController
|
|
22
|
+
? `import { use${pascalName}Controller } from './${name}.controller';\n`
|
|
23
|
+
: '';
|
|
24
|
+
|
|
25
|
+
const controllerLogic = hasController
|
|
26
|
+
? ` const { state, canProceed, descriptor, handleAction } = use${pascalName}Controller({
|
|
27
|
+
initialState: { status: 'idle' },
|
|
28
|
+
onAction
|
|
29
|
+
});`
|
|
30
|
+
: ` const canProceed = true;
|
|
31
|
+
const descriptor = { text: 'Ready', className: '${name}__badge ${name}__badge--ready' };
|
|
32
|
+
const handleAction = () => {
|
|
33
|
+
onAction?.();
|
|
34
|
+
};`;
|
|
35
|
+
|
|
36
|
+
return `import React from 'react';
|
|
37
|
+
${atomImport}import type { ${pascalName}Props } from './types';
|
|
38
|
+
${controllerImport}
|
|
39
|
+
export const ${pascalName}: React.FC<${pascalName}Props> = ({
|
|
40
|
+
title,
|
|
41
|
+
subtitle,
|
|
42
|
+
variant = 'standard',
|
|
43
|
+
onAction
|
|
44
|
+
}) => {
|
|
45
|
+
${controllerLogic}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className="${name}">
|
|
49
|
+
<div className="${name}__header">
|
|
50
|
+
<h3 className="${name}__title">{title}</h3>
|
|
51
|
+
{subtitle && <p className="${name}__subtitle">{subtitle}</p>}
|
|
52
|
+
<span className={descriptor.className}>{descriptor.text}</span>
|
|
53
|
+
</div>
|
|
54
|
+
<div className="${name}__body">
|
|
55
|
+
${actionButton}
|
|
56
|
+
</div>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default ${pascalName};
|
|
62
|
+
`;
|
|
63
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const buildComponentSpec = (name, pascalName, hasController = true) => {
|
|
2
|
+
if (hasController) {
|
|
3
|
+
return `import { describe, it } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { use${pascalName}Controller } from './${name}.controller.ts';
|
|
6
|
+
|
|
7
|
+
describe('${pascalName} Capsule Controller', () => {
|
|
8
|
+
it('exports pure controller hook', () => {
|
|
9
|
+
assert.equal(typeof use${pascalName}Controller, 'function');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return `import { describe, it } from 'node:test';
|
|
16
|
+
import assert from 'node:assert/strict';
|
|
17
|
+
|
|
18
|
+
describe('${pascalName} Atom Foundation', () => {
|
|
19
|
+
it('defines foundational UI atom contract', () => {
|
|
20
|
+
assert.ok(true);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
`;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const buildIndex = (name, pascalName, ext, hasController = true) => {
|
|
27
|
+
const compExport = ext === 'vue' || ext === 'svelte'
|
|
28
|
+
? `export { default as ${pascalName} } from './${name}.${ext}';`
|
|
29
|
+
: `export { ${pascalName} } from './${name}';`;
|
|
30
|
+
|
|
31
|
+
const controllerExport = hasController
|
|
32
|
+
? `export { use${pascalName}Controller } from './${name}.controller';\n`
|
|
33
|
+
: '';
|
|
34
|
+
|
|
35
|
+
return `${compExport}
|
|
36
|
+
${controllerExport}export type * from './types';
|
|
37
|
+
`;
|
|
38
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const buildScss = (name) => `.${name} {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
padding: 16px;
|
|
5
|
+
background: rgba(19, 30, 58, 0.7);
|
|
6
|
+
backdrop-filter: blur(12px);
|
|
7
|
+
border: 1px solid rgba(98, 201, 255, 0.15);
|
|
8
|
+
border-radius: 8px;
|
|
9
|
+
|
|
10
|
+
&__header {
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: space-between;
|
|
13
|
+
align-items: center;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
&__title {
|
|
17
|
+
margin: 0;
|
|
18
|
+
font-size: 16px;
|
|
19
|
+
color: #ffffff;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
&__subtitle {
|
|
23
|
+
margin: 4px 0 0;
|
|
24
|
+
font-size: 12px;
|
|
25
|
+
color: #94a3b8;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&__badge {
|
|
29
|
+
font-size: 11px;
|
|
30
|
+
padding: 2px 8px;
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
background: #0b1329;
|
|
33
|
+
|
|
34
|
+
&--ready { color: #62c9ff; }
|
|
35
|
+
&--active { color: #4ade80; }
|
|
36
|
+
&--pending { color: #facc15; }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&__body {
|
|
40
|
+
margin-top: 14px;
|
|
41
|
+
display: flex;
|
|
42
|
+
justify-content: flex-end;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&__action {
|
|
46
|
+
padding: 6px 14px;
|
|
47
|
+
border-radius: 4px;
|
|
48
|
+
background: #1e293b;
|
|
49
|
+
border: 1px solid #334155;
|
|
50
|
+
color: #ffffff;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
|
|
53
|
+
&:hover:not(:disabled) {
|
|
54
|
+
background: #334155;
|
|
55
|
+
border-color: #62c9ff;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&:disabled {
|
|
59
|
+
opacity: 0.5;
|
|
60
|
+
cursor: not-allowed;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
`;
|