3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """Inlines all module.json files into modules.js."""
14 import simplejson as json
19 def read_file(filename):
20 with open(filename, 'rt') as file:
24 def build_modules(module_jsons):
26 for json_filename in module_jsons:
27 if not path.exists(json_filename):
29 module_name = path.basename(path.dirname(json_filename))
31 # pylint: disable=E1103
32 module_json = json.loads(read_file(json_filename))
33 module_json['name'] = module_name
35 # Clear scripts, as they are not used at runtime
36 # (only the fact of their presence is important).
37 if module_json.get('scripts'):
38 module_json['scripts'] = []
39 result.append(module_json)
40 return json.dumps(result)
44 input_filename = argv[1]
45 output_filename = argv[2]
46 module_jsons = argv[3:]
48 with open(output_filename, 'w') as output_file:
49 output_file.write('var allDescriptors=%s;' % build_modules(module_jsons))
52 if __name__ == '__main__':
53 sys.exit(main(sys.argv))