This repository was archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpostBuildStep.ts
More file actions
80 lines (64 loc) · 2.19 KB
/
postBuildStep.ts
File metadata and controls
80 lines (64 loc) · 2.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
// 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/patch/inspectorContentPolicy";
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 css file to the out directory
const commonSrcDir = "./src/common/";
const commonOutDir = "./out/common/";
await fse.ensureDir(commonOutDir);
await copyFile(commonSrcDir, commonOutDir, "styles.css");
const toolsSrcDir =
`node_modules/chrome-devtools-frontend/front_end/`;
if (!isDirectory(toolsSrcDir)) {
throw new Error(`Could not find Chrome DevTools path at '${toolsSrcDir}'. ` +
"Did you run npm install?");
}
// Copy the devtools to the out directory
const toolsOutDir = "./out/tools/front_end/";
await fse.ensureDir(toolsOutDir);
await fse.copy(toolsSrcDir, toolsOutDir);
// Patch older versions of the webview with our workarounds
await patchFilesForWebView(toolsOutDir);
}
async function patchFilesForWebView(toolsOutDir: string) {
// Release file versions
await patchFileForWebView("inspector.html", toolsOutDir, true, [
applyContentSecurityPolicyPatch,
]);
// Debug file versions
}
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();