forked from microsoft/vscode-edge-devtools-network
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostBuildStep.ts
More file actions
122 lines (101 loc) · 4.19 KB
/
postBuildStep.ts
File metadata and controls
122 lines (101 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as fse from "fs-extra";
import path from "path";
import { applyContentSecurityPolicyPatch } from "./src/host/polyfills/inspectorContentPolicy";
import {
applyDrawerTabLocationPatch,
applyInspectorCommonCssPatch,
applyMainTabTabLocationPatch,
applySelectTabPatch,
applyShowTabElement,
} from "./src/host/polyfills/simpleView";
async function copyFile(srcDir: string, outDir: string, name: string) {
await fse.copy(
path.join(srcDir, name),
path.join(outDir, name),
);
}
async function copyStaticFiles() {
// Copy the static html file to the out directory
// Copy the static css file to the out directory
const commonSrcDir = "./src/common/";
const commonOutDir = "./out/common/";
await fse.ensureDir(commonOutDir);
await copyFile(commonSrcDir, commonOutDir, "styles.css");
// Must set environment variables EDGE_CHROMIUM_PATH and EDGE_CHROMIUM_OUT_DIR
// E.g. set EDGE_CHROMIUM_PATH=F:/git/Edge/src
// set EDGE_CHROMIUM_OUT_DIR=debug_x64
// See CONTRIBUTING.md for more details
const toolsSrcDir =
`${process.env.EDGE_CHROMIUM_PATH}/third_party/devtools-frontend/src/front_end/`;
if (!isDirectory(toolsSrcDir)) {
throw new Error(`Could not find Microsoft Edge (Chromium) DevTools path at '${toolsSrcDir}'. ` +
"Did you set the EDGE_CHROMIUM_PATH environment variable?");
}
const toolsGenDir =
`${process.env.EDGE_CHROMIUM_PATH}/out/${process.env.EDGE_CHROMIUM_OUT_DIR}/gen/devtools/`;
if (!isDirectory(toolsGenDir)) {
throw new Error(`Could not find Microsoft Edge (Chromium) output path at '${toolsGenDir}'. ` +
"Did you set the EDGE_CHROMIUM_OUT_DIR environment variable?");
}
const toolsResDir =
`${process.env.EDGE_CHROMIUM_PATH}/out/${process.env.EDGE_CHROMIUM_OUT_DIR}/resources/inspector/`;
// Copy the devtools to the out directory
const toolsOutDir = "./out/tools/front_end/";
await fse.ensureDir(toolsOutDir);
await fse.copy(toolsSrcDir, toolsOutDir);
// Copy the devtools generated files to the out directory
await fse.copy(toolsGenDir, toolsOutDir);
// Copy the optional devtools resource files to the out directory
if (isDirectory(toolsResDir)) {
await copyFile(toolsResDir, toolsOutDir, "InspectorBackendCommands.js");
await copyFile(toolsResDir, toolsOutDir, "SupportedCSSProperties.js");
}
// Patch older versions of the webview with our workarounds
await patchFilesForWebView(toolsOutDir);
}
async function patchFilesForWebView(toolsOutDir: string) {
// Release file versions
await patchFileForWebView("shell.js", toolsOutDir, true, [
applyInspectorCommonCssPatch,
applySelectTabPatch,
applyDrawerTabLocationPatch,
applyMainTabTabLocationPatch,
applyShowTabElement,
]);
await patchFileForWebView("inspector.html", toolsOutDir, true, [applyContentSecurityPolicyPatch]);
// Debug file versions
await patchFileForWebView("ui/TabbedPane.js", toolsOutDir, false, [applySelectTabPatch, applyShowTabElement]);
await patchFileForWebView("ui/InspectorView.js", toolsOutDir, false, [
applyDrawerTabLocationPatch,
applyMainTabTabLocationPatch,
]);
}
async function patchFileForWebView(
filename: string,
dir: string,
isRelease: boolean,
patches: Array<(content: string, isRelease?: boolean) => string>) {
const file = path.join(dir, filename);
// Ignore missing files
if (!await fse.pathExists(file)) {
return;
}
// Read in the file
let content = (await fse.readFile(file)).toString();
// Apply each patch in order
patches.forEach((patchFunction) => {
content = patchFunction(content, isRelease);
});
// Write out the final content
await fse.writeFile(file, content);
}
function isDirectory(fullPath: string) {
try {
return fse.statSync(fullPath).isDirectory();
} catch {
return false;
}
}
copyStaticFiles();