1
- import browserify from "browserify"
2
1
import * as cp from "child_process"
3
- import * as fs from "fs"
4
2
import * as path from "path"
5
3
import { onLine } from "../../src/node/util"
6
4
7
5
async function main ( ) : Promise < void > {
8
6
try {
9
7
const watcher = new Watcher ( )
10
8
await watcher . watch ( )
11
- } catch ( error ) {
9
+ } catch ( error : any ) {
12
10
console . error ( error . message )
13
11
process . exit ( 1 )
14
12
}
@@ -38,6 +36,9 @@ class Watcher {
38
36
}
39
37
40
38
const vscode = cp . spawn ( "yarn" , [ "watch" ] , { cwd : this . vscodeSourcePath } )
39
+
40
+ const vscodeWebExtensions = cp . spawn ( "yarn" , [ "watch-web" ] , { cwd : this . vscodeSourcePath } )
41
+
41
42
const tsc = cp . spawn ( "tsc" , [ "--watch" , "--pretty" , "--preserveWatchOutput" ] , { cwd : this . rootPath } )
42
43
const plugin = process . env . PLUGIN_DIR
43
44
? cp . spawn ( "yarn" , [ "build" , "--watch" ] , { cwd : process . env . PLUGIN_DIR } )
@@ -48,6 +49,10 @@ class Watcher {
48
49
vscode . removeAllListeners ( )
49
50
vscode . kill ( )
50
51
52
+ Watcher . log ( "killing vs code web extension watcher" )
53
+ vscodeWebExtensions . removeAllListeners ( )
54
+ vscodeWebExtensions . kill ( )
55
+
51
56
Watcher . log ( "killing tsc" )
52
57
tsc . removeAllListeners ( )
53
58
tsc . kill ( )
@@ -75,29 +80,32 @@ class Watcher {
75
80
Watcher . log ( "vs code watcher terminated unexpectedly" )
76
81
cleanup ( code )
77
82
} )
83
+
84
+ vscodeWebExtensions . on ( "exit" , ( code ) => {
85
+ Watcher . log ( "vs code extension watcher terminated unexpectedly" )
86
+ cleanup ( code )
87
+ } )
88
+
78
89
tsc . on ( "exit" , ( code ) => {
79
90
Watcher . log ( "tsc terminated unexpectedly" )
80
91
cleanup ( code )
81
92
} )
93
+
82
94
if ( plugin ) {
83
95
plugin . on ( "exit" , ( code ) => {
84
96
Watcher . log ( "plugin terminated unexpectedly" )
85
97
cleanup ( code )
86
98
} )
87
99
}
88
100
101
+ vscodeWebExtensions . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
89
102
vscode . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
90
103
tsc . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
104
+
91
105
if ( plugin ) {
92
106
plugin . stderr . on ( "data" , ( d ) => process . stderr . write ( d ) )
93
107
}
94
108
95
- const browserFiles = [
96
- path . join ( this . rootPath , "out/browser/register.js" ) ,
97
- path . join ( this . rootPath , "out/browser/pages/login.js" ) ,
98
- path . join ( this . rootPath , "out/browser/pages/vscode.js" ) ,
99
- ]
100
-
101
109
let startingVscode = false
102
110
let startedVscode = false
103
111
onLine ( vscode , ( line , original ) => {
@@ -120,7 +128,6 @@ class Watcher {
120
128
console . log ( "[tsc]" , original )
121
129
}
122
130
if ( line . includes ( "Watching for file changes" ) ) {
123
- bundleBrowserCode ( browserFiles )
124
131
restartServer ( )
125
132
}
126
133
} )
@@ -139,19 +146,4 @@ class Watcher {
139
146
}
140
147
}
141
148
142
- function bundleBrowserCode ( inputFiles : string [ ] ) {
143
- console . log ( `[browser] bundling...` )
144
- inputFiles . forEach ( async ( path : string ) => {
145
- const outputPath = path . replace ( ".js" , ".browserified.js" )
146
- browserify ( )
147
- . add ( path )
148
- . bundle ( )
149
- . on ( "error" , function ( error : Error ) {
150
- console . error ( error . toString ( ) )
151
- } )
152
- . pipe ( fs . createWriteStream ( outputPath ) )
153
- } )
154
- console . log ( `[browser] done bundling` )
155
- }
156
-
157
149
main ( )
0 commit comments