|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import {createDir, copyDir, copyFile, color, delDir} from './helpers.js'; |
| 5 | +import {existsSync} from 'fs'; |
| 6 | +import {exec} from 'child_process'; |
| 7 | +import {promisify} from 'util'; |
| 8 | +import process from 'process'; |
| 9 | + |
| 10 | +const execShellCommand = promisify(exec); |
| 11 | + |
| 12 | +async function main() { |
| 13 | + // Empty print line to pretty-ify command line output |
| 14 | + console.log(); |
| 15 | + |
| 16 | + // Copy webview test environment locally if it does not already exist |
| 17 | + if (!existsSync('./test-webview')) { |
| 18 | + try { |
| 19 | + console.log( |
| 20 | + color(['dim'], 'Copying webview test environment locally...') |
| 21 | + ); |
| 22 | + await execShellCommand( |
| 23 | + 'npx degit microsoft/vscode-webview-ui-toolkit-samples/frameworks/component-gallery-react test-webview' |
| 24 | + ); |
| 25 | + } catch (err) { |
| 26 | + console.log( |
| 27 | + `${color( |
| 28 | + ['red'], |
| 29 | + 'Error: Could not copy webview test environment locally' |
| 30 | + )}\n ${err}` |
| 31 | + ); |
| 32 | + process.exit(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + // Install the webview test environment dependencies if they do not exist |
| 37 | + if (!existsSync('./test-webview/node_modules')) { |
| 38 | + try { |
| 39 | + console.log( |
| 40 | + color( |
| 41 | + ['dim'], |
| 42 | + 'Installing webview test environment dependencies...' |
| 43 | + ) |
| 44 | + ); |
| 45 | + await execShellCommand('cd ./test-webview && npm run install:all'); |
| 46 | + } catch (err) { |
| 47 | + console.log( |
| 48 | + `${color( |
| 49 | + ['red'], |
| 50 | + 'Error: Could not install webview test environment dependencies' |
| 51 | + )}\n ${err}` |
| 52 | + ); |
| 53 | + process.exit(); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + // Copy latest toolkit build into the webview test environment |
| 58 | + try { |
| 59 | + console.log( |
| 60 | + color( |
| 61 | + ['dim'], |
| 62 | + 'Copying latest toolkit build into webview test environment...' |
| 63 | + ) |
| 64 | + ); |
| 65 | + // Copy web component build directory |
| 66 | + delDir( |
| 67 | + './test-webview/webview-ui/node_modules/@vscode/webview-ui-toolkit/dist' |
| 68 | + ); |
| 69 | + createDir( |
| 70 | + './test-webview/webview-ui/node_modules/@vscode/webview-ui-toolkit/dist' |
| 71 | + ); |
| 72 | + copyDir( |
| 73 | + '../toolkit/dist', |
| 74 | + './test-webview/webview-ui/node_modules/@vscode/webview-ui-toolkit' |
| 75 | + ); |
| 76 | + // Copy react build directory |
| 77 | + delDir( |
| 78 | + './test-webview/webview-ui/node_modules/@vscode/webview-ui-toolkit/react' |
| 79 | + ); |
| 80 | + createDir( |
| 81 | + './test-webview/webview-ui/node_modules/@vscode/webview-ui-toolkit/react' |
| 82 | + ); |
| 83 | + copyFile( |
| 84 | + './dist/index.js', |
| 85 | + './test-webview/webview-ui/node_modules/@vscode/webview-ui-toolkit/react' |
| 86 | + ); |
| 87 | + copyFile( |
| 88 | + './dist/index.d.ts', |
| 89 | + './test-webview/webview-ui/node_modules/@vscode/webview-ui-toolkit/react' |
| 90 | + ); |
| 91 | + } catch (err) { |
| 92 | + console.log( |
| 93 | + `${color( |
| 94 | + ['red'], |
| 95 | + 'Error: Failed to copy latest toolkit build into webview test environment' |
| 96 | + )}\n ${err}` |
| 97 | + ); |
| 98 | + process.exit(); |
| 99 | + } |
| 100 | + |
| 101 | + // Build the React webview |
| 102 | + try { |
| 103 | + console.log(color(['dim'], 'Building React webview...')); |
| 104 | + await execShellCommand('cd ./test-webview && npm run build:webview'); |
| 105 | + } catch (err) { |
| 106 | + console.log( |
| 107 | + `${color( |
| 108 | + ['red'], |
| 109 | + 'Error: Could not build React webview' |
| 110 | + )}\n ${err}` |
| 111 | + ); |
| 112 | + process.exit(); |
| 113 | + } |
| 114 | + |
| 115 | + // Print success and next steps messages |
| 116 | + console.log(); |
| 117 | + console.log( |
| 118 | + color( |
| 119 | + ['bold', 'green'], |
| 120 | + 'Webview test environment successfully configured!' |
| 121 | + ) |
| 122 | + ); |
| 123 | + console.log(); |
| 124 | + console.log('Next steps:'); |
| 125 | + console.log( |
| 126 | + ` 1. Open the ${color( |
| 127 | + ['cyan'], |
| 128 | + 'packages/toolkit-react/test-webview' |
| 129 | + )} folder in a new VS Code window` |
| 130 | + ); |
| 131 | + console.log( |
| 132 | + ` 2. Press ${color( |
| 133 | + ['cyan'], |
| 134 | + 'F5' |
| 135 | + )} to open the webview test extension with the most recent toolkit build loaded` |
| 136 | + ); |
| 137 | + console.log( |
| 138 | + ` 3. Run the "${color( |
| 139 | + ['cyan'], |
| 140 | + 'Component Gallery (React): Show' |
| 141 | + )}" command using the VS Code command palette` |
| 142 | + ); |
| 143 | + console.log(); |
| 144 | +} |
| 145 | + |
| 146 | +main(); |
0 commit comments