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
window.c = (type, text) => { | |
let e = document.createElement(type) | |
e.innerText = text | |
return e | |
} | |
window.i = (c) => document.body.insertBefore(c,document.body.firstChild) | |
i(c('style', `*{animation: FadeIn 0.5s} @keyframes FadeIn{0% {opacity: 0;transform: translateX(-20px);}}`)) |
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
// https://mostly-adequate.gitbooks.io/mostly-adequate-guide/ch03.html#the-case-for-purity | |
const memoize = (f) => { | |
const cache = {}; | |
return (...args) => { | |
const argStr = JSON.stringify(args); | |
cache[argStr] = cache[argStr] || f(...args); | |
console.log(cache) // added for checking out the cache | |
return cache[argStr]; | |
}; |
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
function getRandomInt(max) { // From MDN | |
return Math.floor(Math.random() * Math.floor(max)); | |
} | |
const length = array => array.length | |
const verbs = ['smell', 'fart', 'look', 'move', 'eat', 'walk', 'talk', 'sleep', 'smile'] | |
const presentSimpleVerbs = ['worries', 'sings', 'cooks', 'fidgets', 'wriggles', 'dances', 'runs', 'sets stuff on fire'] | |
const nouns = ['house', 'dog', 'poop', 'worm', 'lawyer', 'little girl', 'piece of cheese', 'french poodle'] | |
const timeRelatedAdverbs = ['always', 'never', 'sometimes', 'often', 'rarely', 'occasionally'] |
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
Show hidden characters
{ | |
"presets": [ | |
"react", | |
"flow" | |
], | |
"retainLines": true | |
} |
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
const chokidar = require("chokidar"); | |
const fs = require("fs"); | |
const templates = { | |
index: name => | |
`// @flow | |
import React from 'react'; | |
import './${name}.css'; |
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
const templates = { | |
index: name => `// @flow | |
import React from 'react'; | |
import './${name}.css'; | |
// TODO: write rest of ${name} component | |
const ${name} = () => ( | |
<div className="${name.toLowerCase()}"> | |
<span>rest of component</span> |
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
const fs = require('fs'); | |
const fileExists = path => file => fs.existsSync(`${path}/${file}`); | |
const writeToPath = path => (file, content) => { | |
const filePath = `${path}/${file}`; | |
fs.writeFile(filePath, content, err => { | |
if (err) throw err; | |
console.log("Created file: ", filePath); |
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
const fs = require('fs'); | |
const fileExists = path => file => fs.existsSync(`${path}/${file}`); | |
const fileExistsInSrc = fileExists('/src'); // file => fs.existsSync(`${path}/${file}`) | |
fileExistsInSrc('index.js') // true || false |
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
function createFiles(path, name) { | |
const files = { | |
index: "index.jsx", | |
test: `${name}.test.js`, | |
sass: `${name}.sass` | |
}; | |
if (name !== "components") { | |
const writeFile = writeToPath(path); | |
const toFileMissingBool = file => !fileExists(path)(file); |
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
const chokidar = require("chokidar"); | |
const watcher = chokidar | |
.watch("src/components/**", { ignored: /node_modules/ }) | |
.on("addDir", (path, event) => { | |
const name = path.replace(/.*\/components\//, ""); | |
const goodToGo = /^[^\/_]*$/.test(name); | |
if (goodToGo) createFiles(path, name); | |
}); |
OlderNewer