Created
January 12, 2018 11:02
-
-
Save ptbrowne/41ef65b7097ea0977ddfa02b915cc19d to your computer and use it in GitHub Desktop.
Predict requires according to variables used
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
#-*- coding: utf-8 -*- | |
import fnmatch | |
import os | |
def glob(dir, pattern): | |
for root, dirnames, filenames in os.walk(dir): | |
for filename in fnmatch.filter(filenames, pattern): | |
yield os.path.join(root, filename) | |
def mkObject(str): | |
lines = [l for l in str.split('\n') if len(l.strip()) > 0] | |
return {k:v for (k,v) in map(lambda l: l.lstrip().split(' : '), lines)} | |
def format_require(require): | |
return '@require \'%s\'' % require | |
def format_requires(requires): | |
return '\n'.join([format_require(require) for require in requires]) | |
def main(): | |
for filepath in glob('src', '*.styl'): | |
if 'node_modules' in filepath: | |
continue | |
with open(filepath) as f: | |
content = f.read() | |
requires = [] | |
for needle, require in search.iteritems(): | |
if needle in content and format_require(require) not in content: | |
requires.append(require) | |
requires = sorted(list(set(requires))) | |
if len(requires) > 0: | |
print filepath | |
print format_requires(requires) | |
if __name__ == '__main__': | |
search = mkObject(""" | |
$form : components/forms.styl | |
$button : components/button.styl | |
$empty : components/empty.styl | |
$form-text : components/forms.styl | |
$popover : components/popover.styl | |
$icon-16 : settings/icons.styl | |
$icon-24 : settings/icons.styl | |
$icon-spinner-blue : settings/icons.styl | |
$icon-spinner-grey : settings/icons.styl | |
$alerts : components/alerts.styl | |
$bar-index : settings/z-index.styl | |
$nav-index : settings/z-index.styl | |
$modal-index : settings/z-index.styl | |
$alert-index-mobile : settings/z-index.styl | |
$overlay-index : settings/z-index.styl | |
$file-action-menu : settings/z-index.styl | |
coolGrey : settings/palette.styl | |
dodgerBlue : settings/palette.styl | |
paleGrey : settings/palette.styl | |
charcoalGrey : settings/palette.styl | |
medium-screen : settings/breakpoints.styl | |
small-screen : settings/breakpoints.styl | |
large-screen : settings/breakpoints.styl | |
tiny-screen : settings/breakpoints.styl | |
$app-2panes-sticky : objects/layouts.styl | |
$visuallyhidden : utilities/display.styl | |
$hide--mob : utilities/display.styl | |
$selectionbar : components/selectionbar.styl | |
""") | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment