@sdeverywhere/cli 0.7.35 → 0.7.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeverywhere/cli",
3
- "version": "0.7.35",
3
+ "version": "0.7.37",
4
4
  "description": "Contains the `sde` command line interface for the SDEverywhere tool suite.",
5
5
  "type": "module",
6
6
  "files": [
@@ -11,12 +11,12 @@
11
11
  "sde": "src/main.js"
12
12
  },
13
13
  "dependencies": {
14
- "@sdeverywhere/build": "^0.3.7",
15
- "@sdeverywhere/compile": "^0.7.25",
16
- "bufx": "^1.0.5",
14
+ "@sdeverywhere/build": "^0.3.8",
15
+ "@sdeverywhere/compile": "^0.7.26",
17
16
  "byline": "^5.0.0",
18
17
  "ramda": "^0.27.0",
19
18
  "shelljs": "^0.10.0",
19
+ "strip-bom": "^5.0.0",
20
20
  "yargs": "^17.5.1"
21
21
  },
22
22
  "engines": {
package/src/bufx.js ADDED
@@ -0,0 +1,66 @@
1
+ import * as fs from 'node:fs'
2
+ import stripBom from 'strip-bom'
3
+
4
+ // Numeric value of a string or number
5
+ let num = x => (typeof x === 'number' ? x : Number.parseFloat(x))
6
+ // Split a string into lines that may have Windows, Unix, or old Mac line endings.
7
+ let lines = s => s.split(/\r\n|\n|\r/)
8
+ // Print a string to the console
9
+ let print = s => {
10
+ console.log(s)
11
+ }
12
+ // Read a UTF-8 file into a string. Strip the BOM if present.
13
+ let read = pathname => stripBom(fs.readFileSync(pathname, 'utf8'))
14
+ // Write a string to a UTF-8 file
15
+ let write = (s, pathname) => {
16
+ fs.writeFileSync(pathname, s, { encoding: 'utf8' })
17
+ }
18
+
19
+ // Output buffer
20
+ let bufs = { _: '' }
21
+ // Open a buffer for writing
22
+ let open = channel => (bufs[channel] = '')
23
+ // Emit a string to a buffer
24
+ let emit = (a, channel = null) => {
25
+ channel = channel || '_'
26
+ bufs[channel] += a
27
+ }
28
+ // Emit a string to a buffer terminated by a newline
29
+ let emitLine = (a, channel = null) => {
30
+ channel = channel || '_'
31
+ bufs[channel] += a + '\n'
32
+ }
33
+ // Print a buffer to the console
34
+ let printBuf = (channel = null) => {
35
+ channel = channel || '_'
36
+ print(bufs[channel])
37
+ }
38
+ // Write a buffer to a file
39
+ let writeBuf = (pathname, channel = null) => {
40
+ channel = channel || '_'
41
+ write(bufs[channel], pathname)
42
+ }
43
+ // Get buffer contents as a string
44
+ let getBuf = (channel = null) => {
45
+ channel = channel || '_'
46
+ return bufs[channel]
47
+ }
48
+ // Clear a buffer
49
+ let clearBuf = (channel = null) => {
50
+ channel = channel || '_'
51
+ bufs[channel] = ''
52
+ }
53
+
54
+ export default {
55
+ clearBuf,
56
+ emit,
57
+ emitLine,
58
+ getBuf,
59
+ lines,
60
+ num,
61
+ open,
62
+ printBuf,
63
+ read,
64
+ write,
65
+ writeBuf
66
+ }
@@ -1,6 +1,5 @@
1
1
  import { existsSync } from 'fs'
2
2
 
3
- import { pr } from 'bufx'
4
3
  import * as R from 'ramda'
5
4
 
6
5
  import { readDat } from '@sdeverywhere/compile'
@@ -70,7 +69,7 @@ export let compare = async (vensimfile, sdefile, opts) => {
70
69
  let diff = difference(sdeValue, vensimValue)
71
70
  if (diff > ε) {
72
71
  let diffPct = (diff * 100).toFixed(6)
73
- pr(`${varName} time=${t.toFixed(2)} vensim=${vensimValue} sde=${sdeValue} diff=${diffPct}%`)
72
+ console.log(`${varName} time=${t.toFixed(2)} vensim=${vensimValue} sde=${sdeValue} diff=${diffPct}%`)
74
73
  noDATDifference = false
75
74
  }
76
75
  }
@@ -78,10 +77,10 @@ export let compare = async (vensimfile, sdefile, opts) => {
78
77
  }
79
78
  }
80
79
  if (noDATDifference) {
81
- pr(`Data were the same for ${vensimfile} and ${sdefile}`)
80
+ console.log(`Data were the same for ${vensimfile} and ${sdefile}`)
82
81
  return true
83
82
  } else {
84
- pr(`Data differences detected for ${vensimfile} and ${sdefile}`)
83
+ console.log(`Data differences detected for ${vensimfile} and ${sdefile}`)
85
84
  return false
86
85
  }
87
86
  }
package/src/sde-dev.js CHANGED
@@ -23,6 +23,11 @@ export let handler = argv => {
23
23
  dev(argv.config, argv.verbose)
24
24
  }
25
25
  export let dev = async (configPath, verbose) => {
26
+ if (process.env.NODE_ENV === undefined) {
27
+ // XXX: Force "development" mode so that HMR works in Vite (see #694 for details)
28
+ process.env.NODE_ENV = 'development'
29
+ }
30
+
26
31
  const logLevels = ['error', 'info']
27
32
  if (verbose) {
28
33
  logLevels.push('verbose')
@@ -1,10 +1,9 @@
1
1
  import { readFileSync } from 'fs'
2
2
  import path from 'path'
3
3
 
4
- import B from 'bufx'
5
-
6
4
  import { preprocessVensimModel } from '@sdeverywhere/compile'
7
5
 
6
+ import B from './bufx.js'
8
7
  import { buildDir, modelPathProps } from './utils.js'
9
8
 
10
9
  const command = 'flatten [options] <outmodel>'
@@ -1,9 +1,9 @@
1
1
  import path from 'path'
2
2
  import { readFileSync } from 'fs'
3
- import B from 'bufx'
4
3
 
5
4
  import { parseAndGenerate, preprocessVensimModel } from '@sdeverywhere/compile'
6
5
 
6
+ import B from './bufx.js'
7
7
  import { buildDir, modelPathProps, parseSpec } from './utils.js'
8
8
 
9
9
  export let command = 'generate [options] <model>'
package/src/sde-log.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
3
 
4
- import B from 'bufx'
5
4
  import byline from 'byline'
6
5
  import * as R from 'ramda'
7
6
 
8
7
  import { canonicalName } from '@sdeverywhere/compile'
9
8
 
9
+ import B from './bufx.js'
10
+
10
11
  export let command = 'log [options] <logfile>'
11
12
  export let describe = 'process an SDEverywhere log file'
12
13
  export let builder = {
package/src/utils.js CHANGED
@@ -2,12 +2,13 @@ import fs from 'fs'
2
2
  import path from 'path'
3
3
  import { fileURLToPath } from 'url'
4
4
 
5
- import B from 'bufx'
6
5
  import * as R from 'ramda'
7
6
  import sh from 'shelljs'
8
7
 
9
8
  import { canonicalName } from '@sdeverywhere/compile'
10
9
 
10
+ import B from './bufx.js'
11
+
11
12
  /**
12
13
  * Run a command line silently in the "sh" shell. Print error output on error.
13
14
  *