@algotao/uiscope 0.0.0-stage → 0.1.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/.agents/plugins/marketplace.json +21 -0
- package/.cursor-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +255 -2
- package/README.zh-CN.md +256 -0
- package/bin/uiscope.js +8 -0
- package/package.json +89 -3
- package/plugin.json +17 -0
- package/presets/README.md +11 -0
- package/presets/ocpui/index.ts +107 -0
- package/skills/README.md +7 -0
- package/skills/uiscope-ux-optimize/SKILL.md +267 -0
- package/skills/uiscope-ux-optimize/scripts/uiscope.mjs +43 -0
- package/src/__tests__/cli-parity.spec.ts +59 -0
- package/src/__tests__/cli-read.spec.ts +141 -0
- package/src/__tests__/component-tree.spec.ts +72 -0
- package/src/__tests__/enhance-core-ux.spec.ts +72 -0
- package/src/__tests__/enhance-feedback-states.spec.ts +104 -0
- package/src/__tests__/facet-analyze.spec.ts +55 -0
- package/src/__tests__/fixtures/exmarket-integration.config.ts +19 -0
- package/src/__tests__/format-scan-stats.spec.ts +32 -0
- package/src/__tests__/install-skill.spec.ts +41 -0
- package/src/__tests__/merge-cli-config.spec.ts +56 -0
- package/src/__tests__/react-tree.spec.ts +29 -0
- package/src/__tests__/read-scan-report-boundaries.spec.ts +139 -0
- package/src/__tests__/read-scan-report.spec.ts +91 -0
- package/src/__tests__/resolve-enhancements.spec.ts +21 -0
- package/src/__tests__/resolve-presets.spec.ts +51 -0
- package/src/__tests__/resolve-scan-scope.spec.ts +28 -0
- package/src/__tests__/run-scan-ux.spec.ts +51 -0
- package/src/__tests__/scan-progress.spec.ts +52 -0
- package/src/__tests__/skill-forwarder.spec.ts +53 -0
- package/src/__tests__/style-path.spec.ts +11 -0
- package/src/__tests__/style-rules.spec.ts +25 -0
- package/src/__tests__/template-hints.spec.ts +19 -0
- package/src/__tests__/wrapper-roles.spec.ts +31 -0
- package/src/adapters/react/collect-react-files.ts +17 -0
- package/src/adapters/react/component-tree.tsx.ts +79 -0
- package/src/adapters/react/index.ts +3 -0
- package/src/adapters/react/parse-jsx-imports.ts +38 -0
- package/src/adapters/vue/index.ts +4 -0
- package/src/cli/brand.ts +35 -0
- package/src/cli/install-skill.ts +90 -0
- package/src/cli/main.ts +578 -0
- package/src/cli/merge-cli-config.ts +86 -0
- package/src/config/defaults.ts +65 -0
- package/src/config/frameworks.ts +20 -0
- package/src/config/load-config.ts +81 -0
- package/src/config/normalize-legacy-config.ts +39 -0
- package/src/config/preset-types.ts +16 -0
- package/src/config/resolve-preset-library-roots.ts +49 -0
- package/src/config/resolve-presets.ts +142 -0
- package/src/config/resolve-scan-scope.ts +12 -0
- package/src/config/resolve-thresholds.ts +12 -0
- package/src/enhance/dir-utils.ts +25 -0
- package/src/enhance/registry.ts +107 -0
- package/src/enhance/resolve-enhancements.ts +56 -0
- package/src/enhance/rules/action-semantics.ts +60 -0
- package/src/enhance/rules/core-ux.ts +139 -0
- package/src/enhance/rules/facet-hygiene.ts +44 -0
- package/src/enhance/rules/feedback-states.ts +39 -0
- package/src/enhance/rules/form-a11y.ts +62 -0
- package/src/enhance/rules/hollow-shell.ts +39 -0
- package/src/enhance/rules/i18n-hints.ts +29 -0
- package/src/enhance/rules/list-templating.ts +38 -0
- package/src/enhance/rules/page-rollup.ts +82 -0
- package/src/enhance/tree-walk.ts +29 -0
- package/src/enhance/types.ts +48 -0
- package/src/enhance/ux-rule-pack.ts +40 -0
- package/src/enhance/workbench-defaults.ts +28 -0
- package/src/index.ts +80 -0
- package/src/manifest/consumer-wrapper-roles.ts +34 -0
- package/src/manifest/library-components.ts +46 -0
- package/src/manifest/library-style-classes.ts +31 -0
- package/src/manifest/library-style-whitelist.ts +82 -0
- package/src/manifest/library-ux-taxonomy.ts +103 -0
- package/src/paths/monorepo-root.ts +13 -0
- package/src/report/facet-output-limits.ts +56 -0
- package/src/report/format-scan-stats.ts +18 -0
- package/src/report/format-ux-scan-report.ts +59 -0
- package/src/report/markdown-report.ts +108 -0
- package/src/report/print-facets.ts +129 -0
- package/src/report/print-styles.ts +20 -0
- package/src/report/print-tree.ts +70 -0
- package/src/report/print-ux-findings.ts +53 -0
- package/src/report/read-scan-report.ts +201 -0
- package/src/report/run-report-scenarios.ts +139 -0
- package/src/run-scan.ts +341 -0
- package/src/scan/collect-source-files.ts +36 -0
- package/src/scan/component-tree.ts +155 -0
- package/src/scan/extract-node-attrs.ts +49 -0
- package/src/scan/facet-analyze.ts +318 -0
- package/src/scan/file-uses-library.ts +37 -0
- package/src/scan/library-meta.ts +71 -0
- package/src/scan/parse-imports.ts +88 -0
- package/src/scan/scan-progress.ts +89 -0
- package/src/scan/style-path.ts +26 -0
- package/src/scan/style-rules.ts +127 -0
- package/src/scan/style-trace.ts +181 -0
- package/src/scan/template-hints.ts +70 -0
- package/src/types.ts +274 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import type { ScanResult } from '../types.js';
|
|
6
|
+
import {
|
|
7
|
+
getScanReportCounts,
|
|
8
|
+
readScanReportSectionFromFile,
|
|
9
|
+
readTextReportLinesSync,
|
|
10
|
+
sliceScanReportSection,
|
|
11
|
+
} from '../report/read-scan-report.js';
|
|
12
|
+
|
|
13
|
+
const mini: ScanResult = {
|
|
14
|
+
trees: [{ file: 'a.vue', usesLibrary: true, importSources: [], tree: { kind: 'root', name: 'a', children: [] } }],
|
|
15
|
+
styleOverrides: [],
|
|
16
|
+
styleChains: [],
|
|
17
|
+
facetReports: [
|
|
18
|
+
{ file: 'a.vue', facetCount: 2, avgTemplatingRate: 0, facets: [] },
|
|
19
|
+
{ file: 'b.vue', facetCount: 0, avgTemplatingRate: 0, facets: [] },
|
|
20
|
+
],
|
|
21
|
+
uxFindings: [
|
|
22
|
+
{
|
|
23
|
+
id: 'x',
|
|
24
|
+
ruleId: 'core',
|
|
25
|
+
severity: 'info',
|
|
26
|
+
file: 'a.vue',
|
|
27
|
+
message: 'm',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'y',
|
|
31
|
+
ruleId: 'core',
|
|
32
|
+
severity: 'info',
|
|
33
|
+
file: 'b.vue',
|
|
34
|
+
message: 'm2',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'z',
|
|
38
|
+
ruleId: 'core',
|
|
39
|
+
severity: 'info',
|
|
40
|
+
file: 'c.vue',
|
|
41
|
+
message: 'm3',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
enhancementsRun: ['core-ux'],
|
|
45
|
+
warnings: ['w1'],
|
|
46
|
+
stats: {
|
|
47
|
+
vueFilesScanned: 1,
|
|
48
|
+
vueFilesLibraryConsumers: 1,
|
|
49
|
+
reactFilesScanned: 0,
|
|
50
|
+
reactFilesLibraryConsumers: 0,
|
|
51
|
+
cssFilesScanned: 0,
|
|
52
|
+
facetRegions: 2,
|
|
53
|
+
uxFindings: 3,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
describe('read-scan-report', () => {
|
|
58
|
+
it('counts sections', () => {
|
|
59
|
+
const c = getScanReportCounts(mini);
|
|
60
|
+
expect(c.trees).toBe(1);
|
|
61
|
+
expect(c.facetReports).toBe(2);
|
|
62
|
+
expect(c.uxFindings).toBe(3);
|
|
63
|
+
expect(c.warnings).toBe(1);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('slices uxFindings with offset and limit', () => {
|
|
67
|
+
const slice = sliceScanReportSection(mini, 'uxFindings', { offset: 1, limit: 1 });
|
|
68
|
+
expect(slice.total).toBe(3);
|
|
69
|
+
expect(slice.offset).toBe(1);
|
|
70
|
+
expect(slice.items).toHaveLength(1);
|
|
71
|
+
expect(slice.items[0]).toMatchObject({ id: 'y' });
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('reads from json file', () => {
|
|
75
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'uiscope-read-'));
|
|
76
|
+
const file = path.join(dir, 'r.json');
|
|
77
|
+
fs.writeFileSync(file, JSON.stringify(mini));
|
|
78
|
+
const slice = readScanReportSectionFromFile(file, 'facetReports', { limit: 1 });
|
|
79
|
+
expect(slice.items).toHaveLength(1);
|
|
80
|
+
expect(slice.items[0]).toMatchObject({ file: 'a.vue' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('reads markdown line range', () => {
|
|
84
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'uiscope-md-'));
|
|
85
|
+
const file = path.join(dir, 'r.md');
|
|
86
|
+
fs.writeFileSync(file, 'L1\nL2\nL3', 'utf8');
|
|
87
|
+
const slice = readTextReportLinesSync(file, { startLine: 2, endLine: 3 });
|
|
88
|
+
expect(slice.totalLines).toBe(3);
|
|
89
|
+
expect(slice.text).toBe('L2\nL3');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { parseEnhanceCliArgs, resolveEnhancements } from '../enhance/resolve-enhancements.js';
|
|
3
|
+
|
|
4
|
+
describe('resolveEnhancements', () => {
|
|
5
|
+
it('always includes core-ux for ux mode', () => {
|
|
6
|
+
const ids = resolveEnhancements({ mode: 'ux', cliEnhance: ['feedback-states'] });
|
|
7
|
+
expect(ids[0]).toBe('core-ux');
|
|
8
|
+
expect(ids).toContain('feedback-states');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('skips enhancements for styles-only mode', () => {
|
|
12
|
+
expect(resolveEnhancements({ mode: 'styles' })).toEqual([]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('parses comma-separated --enhance', () => {
|
|
16
|
+
const { ids, all, invalid } = parseEnhanceCliArgs(['feedback-states,page-rollup', 'all']);
|
|
17
|
+
expect(ids).toEqual(['feedback-states', 'page-rollup']);
|
|
18
|
+
expect(all).toBe(true);
|
|
19
|
+
expect(invalid).toEqual([]);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { applyPresets, resolvePreset } from '../config/resolve-presets.js';
|
|
6
|
+
|
|
7
|
+
const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
8
|
+
const monoRoot = path.resolve(pkgRoot, '../..');
|
|
9
|
+
const hasMonorepoOcpuiLib = fs.existsSync(path.join(monoRoot, 'packages/ocpui/core/vue'));
|
|
10
|
+
|
|
11
|
+
describe('resolvePresets', () => {
|
|
12
|
+
it('loads builtin presets/ocpui by short id', async () => {
|
|
13
|
+
const preset = await resolvePreset(pkgRoot, 'ocpui');
|
|
14
|
+
expect(preset.id).toBe('ocpui');
|
|
15
|
+
expect(preset.libraryImportSources?.length).toBeGreaterThan(0);
|
|
16
|
+
expect(preset.styleWhitelist?.length).toBeGreaterThan(0);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('loads via presetModules path override', async () => {
|
|
20
|
+
const preset = await resolvePreset(pkgRoot, 'alias-ocp', {
|
|
21
|
+
'alias-ocp': path.join(pkgRoot, 'presets/ocpui/index.ts'),
|
|
22
|
+
});
|
|
23
|
+
expect(preset.id).toBe('ocpui');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('merges import sources from preset into config', async () => {
|
|
27
|
+
const out = await applyPresets(pkgRoot, {
|
|
28
|
+
roots: ['src'],
|
|
29
|
+
ignore: [],
|
|
30
|
+
libraryImportSources: ['@app/ui'],
|
|
31
|
+
libraryRoots: [],
|
|
32
|
+
presets: ['ocpui'],
|
|
33
|
+
});
|
|
34
|
+
expect(out.libraryImportSources).toContain('@app/ui');
|
|
35
|
+
expect(out.libraryImportSources?.some((s) => s.includes('ocpui'))).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it.skipIf(!hasMonorepoOcpuiLib)('applies ocpui configPatch and auto libraryRoots in monorepo', async () => {
|
|
39
|
+
const out = await applyPresets(monoRoot, {
|
|
40
|
+
roots: ['app'],
|
|
41
|
+
ignore: [],
|
|
42
|
+
libraryImportSources: [],
|
|
43
|
+
libraryRoots: [],
|
|
44
|
+
presets: ['ocpui'],
|
|
45
|
+
});
|
|
46
|
+
expect(out.frameworks).toEqual(['vue']);
|
|
47
|
+
expect(out.onlyLibraryConsumers).toBe(true);
|
|
48
|
+
expect(out.defaultEnhancements).toContain('feedback-states');
|
|
49
|
+
expect(out.libraryRoots?.length).toBeGreaterThan(0);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { DEFAULT_CONFIG } from '../config/load-config.js';
|
|
3
|
+
import { resolveOnlyLibraryConsumers } from '../config/resolve-scan-scope.js';
|
|
4
|
+
|
|
5
|
+
describe('resolveOnlyLibraryConsumers', () => {
|
|
6
|
+
it('scans all vue when no library sources and no explicit flag', () => {
|
|
7
|
+
expect(resolveOnlyLibraryConsumers({ ...DEFAULT_CONFIG })).toBe(false);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('narrows when libraryImportSources configured', () => {
|
|
11
|
+
expect(
|
|
12
|
+
resolveOnlyLibraryConsumers({
|
|
13
|
+
...DEFAULT_CONFIG,
|
|
14
|
+
libraryImportSources: ['@acme/ui'],
|
|
15
|
+
}),
|
|
16
|
+
).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('explicit false overrides library sources', () => {
|
|
20
|
+
expect(
|
|
21
|
+
resolveOnlyLibraryConsumers({
|
|
22
|
+
...DEFAULT_CONFIG,
|
|
23
|
+
libraryImportSources: ['@acme/ui'],
|
|
24
|
+
onlyLibraryConsumers: false,
|
|
25
|
+
}),
|
|
26
|
+
).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { loadScanConfig, mergeConfig } from '../config/load-config.js';
|
|
6
|
+
import { runScan } from '../run-scan.js';
|
|
7
|
+
|
|
8
|
+
const scanPkgDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
9
|
+
const webRoot = path.resolve(scanPkgDir, '../../../../apps/web');
|
|
10
|
+
const hasWeb = fs.existsSync(path.join(webRoot, 'package.json'));
|
|
11
|
+
|
|
12
|
+
describe('runScan ux integration', () => {
|
|
13
|
+
it.skipIf(!hasWeb)('scans exmarket with page-rollup', async () => {
|
|
14
|
+
const base = await loadScanConfig(webRoot);
|
|
15
|
+
const result = await runScan({
|
|
16
|
+
cwd: webRoot,
|
|
17
|
+
config: mergeConfig(base, { roots: ['app/components/exmarket'] }),
|
|
18
|
+
mode: 'ux',
|
|
19
|
+
onlyLibraryTrees: true,
|
|
20
|
+
enhance: ['page-rollup', 'feedback-states'],
|
|
21
|
+
});
|
|
22
|
+
expect(result.enhancementsRun).toEqual(
|
|
23
|
+
expect.arrayContaining(['core-ux', 'page-rollup', 'feedback-states']),
|
|
24
|
+
);
|
|
25
|
+
expect(result.stats.facetRegions).toBeGreaterThan(0);
|
|
26
|
+
expect(
|
|
27
|
+
result.uxFindings.some(
|
|
28
|
+
(f) => f.ruleId === 'filter-bar-no-input' && f.file.includes('ExMarketEmptyState'),
|
|
29
|
+
),
|
|
30
|
+
).toBe(false);
|
|
31
|
+
expect(
|
|
32
|
+
result.uxFindings.some(
|
|
33
|
+
(f) => f.ruleId === 'list-missing-feedback' && f.file.includes('ExMarketWorkbench'),
|
|
34
|
+
),
|
|
35
|
+
).toBe(false);
|
|
36
|
+
expect(result.facetReports.some((f) => f.file.includes('ExMarketFilterBar'))).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('runScan ux minimal', () => {
|
|
41
|
+
it('returns empty ux when mode tree', async () => {
|
|
42
|
+
const result = await runScan({
|
|
43
|
+
cwd: scanPkgDir,
|
|
44
|
+
config: mergeConfig(await loadScanConfig(scanPkgDir), { roots: ['src'] }),
|
|
45
|
+
mode: 'tree',
|
|
46
|
+
onlyLibraryTrees: true,
|
|
47
|
+
});
|
|
48
|
+
expect(result.enhancementsRun).toEqual([]);
|
|
49
|
+
expect(result.uxFindings).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { createTerminalProgressReporter, emitScanProgress } from '../scan/scan-progress.js';
|
|
3
|
+
|
|
4
|
+
describe('scan-progress', () => {
|
|
5
|
+
it('emitScanProgress no-ops without handler', () => {
|
|
6
|
+
expect(() =>
|
|
7
|
+
emitScanProgress(undefined, { phase: 'vue', current: 1, total: 1 }),
|
|
8
|
+
).not.toThrow();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('terminal reporter (non-TTY stream)', () => {
|
|
12
|
+
let chunks: string[];
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
chunks = [];
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function reporter() {
|
|
19
|
+
return createTerminalProgressReporter({
|
|
20
|
+
stream: {
|
|
21
|
+
write(s: string) {
|
|
22
|
+
chunks.push(s);
|
|
23
|
+
return true;
|
|
24
|
+
},
|
|
25
|
+
isTTY: false,
|
|
26
|
+
} as NodeJS.WriteStream,
|
|
27
|
+
nonTtyStep: 2,
|
|
28
|
+
throttleMs: 0,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
it('logs first step, every nonTtyStep, and last', () => {
|
|
33
|
+
const on = reporter();
|
|
34
|
+
for (let i = 1; i <= 5; i++) {
|
|
35
|
+
on({ phase: 'vue', current: i, total: 5, label: `f${i}.vue` });
|
|
36
|
+
}
|
|
37
|
+
on({ phase: 'done', current: 1, total: 1 });
|
|
38
|
+
const joined = chunks.join('');
|
|
39
|
+
expect(joined).toMatch(/解析 Vue 1\/5/);
|
|
40
|
+
expect(joined).toMatch(/解析 Vue 2\/5/);
|
|
41
|
+
expect(joined).toMatch(/解析 Vue 4\/5/);
|
|
42
|
+
expect(joined).toMatch(/解析 Vue 5\/5/);
|
|
43
|
+
expect(joined).toMatch(/完成/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('collect phase prints summary label', () => {
|
|
47
|
+
const on = reporter();
|
|
48
|
+
on({ phase: 'collect', current: 1, total: 1, label: '10 vue, 2 css' });
|
|
49
|
+
expect(chunks.join('')).toContain('10 vue, 2 css');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
7
|
+
import { runInstallSkill } from '../cli/install-skill.js';
|
|
8
|
+
|
|
9
|
+
const pkgRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
10
|
+
|
|
11
|
+
describe('skill forwarder uiscope.mjs', () => {
|
|
12
|
+
const tmpRoots: string[] = [];
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
for (const root of tmpRoots) {
|
|
16
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
17
|
+
}
|
|
18
|
+
tmpRoots.length = 0;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it(
|
|
22
|
+
'forwards to published-layout CLI after npm install',
|
|
23
|
+
() => {
|
|
24
|
+
const packDir = fs.mkdtempSync(path.join(os.tmpdir(), 'uiscope-pack-'));
|
|
25
|
+
tmpRoots.push(packDir);
|
|
26
|
+
const pack = spawnSync('npm', ['pack', '--pack-destination', packDir], {
|
|
27
|
+
cwd: pkgRoot,
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
shell: true,
|
|
30
|
+
});
|
|
31
|
+
expect(pack.status).toBe(0);
|
|
32
|
+
const tgz = pack.stdout
|
|
33
|
+
.trim()
|
|
34
|
+
.split(/\r?\n/)
|
|
35
|
+
.filter((l) => l.endsWith('.tgz'))
|
|
36
|
+
.pop();
|
|
37
|
+
expect(tgz).toBeTruthy();
|
|
38
|
+
|
|
39
|
+
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'uiscope-fwd-'));
|
|
40
|
+
tmpRoots.push(cwd);
|
|
41
|
+
expect(spawnSync('npm', ['init', '-y'], { cwd, shell: true }).status).toBe(0);
|
|
42
|
+
const install = spawnSync('npm', ['install', path.join(packDir, tgz!)], { cwd, shell: true });
|
|
43
|
+
expect(install.status).toBe(0);
|
|
44
|
+
|
|
45
|
+
expect(runInstallSkill(cwd, {})).toBe(0);
|
|
46
|
+
const script = path.join(cwd, '.cursor/skills/uiscope-ux-optimize/scripts/uiscope.mjs');
|
|
47
|
+
const r = spawnSync(process.execPath, [script, '--help'], { cwd, encoding: 'utf8' });
|
|
48
|
+
expect(r.status, r.stderr).toBe(0);
|
|
49
|
+
expect(r.stdout).toContain('uiscope [install');
|
|
50
|
+
},
|
|
51
|
+
120_000,
|
|
52
|
+
);
|
|
53
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { isStylePathExcluded } from '../scan/style-path.js';
|
|
3
|
+
|
|
4
|
+
describe('isStylePathExcluded', () => {
|
|
5
|
+
it('matches glob suffix', () => {
|
|
6
|
+
expect(
|
|
7
|
+
isStylePathExcluded('D:/app/assets/css/site-layout.css', ['**/site-layout.css']),
|
|
8
|
+
).toBe(true);
|
|
9
|
+
expect(isStylePathExcluded('D:/app/foo.css', ['**/site-layout.css'])).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { matchLibraryClassesInSelector } from '../manifest/library-style-classes.js';
|
|
3
|
+
import { analyzeStyleOverrides } from '../scan/style-rules.js';
|
|
4
|
+
|
|
5
|
+
describe('matchLibraryClassesInSelector', () => {
|
|
6
|
+
it('matches manifest classes only', () => {
|
|
7
|
+
expect(matchLibraryClassesInSelector('.btn-primary:hover')).toEqual(['btn-primary']);
|
|
8
|
+
expect(matchLibraryClassesInSelector('.ui-btn.btn')).toEqual(['btn']);
|
|
9
|
+
expect(matchLibraryClassesInSelector('.not-ocp')).toEqual([]);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('analyzeStyleOverrides', () => {
|
|
14
|
+
it('warns when count exceeds threshold', () => {
|
|
15
|
+
const map = new Map<string, Array<{ file: string; selector: string }>>();
|
|
16
|
+
map.set('btn', [
|
|
17
|
+
{ file: 'a.vue', selector: '.btn' },
|
|
18
|
+
{ file: 'b.vue', selector: '.btn' },
|
|
19
|
+
{ file: 'c.vue', selector: '.x .btn' },
|
|
20
|
+
{ file: 'd.css', selector: '.btn-primary' },
|
|
21
|
+
]);
|
|
22
|
+
const { warnings } = analyzeStyleOverrides(map, 3);
|
|
23
|
+
expect(warnings.some((w) => w.includes('.btn'))).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { analyzeTemplateHints } from '../scan/template-hints.js';
|
|
3
|
+
|
|
4
|
+
describe('analyzeTemplateHints', () => {
|
|
5
|
+
it('detects v-for on list-like tags', () => {
|
|
6
|
+
const hints = analyzeTemplateHints(`
|
|
7
|
+
<ul>
|
|
8
|
+
<li v-for="item in items" :key="item.id">{{ item.name }}</li>
|
|
9
|
+
</ul>
|
|
10
|
+
`);
|
|
11
|
+
expect(hints.vForCount).toBe(1);
|
|
12
|
+
expect(hints.vForOnRepeatableTags).toBe(1);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('detects static chinese placeholder', () => {
|
|
16
|
+
const hints = analyzeTemplateHints(`<input placeholder="请输入关键词" />`);
|
|
17
|
+
expect(hints.staticChineseLiterals.length).toBeGreaterThan(0);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { analyzeFileFacets } from '../scan/facet-analyze.js';
|
|
3
|
+
import type { ComponentTreeNode } from '../types.js';
|
|
4
|
+
import { mergeConfig, DEFAULT_CONFIG } from '../config/load-config.js';
|
|
5
|
+
|
|
6
|
+
describe('consumer wrapper roles', () => {
|
|
7
|
+
it('counts FlowWorkbenchFilter as filter role', () => {
|
|
8
|
+
const tree: ComponentTreeNode = {
|
|
9
|
+
kind: 'root',
|
|
10
|
+
name: 'Bar.vue',
|
|
11
|
+
children: [
|
|
12
|
+
{
|
|
13
|
+
kind: 'unknown',
|
|
14
|
+
name: 'FlowWorkbenchFilter',
|
|
15
|
+
attrs: { class: 'flow-wb-filter' },
|
|
16
|
+
children: [
|
|
17
|
+
{ kind: 'library', name: 'Input', children: [] },
|
|
18
|
+
{ kind: 'unknown', name: 'SiteButton', children: [] },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
const config = mergeConfig(DEFAULT_CONFIG, {
|
|
24
|
+
consumerWrapperTags: ['FlowWorkbenchFilter', 'SiteButton'],
|
|
25
|
+
});
|
|
26
|
+
const report = analyzeFileFacets('Bar.vue', tree, undefined, config);
|
|
27
|
+
const filterFacet = report.facets.find((f) => f.kind === 'filter-bar');
|
|
28
|
+
expect(filterFacet).toBeDefined();
|
|
29
|
+
expect((filterFacet?.stats.roles.filter ?? 0) + (filterFacet?.stats.interactiveControls ?? 0)).toBeGreaterThan(0);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fg from 'fast-glob';
|
|
3
|
+
|
|
4
|
+
function globPattern(root: string, tail: string): string {
|
|
5
|
+
return `${path.resolve(root).replace(/\\/g, '/')}/${tail}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function collectReactFiles(roots: string[], ignore: string[]): Promise<string[]> {
|
|
9
|
+
const patterns = roots.map((root) => globPattern(root, '**/*.{tsx,jsx}'));
|
|
10
|
+
const files = await fg(patterns, {
|
|
11
|
+
ignore: [...ignore, '**/*.vue'],
|
|
12
|
+
absolute: true,
|
|
13
|
+
onlyFiles: true,
|
|
14
|
+
dot: false,
|
|
15
|
+
});
|
|
16
|
+
return [...new Set(files)].sort();
|
|
17
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ComponentTreeNode, FileComponentReport } from '../../types.js';
|
|
3
|
+
import type { UiscopeConfig } from '../../types.js';
|
|
4
|
+
import { parseJsxImports } from './parse-jsx-imports.js';
|
|
5
|
+
|
|
6
|
+
const TAG_RE = /<(\/?)([A-Za-z][\w.-]*)([^>]*)>/g;
|
|
7
|
+
const SELF_CLOSE = /\/>$/;
|
|
8
|
+
|
|
9
|
+
function isHtmlTag(tag: string): boolean {
|
|
10
|
+
return tag === tag.toLowerCase() && tag.includes('-') === false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function resolveTag(
|
|
14
|
+
tag: string,
|
|
15
|
+
bindings: ReturnType<typeof parseJsxImports>,
|
|
16
|
+
libraryNames: Set<string>,
|
|
17
|
+
): Pick<ComponentTreeNode, 'kind' | 'name' | 'source'> {
|
|
18
|
+
const binding = bindings.find((b) => b.local === tag);
|
|
19
|
+
if (binding?.fromLibrary) {
|
|
20
|
+
return { kind: 'library', name: tag, source: binding.source };
|
|
21
|
+
}
|
|
22
|
+
if (binding) return { kind: 'local', name: tag, source: binding.source };
|
|
23
|
+
if (libraryNames.has(tag)) return { kind: 'library', name: tag, source: 'lib:intrinsic' };
|
|
24
|
+
if (isHtmlTag(tag)) return { kind: 'html', name: tag };
|
|
25
|
+
if (/^[A-Z]/.test(tag)) return { kind: 'unknown', name: tag };
|
|
26
|
+
return { kind: 'html', name: tag };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function buildReactComponentTree(
|
|
30
|
+
filePath: string,
|
|
31
|
+
source: string,
|
|
32
|
+
config: UiscopeConfig,
|
|
33
|
+
libraryNames: Set<string>,
|
|
34
|
+
): FileComponentReport {
|
|
35
|
+
const bindings = parseJsxImports(source, config);
|
|
36
|
+
const usesLibrary = bindings.some((b) => b.fromLibrary);
|
|
37
|
+
const importSources = [...new Set(bindings.filter((b) => b.fromLibrary).map((b) => b.source))];
|
|
38
|
+
|
|
39
|
+
const stack: ComponentTreeNode[] = [{ kind: 'root', name: path.basename(filePath), children: [] }];
|
|
40
|
+
let match: RegExpExecArray | null;
|
|
41
|
+
TAG_RE.lastIndex = 0;
|
|
42
|
+
while ((match = TAG_RE.exec(source)) !== null) {
|
|
43
|
+
const closing = match[1] === '/';
|
|
44
|
+
const tag = match[2];
|
|
45
|
+
const attrsChunk = match[3] ?? '';
|
|
46
|
+
if (closing) {
|
|
47
|
+
if (stack.length > 1) stack.pop();
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const resolved = resolveTag(tag, bindings, libraryNames);
|
|
51
|
+
const node: ComponentTreeNode = { ...resolved, children: [] };
|
|
52
|
+
if (!SELF_CLOSE.test(attrsChunk.trim()) && !attrsChunk.endsWith('/')) {
|
|
53
|
+
stack[stack.length - 1]!.children.push(node);
|
|
54
|
+
stack.push(node);
|
|
55
|
+
} else {
|
|
56
|
+
stack[stack.length - 1]!.children.push(node);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
file: filePath,
|
|
62
|
+
usesLibrary,
|
|
63
|
+
importSources,
|
|
64
|
+
tree: stack[0]!,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function reactFileUsesLibrary(
|
|
69
|
+
source: string,
|
|
70
|
+
config: UiscopeConfig,
|
|
71
|
+
libraryNames: Set<string>,
|
|
72
|
+
): boolean {
|
|
73
|
+
if (parseJsxImports(source, config).some((b) => b.fromLibrary)) return true;
|
|
74
|
+
for (const name of libraryNames) {
|
|
75
|
+
const re = new RegExp(`<${name}[\\s/>]`);
|
|
76
|
+
if (re.test(source)) return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { UiscopeConfig } from '../../types.js';
|
|
2
|
+
|
|
3
|
+
export interface ReactImportBinding {
|
|
4
|
+
local: string;
|
|
5
|
+
fromLibrary: boolean;
|
|
6
|
+
source: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const IMPORT_RE =
|
|
10
|
+
/import\s+(?:type\s+)?(?:(?:\{([^}]+)\})|(\w+))\s+from\s+['"]([^'"]+)['"]/g;
|
|
11
|
+
|
|
12
|
+
function isLibrarySource(source: string, patterns: string[]): boolean {
|
|
13
|
+
return patterns.some((p) => source === p || source.startsWith(p));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function parseJsxImports(source: string, config: UiscopeConfig): ReactImportBinding[] {
|
|
17
|
+
const bindings: ReactImportBinding[] = [];
|
|
18
|
+
let match: RegExpExecArray | null;
|
|
19
|
+
IMPORT_RE.lastIndex = 0;
|
|
20
|
+
while ((match = IMPORT_RE.exec(source)) !== null) {
|
|
21
|
+
const named = match[1];
|
|
22
|
+
const defaultName = match[2];
|
|
23
|
+
const from = match[3];
|
|
24
|
+
const fromLibrary = isLibrarySource(from, config.libraryImportSources);
|
|
25
|
+
if (defaultName) bindings.push({ local: defaultName, fromLibrary, source: from });
|
|
26
|
+
if (named) {
|
|
27
|
+
for (const part of named.split(',')) {
|
|
28
|
+
const trimmed = part.trim();
|
|
29
|
+
if (!trimmed) continue;
|
|
30
|
+
const aliasMatch = trimmed.match(/^(\w+)(?:\s+as\s+(\w+))?$/);
|
|
31
|
+
if (!aliasMatch) continue;
|
|
32
|
+
const local = aliasMatch[2] ?? aliasMatch[1];
|
|
33
|
+
bindings.push({ local, fromLibrary, source: fromLibrary ? `lib:${aliasMatch[1]}` : from });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return bindings;
|
|
38
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { collectVueFiles, collectStyleFiles, isUnderLibraryRoots } from '../../scan/collect-source-files.js';
|
|
2
|
+
export { buildFileComponentTree } from '../../scan/component-tree.js';
|
|
3
|
+
export { fileUsesLibrary } from '../../scan/file-uses-library.js';
|
|
4
|
+
export { discoverLibraryComponentNames } from '../../manifest/library-components.js';
|
package/src/cli/brand.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const CLI_NAME = 'uiscope';
|
|
2
|
+
|
|
3
|
+
export function cliBrandName(): string {
|
|
4
|
+
return CLI_NAME;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function cliTag(scope?: string): string {
|
|
8
|
+
return scope ? `[${CLI_NAME}:${scope}]` : `[${CLI_NAME}]`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isUxWarningLine(line: string): boolean {
|
|
12
|
+
return line.includes('[uiscope:ux]');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CONFIG_FILE_CANDIDATES = [
|
|
16
|
+
'uiscope.config.ts',
|
|
17
|
+
'uiscope.config.mts',
|
|
18
|
+
'uiscope.config.js',
|
|
19
|
+
'uiscope.config.mjs',
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export const LEGACY_CONFIG_FILE_CANDIDATES = [
|
|
23
|
+
'ocp-scan.config.ts',
|
|
24
|
+
'ocp-scan.config.mts',
|
|
25
|
+
'ocp-scan.config.js',
|
|
26
|
+
'ocp-scan.config.mjs',
|
|
27
|
+
] as const;
|
|
28
|
+
|
|
29
|
+
export function defaultMaintenanceReportBasename(): string {
|
|
30
|
+
return 'uiscope-maintenance-report.md';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function defaultConfigHintBasename(): string {
|
|
34
|
+
return 'uiscope.config.ts';
|
|
35
|
+
}
|