UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

112 lines (110 loc) 5.36 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7cf3aa5a-8d27-5f3d-9770-bd15a8c4944a")}catch(e){}}(); import path from "node:path"; import { analyzeComponentUsage } from "../analyzers/component-usage.js"; import { analyzeJsDoc } from "../analyzers/jsdoc.js"; import { analyzeStaticComponents } from "../analyzers/static-components.js"; import { analyzeStorybookDocs } from "../analyzers/storybook-docs.js"; import { analyzeStorybookStories } from "../analyzers/storybook-stories.js"; import { analyzeTypescriptApi } from "../analyzers/typescript-api.js"; import { writeSnapshot } from "../snapshot/write-snapshot.js"; function createSnapshotId() { const now = new Date(); const yyyy = now.getUTCFullYear(); const mm = String(now.getUTCMonth() + 1).padStart(2, "0"); const dd = String(now.getUTCDate()).padStart(2, "0"); const hh = String(now.getUTCHours()).padStart(2, "0"); const mi = String(now.getUTCMinutes()).padStart(2, "0"); const ss = String(now.getUTCSeconds()).padStart(2, "0"); const ms = String(now.getUTCMilliseconds()).padStart(3, "0"); return `snap-${yyyy}${mm}${dd}-${hh}${mi}${ss}${ms}`; } async function runAnalyzer(name, work) { const startedAt = new Date().toISOString(); const started = Date.now(); try { const output = await work(); return { output, run: { analyzer: name, durationMs: Date.now() - started, finishedAt: new Date().toISOString(), startedAt, status: "done", }, }; } catch (error) { return { run: { analyzer: name, durationMs: Date.now() - started, finishedAt: new Date().toISOString(), message: error instanceof Error ? error.message : String(error), startedAt, status: "failed", }, }; } } export async function runCodeAnalysis(input) { const snapshotId = input.snapshotId ?? createSnapshotId(); const snapshotRoot = path.join(input.snapshotBaseRoot ?? input.projectRoot, ".supernova", "snapshots", snapshotId); const excludePaths = input.excludePaths ?? []; const mode = input.mode ?? "components"; const runComponentPipeline = mode === "components" || mode === "all"; const runUsagePipeline = mode === "usage" || mode === "all"; const usageImportFromPackages = (Array.isArray(input.importFrom) ? input.importFrom : [input.importFrom]) .map(item => item.trim()) .filter(Boolean); const artifacts = { componentUsage: {}, jsdoc: {}, staticComponents: [], storybookDocs: {}, storybookStories: {}, typescriptApi: {}, }; let components = []; if (runComponentPipeline) { const componentsImportFrom = Array.isArray(input.importFrom) ? input.importFrom[0] : input.importFrom; const staticRun = await runAnalyzer("static-components", async () => analyzeStaticComponents(input.projectRoot, componentsImportFrom, { includeAllProps: input.includeAllProps, })); const staticResult = staticRun.output; components = staticResult?.components ?? []; artifacts.staticComponents = components; const typescriptApiRun = await runAnalyzer("typescript-api", async () => staticResult ? analyzeTypescriptApi(staticResult) : Promise.resolve({})); artifacts.typescriptApi = typescriptApiRun.output ?? {}; const storiesRun = await runAnalyzer("storybook-stories", async () => analyzeStorybookStories(input.projectRoot, components, excludePaths)); artifacts.storybookStories = storiesRun.output ?? {}; const docsRun = await runAnalyzer("storybook-docs", async () => analyzeStorybookDocs(input.projectRoot, components, excludePaths)); artifacts.storybookDocs = docsRun.output ?? {}; const jsdocRun = await runAnalyzer("jsdoc", async () => staticResult ? analyzeJsDoc(staticResult) : Promise.resolve({})); artifacts.jsdoc = jsdocRun.output ?? {}; } if (runUsagePipeline) { const usageRun = await runAnalyzer("component-usage", async () => analyzeComponentUsage(input.projectRoot, components, input.importFrom, excludePaths)); artifacts.componentUsage = usageRun.output?.records ?? {}; if (components.length === 0 && usageRun.output?.components.length) { components = usageRun.output.components; } } await writeSnapshot({ artifacts, rawArtifacts: mode === "usage" ? ["component-usage"] : mode === "components" ? ["static-components", "typescript-api", "storybook-stories", "storybook-docs", "jsdoc"] : ["static-components", "typescript-api", "storybook-stories", "storybook-docs", "jsdoc", "component-usage"], snapshotRoot, usageImportFromPackages, }); return { components, snapshotId, snapshotRoot, }; } //# sourceMappingURL=run-analysis.js.map //# debugId=7cf3aa5a-8d27-5f3d-9770-bd15a8c4944a