Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1403)

Side by Side Diff: mojo/public/sky/convert_amd_modules_to_sky.py

Issue 697723003: Switch "html" Mojo modules to the Sky module system (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import sys 7 import sys
8 import re 8 import re
9 9
10 IMPORT_TEMPLATE = '<link rel="import" href="/%s.html" as="%s" />' 10 IMPORT_TEMPLATE = '<link rel="import" href="/%s.sky" as="%s" />'
11 PREAMBLE_TEMPLATE = '<script>' 11 PREAMBLE_TEMPLATE = '<script>'
12 POSTAMBLE_TEMPLATE = ' this.exports = exports;\n</script>' 12 POSTAMBLE_TEMPLATE = ' module.exports = exports;\n</script>'
13 13
14 class Import(object): 14 class Import(object):
15 def __init__(self, path, name): 15 def __init__(self, path, name):
16 self.path = path 16 self.path = path
17 self.name = name 17 self.name = name
18 18
19 class Module(object): 19 class Module(object):
20 def __init__(self): 20 def __init__(self):
21 self.name = "" 21 self.name = ""
22 self.imports = [] 22 self.imports = []
(...skipping 12 matching lines...) Expand all
35 import_regex = re.compile(r' +"([^"]+)",') 35 import_regex = re.compile(r' +"([^"]+)",')
36 begin_body_regexp = re.compile(r', function\(([^)]*)\)') 36 begin_body_regexp = re.compile(r', function\(([^)]*)\)')
37 end_body_regexp = re.compile(r'return exports') 37 end_body_regexp = re.compile(r'return exports')
38 38
39 def AddImportNames(module, unparsed_names): 39 def AddImportNames(module, unparsed_names):
40 names = [n.strip() for n in unparsed_names.split(',')] 40 names = [n.strip() for n in unparsed_names.split(',')]
41 for i in range(len(module.imports)): 41 for i in range(len(module.imports)):
42 module.imports[i].name = names[i] 42 module.imports[i].name = names[i]
43 43
44 def RewritePathNames(path): 44 def RewritePathNames(path):
45 return path.replace("mojo/public/js/bindings", "mojo/public/html") 45 return path.replace("mojo/public/js/bindings", "mojo/public/sky")
46 46
47 def Parse(amd_module): 47 def Parse(amd_module):
48 module = Module() 48 module = Module()
49 body_lines = [] 49 body_lines = []
50 state = "name" 50 state = "name"
51 for line in amd_module.splitlines(): 51 for line in amd_module.splitlines():
52 if state == "name": 52 if state == "name":
53 m = name_regex.search(line) 53 m = name_regex.search(line)
54 if m: 54 if m:
55 module.name = m.group(1) 55 module.name = m.group(1)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 with open(args.input, "r") as input_file: 90 with open(args.input, "r") as input_file:
91 module = Parse(input_file.read()) 91 module = Parse(input_file.read())
92 92
93 with open(args.output, "w+") as output_file: 93 with open(args.output, "w+") as output_file:
94 output_file.write(Serialize(module)) 94 output_file.write(Serialize(module))
95 95
96 return 0 96 return 0
97 97
98 if __name__ == "__main__": 98 if __name__ == "__main__":
99 sys.exit(main()) 99 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/public/sky/BUILD.gn ('k') | mojo/public/tools/bindings/generators/js_templates/module.html.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698