OLD | NEW |
1 const fs = require('fs'); | 1 const fs = require('fs'); |
2 | 2 |
3 function depends(module, from) | 3 function depends(module, from) |
4 { | 4 { |
5 if (module === from) | 5 if (module === from) |
6 return true; | 6 return true; |
7 var desc = descriptors[module]; | 7 var desc = descriptors[module]; |
8 if (!desc) | 8 if (!desc) |
9 return false; | 9 return false; |
10 for (var dep of desc.dependencies || []) { | 10 for (var dep of desc.dependencies || []) { |
11 if (dep === from) | 11 if (dep === from) |
12 return true; | 12 return true; |
13 if (depends(dep, from)) | 13 if (depends(dep, from)) |
14 return true; | 14 return true; |
15 } | 15 } |
16 return false; | 16 return false; |
17 } | 17 } |
18 | 18 |
19 var map = new Map(); | 19 var map = new Map(); |
20 var sortedKeys; | 20 var sortedKeys; |
21 var moduleNames = new Set(); | 21 var moduleNames = new Set(); |
22 | 22 |
23 String.prototype.replaceAll = function(a, b) | 23 String.prototype.replaceAll = function(a, b) |
24 { | 24 { |
25 var result = this; | 25 var result = this; |
26 while (result.includes(a)) | 26 return result.split(a).join(b); |
27 result = result.replace(a, b); | 27 }; |
28 return result; | |
29 } | |
30 | 28 |
31 function read(filePath) | 29 function read(filePath) |
32 { | 30 { |
33 var content = fs.readFileSync(filePath).toString(); | 31 var content = fs.readFileSync(filePath).toString(); |
34 | 32 |
35 var oldModuleName = filePath.replace(/front_end\/([^/]+)\/.*/, "$1"); | 33 var oldModuleName = filePath.replace(/front_end\/([^/]+)\/.*/, "$1"); |
36 if (oldModuleName.endsWith("_lazy")) | 34 if (oldModuleName.endsWith("_lazy")) |
37 oldModuleName = oldModuleName.substring(0, oldModuleName.length - "_lazy
".length); | 35 oldModuleName = oldModuleName.substring(0, oldModuleName.length - "_lazy
".length); |
38 | 36 |
39 var moduleName = oldModuleName; | 37 var moduleName = oldModuleName; |
40 | 38 |
41 // if (oldModuleName === "accessibility") | |
42 // moduleName = "a11y"; | |
43 // if (oldModuleName === "resources") | |
44 // moduleName = "storage"; | |
45 // if (oldModuleName === "console") | |
46 // moduleName = "consoleUI"; | |
47 | |
48 | |
49 // if (oldModuleName === "timeline") | |
50 // moduleName = "timelineUI"; | |
51 // if (oldModuleName === "timeline_model") | |
52 // moduleName = "timeline"; | |
53 | |
54 // moduleName = "com.google.chrome.devtools." + moduleName; | |
55 // moduleName = "dt";// + moduleName; | |
56 if (moduleName === "sdk" || moduleName == "ui") | 39 if (moduleName === "sdk" || moduleName == "ui") |
57 moduleName = moduleName.toUpperCase(); | 40 moduleName = moduleName.toUpperCase(); |
58 // moduleName = "dt" + moduleName.substring(0, 1).toUpperCase() + moduleName
.substring(1); | |
59 moduleName = moduleName.split("_").map(a => a.substring(0, 1).toUpperCase()
+ a.substring(1)).join(""); | 41 moduleName = moduleName.split("_").map(a => a.substring(0, 1).toUpperCase()
+ a.substring(1)).join(""); |
60 if (moduleName.includes("/")) | 42 if (moduleName.includes("/")) |
61 return; | 43 return; |
62 moduleNames.add(moduleName); | 44 moduleNames.add(moduleName); |
63 | 45 |
64 var lines = content.split("\n"); | 46 var lines = content.split("\n"); |
65 for (var line of lines) { | 47 for (var line of lines) { |
66 var line = line.trim(); | 48 // Replace with your own logic |
67 if (!line.startsWith("WebInspector.")) | 49 if (!line.startsWith("var ")) |
68 continue; | 50 continue; |
69 var match = line.match(/^(WebInspector.[a-z_A-Z0-9]+)\s*(\=[^,}]|[;])/)
|| line.match(/^(WebInspector.[a-z_A-Z0-9]+)\s*\=$/); | 51 var globalVariableMatch = line.match(/^var ([a-z_A-Z0-9]+)\s*(\=)/); |
| 52 var match = globalVariableMatch; |
| 53 |
70 if (!match) | 54 if (!match) |
71 continue; | 55 continue; |
72 var name = match[1]; | 56 var name = match[1]; |
73 if (name.split(".").length !== 2) | |
74 continue; | |
75 var weight = line.endsWith(name + ";") ? 2 : 1; | 57 var weight = line.endsWith(name + ";") ? 2 : 1; |
76 | 58 |
77 var newName; | 59 var newName; |
78 var shortName = newName; | |
79 | 60 |
80 newName = name.replace("WebInspector.", moduleName + "."); | 61 newName = moduleName + "." + name; |
81 shortName = newName.replace(moduleName + ".", ""); | |
82 var existing = map.get(name); | 62 var existing = map.get(name); |
83 if (existing && existing.weight > weight) | 63 if (existing && existing.weight > weight) |
84 continue; | 64 continue; |
85 if (existing && existing.weight === weight && newName !== existing.name) | 65 if (existing && existing.weight === weight && newName !== existing.name) |
86 console.log("Conflict: " + newName + " vs " + existing.name + " " +
weight); | 66 console.log("Conflict: " + newName + " vs " + existing.name + " " +
weight); |
87 map.set(name, {name:newName, weight}); | 67 map.set(name, {name:newName, weight}); |
88 } | 68 } |
89 } | 69 } |
90 | 70 |
91 | |
92 function write(filePath) | 71 function write(filePath) |
93 { | 72 { |
94 var content = fs.readFileSync(filePath).toString(); | 73 var content = fs.readFileSync(filePath).toString(); |
95 var newContent = content; | 74 var newContent = content; |
96 for (var key of sortedKeys) | 75 for (var key of sortedKeys) { |
97 newContent = newContent.replaceAll(key, map.get(key).name); | 76 var originalIdentifier = key; |
98 newContent = newContent.replaceAll("UI._focusChanged.bind(WebInspector", "UI
._focusChanged.bind(UI"); | 77 var newIdentifier = map.get(key).name; |
99 newContent = newContent.replaceAll("UI._windowFocused.bind(WebInspector", "U
I._windowFocused.bind(UI"); | 78 newContent = newContent.split("\n").map(function (line) { |
100 newContent = newContent.replaceAll("UI._windowBlurred.bind(WebInspector", "U
I._windowBlurred.bind(UI"); | 79 return processLine(line); |
101 newContent = newContent.replaceAll("UI._focusChanged.bind(WebInspector", "UI
._focusChanged.bind(UI"); | 80 }).join("\n"); |
102 newContent = newContent.replaceAll("UI._focusChanged.bind(WebInspector", "UI
._focusChanged.bind(UI"); | 81 } |
103 newContent = newContent.replaceAll("Components.reload.bind(WebInspector", "C
omponents.reload.bind(Components"); | |
104 newContent = newContent.replaceAll("window.opener.WebInspector['AdvancedApp'
]['_instance']()", "window.opener['Emulation']['AdvancedApp']['_instance']()"); | |
105 newContent = newContent.replaceAll("if (window['WebInspector'][", "if (windo
w['WebInspector'] && window['WebInspector']["); | |
106 | 82 |
107 if (content !== newContent) | 83 if (content !== newContent) |
108 fs.writeFileSync(filePath, newContent); | 84 fs.writeFileSync(filePath, newContent); |
109 } | 85 } |
110 | 86 |
| 87 function processLine(line) { |
| 88 // Add transformation logic |
| 89 return line; |
| 90 } |
| 91 |
111 function walkSync(currentDirPath, process, json) { | 92 function walkSync(currentDirPath, process, json) { |
112 var fs = require('fs'), | 93 var path = require('path'); |
113 path = require('path'); | |
114 fs.readdirSync(currentDirPath).forEach(function (name) { | 94 fs.readdirSync(currentDirPath).forEach(function (name) { |
115 var filePath = path.join(currentDirPath, name); | 95 var filePath = path.join(currentDirPath, name); |
116 var stat = fs.statSync(filePath); | 96 var stat = fs.statSync(filePath); |
117 if (stat.isFile() && (filePath.endsWith(".js") || filePath.endsWith(".ht
ml") || filePath.endsWith(".xhtml") || filePath.endsWith("-expected.txt") || (js
on && filePath.endsWith(".json")))) { | 97 if (stat.isFile() && (filePath.endsWith(".js") || filePath.endsWith(".ht
ml") || filePath.endsWith(".xhtml") || filePath.endsWith("-expected.txt") || (js
on && filePath.endsWith(".json")))) { |
118 if (filePath.includes("ExtensionAPI.js")) | 98 if (filePath.includes("ExtensionAPI.js")) |
119 return; | 99 return; |
120 if (filePath.includes("externs.js")) | 100 if (filePath.includes("externs.js")) |
121 return; | 101 return; |
122 if (filePath.includes("eslint") || filePath.includes("lighthouse-bac
kground.js") || filePath.includes("/cm/") || filePath.includes("/xterm.js/") ||
filePath.includes("/acorn/") || filePath.includes("/gonzales-scss")) | 102 if (filePath.includes("eslint") || filePath.includes("lighthouse-bac
kground.js") || filePath.includes("/cm/") || filePath.includes("/xterm.js/") ||
filePath.includes("/acorn/") || filePath.includes("/gonzales-scss")) |
123 return; | 103 return; |
124 if (filePath.includes("/cm_modes/") && !filePath.includes("DefaultCo
deMirror") && !filePath.includes("module.json")) | 104 if (filePath.includes("/cm_modes/") && !filePath.includes("DefaultCo
deMirror") && !filePath.includes("module.json")) |
125 return; | 105 return; |
126 process(filePath); | 106 process(filePath); |
127 } else if (stat.isDirectory()) { | 107 } else if (stat.isDirectory()) { |
128 walkSync(filePath, process, json); | 108 walkSync(filePath, process, json); |
129 } | 109 } |
130 }); | 110 }); |
131 } | 111 } |
132 | 112 |
133 walkSync('front_end', read); | 113 walkSync('front_end', read); |
| 114 |
134 sortedKeys = Array.from(map.keys()); | 115 sortedKeys = Array.from(map.keys()); |
135 sortedKeys.sort((a, b) => (b.length - a.length) || a.localeCompare(b)); | 116 sortedKeys.sort((a, b) => a.localeCompare(b)); |
| 117 |
136 for (var key of sortedKeys) | 118 for (var key of sortedKeys) |
137 console.log(key + " => " + map.get(key).name); | 119 console.log(key + " => " + map.get(key).name); |
| 120 |
138 walkSync('front_end', write, true); | 121 walkSync('front_end', write, true); |
139 | 122 |
140 walkSync('../../LayoutTests/http/tests/inspector', write, false); | 123 walkSync('../../LayoutTests/http/tests/inspector', write, false); |
141 walkSync('../../LayoutTests/http/tests/inspector-enabled', write, false); | 124 walkSync('../../LayoutTests/http/tests/inspector-enabled', write, false); |
142 walkSync('../../LayoutTests/http/tests/inspector-protocol', write, false); | 125 walkSync('../../LayoutTests/http/tests/inspector-protocol', write, false); |
143 walkSync('../../LayoutTests/http/tests/inspector-unit', write, false); | 126 walkSync('../../LayoutTests/http/tests/inspector-unit', write, false); |
144 walkSync('../../LayoutTests/inspector', write, false); | 127 walkSync('../../LayoutTests/inspector', write, false); |
145 walkSync('../../LayoutTests/inspector-enabled', write, false); | 128 walkSync('../../LayoutTests/inspector-enabled', write, false); |
146 walkSync('../../LayoutTests/inspector-protocol', write, false); | 129 walkSync('../../LayoutTests/inspector-protocol', write, false); |
OLD | NEW |