Skip to content

Instantly share code, notes, and snippets.

@rudifa
Created September 25, 2020 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudifa/f59c113d423f26291f824a162b71c98b to your computer and use it in GitHub Desktop.
Save rudifa/f59c113d423f26291f824a162b71c98b to your computer and use it in GitHub Desktop.
In a node project, list scripts defined in package.json
#!/usr/bin/python3
"""
In a node project, list scripts defined in package.json
@rudifa Rudi Farkas 2020
"""
from os import path
import json
file = "package.json"
if path.exists(file):
f = open("package.json", "r")
ds = json.loads(f.read())["scripts"]
print('scripts:')
ml = max(list(map(len, ds.keys())))
for k,v in ds.items():
k += ' ' * (ml - len(k))
print(f' {k} {v}')
else:
print(f'*** no such file: {file}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment