Created
April 25, 2017 22:56
-
-
Save ooooooo-q/a4f3b4443365a42f3670b7c9323a2a54 to your computer and use it in GitHub Desktop.
storiesからreftest runnerにかけるためにstoryを抜き出すサンプル
This file contains 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
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