This repository was archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathsetup-webview-test-env.js
65 lines (57 loc) · 2.69 KB
/
setup-webview-test-env.js
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import {createDir, copyDir, color, delDir} from './helpers.js';
import {existsSync} from 'fs';
import {exec} from 'child_process';
import {promisify} from 'util';
import process from 'process';
const execShellCommand = promisify(exec);
async function main() {
// Empty print line to pretty-ify command line output
console.log();
// Copy webview test environment locally if it does not already exist
if (!existsSync('./test-webview')) {
try {
console.log(color(['dim'], 'Copying webview test environment locally...'));
await execShellCommand('npx degit microsoft/vscode-webview-ui-toolkit-samples/default/component-gallery test-webview');
} catch (err) {
console.log(`${color(['red'], 'Error: Could not copy webview test environment locally')}\n ${err}`);
process.exit();
}
}
// Install the webview test environment dependencies if they do not exist
if (!existsSync('./test-webview/node_modules')) {
try {
console.log(color(['dim'], 'Installing webview test environment dependencies...'));
await execShellCommand('cd ./test-webview && npm install');
} catch (err) {
console.log(`${color(['red'], 'Error: Could not install webview test environment dependencies')}\n ${err}`);
process.exit();
}
}
// Copy latest toolkit build into the webview test environment
try {
console.log(color(['dim'], 'Copying latest toolkit build into webview test environment...'));
// Copy web component build directory
delDir('./test-webview/node_modules/@vscode/webview-ui-toolkit/dist');
createDir('./test-webview/node_modules/@vscode/webview-ui-toolkit/dist');
copyDir('./dist', './test-webview/node_modules/@vscode/webview-ui-toolkit');
// Copy react build directory
delDir('./test-webview/node_modules/@vscode/webview-ui-toolkit/react');
createDir('./test-webview/node_modules/@vscode/webview-ui-toolkit/react');
copyDir('./react', './test-webview/node_modules/@vscode/webview-ui-toolkit');
} catch (err) {
console.log(`${color(['red'], 'Error: Failed to copy latest toolkit build into webview test environment')}\n ${err}`);
process.exit();
}
// Print success and next steps messages
console.log();
console.log(color(['bold', 'green'], 'Webview test environment successfully configured!'));
console.log();
console.log('Next steps:');
console.log(` 1. Open the ${color(['cyan'], 'test-webview')} folder in a new VS Code window`);
console.log(` 2. Press ${color(['cyan'], 'F5')} to open the webview test extension with the most recent toolkit build loaded`);
console.log(` 3. Run the "${color(['cyan'], 'Component Gallery: Show')}" command using the VS Code command palette`);
console.log();
}
main();