Skip to content

Commit e60bc7a

Browse files
eirikhmchristianalfoni
authored andcommitted
feat(overmind): support running in dev and prod
1 parent a24591e commit e60bc7a

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

packages/node_modules/overmind-devtools-vscode/.vscode/launch.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
"runtimeExecutable": "${execPath}",
1313
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1414
"outFiles": ["${workspaceFolder}/out/**/*.js"],
15-
"preLaunchTask": "npm: watch"
15+
"preLaunchTask": "npm: watch",
16+
"env": {
17+
"VSCODE_DEBUG_MODE": "true"
18+
}
1619
},
1720
{
1821
"name": "Extension Tests",

packages/node_modules/overmind-devtools-vscode/src/DevtoolsPanel.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode'
22
import { log } from './utils/Logger'
3+
import * as path from 'path'
34

45
export class DevtoolsPanel {
56
public static currentPanel: DevtoolsPanel | undefined
@@ -10,6 +11,8 @@ export class DevtoolsPanel {
1011

1112
private _disposables: vscode.Disposable[] = []
1213

14+
public static markup: string = ''
15+
1316
private constructor(panel: vscode.WebviewPanel, extensionPath: string) {
1417
this._panel = panel
1518
this.update()
@@ -55,27 +58,7 @@ export class DevtoolsPanel {
5558
}
5659

5760
private getHtmlForWevbiew(): string {
58-
return `<!DOCTYPE html>
59-
<html lang="en">
60-
<head>
61-
<meta charset="UTF-8" />
62-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
63-
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
64-
<title>Document</title>
65-
<link
66-
href="https://fonts.googleapis.com/css?family=Source+Code+Pro"
67-
rel="stylesheet"
68-
/>
69-
<link
70-
href="https://fonts.googleapis.com/css?family=Nunito:400,700"
71-
rel="stylesheet"
72-
/>
73-
</head>
74-
<body>
75-
<script type="text/javascript" src="http://localhost:8080/bundle.js"></script>
76-
</body>
77-
</html>
78-
`
61+
return DevtoolsPanel.markup
7962
}
8063

8164
static createOrShow(extensionPath: string) {
@@ -94,7 +77,9 @@ export class DevtoolsPanel {
9477
{
9578
enableScripts: true,
9679
retainContextWhenHidden: true,
97-
localResourceRoots: [],
80+
localResourceRoots: [
81+
vscode.Uri.file(path.join(extensionPath, 'devtoolsDist')),
82+
],
9883
}
9984
)
10085

packages/node_modules/overmind-devtools-vscode/src/extension.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
import * as vscode from 'vscode'
22
import { DevtoolsPanel } from './DevtoolsPanel'
33
import { log } from './utils/Logger'
4+
import * as path from 'path'
5+
6+
function getMarkup(scriptSource: vscode.Uri | string): string {
7+
return `<!DOCTYPE html>
8+
<html lang="en">
9+
<head>
10+
<meta charset="UTF-8" />
11+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
12+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
13+
<title>Document</title>
14+
<link
15+
href="https://fonts.googleapis.com/css?family=Source+Code+Pro"
16+
rel="stylesheet"
17+
/>
18+
<link
19+
href="https://fonts.googleapis.com/css?family=Nunito:400,700"
20+
rel="stylesheet"
21+
/>
22+
</head>
23+
<body>
24+
<script type="text/javascript" src="${scriptSource}"></script>
25+
</body>
26+
</html>
27+
`
28+
}
429

530
// this method is called when your extension is activated
631
// your extension is activated the very first time the command is executed
@@ -37,6 +62,19 @@ export function activate(context: vscode.ExtensionContext) {
3762

3863
context.subscriptions.push(
3964
vscode.commands.registerCommand('overmind-devtools.start', () => {
65+
let scriptFile: vscode.Uri | string
66+
67+
// TODO consider https://github.com/microsoft/vscode/commit/fbcdb4c6a736ff38e60a7e9d0a3f1be5ccbaf3af ?
68+
if (process.env.VSCODE_DEBUG_MODE) {
69+
scriptFile = 'http://localhost:8080/bundle.js'
70+
} else {
71+
const onDiskPath = vscode.Uri.file(
72+
path.join(context.extensionPath, 'devtoolsDist', 'bundle.js')
73+
)
74+
scriptFile = onDiskPath.with({ scheme: 'vscode-resource' })
75+
}
76+
77+
DevtoolsPanel.markup = getMarkup(scriptFile)
4078
DevtoolsPanel.createOrShow(context.extensionPath) // refactor to keep local reference to panel
4179
})
4280
)

0 commit comments

Comments
 (0)