@sdeverywhere/build 0.3.17 → 0.3.18
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/dist/index.d.ts +493 -483
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +884 -959
- package/dist/index.js.map +1 -1
- package/package.json +5 -7
- package/dist/index.cjs +0 -1055
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -603
package/dist/index.d.cts
DELETED
|
@@ -1,603 +0,0 @@
|
|
|
1
|
-
import { ModelSpec as ModelSpec$1 } from '@sdeverywhere/compile';
|
|
2
|
-
import { Result } from 'neverthrow';
|
|
3
|
-
|
|
4
|
-
type LogLevel = 'error' | 'info' | 'verbose';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The mode used for the build process, either 'development' for local "dev mode"
|
|
8
|
-
* (with live reload, etc) or 'production' for generating a production-ready build.
|
|
9
|
-
*/
|
|
10
|
-
type BuildMode = 'development' | 'production';
|
|
11
|
-
|
|
12
|
-
/** A variable name as used in the modeling tool. */
|
|
13
|
-
type VarName = string;
|
|
14
|
-
/**
|
|
15
|
-
* Describes a model input variable.
|
|
16
|
-
*/
|
|
17
|
-
interface InputSpec {
|
|
18
|
-
/** The variable name (as used in the modeling tool). */
|
|
19
|
-
varName: VarName;
|
|
20
|
-
/**
|
|
21
|
-
* The stable input identifier. It is recommended to set this to a value (for example, a
|
|
22
|
-
* numeric string like what `plugin-config` uses) that is separate from `varName` and is
|
|
23
|
-
* stable between two versions of the model. This way, if an input variable is renamed
|
|
24
|
-
* between two versions of the model, comparisons can still be performed between the two.
|
|
25
|
-
* If a distinct `inputId` is not available, plugins can infer one from `varName`, but
|
|
26
|
-
* note that this approach will be less resilient to renames.
|
|
27
|
-
*/
|
|
28
|
-
inputId?: string;
|
|
29
|
-
/** The default value for the input. */
|
|
30
|
-
defaultValue?: number;
|
|
31
|
-
/** The minimum value for the input. */
|
|
32
|
-
minValue?: number;
|
|
33
|
-
/** The maximum value for the input. */
|
|
34
|
-
maxValue?: number;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Describes a model output variable.
|
|
38
|
-
*/
|
|
39
|
-
interface OutputSpec {
|
|
40
|
-
/** The variable name (as used in the modeling tool). */
|
|
41
|
-
varName: VarName;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* The model spec properties that are shared with (and passed through unchanged to) the
|
|
45
|
-
* `ModelSpec` type from the compile package.
|
|
46
|
-
*
|
|
47
|
-
* The `inputVarNames` and `outputVarNames` properties are excluded because this package
|
|
48
|
-
* declares higher-level `inputs` and `outputs` properties in their place, which accept
|
|
49
|
-
* richer `InputSpec` and `OutputSpec` forms in addition to plain variable names. The
|
|
50
|
-
* deprecated and derived properties from the compile package are excluded because a
|
|
51
|
-
* `sde.config.js` file should only use the preferred names.
|
|
52
|
-
*/
|
|
53
|
-
type CommonModelSpecProps = Omit<ModelSpec$1, 'inputVarNames' | 'outputVarNames' | 'externalDatfiles' | 'inputVars' | 'outputVars' | 'name'>;
|
|
54
|
-
/**
|
|
55
|
-
* The `CommonModelSpecProps` properties that are filled in with a default value when a
|
|
56
|
-
* `ModelSpec` is resolved, and are therefore always defined in a `ResolvedModelSpec`.
|
|
57
|
-
* These are redeclared in `ResolvedModelSpec` so that they can be documented in terms of
|
|
58
|
-
* the resolved (non-optional) values.
|
|
59
|
-
*/
|
|
60
|
-
type ResolvedModelSpecProps = Omit<CommonModelSpecProps, 'datFiles' | 'bundleListing' | 'customConstants' | 'customLookups' | 'customOutputs'>;
|
|
61
|
-
/**
|
|
62
|
-
* Describes a model (e.g., a Vensim `mdl` or Stella `stmx` file) and the input/output variables
|
|
63
|
-
* that should be included in the model generated by SDEverywhere.
|
|
64
|
-
*
|
|
65
|
-
* Aside from the `inputs` and `outputs` properties (which allow for richer `InputSpec`
|
|
66
|
-
* and `OutputSpec` forms here), the properties of this interface are shared with the
|
|
67
|
-
* `ModelSpec` type from the compile package, which describes the `spec.json` file format
|
|
68
|
-
* used by the lower-level `sde` commands.
|
|
69
|
-
*/
|
|
70
|
-
interface ModelSpec extends CommonModelSpecProps {
|
|
71
|
-
/**
|
|
72
|
-
* The input variables for the model. This can either be a simple array of
|
|
73
|
-
* input variable names, or an array of `InputSpec` instances.
|
|
74
|
-
*
|
|
75
|
-
* The builder requires only variable names for the purposes of generating
|
|
76
|
-
* a model, but some plugins may require full `InputSpec` instances.
|
|
77
|
-
*/
|
|
78
|
-
inputs: VarName[] | InputSpec[];
|
|
79
|
-
/**
|
|
80
|
-
* The output variables for the model. This can either be a simple array of
|
|
81
|
-
* output variable names, or an array of `OutputSpec` instances.
|
|
82
|
-
*/
|
|
83
|
-
outputs: VarName[] | OutputSpec[];
|
|
84
|
-
/**
|
|
85
|
-
* Additional properties to include in the generated `spec.json` file.
|
|
86
|
-
*
|
|
87
|
-
* @deprecated All properties that are supported in a `spec.json` file are now declared
|
|
88
|
-
* directly on this interface, so it is no longer necessary to use this escape hatch.
|
|
89
|
-
* Any properties provided here will be merged into the resolved model spec (a property
|
|
90
|
-
* that is configured directly on this interface takes precedence over the same property
|
|
91
|
-
* provided here), but this property will be removed in a future release.
|
|
92
|
-
*/
|
|
93
|
-
options?: ModelSpec$1;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Describes a model (e.g., a Vensim `mdl` or Stella `stmx` file) and the input/output variables
|
|
97
|
-
* that should be included in the model generated by SDEverywhere. This is
|
|
98
|
-
* largely the same as the `ModelSpec` interface, except this one has been
|
|
99
|
-
* fully resolved (paths have been validated, input and output variables have
|
|
100
|
-
* been checked, etc). This is the spec object that will be passed to plugin
|
|
101
|
-
* functions.
|
|
102
|
-
*/
|
|
103
|
-
interface ResolvedModelSpec extends ResolvedModelSpecProps {
|
|
104
|
-
/**
|
|
105
|
-
* The input variable names for the model. This will be defined regardless
|
|
106
|
-
* of whether `ModelSpec.inputs` was defined as an array of variable names
|
|
107
|
-
* or an array of `InputSpec` instances. (The input variable names are
|
|
108
|
-
* derived from the `InputSpec` instances as needed.)
|
|
109
|
-
*/
|
|
110
|
-
inputVarNames: VarName[];
|
|
111
|
-
/**
|
|
112
|
-
* The input variable specs for the model.
|
|
113
|
-
*/
|
|
114
|
-
inputs: InputSpec[];
|
|
115
|
-
/**
|
|
116
|
-
* The output variable names for the model. This will be defined regardless
|
|
117
|
-
* of whether `ModelSpec.outputs` was defined as an array of variable names
|
|
118
|
-
* or an array of `OutputSpec` instances. (The output variable names are
|
|
119
|
-
* derived from the `OutputSpec` instances as needed.)
|
|
120
|
-
*/
|
|
121
|
-
outputVarNames: VarName[];
|
|
122
|
-
/**
|
|
123
|
-
* The output variable specs for the model.
|
|
124
|
-
*/
|
|
125
|
-
outputs: OutputSpec[];
|
|
126
|
-
/**
|
|
127
|
-
* The dat files that provide the data for exogenous data variables in the
|
|
128
|
-
* model.
|
|
129
|
-
*/
|
|
130
|
-
datFiles: NonNullable<ModelSpec$1['datFiles']>;
|
|
131
|
-
/**
|
|
132
|
-
* Whether to bundle a model listing with the generated model.
|
|
133
|
-
*
|
|
134
|
-
* When this is true, a model listing will be bundled with the generated
|
|
135
|
-
* model to allow the `runtime` package to resolve variables that are
|
|
136
|
-
* referenced by name or identifier. This listing will increase the size
|
|
137
|
-
* of the generated model, so it is recommended to set this to true only
|
|
138
|
-
* if it is needed.
|
|
139
|
-
*/
|
|
140
|
-
bundleListing: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Whether to allow constants to be overridden at runtime using `setConstant`.
|
|
143
|
-
*
|
|
144
|
-
* If false, the generated model will contain a `setConstant` function that
|
|
145
|
-
* throws an error, meaning that constants cannot be overridden at runtime.
|
|
146
|
-
*
|
|
147
|
-
* If true, all constants in the generated model will be available to be
|
|
148
|
-
* overridden.
|
|
149
|
-
*
|
|
150
|
-
* If an array is provided, only those variable names in the array will
|
|
151
|
-
* be available to be overridden.
|
|
152
|
-
*/
|
|
153
|
-
customConstants: boolean | VarName[];
|
|
154
|
-
/**
|
|
155
|
-
* Whether to allow lookups to be overridden at runtime using `setLookup`.
|
|
156
|
-
*
|
|
157
|
-
* If false, the generated model will contain a `setLookup` function that
|
|
158
|
-
* throws an error, meaning that lookups cannot be overridden at runtime.
|
|
159
|
-
*
|
|
160
|
-
* If true, all lookups in the generated model will be available to be
|
|
161
|
-
* overridden.
|
|
162
|
-
*
|
|
163
|
-
* If an array is provided, only those variable names in the array will
|
|
164
|
-
* be available to be overridden.
|
|
165
|
-
*/
|
|
166
|
-
customLookups: boolean | VarName[];
|
|
167
|
-
/**
|
|
168
|
-
* Whether to allow for capturing the data for arbitrary variables at
|
|
169
|
-
* runtime (including variables that are not configured in the `outputs`
|
|
170
|
-
* array).
|
|
171
|
-
*
|
|
172
|
-
* If false, the generated model will contain a `storeOutput` function
|
|
173
|
-
* that throws an error, meaning that the data for arbitrary variables
|
|
174
|
-
* cannot be captured at runtime.
|
|
175
|
-
*
|
|
176
|
-
* If true, all variables in the generated model will be available to be
|
|
177
|
-
* captured at runtime.
|
|
178
|
-
*
|
|
179
|
-
* If an array is provided, only those variable names in the array will
|
|
180
|
-
* be available to be captured at runtime.
|
|
181
|
-
*/
|
|
182
|
-
customOutputs: boolean | VarName[];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* The sde configuration derived from a `UserConfig` that has been resolved (i.e.,
|
|
187
|
-
* paths have been checked). This is the config object that will be passed to
|
|
188
|
-
* plugin functions. It contains a subset of the original `UserConfig` (to disallow
|
|
189
|
-
* access to the `plugins` field of the original config).
|
|
190
|
-
*/
|
|
191
|
-
interface ResolvedConfig {
|
|
192
|
-
/**
|
|
193
|
-
* The mode used for the build process, either 'development' or 'production'.
|
|
194
|
-
*/
|
|
195
|
-
mode: BuildMode;
|
|
196
|
-
/**
|
|
197
|
-
* The absolute path to the project root directory, which has been confirmed to exist.
|
|
198
|
-
*/
|
|
199
|
-
rootDir: string;
|
|
200
|
-
/**
|
|
201
|
-
* The absolute path to the directory used to prepare the model. This directory has
|
|
202
|
-
* been created if it did not previously exist.
|
|
203
|
-
*/
|
|
204
|
-
prepDir: string;
|
|
205
|
-
/**
|
|
206
|
-
* The mdl files to be built.
|
|
207
|
-
*/
|
|
208
|
-
modelFiles: string[];
|
|
209
|
-
/**
|
|
210
|
-
* Paths to files that are considered to be inputs to the model build process.
|
|
211
|
-
* These can be paths to files or glob patterns (relative to the project directory).
|
|
212
|
-
*/
|
|
213
|
-
modelInputPaths: string[];
|
|
214
|
-
/**
|
|
215
|
-
* Paths to files that when changed will trigger a rebuild in watch mode. These
|
|
216
|
-
* can be paths to files or glob patterns (relative to the project directory).
|
|
217
|
-
*/
|
|
218
|
-
watchPaths: string[];
|
|
219
|
-
/**
|
|
220
|
-
* The code format to generate. If 'js', the model will be compiled to a JavaScript
|
|
221
|
-
* file. If 'c', the model will be compiled to a C file (in which case an additional
|
|
222
|
-
* plugin will be needed to convert the C code to a WebAssembly module).
|
|
223
|
-
*/
|
|
224
|
-
genFormat: 'js' | 'c';
|
|
225
|
-
/**
|
|
226
|
-
* The absolute path to the JSON file that will be written by the build process that
|
|
227
|
-
* lists all dimensions and variables in the model.
|
|
228
|
-
*/
|
|
229
|
-
outListingFile?: string;
|
|
230
|
-
/**
|
|
231
|
-
* The path to the `@sdeverywhere/cli` package. This is currently only used to get
|
|
232
|
-
* access to the files in the `src/c` directory.
|
|
233
|
-
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
234
|
-
*/
|
|
235
|
-
sdeDir: string;
|
|
236
|
-
/**
|
|
237
|
-
* The path to the `sde` command.
|
|
238
|
-
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
239
|
-
*/
|
|
240
|
-
sdeCmdPath: string;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* @hidden This isn't ready to be included in the public API just yet.
|
|
245
|
-
*/
|
|
246
|
-
interface ProcessOptions {
|
|
247
|
-
logOutput?: boolean;
|
|
248
|
-
ignoredMessageFilter?: string;
|
|
249
|
-
captureOutput?: boolean;
|
|
250
|
-
ignoreError?: boolean;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* @hidden This isn't ready to be included in the public API just yet.
|
|
254
|
-
*/
|
|
255
|
-
interface ProcessOutput {
|
|
256
|
-
exitCode: number;
|
|
257
|
-
stdoutMessages: string[];
|
|
258
|
-
stderrMessages: string[];
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
declare class StagedFiles {
|
|
262
|
-
private readonly baseStagedDir;
|
|
263
|
-
private readonly stagedFiles;
|
|
264
|
-
constructor(prepDir: string);
|
|
265
|
-
/**
|
|
266
|
-
* Prepare for writing a file to the staged directory.
|
|
267
|
-
*
|
|
268
|
-
* This will add the path to the array of tracked files and will create the
|
|
269
|
-
* staged directory if needed.
|
|
270
|
-
*
|
|
271
|
-
* @param srcDir The directory underneath the configured `staged` directory where
|
|
272
|
-
* the file will be written (this must be a relative path).
|
|
273
|
-
* @param srcFile The name of the file as written to the `staged` directory.
|
|
274
|
-
* @param dstDir The absolute path to the destination directory where the staged
|
|
275
|
-
* file will be copied when the build has completed.
|
|
276
|
-
* @param dstFile The name of the file as written to the destination directory.
|
|
277
|
-
* @return The absolute path to the staged file.
|
|
278
|
-
*/
|
|
279
|
-
prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
|
|
280
|
-
/**
|
|
281
|
-
* Write a file to the staged directory.
|
|
282
|
-
*
|
|
283
|
-
* This file will be copied (along with other staged files) into the destination
|
|
284
|
-
* directory only after the build process has completed. Copying all staged files
|
|
285
|
-
* at once helps improve the local development experience by making it so that
|
|
286
|
-
* live reloading tools only need to refresh once instead of every time a build
|
|
287
|
-
* file is written.
|
|
288
|
-
*
|
|
289
|
-
* @param srcDir The directory underneath the configured `staged` directory where
|
|
290
|
-
* the file will be written (this must be a relative path).
|
|
291
|
-
* @param dstDir The absolute path to the destination directory where the staged
|
|
292
|
-
* file will be copied when the build has completed.
|
|
293
|
-
* @param filename The name of the file.
|
|
294
|
-
* @param content The file content.
|
|
295
|
-
*/
|
|
296
|
-
writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
|
|
297
|
-
/**
|
|
298
|
-
* Return the absolute path to the staged file for the given source directory and file name.
|
|
299
|
-
*
|
|
300
|
-
* @param srcDir The directory underneath the configured `staged` directory where
|
|
301
|
-
* the file would be written initially (this must be a relative path).
|
|
302
|
-
* @param srcFile The name of the file.
|
|
303
|
-
*/
|
|
304
|
-
getStagedFilePath(srcDir: string, srcFile: string): string;
|
|
305
|
-
/**
|
|
306
|
-
* Return true if the staged file exists for the given source directory and file name.
|
|
307
|
-
*
|
|
308
|
-
* @param srcDir The directory underneath the configured `staged` directory where
|
|
309
|
-
* the file would be written initially (this must be a relative path).
|
|
310
|
-
* @param srcFile The name of the file.
|
|
311
|
-
*/
|
|
312
|
-
stagedFileExists(srcDir: string, srcFile: string): boolean;
|
|
313
|
-
/**
|
|
314
|
-
* Return true if the destination file exists for the given source directory and file name.
|
|
315
|
-
*
|
|
316
|
-
* @param srcDir The directory underneath the configured `staged` directory where
|
|
317
|
-
* the file would be written initially (this must be a relative path).
|
|
318
|
-
* @param srcFile The name of the file.
|
|
319
|
-
*/
|
|
320
|
-
destinationFileExists(srcDir: string, srcFile: string): boolean;
|
|
321
|
-
/**
|
|
322
|
-
* Copy staged files to their destination; this will only copy the staged
|
|
323
|
-
* files if they are different than the existing destination files. We
|
|
324
|
-
* copy the files in a batch like this so that hot module reload is only
|
|
325
|
-
* triggered once at the end of the whole build process.
|
|
326
|
-
*/
|
|
327
|
-
copyChangedFiles(): void;
|
|
328
|
-
/**
|
|
329
|
-
* Copy a file from the `staged` directory to its destination. If the file already
|
|
330
|
-
* exists in the destination directory and has the same contents as the source file,
|
|
331
|
-
* the file will not be copied and this function will return false.
|
|
332
|
-
*
|
|
333
|
-
* @param f The staged file entry.
|
|
334
|
-
*/
|
|
335
|
-
private copyStagedFile;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Provides access to common functionality that is needed during the build process.
|
|
340
|
-
* This is passed to most plugin functions.
|
|
341
|
-
*/
|
|
342
|
-
declare class BuildContext {
|
|
343
|
-
readonly config: ResolvedConfig;
|
|
344
|
-
private readonly stagedFiles;
|
|
345
|
-
private readonly abortSignal;
|
|
346
|
-
/**
|
|
347
|
-
* @param config The resolved configuration.
|
|
348
|
-
* @hidden
|
|
349
|
-
*/
|
|
350
|
-
constructor(config: ResolvedConfig, stagedFiles: StagedFiles, abortSignal: AbortSignal | undefined);
|
|
351
|
-
/**
|
|
352
|
-
* Log a message to the console and/or the in-browser overlay panel.
|
|
353
|
-
*
|
|
354
|
-
* @param level The log level (verbose, info, error).
|
|
355
|
-
* @param msg The message.
|
|
356
|
-
*/
|
|
357
|
-
log(level: LogLevel, msg: string): void;
|
|
358
|
-
/**
|
|
359
|
-
* Prepare for writing a file to the staged directory.
|
|
360
|
-
*
|
|
361
|
-
* This will add the path to the array of tracked files and will create the
|
|
362
|
-
* staged directory if needed.
|
|
363
|
-
*
|
|
364
|
-
* @param srcDir The directory underneath the configured `staged` directory where
|
|
365
|
-
* the file will be written (this must be a relative path).
|
|
366
|
-
* @param srcFile The name of the file as written to the `staged` directory.
|
|
367
|
-
* @param dstDir The absolute path to the destination directory where the staged
|
|
368
|
-
* file will be copied when the build has completed.
|
|
369
|
-
* @param dstFile The name of the file as written to the destination directory.
|
|
370
|
-
* @return The absolute path to the staged file.
|
|
371
|
-
*/
|
|
372
|
-
prepareStagedFile(srcDir: string, srcFile: string, dstDir: string, dstFile: string): string;
|
|
373
|
-
/**
|
|
374
|
-
* Write a file to the staged directory.
|
|
375
|
-
*
|
|
376
|
-
* This file will be copied (along with other staged files) into the destination
|
|
377
|
-
* directory only after the build process has completed. Copying all staged files
|
|
378
|
-
* at once helps improve the local development experience by making it so that
|
|
379
|
-
* live reloading tools only need to refresh once instead of every time a build
|
|
380
|
-
* file is written.
|
|
381
|
-
*
|
|
382
|
-
* @param srcDir The directory underneath the configured `staged` directory where
|
|
383
|
-
* the file will be written (this must be a relative path).
|
|
384
|
-
* @param dstDir The absolute path to the destination directory where the staged
|
|
385
|
-
* file will be copied when the build has completed.
|
|
386
|
-
* @param filename The name of the file.
|
|
387
|
-
* @param content The file content.
|
|
388
|
-
*/
|
|
389
|
-
writeStagedFile(srcDir: string, dstDir: string, filename: string, content: string): void;
|
|
390
|
-
/**
|
|
391
|
-
* Spawn a child process that runs the given command.
|
|
392
|
-
*
|
|
393
|
-
* @param cwd The directory in which the command will be executed.
|
|
394
|
-
* @param command The command to execute.
|
|
395
|
-
* @param args The arguments to pass to the command.
|
|
396
|
-
* @param opts Additional options to configure the process.
|
|
397
|
-
* @returns The output of the process.
|
|
398
|
-
*/
|
|
399
|
-
spawnChild(cwd: string, command: string, args: string[], opts?: ProcessOptions): Promise<ProcessOutput>;
|
|
400
|
-
/**
|
|
401
|
-
* Format a (subscripted or non-subscripted) model variable name into a canonical
|
|
402
|
-
* identifier (with special characters converted to underscore, and subscript/dimension
|
|
403
|
-
* parts separated by commas).
|
|
404
|
-
*
|
|
405
|
-
* @param name The name of the variable in the source model, e.g., `Variable name[DimA, B2]`.
|
|
406
|
-
* @returns The canonical identifier for the given name, e.g., `_variable_name[_dima,_b2]`.
|
|
407
|
-
*/
|
|
408
|
-
canonicalVarId(name: string): string;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* The plugin interface that can be implemented to customize the model
|
|
413
|
-
* generation and build process.
|
|
414
|
-
*
|
|
415
|
-
* These functions are all optional.
|
|
416
|
-
*
|
|
417
|
-
* These functions will be called during the build process in the order
|
|
418
|
-
* listed below:
|
|
419
|
-
* - init (only called once before initial build steps)
|
|
420
|
-
* - preGenerate
|
|
421
|
-
* - preProcessMdl
|
|
422
|
-
* - postProcessMdl
|
|
423
|
-
* - preGenerateCode
|
|
424
|
-
* - postGenerateCode
|
|
425
|
-
* - postGenerate
|
|
426
|
-
* - postBuild
|
|
427
|
-
* - watch (only called once after initial build steps when mode==development)
|
|
428
|
-
*/
|
|
429
|
-
interface Plugin {
|
|
430
|
-
/**
|
|
431
|
-
* Called after the user configuration has been resolved, but before the
|
|
432
|
-
* model is generated and other build steps.
|
|
433
|
-
*
|
|
434
|
-
* @param config The build configuration.
|
|
435
|
-
*/
|
|
436
|
-
init?(config: ResolvedConfig): Promise<void>;
|
|
437
|
-
/**
|
|
438
|
-
* Called before the "generate model" steps are performed.
|
|
439
|
-
*
|
|
440
|
-
* @param context The build context (for logging, etc).
|
|
441
|
-
* @param modelSpec The spec that controls how the model is generated.
|
|
442
|
-
*/
|
|
443
|
-
preGenerate?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<void>;
|
|
444
|
-
/**
|
|
445
|
-
* Called before SDE preprocesses the mdl file (in the case of one mdl file),
|
|
446
|
-
* or before SDE flattens the mdl files (in the case of multiple mdl files).
|
|
447
|
-
*
|
|
448
|
-
* @param context The build context (for logging, etc).
|
|
449
|
-
*/
|
|
450
|
-
preProcessMdl?(context: BuildContext): Promise<void>;
|
|
451
|
-
/**
|
|
452
|
-
* Called after SDE preprocesses the mdl file (in the case of one mdl file),
|
|
453
|
-
* or after SDE flattens the mdl files (in the case of multiple mdl files).
|
|
454
|
-
*
|
|
455
|
-
* @param context The build context (for logging, etc).
|
|
456
|
-
* @param mdlContent The resulting mdl file content.
|
|
457
|
-
* @return The modified mdl file content (if postprocessing was needed).
|
|
458
|
-
*/
|
|
459
|
-
postProcessMdl?(context: BuildContext, mdlContent: string): Promise<string>;
|
|
460
|
-
/**
|
|
461
|
-
* Called before SDE generates a JS or C file from the mdl file.
|
|
462
|
-
*
|
|
463
|
-
* @param context The build context (for logging, etc).
|
|
464
|
-
* @param format The generated code format, either 'js' or 'c'.
|
|
465
|
-
*/
|
|
466
|
-
preGenerateCode?(context: BuildContext, format: 'js' | 'c'): Promise<void>;
|
|
467
|
-
/**
|
|
468
|
-
* Called after SDE generates a JS or C file from the mdl file.
|
|
469
|
-
*
|
|
470
|
-
* @param context The build context (for logging, etc).
|
|
471
|
-
* @param format The generated code format, either 'js' or 'c'.
|
|
472
|
-
* @param content The resulting JS or C file content.
|
|
473
|
-
* @return The modified JS or C file content (if postprocessing was needed).
|
|
474
|
-
*/
|
|
475
|
-
postGenerateCode?(context: BuildContext, format: 'js' | 'c', content: string): Promise<string>;
|
|
476
|
-
/**
|
|
477
|
-
* Called after the "generate model" process has completed (but before the staged
|
|
478
|
-
* files are copied to their destination).
|
|
479
|
-
*
|
|
480
|
-
* @param context The build context (for logging, etc).
|
|
481
|
-
* @param modelSpec The spec that controls how the model is generated.
|
|
482
|
-
* @return Whether the plugin succeeded (for example, a plugin that runs tests can
|
|
483
|
-
* return false to indicate that one or more tests failed).
|
|
484
|
-
*/
|
|
485
|
-
postGenerate?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<boolean>;
|
|
486
|
-
/**
|
|
487
|
-
* Called after the model has been generated and after the staged files
|
|
488
|
-
* have been copied to their destination.
|
|
489
|
-
*
|
|
490
|
-
* @param context The build context (for logging, etc).
|
|
491
|
-
* @param modelSpec The spec that controls how the model is generated.
|
|
492
|
-
* @return Whether the plugin succeeded (for example, a plugin that runs tests can
|
|
493
|
-
* return false to indicate that one or more tests failed).
|
|
494
|
-
*/
|
|
495
|
-
postBuild?(context: BuildContext, modelSpec: ResolvedModelSpec): Promise<boolean>;
|
|
496
|
-
/**
|
|
497
|
-
* Called in development/watch mode after the initial build has completed
|
|
498
|
-
* (i.e., after the model has been generated and after the staged files
|
|
499
|
-
* have been copied to their destination).
|
|
500
|
-
*
|
|
501
|
-
* @param config The build configuration.
|
|
502
|
-
*/
|
|
503
|
-
watch?(config: ResolvedConfig): Promise<void>;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* The sde configuration as defined by the user, either inline or in a `sde.config.js` file.
|
|
508
|
-
*/
|
|
509
|
-
interface UserConfig {
|
|
510
|
-
/**
|
|
511
|
-
* The project root directory. If undefined, the current directory is
|
|
512
|
-
* assumed to be the project root. This directory should contain all the
|
|
513
|
-
* model and config files referenced during the build process.
|
|
514
|
-
*/
|
|
515
|
-
rootDir?: string;
|
|
516
|
-
/**
|
|
517
|
-
* The directory used to prepare the model. If undefined, an 'sde-prep'
|
|
518
|
-
* directory will be created under the resolved `rootDir`.
|
|
519
|
-
*/
|
|
520
|
-
prepDir?: string;
|
|
521
|
-
/**
|
|
522
|
-
* The mdl files to be built (must provide one or more).
|
|
523
|
-
*/
|
|
524
|
-
modelFiles: string[];
|
|
525
|
-
/**
|
|
526
|
-
* Paths to files that are considered to be inputs to the model build process.
|
|
527
|
-
* These can be paths to files or glob patterns (relative to the project directory).
|
|
528
|
-
* If left undefined, this will resolve to the `modelFiles` array.
|
|
529
|
-
*/
|
|
530
|
-
modelInputPaths?: string[];
|
|
531
|
-
/**
|
|
532
|
-
* Paths to files that when changed will trigger a rebuild in watch mode. These
|
|
533
|
-
* can be paths to files or glob patterns (relative to the project directory).
|
|
534
|
-
* If left undefined, this will resolve to the `modelFiles` array.
|
|
535
|
-
*/
|
|
536
|
-
watchPaths?: string[];
|
|
537
|
-
/**
|
|
538
|
-
* The code format to generate. If 'js', the model will be compiled to a JavaScript
|
|
539
|
-
* file. If 'c', the model will be compiled to a C file (in which case an additional
|
|
540
|
-
* plugin will be needed to convert the C code to a WebAssembly module). If undefined,
|
|
541
|
-
* defaults to 'js'.
|
|
542
|
-
*/
|
|
543
|
-
genFormat?: 'js' | 'c';
|
|
544
|
-
/**
|
|
545
|
-
* If defined, the build process will write a JSON file to the provided path that lists
|
|
546
|
-
* all dimensions and variables in the model. This can be an absolute path, or if it
|
|
547
|
-
* is a relative path it will be resolved relative to the `rootDir` for the project.
|
|
548
|
-
*/
|
|
549
|
-
outListingFile?: string;
|
|
550
|
-
/**
|
|
551
|
-
* The array of plugins that are used to customize the build process. These will be
|
|
552
|
-
* executed in the order defined here.
|
|
553
|
-
*/
|
|
554
|
-
plugins?: Plugin[];
|
|
555
|
-
/**
|
|
556
|
-
* Called before the "generate model" steps are performed.
|
|
557
|
-
*
|
|
558
|
-
* You must implement this function so that the generated model is
|
|
559
|
-
* configured with the desired inputs and outputs.
|
|
560
|
-
*
|
|
561
|
-
* @return A `ModelSpec` that defines the model inputs and outputs.
|
|
562
|
-
*/
|
|
563
|
-
modelSpec: (context: BuildContext) => Promise<ModelSpec>;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
interface BuildOptions {
|
|
567
|
-
/** The path to an `sde.config.js` file, or a `UserConfig` object. */
|
|
568
|
-
config?: string | UserConfig;
|
|
569
|
-
/**
|
|
570
|
-
* The log levels to include. If undefined, the default 'info' and 'error' levels
|
|
571
|
-
* will be active.
|
|
572
|
-
*/
|
|
573
|
-
logLevels?: LogLevel[];
|
|
574
|
-
/**
|
|
575
|
-
* The path to the `@sdeverywhere/cli` package. This is currently only used to get
|
|
576
|
-
* access to the files in the `src/c` directory.
|
|
577
|
-
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
578
|
-
*/
|
|
579
|
-
sdeDir: string;
|
|
580
|
-
/**
|
|
581
|
-
* The path to the `sde` command.
|
|
582
|
-
* @hidden This should be removed once we have tighter integration with the `cli` package.
|
|
583
|
-
*/
|
|
584
|
-
sdeCmdPath: string;
|
|
585
|
-
}
|
|
586
|
-
interface BuildResult {
|
|
587
|
-
/**
|
|
588
|
-
* The exit code that should be set by the process. This will be undefined
|
|
589
|
-
* if `mode` is 'development', indicating that the process should be kept alive.
|
|
590
|
-
*/
|
|
591
|
-
exitCode?: number;
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* Initiate the build process, which can either be a single build if `mode` is
|
|
595
|
-
* 'production', or a live development environment if `mode` is 'development'.
|
|
596
|
-
*
|
|
597
|
-
* @param mode The build mode.
|
|
598
|
-
* @param options The build options.
|
|
599
|
-
* @return An `ok` result if the build completed, otherwise an `err` result.
|
|
600
|
-
*/
|
|
601
|
-
declare function build(mode: BuildMode, options: BuildOptions): Promise<Result<BuildResult, Error>>;
|
|
602
|
-
|
|
603
|
-
export { BuildContext, type BuildMode, type BuildOptions, type BuildResult, type InputSpec, type LogLevel, type ModelSpec, type OutputSpec, type Plugin, type ResolvedConfig, type ResolvedModelSpec, type UserConfig, type VarName, build };
|