@sdeverywhere/cli 0.7.39 → 0.7.40
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 +3 -3
- package/src/sde-causes.js +2 -2
- package/src/sde-generate.js +2 -2
- package/src/sde-names.js +2 -2
- package/src/sde-test.js +16 -5
- package/src/utils.js +23 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdeverywhere/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.40",
|
|
4
4
|
"description": "Contains the `sde` command line interface for the SDEverywhere tool suite.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"sde": "src/main.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@sdeverywhere/build": "^0.3.
|
|
15
|
-
"@sdeverywhere/compile": "^0.7.
|
|
14
|
+
"@sdeverywhere/build": "^0.3.11",
|
|
15
|
+
"@sdeverywhere/compile": "^0.7.28",
|
|
16
16
|
"byline": "^5.0.0",
|
|
17
17
|
"ramda": "^0.27.0",
|
|
18
18
|
"shelljs": "^0.10.0",
|
package/src/sde-causes.js
CHANGED
|
@@ -18,11 +18,11 @@ let handler = argv => {
|
|
|
18
18
|
}
|
|
19
19
|
let causes = async (model, varname, opts) => {
|
|
20
20
|
// Get the model name and directory from the model argument.
|
|
21
|
-
let { modelDirname, modelPathname, modelName } = modelPathProps(model)
|
|
21
|
+
let { modelDirname, modelPathname, modelName, modelKind } = modelPathProps(model)
|
|
22
22
|
let spec = parseSpec(opts.spec)
|
|
23
23
|
// Parse the model to get variable and subscript information.
|
|
24
24
|
let input = readFileSync(modelPathname, 'utf8')
|
|
25
|
-
await parseAndGenerate(input, spec, ['printRefGraph'], modelDirname, modelName, '', varname)
|
|
25
|
+
await parseAndGenerate(input, modelKind, spec, ['printRefGraph'], modelDirname, modelName, '', varname)
|
|
26
26
|
}
|
|
27
27
|
export default {
|
|
28
28
|
command,
|
package/src/sde-generate.js
CHANGED
|
@@ -57,7 +57,7 @@ export let handler = async argv => {
|
|
|
57
57
|
|
|
58
58
|
export let generate = async (model, opts) => {
|
|
59
59
|
// Get the model name and directory from the model argument.
|
|
60
|
-
let { modelDirname, modelName, modelPathname } = modelPathProps(model)
|
|
60
|
+
let { modelDirname, modelName, modelPathname, modelKind } = modelPathProps(model)
|
|
61
61
|
// Ensure the build directory exists.
|
|
62
62
|
let buildDirname = buildDir(opts.builddir, modelDirname)
|
|
63
63
|
let spec = parseSpec(opts.spec)
|
|
@@ -87,7 +87,7 @@ export let generate = async (model, opts) => {
|
|
|
87
87
|
if (opts.refidtest) {
|
|
88
88
|
operations.push('printRefIdTest')
|
|
89
89
|
}
|
|
90
|
-
await parseAndGenerate(mdlContent, spec, operations, modelDirname, modelName, buildDirname)
|
|
90
|
+
await parseAndGenerate(mdlContent, modelKind, spec, operations, modelDirname, modelName, buildDirname)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export default {
|
package/src/sde-names.js
CHANGED
|
@@ -26,11 +26,11 @@ let handler = argv => {
|
|
|
26
26
|
}
|
|
27
27
|
let names = async (model, namesPathname, opts) => {
|
|
28
28
|
// Get the model name and directory from the model argument.
|
|
29
|
-
let { modelDirname, modelPathname, modelName } = modelPathProps(model)
|
|
29
|
+
let { modelDirname, modelPathname, modelName, modelKind } = modelPathProps(model)
|
|
30
30
|
let spec = parseSpec(opts.spec)
|
|
31
31
|
// Parse the model to get variable and subscript information.
|
|
32
32
|
let input = readFileSync(modelPathname, 'utf8')
|
|
33
|
-
await parseAndGenerate(input, spec, ['convertNames'], modelDirname, modelName, '')
|
|
33
|
+
await parseAndGenerate(input, modelKind, spec, ['convertNames'], modelDirname, modelName, '')
|
|
34
34
|
// Read each variable name from the names file and convert it.
|
|
35
35
|
printNames(namesPathname, opts.toc ? 'to-c' : 'to-vensim')
|
|
36
36
|
}
|
package/src/sde-test.js
CHANGED
|
@@ -18,6 +18,10 @@ export let builder = {
|
|
|
18
18
|
choices: ['js', 'c'],
|
|
19
19
|
default: 'js'
|
|
20
20
|
},
|
|
21
|
+
tooldat: {
|
|
22
|
+
describe: 'pathname of the tool DAT file to compare to SDE output',
|
|
23
|
+
type: 'string'
|
|
24
|
+
},
|
|
21
25
|
builddir: {
|
|
22
26
|
describe: 'build directory',
|
|
23
27
|
type: 'string',
|
|
@@ -53,12 +57,19 @@ export let test = async (model, opts) => {
|
|
|
53
57
|
// Convert the TSV log file to a DAT file in the same directory.
|
|
54
58
|
opts.dat = true
|
|
55
59
|
await log(logPathname, opts)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
let toolDatPathname
|
|
61
|
+
if (opts.tooldat) {
|
|
62
|
+
// Use the provided DAT file for comparison
|
|
63
|
+
toolDatPathname = opts.tooldat
|
|
64
|
+
} else {
|
|
65
|
+
// Assume there is a DAT file created by the modeling tool named {modelName}.dat
|
|
66
|
+
// in the model directory
|
|
67
|
+
toolDatPathname = path.join(modelDirname, `${modelName}.dat`)
|
|
68
|
+
}
|
|
59
69
|
let p = path.parse(logPathname)
|
|
60
|
-
let
|
|
61
|
-
|
|
70
|
+
let sdeDatPathname = path.format({ dir: p.dir, name: p.name, ext: '.dat' })
|
|
71
|
+
// Compare SDE-generated DAT file to the tool-generated DAT file
|
|
72
|
+
let noDiffs = await compare(toolDatPathname, sdeDatPathname, opts)
|
|
62
73
|
if (!noDiffs) {
|
|
63
74
|
// Exit with a non-zero error code if differences were detected
|
|
64
75
|
console.error()
|
package/src/utils.js
CHANGED
|
@@ -25,25 +25,45 @@ export function execCmd(cmd) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Normalize a model pathname that may or may not include the .mdl extension.
|
|
28
|
+
* Normalize a model pathname that may or may not include the .mdl or .xmile/.stmx/.itmx extension.
|
|
29
|
+
* If the pathname does not end with .mdl, .xmile, .stmx, or .itmx, this will attempt to find a
|
|
30
|
+
* file with one of those extensions.
|
|
29
31
|
* If there is not a path in the model argument, default to the current working directory.
|
|
32
|
+
*
|
|
30
33
|
* Return an object with properties that look like this:
|
|
31
34
|
* modelDirname: '/Users/todd/src/models/arrays'
|
|
32
35
|
* modelName: 'arrays'
|
|
33
36
|
* modelPathname: '/Users/todd/src/models/arrays/arrays.mdl'
|
|
37
|
+
* modelKind: 'vensim'
|
|
34
38
|
*
|
|
35
39
|
* @param model A path to a Vensim model file.
|
|
36
40
|
* @return An object with the properties specified above.
|
|
37
41
|
*/
|
|
38
42
|
export function modelPathProps(model) {
|
|
39
|
-
|
|
43
|
+
const parsedPath = path.parse(model)
|
|
44
|
+
if (parsedPath.ext === '') {
|
|
45
|
+
const exts = ['.mdl', '.xmile', '.stmx', '.itmx']
|
|
46
|
+
const paths = exts.map(ext => path.join(parsedPath.dir, parsedPath.name + ext))
|
|
47
|
+
const existingPaths = paths.filter(path => fs.existsSync(path))
|
|
48
|
+
if (existingPaths.length > 1) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Found multiple files that match '${model}'; please specify a file with a .mdl, .xmile, .stmx, or .itmx extension`
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
if (existingPaths.length === 0) {
|
|
54
|
+
throw new Error(`No {mdl,xmile,stmx,itmx} file found for ${model}`)
|
|
55
|
+
}
|
|
56
|
+
parsedPath.ext = path.extname(existingPaths[0])
|
|
57
|
+
}
|
|
58
|
+
let p = R.merge({ ext: parsedPath.ext }, R.pick(['dir', 'name'], parsedPath))
|
|
40
59
|
if (R.isEmpty(p.dir)) {
|
|
41
60
|
p.dir = process.cwd()
|
|
42
61
|
}
|
|
43
62
|
return {
|
|
44
63
|
modelDirname: p.dir,
|
|
45
64
|
modelName: p.name,
|
|
46
|
-
modelPathname: path.format(p)
|
|
65
|
+
modelPathname: path.format(p),
|
|
66
|
+
modelKind: p.ext === '.mdl' ? 'vensim' : 'xmile'
|
|
47
67
|
}
|
|
48
68
|
}
|
|
49
69
|
|