@sdeverywhere/build 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/dist/index.cjs +142 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +440 -0
- package/dist/index.d.ts +17 -8
- package/dist/index.js +133 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { Result } from 'neverthrow';
|
|
2
|
+
|
|
3
|
+
type LogLevel = 'error' | 'info' | 'verbose';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The mode used for the build process, either 'development' for local "dev mode"
|
|
7
|
+
* (with live reload, etc) or 'production' for generating a production-ready build.
|
|
8
|
+
*/
|
|
9
|
+
type BuildMode = 'development' | 'production';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Describes a model input variable.
|
|
13
|
+
*/
|
|
14
|
+
interface InputSpec {
|
|
15
|
+
/**
|
|
16
|
+
* The stable input identifier. It is recommended to set this to a value (for example, a
|
|
17
|
+
* numeric string like what `plugin-config` uses) that is separate from `varName` and is
|
|
18
|
+
* stable between two versions of the model. This way, if an input variable is renamed
|
|
19
|
+
* between two versions of the model, comparisons can still be performed between the two.
|
|
20
|
+
* If a distinct `inputId` is not available, plugins can infer one from `varName`, but
|
|
21
|
+
* note that this approach will be less resilient to renames.
|
|
22
|
+
*/
|
|
23
|
+
inputId?: string;
|
|
24
|
+
/** The variable name (as used in the modeling tool). */
|
|
25
|
+
varName: string;
|
|
26
|
+
/** The default value for the input. */
|
|
27
|
+
defaultValue: number;
|
|
28
|
+
/** The minimum value for the input. */
|
|
29
|
+
minValue: number;
|
|
30
|
+
/** The maximum value for the input. */
|
|
31
|
+
maxValue: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Describes a model output variable.
|
|
35
|
+
*/
|
|
36
|
+
interface OutputSpec {
|
|
37
|
+
/** The variable name (as used in the modeling tool). */
|
|
38
|
+
varName: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Describes a model (e.g., a Vensim mdl file) and the input/output variables
|
|
42
|
+
* that should be included in the model generated by SDE.
|
|
43
|
+
*/
|
|
44
|
+
interface ModelSpec {
|
|
45
|
+
/** The input variable specs. */
|
|
46
|
+
inputs: InputSpec[];
|
|
47
|
+
/** The output variable specs. */
|
|
48
|
+
outputs: OutputSpec[];
|
|
49
|
+
/** The dat files to be included with the SDE `spec.json` file. */
|
|
50
|
+
datFiles: string[];
|
|
51
|
+
/** Additional options included with the SDE `spec.json` file. */
|
|
52
|
+
options?: {
|
|
53
|
+
[key: string]: any;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The sde configuration derived from a `UserConfig` that has been resolved (i.e.,
|
|
59
|
+
* paths have been checked). This is the config object that will be passed to
|
|
60
|
+
* plugin functions. It contains a subset of the original `UserConfig` (to disallow
|
|
61
|
+
* access to the `plugins` field of the original config).
|
|
62
|
+
*/
|
|
63
|
+
interface ResolvedConfig {
|
|
64
|
+
/**
|
|
65
|
+
* The mode used for the build process, either 'development' or 'production'.
|
|
66
|
+
*/
|
|
67
|
+
mode: BuildMode;
|
|
68
|
+
/**
|
|
69
|
+
* The absolute path to the project root directory, which has been confirmed to exist.
|
|
70
|
+
*/
|
|
71
|
+
rootDir: string;
|
|
72
|
+
/**
|
|
73
|
+
* The absolute path to the directory used to prepare the model. This directory has
|
|
74
|
+
* been created if it did not previously exist.
|
|
75
|
+
*/
|
|
76
|
+
prepDir: string;
|
|
77
|
+
/**
|
|
78
|
+
* The mdl files to be built.
|
|
79
|
+
*/
|
|
80
|
+
modelFiles: string[];
|
|
81
|
+
/**
|
|
82
|
+
* Paths to files that are considered to be inputs to the model build process.
|
|
83
|
+
* These can be paths to files or glob patterns (relative to the project directory).
|
|
84
|
+
*/
|
|
85
|
+
modelInputPaths: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Paths to files that when changed will trigger a rebuild in watch mode. These
|
|
88
|
+
* can be paths to files or glob patterns (relative to the project directory).
|
|
89
|
+
*/
|
|
90
|
+
watchPaths: string[];
|
|
91
|
+
/**
|
|
92
|
+
* The path to the `@sdeverywhere/cli` package. This is currently only used to get
|
|
93
|
+
* access to the files in the `src/c` directory.
|
|
94
|
+
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
95
|
+
*/
|
|
96
|
+
sdeDir: string;
|
|
97
|
+
/**
|
|
98
|
+
* The path to the `sde` command.
|
|
99
|
+
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
100
|
+
*/
|
|
101
|
+
sdeCmdPath: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @hidden This isn't ready to be included in the public API just yet.
|
|
106
|
+
*/
|
|
107
|
+
interface ProcessOptions {
|
|
108
|
+
logOutput?: boolean;
|
|
109
|
+
ignoredMessageFilter?: string;
|
|
110
|
+
captureOutput?: boolean;
|
|
111
|
+
ignoreError?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @hidden This isn't ready to be included in the public API just yet.
|
|
115
|
+
*/
|
|
116
|
+
interface ProcessOutput {
|
|
117
|
+
exitCode: number;
|
|
118
|
+
stdoutMessages: string[];
|
|
119
|
+
stderrMessages: string[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
declare class StagedFiles {
|
|
123
|
+
private readonly baseStagedDir;
|
|
124
|
+
private readonly stagedFiles;
|
|
125
|
+
constructor(prepDir: string);
|
|
126
|
+
/**
|
|
127
|
+
* Prepare for writing a file to the staged directory.
|
|
128
|
+
*
|
|
129
|
+
* This will add the path to the array of tracked files and will create the
|
|
130
|
+
* staged directory if needed.
|
|
131
|
+
*
|
|
132
|
+
* @param srcDir The directory underneath the configured `staged` directory where
|
|
133
|
+
* the file will be written (this must be a relative path).
|
|
134
|
+
* @param srcFile The name of the file as written to the `staged` directory.
|
|
135
|
+
* @param dstDir The absolute path to the destination directory where the staged
|
|
136
|
+
* file will be copied when the build has completed.
|
|
137
|
+
* @param dstFile The name of the file as written to the destination directory.
|
|
138
|
+
* @return The absolute path to the staged file.
|
|
139
|
+
*/
|
|
140
|
+
prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
|
|
141
|
+
/**
|
|
142
|
+
* Write a file to the staged directory.
|
|
143
|
+
*
|
|
144
|
+
* This file will be copied (along with other staged files) into the destination
|
|
145
|
+
* directory only after the build process has completed. Copying all staged files
|
|
146
|
+
* at once helps improve the local development experience by making it so that
|
|
147
|
+
* live reloading tools only need to refresh once instead of every time a build
|
|
148
|
+
* file is written.
|
|
149
|
+
*
|
|
150
|
+
* @param srcDir The directory underneath the configured `staged` directory where
|
|
151
|
+
* the file will be written (this must be a relative path).
|
|
152
|
+
* @param dstDir The absolute path to the destination directory where the staged
|
|
153
|
+
* file will be copied when the build has completed.
|
|
154
|
+
* @param filename The name of the file.
|
|
155
|
+
* @param content The file content.
|
|
156
|
+
*/
|
|
157
|
+
writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
|
|
158
|
+
/**
|
|
159
|
+
* Return the absolute path to the staged file for the given source directory and file name.
|
|
160
|
+
*
|
|
161
|
+
* @param srcDir The directory underneath the configured `staged` directory where
|
|
162
|
+
* the file would be written initially (this must be a relative path).
|
|
163
|
+
* @param srcFile The name of the file.
|
|
164
|
+
*/
|
|
165
|
+
getStagedFilePath(srcDir: string, srcFile: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* Return true if the staged file exists for the given source directory and file name.
|
|
168
|
+
*
|
|
169
|
+
* @param srcDir The directory underneath the configured `staged` directory where
|
|
170
|
+
* the file would be written initially (this must be a relative path).
|
|
171
|
+
* @param srcFile The name of the file.
|
|
172
|
+
*/
|
|
173
|
+
stagedFileExists(srcDir: string, srcFile: string): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Return true if the destination file exists for the given source directory and file name.
|
|
176
|
+
*
|
|
177
|
+
* @param srcDir The directory underneath the configured `staged` directory where
|
|
178
|
+
* the file would be written initially (this must be a relative path).
|
|
179
|
+
* @param srcFile The name of the file.
|
|
180
|
+
*/
|
|
181
|
+
destinationFileExists(srcDir: string, srcFile: string): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Copy staged files to their destination; this will only copy the staged
|
|
184
|
+
* files if they are different than the existing destination files. We
|
|
185
|
+
* copy the files in a batch like this so that hot module reload is only
|
|
186
|
+
* triggered once at the end of the whole build process.
|
|
187
|
+
*/
|
|
188
|
+
copyChangedFiles(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Copy a file from the `staged` directory to its destination. If the file already
|
|
191
|
+
* exists in the destination directory and has the same contents as the source file,
|
|
192
|
+
* the file will not be copied and this function will return false.
|
|
193
|
+
*
|
|
194
|
+
* @param f The staged file entry.
|
|
195
|
+
*/
|
|
196
|
+
private copyStagedFile;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Provides access to common functionality that is needed during the build process.
|
|
201
|
+
* This is passed to most plugin functions.
|
|
202
|
+
*/
|
|
203
|
+
declare class BuildContext {
|
|
204
|
+
readonly config: ResolvedConfig;
|
|
205
|
+
private readonly stagedFiles;
|
|
206
|
+
private readonly abortSignal;
|
|
207
|
+
/**
|
|
208
|
+
* @param config The resolved configuration.
|
|
209
|
+
* @hidden
|
|
210
|
+
*/
|
|
211
|
+
constructor(config: ResolvedConfig, stagedFiles: StagedFiles, abortSignal: AbortSignal | undefined);
|
|
212
|
+
/**
|
|
213
|
+
* Log a message to the console and/or the in-browser overlay panel.
|
|
214
|
+
*
|
|
215
|
+
* @param level The log level (verbose, info, error).
|
|
216
|
+
* @param msg The message.
|
|
217
|
+
*/
|
|
218
|
+
log(level: LogLevel, msg: string): void;
|
|
219
|
+
/**
|
|
220
|
+
* Prepare for writing a file to the staged directory.
|
|
221
|
+
*
|
|
222
|
+
* This will add the path to the array of tracked files and will create the
|
|
223
|
+
* staged directory if needed.
|
|
224
|
+
*
|
|
225
|
+
* @param srcDir The directory underneath the configured `staged` directory where
|
|
226
|
+
* the file will be written (this must be a relative path).
|
|
227
|
+
* @param srcFile The name of the file as written to the `staged` directory.
|
|
228
|
+
* @param dstDir The absolute path to the destination directory where the staged
|
|
229
|
+
* file will be copied when the build has completed.
|
|
230
|
+
* @param dstFile The name of the file as written to the destination directory.
|
|
231
|
+
* @return The absolute path to the staged file.
|
|
232
|
+
*/
|
|
233
|
+
prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
|
|
234
|
+
/**
|
|
235
|
+
* Write a file to the staged directory.
|
|
236
|
+
*
|
|
237
|
+
* This file will be copied (along with other staged files) into the destination
|
|
238
|
+
* directory only after the build process has completed. Copying all staged files
|
|
239
|
+
* at once helps improve the local development experience by making it so that
|
|
240
|
+
* live reloading tools only need to refresh once instead of every time a build
|
|
241
|
+
* file is written.
|
|
242
|
+
*
|
|
243
|
+
* @param srcDir The directory underneath the configured `staged` directory where
|
|
244
|
+
* the file will be written (this must be a relative path).
|
|
245
|
+
* @param dstDir The absolute path to the destination directory where the staged
|
|
246
|
+
* file will be copied when the build has completed.
|
|
247
|
+
* @param filename The name of the file.
|
|
248
|
+
* @param content The file content.
|
|
249
|
+
*/
|
|
250
|
+
writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
|
|
251
|
+
/**
|
|
252
|
+
* Spawn a child process that runs the given command.
|
|
253
|
+
*
|
|
254
|
+
* @param cwd The directory in which the command will be executed.
|
|
255
|
+
* @param command The command to execute.
|
|
256
|
+
* @param args The arguments to pass to the command.
|
|
257
|
+
* @param opts Additional options to configure the process.
|
|
258
|
+
* @returns The output of the process.
|
|
259
|
+
*/
|
|
260
|
+
spawnChild(cwd: string, command: string, args: string[], opts?: ProcessOptions): Promise<ProcessOutput>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* The plugin interface that can be implemented to customize the model
|
|
265
|
+
* generation and build process.
|
|
266
|
+
*
|
|
267
|
+
* These functions are all optional.
|
|
268
|
+
*
|
|
269
|
+
* These functions will be called during the build process in the order
|
|
270
|
+
* listed below:
|
|
271
|
+
* - init (only called once before initial build steps)
|
|
272
|
+
* - preGenerate
|
|
273
|
+
* - preProcessMdl
|
|
274
|
+
* - postProcessMdl
|
|
275
|
+
* - preGenerateC
|
|
276
|
+
* - postGenerateC
|
|
277
|
+
* - postGenerate
|
|
278
|
+
* - postBuild
|
|
279
|
+
* - watch (only called once after initial build steps when mode==development)
|
|
280
|
+
*/
|
|
281
|
+
interface Plugin {
|
|
282
|
+
/**
|
|
283
|
+
* Called after the user configuration has been resolved, but before the
|
|
284
|
+
* model is generated and other build steps.
|
|
285
|
+
*
|
|
286
|
+
* @param config The build configuration.
|
|
287
|
+
*/
|
|
288
|
+
init?(config: ResolvedConfig): Promise<void>;
|
|
289
|
+
/**
|
|
290
|
+
* Called before the "generate model" steps are performed.
|
|
291
|
+
*
|
|
292
|
+
* @param context The build context (for logging, etc).
|
|
293
|
+
* @param modelSpec The spec that controls how the model is generated.
|
|
294
|
+
*/
|
|
295
|
+
preGenerate?(context: BuildContext, modelSpec: ModelSpec): Promise<void>;
|
|
296
|
+
/**
|
|
297
|
+
* Called before SDE preprocesses the mdl file (in the case of one mdl file),
|
|
298
|
+
* or before SDE flattens the mdl files (in the case of multiple mdl files).
|
|
299
|
+
*
|
|
300
|
+
* @param context The build context (for logging, etc).
|
|
301
|
+
*/
|
|
302
|
+
preProcessMdl?(context: BuildContext): Promise<void>;
|
|
303
|
+
/**
|
|
304
|
+
* Called after SDE preprocesses the mdl file (in the case of one mdl file),
|
|
305
|
+
* or after SDE flattens the mdl files (in the case of multiple mdl files).
|
|
306
|
+
*
|
|
307
|
+
* @param context The build context (for logging, etc).
|
|
308
|
+
* @param mdlContent The resulting mdl file content.
|
|
309
|
+
* @return The modified mdl file content (if postprocessing was needed).
|
|
310
|
+
*/
|
|
311
|
+
postProcessMdl?(context: BuildContext, mdlContent: string): Promise<string>;
|
|
312
|
+
/**
|
|
313
|
+
* Called before SDE generates a C file from the mdl file.
|
|
314
|
+
*
|
|
315
|
+
* @param context The build context (for logging, etc).
|
|
316
|
+
*/
|
|
317
|
+
preGenerateC?(context: BuildContext): Promise<void>;
|
|
318
|
+
/**
|
|
319
|
+
* Called after SDE generates a C file from the mdl file.
|
|
320
|
+
*
|
|
321
|
+
* @param context The build context (for logging, etc).
|
|
322
|
+
* @param cContent The resulting C file content.
|
|
323
|
+
* @return The modified C file content (if postprocessing was needed).
|
|
324
|
+
*/
|
|
325
|
+
postGenerateC?(context: BuildContext, cContent: string): Promise<string>;
|
|
326
|
+
/**
|
|
327
|
+
* Called after the "generate model" process has completed (but before the staged
|
|
328
|
+
* files are copied to their destination).
|
|
329
|
+
*
|
|
330
|
+
* @param context The build context (for logging, etc).
|
|
331
|
+
* @param modelSpec The spec that controls how the model is generated.
|
|
332
|
+
* @return Whether the plugin succeeded (for example, a plugin that runs tests can
|
|
333
|
+
* return false to indicate that one or more tests failed).
|
|
334
|
+
*/
|
|
335
|
+
postGenerate?(context: BuildContext, modelSpec: ModelSpec): Promise<boolean>;
|
|
336
|
+
/**
|
|
337
|
+
* Called after the model has been generated and after the staged files
|
|
338
|
+
* have been copied to their destination.
|
|
339
|
+
*
|
|
340
|
+
* @param context The build context (for logging, etc).
|
|
341
|
+
* @param modelSpec The spec that controls how the model is generated.
|
|
342
|
+
* @return Whether the plugin succeeded (for example, a plugin that runs tests can
|
|
343
|
+
* return false to indicate that one or more tests failed).
|
|
344
|
+
*/
|
|
345
|
+
postBuild?(context: BuildContext, modelSpec: ModelSpec): Promise<boolean>;
|
|
346
|
+
/**
|
|
347
|
+
* Called in development/watch mode after the initial build has completed
|
|
348
|
+
* (i.e., after the model has been generated and after the staged files
|
|
349
|
+
* have been copied to their destination).
|
|
350
|
+
*
|
|
351
|
+
* @param config The build configuration.
|
|
352
|
+
*/
|
|
353
|
+
watch?(config: ResolvedConfig): Promise<void>;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* The sde configuration as defined by the user, either inline or in a `sde.config.js` file.
|
|
358
|
+
*/
|
|
359
|
+
interface UserConfig {
|
|
360
|
+
/**
|
|
361
|
+
* The project root directory. If undefined, the current directory is
|
|
362
|
+
* assumed to be the project root. This directory should contain all the
|
|
363
|
+
* model and config files referenced during the build process.
|
|
364
|
+
*/
|
|
365
|
+
rootDir?: string;
|
|
366
|
+
/**
|
|
367
|
+
* The directory used to prepare the model. If undefined, an 'sde-prep'
|
|
368
|
+
* directory will be created under the resolved `rootDir`.
|
|
369
|
+
*/
|
|
370
|
+
prepDir?: string;
|
|
371
|
+
/**
|
|
372
|
+
* The mdl files to be built (must provide one or more).
|
|
373
|
+
*/
|
|
374
|
+
modelFiles: string[];
|
|
375
|
+
/**
|
|
376
|
+
* Paths to files that are considered to be inputs to the model build process.
|
|
377
|
+
* These can be paths to files or glob patterns (relative to the project directory).
|
|
378
|
+
* If left undefined, this will resolve to the `modelFiles` array.
|
|
379
|
+
*/
|
|
380
|
+
modelInputPaths?: string[];
|
|
381
|
+
/**
|
|
382
|
+
* Paths to files that when changed will trigger a rebuild in watch mode. These
|
|
383
|
+
* can be paths to files or glob patterns (relative to the project directory).
|
|
384
|
+
* If left undefined, this will resolve to the `modelFiles` array.
|
|
385
|
+
*/
|
|
386
|
+
watchPaths?: string[];
|
|
387
|
+
/**
|
|
388
|
+
* The array of plugins that are used to customize the build process. These will be
|
|
389
|
+
* executed in the order defined here.
|
|
390
|
+
*/
|
|
391
|
+
plugins?: Plugin[];
|
|
392
|
+
/**
|
|
393
|
+
* Called before the "generate model" steps are performed.
|
|
394
|
+
*
|
|
395
|
+
* You must implement this function so that the generated model is
|
|
396
|
+
* configured with the desired inputs and outputs.
|
|
397
|
+
*
|
|
398
|
+
* @return A `ModelSpec` that defines the model inputs and outputs.
|
|
399
|
+
*/
|
|
400
|
+
modelSpec: (context: BuildContext) => Promise<ModelSpec>;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
interface BuildOptions {
|
|
404
|
+
/** The path to an `sde.config.js` file, or a `UserConfig` object. */
|
|
405
|
+
config?: string | UserConfig;
|
|
406
|
+
/**
|
|
407
|
+
* The log levels to include. If undefined, the default 'info' and 'error' levels
|
|
408
|
+
* will be active.
|
|
409
|
+
*/
|
|
410
|
+
logLevels?: LogLevel[];
|
|
411
|
+
/**
|
|
412
|
+
* The path to the `@sdeverywhere/cli` package. This is currently only used to get
|
|
413
|
+
* access to the files in the `src/c` directory.
|
|
414
|
+
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
415
|
+
*/
|
|
416
|
+
sdeDir: string;
|
|
417
|
+
/**
|
|
418
|
+
* The path to the `sde` command.
|
|
419
|
+
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
420
|
+
*/
|
|
421
|
+
sdeCmdPath: string;
|
|
422
|
+
}
|
|
423
|
+
interface BuildResult {
|
|
424
|
+
/**
|
|
425
|
+
* The exit code that should be set by the process. This will be undefined
|
|
426
|
+
* if `mode` is 'development', indicating that the process should be kept alive.
|
|
427
|
+
*/
|
|
428
|
+
exitCode?: number;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Initiate the build process, which can either be a single build if `mode` is
|
|
432
|
+
* 'production', or a live development environment if `mode` is 'development'.
|
|
433
|
+
*
|
|
434
|
+
* @param mode The build mode.
|
|
435
|
+
* @param options The build options.
|
|
436
|
+
* @return An `ok` result if the build completed, otherwise an `err` result.
|
|
437
|
+
*/
|
|
438
|
+
declare function build(mode: BuildMode, options: BuildOptions): Promise<Result<BuildResult, Error>>;
|
|
439
|
+
|
|
440
|
+
export { BuildContext, BuildMode, BuildOptions, BuildResult, InputSpec, LogLevel, ModelSpec, OutputSpec, Plugin, ResolvedConfig, UserConfig, build };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import { Result } from 'neverthrow';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type LogLevel = 'error' | 'info' | 'verbose';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The mode used for the build process, either 'development' for local "dev mode"
|
|
7
7
|
* (with live reload, etc) or 'production' for generating a production-ready build.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
type BuildMode = 'development' | 'production';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Describes a model input variable.
|
|
13
13
|
*/
|
|
14
14
|
interface InputSpec {
|
|
15
|
+
/**
|
|
16
|
+
* The stable input identifier. It is recommended to set this to a value (for example, a
|
|
17
|
+
* numeric string like what `plugin-config` uses) that is separate from `varName` and is
|
|
18
|
+
* stable between two versions of the model. This way, if an input variable is renamed
|
|
19
|
+
* between two versions of the model, comparisons can still be performed between the two.
|
|
20
|
+
* If a distinct `inputId` is not available, plugins can infer one from `varName`, but
|
|
21
|
+
* note that this approach will be less resilient to renames.
|
|
22
|
+
*/
|
|
23
|
+
inputId?: string;
|
|
15
24
|
/** The variable name (as used in the modeling tool). */
|
|
16
25
|
varName: string;
|
|
17
26
|
/** The default value for the input. */
|
|
@@ -283,14 +292,14 @@ interface Plugin {
|
|
|
283
292
|
* @param context The build context (for logging, etc).
|
|
284
293
|
* @param modelSpec The spec that controls how the model is generated.
|
|
285
294
|
*/
|
|
286
|
-
preGenerate
|
|
295
|
+
preGenerate?(context: BuildContext, modelSpec: ModelSpec): Promise<void>;
|
|
287
296
|
/**
|
|
288
297
|
* Called before SDE preprocesses the mdl file (in the case of one mdl file),
|
|
289
298
|
* or before SDE flattens the mdl files (in the case of multiple mdl files).
|
|
290
299
|
*
|
|
291
300
|
* @param context The build context (for logging, etc).
|
|
292
301
|
*/
|
|
293
|
-
preProcessMdl
|
|
302
|
+
preProcessMdl?(context: BuildContext): Promise<void>;
|
|
294
303
|
/**
|
|
295
304
|
* Called after SDE preprocesses the mdl file (in the case of one mdl file),
|
|
296
305
|
* or after SDE flattens the mdl files (in the case of multiple mdl files).
|
|
@@ -299,13 +308,13 @@ interface Plugin {
|
|
|
299
308
|
* @param mdlContent The resulting mdl file content.
|
|
300
309
|
* @return The modified mdl file content (if postprocessing was needed).
|
|
301
310
|
*/
|
|
302
|
-
postProcessMdl
|
|
311
|
+
postProcessMdl?(context: BuildContext, mdlContent: string): Promise<string>;
|
|
303
312
|
/**
|
|
304
313
|
* Called before SDE generates a C file from the mdl file.
|
|
305
314
|
*
|
|
306
315
|
* @param context The build context (for logging, etc).
|
|
307
316
|
*/
|
|
308
|
-
preGenerateC
|
|
317
|
+
preGenerateC?(context: BuildContext): Promise<void>;
|
|
309
318
|
/**
|
|
310
319
|
* Called after SDE generates a C file from the mdl file.
|
|
311
320
|
*
|
|
@@ -313,7 +322,7 @@ interface Plugin {
|
|
|
313
322
|
* @param cContent The resulting C file content.
|
|
314
323
|
* @return The modified C file content (if postprocessing was needed).
|
|
315
324
|
*/
|
|
316
|
-
postGenerateC
|
|
325
|
+
postGenerateC?(context: BuildContext, cContent: string): Promise<string>;
|
|
317
326
|
/**
|
|
318
327
|
* Called after the "generate model" process has completed (but before the staged
|
|
319
328
|
* files are copied to their destination).
|
|
@@ -323,7 +332,7 @@ interface Plugin {
|
|
|
323
332
|
* @return Whether the plugin succeeded (for example, a plugin that runs tests can
|
|
324
333
|
* return false to indicate that one or more tests failed).
|
|
325
334
|
*/
|
|
326
|
-
postGenerate
|
|
335
|
+
postGenerate?(context: BuildContext, modelSpec: ModelSpec): Promise<boolean>;
|
|
327
336
|
/**
|
|
328
337
|
* Called after the model has been generated and after the staged files
|
|
329
338
|
* have been copied to their destination.
|