Skip to content

Commit

Permalink
merge dev, adjust package.json, create comparing script
Browse files Browse the repository at this point in the history
  • Loading branch information
eKatchko committed Feb 2, 2022
2 parents a27db42 + b4cddde commit b5756fe
Show file tree
Hide file tree
Showing 5 changed files with 1,910 additions and 1,509 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/LintingAutoFix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Create Pull Request
if: steps.git-check.outputs.modified == 'true'
id: cpr
uses: peter-evans/[email protected].0
uses: peter-evans/[email protected].1
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: fix(Linting):blacked code
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ new_env_and_node: clean_env clean_node_modules default ## Same as default, but r

serve: default ng_serve ## Same as default, but serves the webapp in the end.

check_nodeenv: # Checks if a version of nodeenv is installed by calling nodeenv --version and asserting that a version number exists
check_nodeenv: ## Checks if a version of nodeenv is installed by calling nodeenv --version and asserting that a version number exists
@echo ---Checking your Nodeenv version:
ifeq ($(NODEENV_VERSION),)
$(warning Nodeenv was not found.)
Expand All @@ -24,7 +24,7 @@ else
fi
endif

env: check_nodeenv .nodeenvrc # Creates an env folder if not already existing. Also removes and creates a new env folder if
env: check_nodeenv .nodeenvrc ## Creates an env folder if not already existing. Also removes and creates a new env folder if
@echo ---Checking for env folder and version:; \
if ! test -d env; \
then echo Env folder does not exist. Creating env folder.; \
Expand Down Expand Up @@ -58,17 +58,20 @@ clean_node_modules: ## Removes the node_modules folder without asking. Make sure
rm -R node_modules; \
echo Node modules folder removed.

node_modules: package.json # Activates the virtual environment and creates node_modules/ installs packages from package.json
node_modules: package.json ## Activates the virtual environment and creates node_modules/ installs packages from package.json
@echo ---Installing dependencies from package.json:; \
. env/bin/activate && \
npm install && \
npm install -g @angular/cli

ng_serve: # Activates the env environment and serves the angular webapp
ng_serve: ## Activates the env environment and serves the angular webapp
@ echo ---Starting Webapp; \
. env/bin/activate && \
ng serve

check_deps: ## Checks dependencies and devDependencies of package.json with a dev-package.json
python3 compare_two_package_json.py package.json dev-package.json

.PHONY: default new_environment new_node_modules new_env_and_node serve check_nodeenv clean_env clean_node_modules ng_serve

help:
Expand Down
65 changes: 65 additions & 0 deletions compare_two_package_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import json
import sys


def get_deps_from_package_json(file_name):
with open(file_name, "r") as package_json:
data = json.load(package_json)
return data["dependencies"]


def get_dev_deps_from_package_json(file_name):
with open(file_name, "r") as package_json:
data = json.load(package_json)
return data["devDependencies"]


def compare_deps(dep_one, dep_two):
deps_to_return = {}
for k, v in dep_one.items():
if k in dep_two:
if v != dep_two[k]:
print(f"Different value found for {k}: {v} and {dep_two[k]}. Which one do you want to keep? Choose: 1/2 default is 2")
to_keep = input()
if to_keep == 1:
deps_to_return[k] = v
else:
deps_to_return[k] = dep_two[k]
else:
deps_to_return[k] = v
else:
print(f'First package.json has dependency not found in second package.json: "{k}":"{v}". Do you want to keep it? Choose y/n default is n')
to_keep = input()
if to_keep == "y" or to_keep == "Y" or to_keep == "yes" or to_keep == "Yes":
deps_to_return[k] = v
for k, v in dep_two.items():
if k in dep_one:
continue
else:
print(f'Second package.json has dependency not found in first package.json: "{k}":"{v}". Do you want to keep it? Choose y/n default is n')
to_keep = input()
if to_keep == "y" or to_keep == "Y" or to_keep == "yes" or to_keep == "Yes":
deps_to_return[k] = v
return deps_to_return

def write_deps_to_file(file_name, deps_to_write, dev_deps_to_write):
with open(file_name, "r+") as package_json:
data = json.load(package_json)
data["dependencies"] = deps_to_write
data["devDependencies"] = dev_deps_to_write
package_json.seek(0)
package_json.write(json.dumps(data, indent="\t"))
package_json.truncate()


if __name__ == "__main__":
deps_one = get_deps_from_package_json(sys.argv[1])
dev_deps_one = get_dev_deps_from_package_json(sys.argv[1])
deps_two = get_deps_from_package_json(sys.argv[2])
dev_deps_two = get_dev_deps_from_package_json(sys.argv[2])
print(f"Comparing dependencies of {sys.argv[1]} and {sys.argv[2]}")
deps = compare_deps(deps_one, deps_two)
print()
print(f"Comparing devDependencies of {sys.argv[1]} and {sys.argv[2]}")
dev_deps = compare_deps(dev_deps_one, dev_deps_two)
write_deps_to_file(sys.argv[1], deps, dev_deps)
Loading

0 comments on commit b5756fe

Please sign in to comment.