Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Adding scripts dir and adding script for props check.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCoplan committed Apr 17, 2018
1 parent 968d134 commit 5f984b6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dist
.env.test.local
.env.production.local

# python
*.pyc

npm-debug.log*
yarn-debug.log*
yarn-error.log*
39 changes: 39 additions & 0 deletions scripts/propscheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python

import os
import re
import sys

import repoutils

if not os.getcwd().endswith('/scripts'):
print('[Error] Please run this script from the scripts dir!')
sys.exit(1)

def propsValidator(filePath, contents):
regex = re.compile('.*type Props\s?=\s?({.*?});.*', re.DOTALL)
match = regex.match(contents)
if match is None:
return True

props = match.group(1)
if not (props.startswith('{|') and props.endswith('|}')):
return False

props = [x.strip() for x in props.replace('{|', '').replace('|}', '').split(',')]
for prop in props:
if not prop.startswith('+'):
return False

return True

def successCallback(filePath):
pass

def failureCallback(filePath):
invalidPropFiles.append(filePath)

invalidPropFiles = []
repoutils.walkFileContents(propsValidator, successCallback, failureCallback)
print('The following files had invalid declarations of type Props:\n')
print('\n'.join(invalidPropFiles))
48 changes: 48 additions & 0 deletions scripts/repoutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import os.path

libDir = '../src/'
exampleDir = '../example/src/'

# Functions Parsing/Handling File Names

def walkFileNames(booleanOperator, successCallback, failureCallback):
walkLibFileNames(booleanOperator, successCallback, failureCallback)
walkExampleFileNames(booleanOperator, successCallback, failureCallback)

def walkLibFileNames(booleanOperator, successCallback, failureCallback):
_walk(libDir, False, booleanOperator, successCallback, failureCallback)

def walkExampleFileNames(booleanOperator, successCallback, failureCallback):
_walk(exampleDir, False, booleanOperator, successCallback, failureCallback)

# Functions Parsing/Handling File Contents

def walkFileContents(booleanOperator, successCallback, failureCallback):
walkLibFileContents(booleanOperator, successCallback, failureCallback)
walkExampleFileContents(booleanOperator, successCallback, failureCallback)

def walkLibFileContents(booleanOperator, successCallback, failureCallback):
_walk(libDir, True, booleanOperator, successCallback, failureCallback)

def walkExampleFileContents(booleanOperator, successCallback, failureCallback):
_walk(exampleDir, True, booleanOperator, successCallback, failureCallback)

# Helper Functions

def _readFile(filePath):
with open(filePath, 'r') as file:
return file.read()

def _walk(path, isContents, booleanOperator, successCallback, failureCallback):
for root, _, files in os.walk(path):
path = os.path.relpath(root, os.getcwd())
files = [f for f in files if f.endswith('.js')]
for fileName in files:
filePath = '{}{}{}'.format(path, os.sep, fileName)
stringArg = _readFile(filePath) if isContents else fileName
didSucceed = booleanOperator(filePath, stringArg)
if didSucceed and successCallback is not None:
successCallback(filePath)
elif failureCallback is not None:
failureCallback(filePath)

0 comments on commit 5f984b6

Please sign in to comment.