1
1
// Dependencies
2
- import { dirname } from 'path' ;
3
- import { getConfig } from 'vscode-get-config' ;
4
- import { spawn } from 'child_process' ;
5
- import { workspace , window } from 'vscode' ;
2
+ import { dirname } from "path" ;
3
+ // @ts -expect-error TODO Fix package
4
+ import { getConfig } from "vscode-get-config" ;
5
+ import { spawn } from "child_process" ;
6
+ import { workspace , window } from "vscode" ;
6
7
7
8
// Package Components
8
- import { clearOutput , detectOutput , getPath , pathWarning , runInstaller , sanitize } from './util' ;
9
+ import {
10
+ clearOutput ,
11
+ detectOutput ,
12
+ getPath ,
13
+ pathWarning ,
14
+ runInstaller ,
15
+ sanitize ,
16
+ } from "./util" ;
9
17
10
- const channel = window . createOutputChannel ( ' pynsist' ) ;
18
+ const channel = window . createOutputChannel ( " pynsist" ) ;
11
19
12
20
/*
13
21
* Requires pynsist
@@ -17,88 +25,110 @@ const channel = window.createOutputChannel('pynsist');
17
25
async function generate ( runMakensis : boolean ) : Promise < void > {
18
26
await clearOutput ( channel ) ;
19
27
20
- const doc = window . activeTextEditor . document ;
28
+ const doc = window ?. activeTextEditor ?. document ;
29
+
30
+ if ( ! doc ) {
31
+ console . error ( "[idleberg.applescript] Document not found" ) ;
32
+ return ;
33
+ }
34
+
21
35
const scope = doc . languageId ;
22
36
23
- if ( scope !== 'properties' && doc . fileName === 'installer.cfg' ) {
24
- channel . appendLine ( 'This command is only available for Pynsist Configuration files' ) ;
37
+ if ( scope !== "properties" && doc . fileName === "installer.cfg" ) {
38
+ channel . appendLine (
39
+ "This command is only available for Pynsist Configuration files" ,
40
+ ) ;
25
41
return ;
26
42
}
27
43
28
- const { showNotifications } = await getConfig ( ' pynsist' ) ;
44
+ const { showNotifications } = await getConfig ( " pynsist" ) ;
29
45
30
46
doc . save ( ) . then ( async ( ) => {
31
47
await getPath ( )
32
- . then ( sanitize )
48
+ . then ( ( path ) => sanitize ( path . toString ( ) ) )
33
49
. then ( ( pathToPynsist : string ) => {
34
- if ( typeof pathToPynsist === 'undefined' || pathToPynsist === null ) {
35
- return window . showErrorMessage ( 'No valid `pynsist` was specified in your config' ) ;
50
+ if ( typeof pathToPynsist === "undefined" || pathToPynsist === null ) {
51
+ return window . showErrorMessage (
52
+ "No valid `pynsist` was specified in your config" ,
53
+ ) ;
36
54
}
37
55
38
56
const defaultArguments : Array < string > = [ doc . fileName ] ;
39
57
40
58
if ( runMakensis === false ) {
41
- defaultArguments . push ( ' --no-makensis' ) ;
59
+ defaultArguments . push ( " --no-makensis" ) ;
42
60
}
43
61
44
62
// Let's build
45
63
const pynsist = spawn ( pathToPynsist , defaultArguments ) ;
46
64
47
65
const scriptPath : string = dirname ( doc . fileName ) ;
48
- let outScript = '' ;
49
- let outFile = '' ;
66
+ let outScript = "" ;
67
+ let outFile = "" ;
50
68
51
- pynsist . stdout . on ( ' data' , ( line : string ) => {
69
+ pynsist . stdout . on ( " data" , ( line : string ) => {
52
70
channel . appendLine ( line . toString ( ) . trim ( ) ) ;
53
71
} ) ;
54
72
55
73
// pynsist currently outputs to stderr only (v1.12)
56
- pynsist . stderr . on ( ' data' , async ( line : string ) => {
74
+ pynsist . stderr . on ( " data" , async ( line : string ) => {
57
75
channel . appendLine ( line . toString ( ) . trim ( ) ) ;
58
76
59
- if ( outScript === '' ) {
77
+ if ( outScript === "" ) {
60
78
outScript = await detectOutput ( scriptPath , line , {
61
- string : ' Writing NSI file to ' ,
79
+ string : " Writing NSI file to " ,
62
80
regex : / W r i t i n g N S I f i l e t o ( .* ) \r ? \n / g,
63
81
} ) ;
64
82
}
65
83
66
- if ( outFile === '' && runMakensis === true ) {
84
+ if ( outFile === "" && runMakensis === true ) {
67
85
outFile = await detectOutput ( scriptPath , line , {
68
- string : ' Installer written to ' ,
86
+ string : " Installer written to " ,
69
87
regex : / I n s t a l l e r w r i t t e n t o ( .* ) \r ? \n / g,
70
88
} ) ;
71
89
}
72
90
} ) ;
73
91
74
- pynsist . on ( ' close' , async ( code ) => {
92
+ pynsist . on ( " close" , async ( code ) => {
75
93
if ( code === 0 ) {
76
94
if ( showNotifications ) {
77
95
if ( runMakensis === true ) {
78
96
window
79
- . showInformationMessage ( 'Successfully compiled installer' , 'Run Installer' , 'Open Script' )
97
+ . showInformationMessage (
98
+ "Successfully compiled installer" ,
99
+ "Run Installer" ,
100
+ "Open Script" ,
101
+ )
80
102
. then ( async ( choice ) => {
81
- if ( choice === ' Run Installer' ) {
103
+ if ( choice === " Run Installer" ) {
82
104
await runInstaller ( outFile ) ;
83
- } else if ( choice === ' Open Script' ) {
105
+ } else if ( choice === " Open Script" ) {
84
106
workspace . openTextDocument ( outScript ) . then ( ( doc ) => {
85
107
window . showTextDocument ( doc ) ;
86
108
} ) ;
87
109
}
88
110
} ) ;
89
111
} else {
90
- window . showInformationMessage ( 'Successfully generated script' , 'Open Script' ) . then ( ( choice ) => {
91
- if ( choice === 'Open Script' ) {
92
- workspace . openTextDocument ( outScript ) . then ( ( doc ) => {
93
- window . showTextDocument ( doc ) ;
94
- } ) ;
95
- }
96
- } ) ;
112
+ window
113
+ . showInformationMessage (
114
+ "Successfully generated script" ,
115
+ "Open Script" ,
116
+ )
117
+ . then ( ( choice ) => {
118
+ if ( choice === "Open Script" ) {
119
+ workspace . openTextDocument ( outScript ) . then ( ( doc ) => {
120
+ window . showTextDocument ( doc ) ;
121
+ } ) ;
122
+ }
123
+ } ) ;
97
124
}
98
125
}
99
126
} else {
100
127
channel . show ( true ) ;
101
- if ( showNotifications ) window . showErrorMessage ( 'Something went wrong. See the output for details.' ) ;
128
+ if ( showNotifications )
129
+ window . showErrorMessage (
130
+ "Something went wrong. See the output for details." ,
131
+ ) ;
102
132
}
103
133
} ) ;
104
134
} )
0 commit comments