Revision 93c9effd
Added by Evgeni Golov about 2 years ago
script/filter-package-json.py | ||
---|---|---|
#!/usr/bin/env python3
|
||
|
||
import argparse
|
||
import json
|
||
|
||
parser = argparse.ArgumentParser(description='Filter unneeded dependencies from package.json')
|
||
parser.add_argument('--package-json', dest='package_json', action='store',
|
||
default='package.json',
|
||
help='path to package.json (default: %(default)s)')
|
||
parser.add_argument('--package-exclude', dest='package_exclude', action='store',
|
||
default='package-exclude.json',
|
||
help='path to package-exclude.json (default: %(default)s)')
|
||
|
||
args = parser.parse_args()
|
||
|
||
# We need a list of packages that are devDependencies but not needed to build
|
||
with open('package-exclude.json') as package_exclude:
|
||
with open(args.package_exclude) as package_exclude:
|
||
excludes = json.load(package_exclude)
|
||
|
||
def is_excluded(package):
|
||
... | ... | |
def filter_dependencies(deps):
|
||
return {package: version for package, version in sorted(deps.items()) if not is_excluded(package)}
|
||
|
||
with open('package.json') as package_json:
|
||
with open(args.package_json) as package_json:
|
||
data = json.load(package_json)
|
||
for section in ('devDependencies', 'dependencies'):
|
||
data[section] = filter_dependencies(data.get(section, {}))
|
||
|
||
with open('package.json', 'w') as package_json:
|
||
with open(args.package_json, 'w') as package_json:
|
||
json.dump(data, package_json, indent=2)
|
Also available in: Unified diff
filter-package-json: add cli options for files
this allows to mangle files outside the foreman core checkout