1 | import webpack from 'webpack';
|
2 | import NotificationCenter from 'node-notifier/notifiers/notificationcenter';
|
3 | import { NodeNotifier } from 'node-notifier';
|
4 |
|
5 | /**
|
6 | * Enum representing valid compilation result statuses.
|
7 | */
|
8 | declare enum CompilationStatus {
|
9 | SUCCESS = "success",
|
10 | WARNING = "warning",
|
11 | ERROR = "error"
|
12 | }
|
13 | type CompilationResult = {
|
14 | details?: string;
|
15 | message?: string;
|
16 | module?: {
|
17 | rawRequest?: string;
|
18 | resource?: string;
|
19 | };
|
20 | };
|
21 | type Config = {
|
22 | /**
|
23 | * The notification title prefix. Defaults to `Webpack Build`.
|
24 | */
|
25 | title?: string;
|
26 | /**
|
27 | * The absolute path to the project logo to be displayed as a content image in the notification. Optional.
|
28 | */
|
29 | logo?: string;
|
30 | /**
|
31 | * The sound to play for notifications. Set to false to play no sound. Valid sounds are listed
|
32 | * in the node-notifier project: https://github.com/mikaelbr/node-notifier. Defaults to `Submarine`.
|
33 | */
|
34 | sound?: string | false;
|
35 | /**
|
36 | * The sound to play for success notifications. Defaults to the value of the *sound* configuration option.
|
37 | * Set to false to play no sound for success notifications. Takes precedence over the *sound* configuration option.
|
38 | */
|
39 | successSound?: string | false;
|
40 | /**
|
41 | * The sound to play for warning notifications. Defaults to the value of the *sound* configuration option.
|
42 | * Set to false to play no sound for warning notifications. Takes precedence over the *sound* configuration option.
|
43 | */
|
44 | warningSound?: string | false;
|
45 | /**
|
46 | * The sound to play for failure notifications. Defaults to the value of the *sound* configuration option.
|
47 | * Set to false to play no sound for failure notifications. Takes precedence over the *sound* configuration option.
|
48 | */
|
49 | failureSound?: string | false;
|
50 | /**
|
51 | * The sound to play for compilation notifications. Defaults to the value of the *sound* configuration option.
|
52 | * Set to false to play no sound for compilation notifications. Takes precedence over the *sound* configuration option.
|
53 | */
|
54 | compilationSound?: string | false;
|
55 | /**
|
56 | * A function which is invoked when compilation starts. Optional. The function is passed one parameter:
|
57 | * 1. {webpack.compiler.Compiler} compiler - The webpack Compiler instance.
|
58 | * Note that `suppressCompileStart` must be `false`.
|
59 | */
|
60 | onCompileStart?: (compilation: webpack.Compiler) => void;
|
61 | /**
|
62 | * A function which is invoked when compilation completes. Optional. The function is passed two parameters:
|
63 | * 1. {webpack.compilation.Compilation} compilation - The webpack Compilation instance.
|
64 | * 2. {CompilationStatus} status - one of 'success', 'warning', or 'error'
|
65 | */
|
66 | onComplete?: (compilation: webpack.Compilation, status: CompilationStatus) => void;
|
67 | /**
|
68 | * True to show the duration of a successful compilation, otherwise false (default).
|
69 | */
|
70 | showDuration?: boolean;
|
71 | /**
|
72 | * Defines when success notifications are shown. Can be one of the following values:
|
73 | *
|
74 | * * `false` - Show success notification for each successful compilation (default).
|
75 | * * `true` - Only show success notification for initial successful compilation and after failed compilations.
|
76 | * * `"always"` - Never show the success notifications.
|
77 | * * `"initial"` - Same as true, but suppresses the initial success notification.
|
78 | */
|
79 | suppressSuccess?: boolean | 'always' | 'initial';
|
80 | /**
|
81 | * True to suppress the warning notifications, otherwise false (default).
|
82 | */
|
83 | suppressWarning?: boolean;
|
84 | /**
|
85 | * True to suppress the compilation started notifications (default), otherwise false.
|
86 | */
|
87 | suppressCompileStart?: boolean;
|
88 | /**
|
89 | * True to activate (focus) the terminal window when a compilation error occurs.
|
90 | * Note that this only works on Mac OSX. Defaults to `false`.
|
91 | */
|
92 | activateTerminalOnError?: boolean;
|
93 | /**
|
94 | * The absolute path to the icon to be displayed for success notifications.
|
95 | * Defaults to `./icons/success.png`.
|
96 | */
|
97 | successIcon?: string;
|
98 | /**
|
99 | * The absolute path to the icon to be displayed for warning notifications.
|
100 | * Defaults to `./icons/warning.png`.
|
101 | */
|
102 | warningIcon?: string;
|
103 | /**
|
104 | * The absolute path to the icon to be displayed for failure notifications.
|
105 | * Defaults to `./icons/failure.png`.
|
106 | */
|
107 | failureIcon?: string;
|
108 | /**
|
109 | * The absolute path to the icon to be displayed for compilation started notifications.
|
110 | * Defaults to `./icons/compile.png`.
|
111 | */
|
112 | compileIcon?: string;
|
113 | /**
|
114 | * A function called when clicking on a warning or error notification. By default, it activates the Terminal application.
|
115 | * The function is passed two parameters:
|
116 | *
|
117 | * 1. {NotificationCenter} notifierObject - The notifier object instance.
|
118 | * 2. {NotificationCenter.Notification} options - The notifier object options.
|
119 | */
|
120 | onClick?: (notifier: NodeNotifier, options: NotificationCenter.Notification) => void;
|
121 | /**
|
122 | * A function called when the notification times out (closes). Undefined by default. The function is passed
|
123 | * two parameters:
|
124 | *
|
125 | * 1. {NotificationCenter} notifierObject - The notifier object instance.
|
126 | * 2. {NotificationCenter.Notification} options - The notifier object options.
|
127 | */
|
128 | onTimeout?: (notifier: NotificationCenter, options: NotificationCenter.Notification) => void;
|
129 | /**
|
130 | * A function which returns a formatted notification message on successful compilation.
|
131 | *
|
132 | * This function must return a String.
|
133 | *
|
134 | * The default formatter will display "Build successful!".
|
135 | *
|
136 | * Note that the message will always be limited to 256 characters.
|
137 | */
|
138 | formatSuccess?: () => string | undefined;
|
139 | /**
|
140 | * A function which returns a formatted notification message on error or warning.
|
141 | * The function is passed 4 parameters:
|
142 | *
|
143 | * 1. {CompilationResult} error/warning - The raw error or warning object.
|
144 | * 2. {string} filepath - The path to the file containing the error/warning (if available).
|
145 | * 3. {CompilationStatus} status - Error or warning
|
146 | * 4. {number} count - How many errors or warnings were raised
|
147 | *
|
148 | * This function must return a String.
|
149 | *
|
150 | * The default messageFormatter will display the filename which contains the error/warning followed by the
|
151 | * error/warning message.
|
152 | *
|
153 | * Note that the message will always be limited to 256 characters.
|
154 | */
|
155 | messageFormatter?: (error: CompilationResult, filepath: string, status: CompilationStatus, count: number) => string;
|
156 | /**
|
157 | * Any additional node-notifier options as documented in the node-notifier documentation:
|
158 | * https://github.com/mikaelbr/node-notifier
|
159 | *
|
160 | * This config option can either be provided as a node-notifier `Notification` object, _OR_ a
|
161 | * function which accepts the `CompilationStatus` and returns a `Notification` object.
|
162 | *
|
163 | * Note that options provided here will only be applied to the success/warning/error notifications
|
164 | * (not the "compilation started" notification). The `title`, `message`, `sound`, `contentImage` (logo), and `icon`
|
165 | * options will be ignored, as they will be set via the corresponding {WebpackBuildNotifierConfig} options
|
166 | * (either user-specified or default).
|
167 | */
|
168 | notifyOptions?: NotificationCenter.Notification | ((status: CompilationStatus) => NotificationCenter.Notification | undefined);
|
169 | };
|
170 |
|
171 | declare class WebpackBuildNotifierPlugin {
|
172 | private appName;
|
173 | private buildSuccessful;
|
174 | private hasRun;
|
175 | private title;
|
176 | private logo?;
|
177 | private sound;
|
178 | private successSound;
|
179 | private warningSound;
|
180 | private failureSound;
|
181 | private compilationSound;
|
182 | private suppressSuccess;
|
183 | private suppressWarning;
|
184 | private suppressCompileStart;
|
185 | private activateTerminalOnError;
|
186 | private showDuration;
|
187 | private successIcon;
|
188 | private warningIcon;
|
189 | private failureIcon;
|
190 | private compileIcon;
|
191 | private onCompileStart?;
|
192 | private onComplete?;
|
193 | private onClick;
|
194 | private onTimeout?;
|
195 | private formatSuccess?;
|
196 | private messageFormatter?;
|
197 | private notifyOptions?;
|
198 | constructor(cfg?: Config);
|
199 | apply(compiler: webpack.Compiler): void;
|
200 | private readonly activateTerminalWindow;
|
201 | private readonly formatMessage;
|
202 | private readonly onCompilationDone;
|
203 | private readonly onCompilationWatchRun;
|
204 | private readonly registerSnoreToast;
|
205 | private readonly getFirstWarningOrError;
|
206 | private readonly getWarningOrErrorCount;
|
207 | }
|
208 |
|
209 | export { WebpackBuildNotifierPlugin as default };
|
210 |
|
\ | No newline at end of file |