Created
January 15, 2019 19:20
-
-
Save amcooper/113f85fd04094a3bf7024fce3a4f5ae2 to your computer and use it in GitHub Desktop.
Janky component test generation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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