1
+ // @ts -check
2
+ const path = require ( 'path' ) ;
3
+ const cp = require ( 'child_process' ) ;
4
+
5
+ /**
6
+ * @type {(paths: string[]) => string }
7
+ */
8
+ function root ( ...paths ) {
9
+ return path . join ( __dirname , '..' , ...paths ) ;
10
+ }
11
+ /**
12
+ * @type {(paths: string[]) => string }
13
+ */
14
+ function src ( ...paths ) {
15
+ return root ( 'src' , ...paths ) ;
16
+ }
17
+ /**
18
+ * @type {(paths: string[]) => string }
19
+ */
20
+ function vscode ( ...paths ) {
21
+ return root ( 'vscode' , ...paths ) ;
22
+ }
23
+ /**
24
+ * @type {(paths: string[]) => string }
25
+ */
26
+ function theiaExtension ( ...paths ) {
27
+ return root ( 'vscode-builtin-extensions' , ...paths ) ;
28
+ }
29
+ /**
30
+ * @type {(paths: string[]) => string }
31
+ */
32
+ function extensions ( ...paths ) {
33
+ return theiaExtension ( 'extensions' , ...paths ) ;
34
+ }
35
+
36
+ /**
37
+ * @type {(command: string, args?: ReadonlyArray<string>, cwd?: string) => Promise<string> }
38
+ */
39
+ function run ( command , args , cwd = process . cwd ( ) ) {
40
+ return new Promise ( ( resolve , reject ) => {
41
+ let result = '' ;
42
+ const p = cp . spawn ( command , args , { cwd } ) ;
43
+ p . stdout . on ( 'data' , data => {
44
+ console . log ( String ( data ) ) ;
45
+ result += String ( data ) ;
46
+ } ) ;
47
+ p . stderr . on ( 'data' , data => console . error ( String ( data ) ) ) ;
48
+ p . on ( 'close' , code => ! code ? resolve ( result ) : reject ( ) ) ;
49
+ } ) ;
50
+ }
51
+
52
+ module . exports = { root, src, vscode, theiaExtension, extensions, run } ;
0 commit comments