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

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/namespaces.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 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
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/build/generate_supported_css.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 const fs = require('fs');
2
3 function depends(module, from)
4 {
5 if (module === from)
6 return true;
7 var desc = descriptors[module];
8 if (!desc)
9 return false;
10 for (var dep of desc.dependencies || []) {
11 if (dep === from)
12 return true;
13 if (depends(dep, from))
14 return true;
15 }
16 return false;
17 }
18
19 var map = new Map();
20 var sortedKeys;
21 var moduleNames = new Set();
22
23 String.prototype.replaceAll = function(a, b)
24 {
25 var result = this;
26 while (result.includes(a))
27 result = result.replace(a, b);
28 return result;
29 }
30
31 function read(filePath)
32 {
33 var content = fs.readFileSync(filePath).toString();
34
35 var oldModuleName = filePath.replace(/front_end\/([^/]+)\/.*/, "$1");
36 if (oldModuleName.endsWith("_lazy"))
37 oldModuleName = oldModuleName.substring(0, oldModuleName.length - "_lazy ".length);
38
39 var moduleName = oldModuleName;
40
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")
57 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("");
60 if (moduleName.includes("/"))
61 return;
62 moduleNames.add(moduleName);
63
64 var lines = content.split("\n");
65 for (var line of lines) {
66 var line = line.trim();
67 if (!line.startsWith("WebInspector."))
68 continue;
69 var match = line.match(/^(WebInspector.[a-z_A-Z0-9]+)\s*(\=[^,}]|[;])/) || line.match(/^(WebInspector.[a-z_A-Z0-9]+)\s*\=$/);
70 if (!match)
71 continue;
72 var name = match[1];
73 if (name.split(".").length !== 2)
74 continue;
75 var weight = line.endsWith(name + ";") ? 2 : 1;
76
77 var newName;
78 var shortName = newName;
79
80 newName = name.replace("WebInspector.", moduleName + ".");
81 shortName = newName.replace(moduleName + ".", "");
82 var existing = map.get(name);
83 if (existing && existing.weight > weight)
84 continue;
85 if (existing && existing.weight === weight && newName !== existing.name)
86 console.log("Conflict: " + newName + " vs " + existing.name + " " + weight);
87 map.set(name, {name:newName, weight});
88 }
89 }
90
91
92 function write(filePath)
93 {
94 var content = fs.readFileSync(filePath).toString();
95 var newContent = content;
96 for (var key of sortedKeys)
97 newContent = newContent.replaceAll(key, map.get(key).name);
98 newContent = newContent.replaceAll("UI._focusChanged.bind(WebInspector", "UI ._focusChanged.bind(UI");
99 newContent = newContent.replaceAll("UI._windowFocused.bind(WebInspector", "U I._windowFocused.bind(UI");
100 newContent = newContent.replaceAll("UI._windowBlurred.bind(WebInspector", "U I._windowBlurred.bind(UI");
101 newContent = newContent.replaceAll("UI._focusChanged.bind(WebInspector", "UI ._focusChanged.bind(UI");
102 newContent = newContent.replaceAll("UI._focusChanged.bind(WebInspector", "UI ._focusChanged.bind(UI");
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
107 if (content !== newContent)
108 fs.writeFileSync(filePath, newContent);
109 }
110
111 function walkSync(currentDirPath, process, json) {
112 var fs = require('fs'),
113 path = require('path');
114 fs.readdirSync(currentDirPath).forEach(function (name) {
115 var filePath = path.join(currentDirPath, name);
116 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")))) {
118 if (filePath.includes("ExtensionAPI.js"))
119 return;
120 if (filePath.includes("externs.js"))
121 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"))
123 return;
124 if (filePath.includes("/cm_modes/") && !filePath.includes("DefaultCo deMirror") && !filePath.includes("module.json"))
125 return;
126 process(filePath);
127 } else if (stat.isDirectory()) {
128 walkSync(filePath, process, json);
129 }
130 });
131 }
132
133 walkSync('front_end', read);
134 sortedKeys = Array.from(map.keys());
135 sortedKeys.sort((a, b) => (b.length - a.length) || a.localeCompare(b));
136 for (var key of sortedKeys)
137 console.log(key + " => " + map.get(key).name);
138 walkSync('front_end', write, true);
139
140 walkSync('../../LayoutTests/http/tests/inspector', write, false);
141 walkSync('../../LayoutTests/http/tests/inspector-enabled', write, false);
142 walkSync('../../LayoutTests/http/tests/inspector-protocol', write, false);
143 walkSync('../../LayoutTests/http/tests/inspector-unit', write, false);
144 walkSync('../../LayoutTests/inspector', write, false);
145 walkSync('../../LayoutTests/inspector-enabled', write, false);
146 walkSync('../../LayoutTests/inspector-protocol', write, false);
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/build/generate_supported_css.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698