-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·67 lines (61 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
import { fileURLToPath } from "node:url";
import * as path from "node:path";
import process from "node:process";
import { program } from "commander";
import { build, createServer } from "vite";
import scanner from "react-scanner";
import open from "open";
program
.name("design-system-scanner")
.description("Crawls a codebase and analyzes usage of the design system")
.argument(
"<crawlFrom>",
"The path to crawl from. This should be the path to armada or houston for example"
)
.option(
"-s, --server",
"Start a Vite dev server to work on the package's code"
);
program.parse();
const { server = false } = program.opts();
const [relativeCrawlFrom] = program.args;
const crawlFrom = path.resolve(relativeCrawlFrom);
const scannerResults = await scanner.run(
{
crawlFrom,
includeSubComponents: true,
exclude: [
"node_modules",
"bower_components",
"dist",
"build",
".git",
"tmp",
".circleci",
"__testfixtures__",
],
globs: ["**/!(*.test|*.spec).@(js|ts)?(x)"],
importedFrom: "@optibus-internal/ops-designsys",
processors: ["raw-report"],
},
"."
);
const config = {
configFile: fileURLToPath(import.meta.resolve("./vite.config.ts")),
define: { scannerResults, crawlFrom: { path: crawlFrom } },
server: { port: 4682 },
root: fileURLToPath(import.meta.resolve(".")),
build: {
outDir: "scanner-report",
},
};
if (server) {
const server = await createServer(config);
await server.listen();
server.printUrls();
server.bindCLIShortcuts({ print: true });
} else {
await build(config);
open(fileURLToPath(import.meta.resolve("./scanner-report/index.html")));
}