Skip to content

Commit b63e302

Browse files
committed
fix(cli): added mkidr -p's for when output doesn't exist, updated readme
1 parent 765b5e5 commit b63e302

3 files changed

Lines changed: 54 additions & 27 deletions

File tree

README.md

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ To provide a simple way to write input simpulation files.
66

77
## Installation
88

9-
```
9+
```sh
1010
$ npm install -g simput
1111
```
1212

13+
## Usage
14+
1315
After installing the package you will get one executable **Simput** with
1416
the following set of options:
1517

16-
```
18+
```sh
1719
$ Simput
1820

1921
Usage: Simput [options]
@@ -37,37 +39,58 @@ $ Simput
3739

3840
```
3941

40-
## Development
42+
### Examples
4143

4244
```sh
43-
$ git clone https://github.com/Kitware/tonic.git
44-
$ cd tonic
45-
$ npm run global
46-
$ npm install
47-
$ cd tonic-applications/simput
45+
$ Simput -t pyfr -o ~/pyfr/example
4846
```
4947

50-
## Production
51-
52-
```
53-
$ git clone https://github.com/Kitware/simput.git
54-
$ cd simput
55-
$ git submodule update --init
56-
$ npm install
57-
$ npm link
48+
Starts a server and opens your Web browser, an empty PyFR model is loaded which you can modify.
49+
The _Save_ button will export a pyfr.json file (model) which you can then be loaded later on.
50+
The _Convert_ button will export a `pyfr.ini` file for PyFR execution.
51+
52+
As no initial model was provided, the boundary names will be autogenerated.
53+
In order to pre-define those boundary names, you can either edit the generated model (pyfr.json) or
54+
start with an empty model you've created like the following one.
55+
56+
my-pyfr-model.json
57+
```js
58+
{
59+
"type": "pyfr",
60+
"data": {},
61+
"external": {
62+
"boundary-names": {
63+
"User friendly name": "value-expected-by-code",
64+
"Inlet": "inlet",
65+
"Outlet": "outlet",
66+
"External walls": "external-wall"
67+
}
68+
}
69+
}
5870
```
5971

60-
### Uninstall
61-
In the folder you ran npm link from:
62-
```
63-
$ npm unlink
72+
Then loading it back for further edits can be performed with the following command line:
73+
74+
75+
```sh
76+
$ Simput -i my-pyfr-model.json -o ~/pyfr/example
6477
```
65-
N.B: npm version >=2.4.1 is recommended for this or else you'll get an error and a warning.
6678

67-
## Demos
79+
### Demos
6880

6981
There are a few supplied demos in the folder `types`, each have their own README.
7082

83+
## Development
84+
85+
```sh
86+
$ git clone https://github.com/Kitware/tonic.git
87+
$ cd tonic
88+
$ npm run global
89+
$ npm install
90+
$ cd tonic-applications/simput
91+
$ npm link
92+
```
93+
7194
#### Licensing
7295

7396
**Simput** is licensed under [BSD Clause 3](LICENSE).

bin/converter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('shelljs/global');
2+
13
var fs = require('fs'),
24
path = require('path'),
35
home = process.env.HOME,
@@ -20,7 +22,7 @@ function unitSuffix(size) {
2022
if (size < keys[i]) {
2123
return size / Math.pow(10, Math.log10(keys[i])-3) + suffixes[keys[i]];
2224
}
23-
}
25+
}
2426
return size;
2527
}
2628

@@ -30,15 +32,15 @@ module.exports = function (input, outputDirectory) {
3032
var inputContents = JSON.parse(
3133
fs.readFileSync(input, {encoding: 'utf8'})
3234
);
33-
35+
3436
// import corresponding input type
3537
var type = inputContents.type;
3638
require(path.join(simputFolder, type + '.js'));
37-
39+
3840
// write output
3941
try {
4042
var output = GLOBAL.Simput.types[type].convert(inputContents);
41-
outputDirectory = toAbsolutePath(outputDirectory);
43+
outputDirectory = toAbsolutePath(outputDirectory);
4244
Object.keys(output.results).forEach(function(el) {
4345
fs.writeFileSync(path.join(outputDirectory, el), output.results[el]);
4446
var size = fs.statSync(path.join(outputDirectory, el)).size;

bin/simput-cli.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ if (!process.argv.slice(2).length) {
5353

5454
// inout
5555
if (program.input && program.output && !program.gui) {
56+
mkdir('-p', toAbsolutePath(program.output));
5657
simputConverter(program.input, program.output);
5758
} else if (program.compile) {
59+
mkdir('-p', toAbsolutePath(program.output));
5860
simputCompiler(toAbsolutePath(program.compile), program.type, program.output);
5961
} else if (program.output) {
6062
const app = express();
@@ -106,7 +108,7 @@ if (program.input && program.output && !program.gui) {
106108
})
107109
.post(function(req, res) {
108110
//receive new file content and update the file at program.input
109-
console.log('POST', req.body);
111+
mkdir('-p', toAbsolutePath(program.output));
110112
for (var key in req.body) {
111113
fs.writeFileSync(path.join(program.output, key), req.body[key]);
112114
}

0 commit comments

Comments
 (0)