@sdeverywhere/cli 0.7.0 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeverywhere/cli",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Contains the `sde` command line interface for the SDEverywhere tool suite.",
5
5
  "type": "module",
6
6
  "files": [
@@ -11,11 +11,10 @@
11
11
  "sde": "src/main.js"
12
12
  },
13
13
  "dependencies": {
14
- "@sdeverywhere/build": "^0.1.0",
14
+ "@sdeverywhere/build": "^0.2.0",
15
15
  "@sdeverywhere/compile": "^0.7.0",
16
16
  "bufx": "^1.0.5",
17
17
  "byline": "^5.0.0",
18
- "fs-extra": "^10.1.0",
19
18
  "ramda": "^0.27.0",
20
19
  "shelljs": "^0.8.3",
21
20
  "yargs": "^17.5.1"
package/src/main.js CHANGED
@@ -26,6 +26,7 @@ import fs from 'fs'
26
26
  import path from 'path'
27
27
 
28
28
  import yargs from 'yargs'
29
+
29
30
  import sdeBundle from './sde-bundle.js'
30
31
  import sdeDev from './sde-dev.js'
31
32
  import sdeGenerate from './sde-generate.js'
@@ -41,12 +42,14 @@ import sdeTest from './sde-test.js'
41
42
  import sdeNames from './sde-names.js'
42
43
  import sdeCauses from './sde-causes.js'
43
44
  import sdeWhich from './sde-which.js'
45
+ import { parentDirForFileUrl } from './utils.js'
44
46
 
45
47
  // Workaround yargs issue where it doesn't find version from package.json
46
48
  // automatically in all cases in ESM context
47
- const srcDir = new URL('.', import.meta.url).pathname
49
+ const srcDir = parentDirForFileUrl(import.meta.url)
48
50
  const pkgFile = path.resolve(srcDir, '..', 'package.json')
49
51
  const pkg = JSON.parse(fs.readFileSync(pkgFile))
52
+ const pkgVersion = pkg.version
50
53
 
51
54
  const yarg = yargs(process.argv.slice(2))
52
55
  yarg
@@ -70,7 +73,7 @@ yarg
70
73
  .command(sdeWhich)
71
74
  .demandCommand(1)
72
75
  .help()
73
- .version(pkg.version)
76
+ .version(pkgVersion)
74
77
  .alias('h', 'help')
75
78
  .alias('v', 'version')
76
79
  .wrap(yarg.terminalWidth())
package/src/sde-bundle.js CHANGED
@@ -4,6 +4,8 @@ import path from 'path'
4
4
 
5
5
  import { build as runBuild } from '@sdeverywhere/build'
6
6
 
7
+ import { parentDirForFileUrl } from './utils.js'
8
+
7
9
  export let command = 'bundle [options]'
8
10
  export let describe = 'build and bundle a model as specified by a config file'
9
11
  export let builder = {
@@ -25,7 +27,7 @@ export let bundle = async (configPath, verbose) => {
25
27
  if (verbose) {
26
28
  logLevels.push('verbose')
27
29
  }
28
- const srcDir = new URL('.', import.meta.url).pathname
30
+ const srcDir = parentDirForFileUrl(import.meta.url)
29
31
  const sdeDir = path.resolve(srcDir, '..')
30
32
  const sdeCmdPath = path.resolve(srcDir, 'main.js')
31
33
  const result = await runBuild('production', {
@@ -1,8 +1,8 @@
1
- import fs from 'fs-extra'
1
+ import fs from 'fs'
2
2
  import path from 'path'
3
3
  import sh from 'shelljs'
4
4
 
5
- import { buildDir, execCmd, modelPathProps } from './utils.js'
5
+ import { buildDir, execCmd, modelPathProps, parentDirForFileUrl } from './utils.js'
6
6
 
7
7
  export let command = 'compile [options] <model>'
8
8
  export let describe = 'compile the generated model to an executable file'
@@ -43,15 +43,16 @@ export default {
43
43
  }
44
44
 
45
45
  let linkCSourceFiles = (modelDirname, buildDirname) => {
46
- let cDirname = path.join(new URL('.', import.meta.url).pathname, 'c')
46
+ let srcDir = parentDirForFileUrl(import.meta.url)
47
+ let cDirname = path.join(srcDir, 'c')
47
48
  sh.ls(cDirname).forEach(filename => {
48
- // If a C source file is present in the model directory, link to it instead
49
- // as an override.
49
+ // If a C source file is present in the model directory, copy that one into
50
+ // the build directory to override the one from `src/c`.
50
51
  let srcPathname = path.join(modelDirname, filename)
51
52
  if (!fs.existsSync(srcPathname)) {
52
53
  srcPathname = path.join(cDirname, filename)
53
54
  }
54
55
  let dstPathname = path.join(buildDirname, filename)
55
- fs.ensureSymlinkSync(srcPathname, dstPathname)
56
+ fs.copyFileSync(srcPathname, dstPathname)
56
57
  })
57
58
  }
package/src/sde-dev.js CHANGED
@@ -4,6 +4,8 @@ import path from 'path'
4
4
 
5
5
  import { build as runBuild } from '@sdeverywhere/build'
6
6
 
7
+ import { parentDirForFileUrl } from './utils.js'
8
+
7
9
  export let command = 'dev [options]'
8
10
  export let describe = 'run a model in a live development environment'
9
11
  export let builder = {
@@ -25,7 +27,7 @@ export let dev = async (configPath, verbose) => {
25
27
  if (verbose) {
26
28
  logLevels.push('verbose')
27
29
  }
28
- const srcDir = new URL('.', import.meta.url).pathname
30
+ const srcDir = parentDirForFileUrl(import.meta.url)
29
31
  const sdeDir = path.resolve(srcDir, '..')
30
32
  const sdeCmdPath = path.resolve(srcDir, 'main.js')
31
33
  const result = await runBuild('development', {
package/src/sde-which.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import path from 'path'
2
2
 
3
+ import { parentDirForFileUrl } from './utils.js'
4
+
3
5
  let command = 'which'
4
6
  let describe = 'print the SDEverywhere home directory'
5
7
  let builder = {}
@@ -8,7 +10,8 @@ let handler = argv => {
8
10
  }
9
11
  let which = () => {
10
12
  // The SDEverywhere home directory is one level above the src directory where this code runs.
11
- let homeDir = path.resolve(new URL('..', import.meta.url).pathname)
13
+ let srcDir = parentDirForFileUrl(import.meta.url)
14
+ let homeDir = path.resolve(srcDir, '..')
12
15
  console.log(homeDir)
13
16
  }
14
17
  export default {
package/src/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
+ import { fileURLToPath } from 'url'
3
4
 
4
5
  import B from 'bufx'
5
6
  import R from 'ramda'
@@ -77,6 +78,20 @@ export function parseSpec(specFilename) {
77
78
  return spec
78
79
  }
79
80
 
81
+ /**
82
+ * Return the absolute path to the directory in which the given (source)
83
+ * file is located. (This is a replacement for `__dirname`, which is not
84
+ * available in an ESM context.)
85
+ *
86
+ * @param srcFileUrl The URL for the source file (i.e., `import.meta.url`).
87
+ */
88
+ export function parentDirForFileUrl(srcFileUrl) {
89
+ return path.dirname(fileURLToPath(srcFileUrl))
90
+ }
91
+
92
+ /**
93
+ * Ensure the output directory exists for a given output file path.
94
+ */
80
95
  export function outputDir(outfile, modelDirname) {
81
96
  if (outfile) {
82
97
  outfile = path.dirname(outfile)