geomcli 0.5.12 → 0.5.14

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/src/geom_write.ts DELETED
@@ -1,136 +0,0 @@
1
- // geom_write.ts
2
-
3
- import type { tGeomFunc, tParamVal } from 'geometrix';
4
- import {
5
- EFormat,
6
- fileBinContent,
7
- fileTextContent,
8
- fileSuffix,
9
- fileBin,
10
- createParamFile,
11
- parseParamFile
12
- } from 'geometrix';
13
- import fs from 'fs';
14
-
15
- function dateString(): string {
16
- const re1 = /[-:]/g;
17
- const re2 = /\..*$/;
18
- const rDateStr = new Date().toISOString().replace(re1, '').replace(re2, '').replace('T', '_');
19
- return rDateStr;
20
- }
21
-
22
- function createDir(iDir: string): string {
23
- let rlog = '';
24
- if (!fs.existsSync(iDir)) {
25
- fs.mkdirSync(iDir, { recursive: true });
26
- rlog += `info203: mkdir ${iDir}\n`;
27
- }
28
- return rlog;
29
- }
30
-
31
- async function write_binFile(fName: string, fContent: Blob): Promise<string> {
32
- let rlog = '';
33
- const buffer = await fContent.arrayBuffer();
34
- const arrBufView = new DataView(buffer);
35
- fs.writeFileSync(fName, arrBufView);
36
- rlog += `info304: bin-file ${fName} has been written\n`;
37
- return rlog;
38
- }
39
-
40
- function write_textFile(fName: string, fContent: string): string {
41
- let rlog = '';
42
- fs.writeFileSync(fName, fContent);
43
- rlog += `info405: text-file ${fName} has been written\n`;
44
- return rlog;
45
- }
46
-
47
- function checkDirFName(iDir: string, fName: string): string {
48
- const reSlash = /\//;
49
- if (reSlash.test(fName)) {
50
- throw `err932: the filename ${fName} contains a slash '/'`;
51
- }
52
- if (iDir === '') {
53
- throw `err074: geom_write output-directory is an empty string!`;
54
- }
55
- const fName2 = `${iDir}/${fName}`;
56
- return fName2;
57
- }
58
-
59
- function writeParams(
60
- iPartName: string,
61
- idparams: tParamVal,
62
- oDir: string,
63
- oFileName: string
64
- ): string {
65
- const re1 = /[-:]/g;
66
- const re2 = /\..*$/;
67
- const datestr = new Date().toISOString().replace(re1, '').replace(re2, '').replace('T', '_');
68
- let file_name = `px_${iPartName}_${datestr}.json`;
69
- if (oFileName !== '') {
70
- file_name = oFileName;
71
- }
72
- const paramNb = Object.keys(idparams).length;
73
- const fName2 = checkDirFName(oDir, file_name);
74
- let rlog = `Write ${paramNb} parameters in file ${fName2}\n`;
75
- const file_content = createParamFile(datestr, idparams, 'Written by geom_cli');
76
- rlog += createDir(oDir);
77
- write_textFile(fName2, file_content);
78
- return rlog;
79
- }
80
-
81
- function readParams(paramPath: string, printLog: boolean): tParamVal {
82
- let rParamVal: tParamVal = {};
83
- if (paramPath !== '') {
84
- let rlog = `Read parameter file ${paramPath}\n`;
85
- if (!fs.existsSync(paramPath)) {
86
- throw `err533: file ${paramPath} doesn't exist!`;
87
- }
88
- const fContentStr = fs.readFileSync(paramPath, 'utf8');
89
- const [obj] = parseParamFile(fContentStr);
90
- //const [obj, tlog] = parseParamFile(fContentStr);
91
- //rlog += tlog;
92
- rlog += `file lastModif: ${obj.lastModif}\n`;
93
- rlog += `file comment: ${obj.comment}\n`;
94
- rlog += `info307: ${Object.keys(obj.pVal).length} parameters from file`;
95
- rParamVal = obj.pVal;
96
- if (printLog) {
97
- console.log(rlog);
98
- }
99
- }
100
- return rParamVal;
101
- }
102
-
103
- async function geom_write(
104
- iPartName: string,
105
- fgeom: tGeomFunc,
106
- simTime: number,
107
- iParam: tParamVal,
108
- iFormat: EFormat,
109
- iFace = '',
110
- iDir = '.',
111
- iFname = ''
112
- ): Promise<string> {
113
- let rlog = '';
114
- const fSuffix = fileSuffix(iFormat);
115
- const fBin = fileBin(iFormat);
116
- let nFace = 'all';
117
- if (iFace !== '') {
118
- nFace = iFace;
119
- }
120
- let fName = iFname;
121
- if (fName === '') {
122
- fName = iPartName + '_' + nFace + '_' + dateString() + fSuffix;
123
- }
124
- const fName2 = checkDirFName(iDir, fName);
125
- rlog += createDir(iDir);
126
- if (fBin) {
127
- const fContent = await fileBinContent(fgeom, simTime, iParam, iFormat);
128
- rlog += await write_binFile(fName2, fContent);
129
- } else {
130
- const fContent = fileTextContent(fgeom, iParam, nFace, iFormat);
131
- rlog += write_textFile(fName2, fContent);
132
- }
133
- return rlog;
134
- }
135
-
136
- export { geom_write, writeParams, readParams };
package/src/index.test.ts DELETED
@@ -1,16 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { geom_cli } from './index';
3
- import type { tAllPageDef } from 'geometrix';
4
-
5
- import { heliostatDef, swingDef } from 'designix';
6
-
7
- const designList: tAllPageDef = {
8
- 'heliostat/heliostat': heliostatDef,
9
- 'heliostat/swing': swingDef
10
- };
11
-
12
- describe('geomcli index suit', () => {
13
- it('geom_cli', async () => {
14
- await expect(geom_cli(['node', 'dummy', 'list'], designList)).resolves.toBeUndefined();
15
- });
16
- });
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- // geomcli index.ts
2
-
3
- import { geom_write } from './geom_write';
4
- import { geom_cli } from './geom_cli';
5
-
6
- export { geom_write, geom_cli };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "esnext",
5
- "outDir": "./build",
6
- "esModuleInterop": true,
7
- "resolveJsonModule": true,
8
- "moduleResolution": "bundler",
9
- "declaration": true,
10
- "sourceMap": true,
11
- "strict": true
12
- },
13
- "include": ["./src"]
14
- }
package/vitest.config.ts DELETED
@@ -1,7 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ['src/**/*.{test,spec}.{js,ts}']
6
- }
7
- });