Skip to content

Instantly share code, notes, and snippets.

@ooooooo-q
Created April 25, 2017 22:56
Show Gist options
  • Save ooooooo-q/a4f3b4443365a42f3670b7c9323a2a54 to your computer and use it in GitHub Desktop.
Save ooooooo-q/a4f3b4443365a42f3670b7c9323a2a54 to your computer and use it in GitHub Desktop.
storiesからreftest runnerにかけるためにstoryを抜き出すサンプル
const glob = require('glob');
const fs = require('fs');
glob('./src/stories/**.js', (err, files)=>{
console.log(files)
files.forEach((filename) => {
const file = fs.readFileSync(filename, 'utf-8');
// console.log(file)
const lines = file.split('\n');
const story = {};
let storyName = '';
lines.forEach((line) => {
if(line.match(/storiesOf\(/)){
const sotryName = line.match(/\'(.*)\'|\"(.*)\"|`(.*)`/);
storyName = sotryName[0].slice(1, -1);
story[storyName] = [];
} else if(line.match(/add\(/)){
const addName = line.match(/\'(.*)\'|\"(.*)\"|`(.*)`/);
story[storyName].push(addName[0].slice(1, -1));
}
})
console.log(story);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment