This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding scripts dir and adding script for props check.
- Loading branch information
1 parent
968d134
commit 5f984b6
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ dist | |
.env.test.local | ||
.env.production.local | ||
|
||
# python | ||
*.pyc | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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
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)) |
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
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) |