Skip to content

Instantly share code, notes, and snippets.

@amcooper
Created January 15, 2019 19:20
Show Gist options
  • Save amcooper/113f85fd04094a3bf7024fce3a4f5ae2 to your computer and use it in GitHub Desktop.
Save amcooper/113f85fd04094a3bf7024fce3a4f5ae2 to your computer and use it in GitHub Desktop.
Janky component test generation script
/**
*
* A quick, janky script to generate & colocate Storyshots. Just saving this in case all hell.
*
*/
const fs = require("fs");
const path = require("path");
const elementsDir = path.join(__dirname, "..", "src", "components", "elements");
const modulesDir = path.join(__dirname, "..", "src", "components", "modules");
const sourceFile = fs.readFileSync( path.join(elementsDir, "Card", "__spec.tsx"), "utf-8" );
fs.readdir(modulesDir, (error, files) => {
files.forEach(file => {
if (
fs.statSync(path.join(modulesDir, file)).isDirectory()
&& fs.existsSync(path.join(modulesDir, file, "stories.tsx"))
&& !fs.existsSync(path.join(modulesDir, file, "__spec.tsx"))
) {
fs.writeFileSync(path.join(modulesDir, file, "__spec.tsx"), sourceFile.replace("Card", file));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment