@@ -2,6 +2,7 @@ import { Binary } from "@coder/nbin";
2
2
import { field } from "@coder/logger" ;
3
3
import { register , run } from "@coder/runner" ;
4
4
5
+ import * as cp from "child_process" ;
5
6
import * as fs from "fs" ;
6
7
import * as fse from "fs-extra" ;
7
8
import * as https from "https" ;
@@ -11,8 +12,9 @@ import * as tar from "tar";
11
12
12
13
import { platform } from "./platform" ;
13
14
14
- const libPath = path . join ( __dirname , "../lib" ) ;
15
- const releasePath = path . resolve ( __dirname , "../release" ) ;
15
+ const rootPath = path . resolve ( __dirname , ".." ) ;
16
+ const libPath = path . join ( rootPath , "lib" ) ;
17
+ const releasePath = path . join ( rootPath , "release" ) ;
16
18
const target = `${ platform ( ) } -${ os . arch ( ) } ` ;
17
19
const vscodeVersion = process . env . VSCODE_VERSION || "1.35.0" ;
18
20
@@ -30,25 +32,34 @@ register("build", async (runner, logger, shouldWatch: string) => {
30
32
const outPath = path . join ( __dirname , "../out" ) ;
31
33
const compile = async ( ) : Promise < void > => {
32
34
fse . removeSync ( path . resolve ( outPath ) ) ;
33
-
34
- runner . cwd = path . resolve ( __dirname , ".." ) ;
35
- const resp = await runner . execute (
36
- "tsc" ,
37
- [ "--project" , "tsconfig.build.json" ] . concat ( watch ? [ "--watch" ] : [ ] ) ,
38
- ) ;
39
- if ( resp . exitCode !== 0 ) {
40
- throw new Error ( `Failed to build: ${ resp . stderr } ` ) ;
35
+ if ( watch ) {
36
+ const proc = cp . spawn ( "tsc" , [ "--project" , "tsconfig.build.json" , "--watch" , "--preserveWatchOutput" ] , {
37
+ cwd : rootPath ,
38
+ } ) ;
39
+ await new Promise ( ( resolve , reject ) : void => {
40
+ proc . stdout . setEncoding ( "utf8" ) ;
41
+ proc . stdout . on ( "data" , ( data : string ) => {
42
+ logger . info ( data . split ( "\n" ) . filter ( ( l ) => ! ! l ) . join ( "\n" ) ) ;
43
+ } ) ;
44
+ proc . on ( "exit" , resolve ) ;
45
+ proc . on ( "error" , reject ) ;
46
+ } ) ;
47
+ } else {
48
+ runner . cwd = rootPath ;
49
+ const resp = await runner . execute ( "tsc" , [ "--project" , "tsconfig.build.json" ] ) ;
50
+ if ( resp . exitCode !== 0 ) {
51
+ throw new Error ( `Failed to build: ${ resp . stderr } ` ) ;
52
+ }
41
53
}
42
54
} ;
43
55
44
56
const copy = async ( ) : Promise < void > => {
45
57
// TODO: If watching, copy every time they change.
46
58
await Promise . all ( [
47
59
"packages/protocol/src/proto" ,
48
- [ "tsconfig.runtime.json" , "tsconfig.json" ] ,
49
60
] . map ( ( p ) => fse . copy (
50
- path . resolve ( __dirname , ".." , Array . isArray ( p ) ? p [ 0 ] : p ) ,
51
- path . resolve ( outPath , Array . isArray ( p ) ? p [ 1 ] : p ) ,
61
+ path . resolve ( rootPath , p ) ,
62
+ path . resolve ( outPath , p ) ,
52
63
) ) ) ;
53
64
fse . unlinkSync ( path . resolve ( outPath , "packages/protocol/src/proto/index.ts" ) ) ;
54
65
} ;
@@ -64,15 +75,14 @@ register("build", async (runner, logger, shouldWatch: string) => {
64
75
* Bundle built code into a binary with nbin.
65
76
*/
66
77
register ( "bundle" , async ( ) => {
67
- const root = path . join ( __dirname , ".." ) ;
68
78
const bin = new Binary ( {
69
- mainFile : path . join ( root , "out/packages/server/src/cli .js" ) ,
79
+ mainFile : path . join ( rootPath , "out/packages/server/src/bootstrap .js" ) ,
70
80
target : platform ( ) === "darwin" ? "darwin" : platform ( ) === "musl" ? "alpine" : "linux" ,
71
81
} ) ;
72
82
73
- bin . writeFiles ( path . join ( root , "lib/**" ) ) ;
74
- bin . writeFiles ( path . join ( root , "out/**" ) ) ;
75
- bin . writeFiles ( path . join ( root , "**/node_modules" ) ) ;
83
+ bin . writeFiles ( path . join ( rootPath , "lib/**" ) ) ;
84
+ bin . writeFiles ( path . join ( rootPath , "out/**" ) ) ;
85
+ bin . writeFiles ( path . join ( rootPath , "**/node_modules/** " ) ) ;
76
86
77
87
fse . mkdirpSync ( releasePath ) ;
78
88
0 commit comments