Skip to content

Instantly share code, notes, and snippets.

@giovanniantonaccio
Last active September 28, 2022 16:14
Show Gist options
  • Save giovanniantonaccio/360dd3ab05ed455a5c2d500f9fe59aec to your computer and use it in GitHub Desktop.
Save giovanniantonaccio/360dd3ab05ed455a5c2d500f9fe59aec to your computer and use it in GitHub Desktop.
React scanner config file
#!/usr/bin/env node
const scanner = require("react-scanner");
const os = require("os");
const path = require("path");
const getLastItemFromPath = (thePath) => thePath.substring(thePath.lastIndexOf("/") + 1);
const userHomePath = os.homedir();
const projectPath = process.cwd();
const projectFolderName = getLastItemFromPath(projectPath);
const reportName = `${projectFolderName}-${Date.now()}.json`;
const reportPath = path.join(userHomePath, "react-scanner-reports", reportName);
const config = {
crawlFrom: "./src",
includeSubComponents: true,
// importedFrom: "lib-name",
globs: ["**/!(*.test|*.spec).@(js|ts)?(x)"],
// processors: [["raw-report", { outputTo: "./my-report.json" }]],
// components: { Button: true },
processors: [["count-components-and-props", { outputTo: reportPath }]],
};
scanner
.run(config, "", "programmatic")
.then(() => console.log("Report saved in: ", reportPath))
.catch((err) => console.log(err));
{
"name": "run-js-with-npx-from-gist",
"version": "1.0.0",
"dependencies": {
"react-scanner": "^1.0.4"
},
"bin": "./index.js"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment