geomcli 0.5.13 → 0.5.15
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/dist/index.d.ts +7 -0
- package/dist/index.js +595 -0
- package/package.json +7 -1
- package/.eslintignore +0 -17
- package/.eslintrc.cjs +0 -24
- package/.prettierignore +0 -15
- package/.prettierrc +0 -8
- package/src/geom_cli.ts +0 -550
- package/src/geom_write.ts +0 -136
- package/src/index.test.ts +0 -16
- package/src/index.ts +0 -6
- package/tsconfig.json +0 -14
- package/vitest.config.ts +0 -7
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { tGeomFunc, tParamVal, EFormat, tAllPageDef } from 'geometrix';
|
|
2
|
+
|
|
3
|
+
declare function geom_write(iPartName: string, fgeom: tGeomFunc, simTime: number, iParam: tParamVal, iFormat: EFormat, iFace?: string, iDir?: string, iFname?: string): Promise<string>;
|
|
4
|
+
|
|
5
|
+
declare function geom_cli(iArgs: string[], dList: tAllPageDef, outDir?: string): Promise<void>;
|
|
6
|
+
|
|
7
|
+
export { geom_cli, geom_write };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
// src/geom_write.ts
|
|
2
|
+
import {
|
|
3
|
+
fileBinContent,
|
|
4
|
+
fileTextContent,
|
|
5
|
+
fileSuffix,
|
|
6
|
+
fileBin,
|
|
7
|
+
createParamFile,
|
|
8
|
+
parseParamFile
|
|
9
|
+
} from "geometrix";
|
|
10
|
+
import fs from "fs";
|
|
11
|
+
function dateString() {
|
|
12
|
+
const re1 = /[-:]/g;
|
|
13
|
+
const re2 = /\..*$/;
|
|
14
|
+
const rDateStr = (/* @__PURE__ */ new Date()).toISOString().replace(re1, "").replace(re2, "").replace("T", "_");
|
|
15
|
+
return rDateStr;
|
|
16
|
+
}
|
|
17
|
+
function createDir(iDir) {
|
|
18
|
+
let rlog = "";
|
|
19
|
+
if (!fs.existsSync(iDir)) {
|
|
20
|
+
fs.mkdirSync(iDir, { recursive: true });
|
|
21
|
+
rlog += `info203: mkdir ${iDir}
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
return rlog;
|
|
25
|
+
}
|
|
26
|
+
async function write_binFile(fName, fContent) {
|
|
27
|
+
let rlog = "";
|
|
28
|
+
const buffer = await fContent.arrayBuffer();
|
|
29
|
+
const arrBufView = new DataView(buffer);
|
|
30
|
+
fs.writeFileSync(fName, arrBufView);
|
|
31
|
+
rlog += `info304: bin-file ${fName} has been written
|
|
32
|
+
`;
|
|
33
|
+
return rlog;
|
|
34
|
+
}
|
|
35
|
+
function write_textFile(fName, fContent) {
|
|
36
|
+
let rlog = "";
|
|
37
|
+
fs.writeFileSync(fName, fContent);
|
|
38
|
+
rlog += `info405: text-file ${fName} has been written
|
|
39
|
+
`;
|
|
40
|
+
return rlog;
|
|
41
|
+
}
|
|
42
|
+
function checkDirFName(iDir, fName) {
|
|
43
|
+
const reSlash = /\//;
|
|
44
|
+
if (reSlash.test(fName)) {
|
|
45
|
+
throw `err932: the filename ${fName} contains a slash '/'`;
|
|
46
|
+
}
|
|
47
|
+
if (iDir === "") {
|
|
48
|
+
throw `err074: geom_write output-directory is an empty string!`;
|
|
49
|
+
}
|
|
50
|
+
const fName2 = `${iDir}/${fName}`;
|
|
51
|
+
return fName2;
|
|
52
|
+
}
|
|
53
|
+
function writeParams(iPartName, idparams, oDir, oFileName) {
|
|
54
|
+
const re1 = /[-:]/g;
|
|
55
|
+
const re2 = /\..*$/;
|
|
56
|
+
const datestr = (/* @__PURE__ */ new Date()).toISOString().replace(re1, "").replace(re2, "").replace("T", "_");
|
|
57
|
+
let file_name = `px_${iPartName}_${datestr}.json`;
|
|
58
|
+
if (oFileName !== "") {
|
|
59
|
+
file_name = oFileName;
|
|
60
|
+
}
|
|
61
|
+
const paramNb = Object.keys(idparams).length;
|
|
62
|
+
const fName2 = checkDirFName(oDir, file_name);
|
|
63
|
+
let rlog = `Write ${paramNb} parameters in file ${fName2}
|
|
64
|
+
`;
|
|
65
|
+
const file_content = createParamFile(datestr, idparams, "Written by geom_cli");
|
|
66
|
+
rlog += createDir(oDir);
|
|
67
|
+
write_textFile(fName2, file_content);
|
|
68
|
+
return rlog;
|
|
69
|
+
}
|
|
70
|
+
function readParams(paramPath, printLog) {
|
|
71
|
+
let rParamVal = {};
|
|
72
|
+
if (paramPath !== "") {
|
|
73
|
+
let rlog = `Read parameter file ${paramPath}
|
|
74
|
+
`;
|
|
75
|
+
if (!fs.existsSync(paramPath)) {
|
|
76
|
+
throw `err533: file ${paramPath} doesn't exist!`;
|
|
77
|
+
}
|
|
78
|
+
const fContentStr = fs.readFileSync(paramPath, "utf8");
|
|
79
|
+
const [obj] = parseParamFile(fContentStr);
|
|
80
|
+
rlog += `file lastModif: ${obj.lastModif}
|
|
81
|
+
`;
|
|
82
|
+
rlog += `file comment: ${obj.comment}
|
|
83
|
+
`;
|
|
84
|
+
rlog += `info307: ${Object.keys(obj.pVal).length} parameters from file`;
|
|
85
|
+
rParamVal = obj.pVal;
|
|
86
|
+
if (printLog) {
|
|
87
|
+
console.log(rlog);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return rParamVal;
|
|
91
|
+
}
|
|
92
|
+
async function geom_write(iPartName, fgeom, simTime, iParam, iFormat, iFace = "", iDir = ".", iFname = "") {
|
|
93
|
+
let rlog = "";
|
|
94
|
+
const fSuffix = fileSuffix(iFormat);
|
|
95
|
+
const fBin = fileBin(iFormat);
|
|
96
|
+
let nFace = "all";
|
|
97
|
+
if (iFace !== "") {
|
|
98
|
+
nFace = iFace;
|
|
99
|
+
}
|
|
100
|
+
let fName = iFname;
|
|
101
|
+
if (fName === "") {
|
|
102
|
+
fName = iPartName + "_" + nFace + "_" + dateString() + fSuffix;
|
|
103
|
+
}
|
|
104
|
+
const fName2 = checkDirFName(iDir, fName);
|
|
105
|
+
rlog += createDir(iDir);
|
|
106
|
+
if (fBin) {
|
|
107
|
+
const fContent = await fileBinContent(fgeom, simTime, iParam, iFormat);
|
|
108
|
+
rlog += await write_binFile(fName2, fContent);
|
|
109
|
+
} else {
|
|
110
|
+
const fContent = fileTextContent(fgeom, iParam, nFace, iFormat);
|
|
111
|
+
rlog += write_textFile(fName2, fContent);
|
|
112
|
+
}
|
|
113
|
+
return rlog;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/geom_cli.ts
|
|
117
|
+
import { PType, EFormat as EFormat2, designParam, prefixLog, paramListToVal } from "geometrix";
|
|
118
|
+
import yargs from "yargs";
|
|
119
|
+
import { hideBin } from "yargs/helpers";
|
|
120
|
+
|
|
121
|
+
// package.json
|
|
122
|
+
var version = "0.5.15";
|
|
123
|
+
|
|
124
|
+
// src/geom_cli.ts
|
|
125
|
+
function get_design_array(dList) {
|
|
126
|
+
const rDesignArray = Object.keys(dList);
|
|
127
|
+
return rDesignArray;
|
|
128
|
+
}
|
|
129
|
+
function selectDesign(dList, selD) {
|
|
130
|
+
if (!Object.keys(dList).includes(selD)) {
|
|
131
|
+
console.log(`err918: design ${selD} is not defined`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
return dList[selD];
|
|
135
|
+
}
|
|
136
|
+
function selectDesignN(dList, selD) {
|
|
137
|
+
const theD = selectDesign(dList, selD);
|
|
138
|
+
const dName = theD.pDef.partName;
|
|
139
|
+
return dName;
|
|
140
|
+
}
|
|
141
|
+
function parseModif(modif, printLog) {
|
|
142
|
+
const pVal = {};
|
|
143
|
+
const arrayLen = modif.length;
|
|
144
|
+
if (arrayLen % 2 === 1) {
|
|
145
|
+
throw `err903: length ${arrayLen} of modif string array is odd!`;
|
|
146
|
+
}
|
|
147
|
+
for (let i = 0; i < arrayLen / 2; i++) {
|
|
148
|
+
const valStr = modif[2 * i + 1];
|
|
149
|
+
const val = parseFloat(valStr);
|
|
150
|
+
if (isNaN(val)) {
|
|
151
|
+
throw `err908: ${valStr} is not a number!`;
|
|
152
|
+
}
|
|
153
|
+
pVal[modif[2 * i]] = val;
|
|
154
|
+
}
|
|
155
|
+
const pValLen = Object.keys(pVal).length;
|
|
156
|
+
if (printLog && pValLen > 0) {
|
|
157
|
+
const rlog = `info308: ${pValLen} parameters of modifier`;
|
|
158
|
+
console.log(rlog);
|
|
159
|
+
}
|
|
160
|
+
return pVal;
|
|
161
|
+
}
|
|
162
|
+
function computeGeom(dList, selD, paramPath, modif, printLog) {
|
|
163
|
+
const theD = selectDesign(dList, selD);
|
|
164
|
+
let rlog = `Compute design ${selD} (${theD.pDef.partName}):
|
|
165
|
+
`;
|
|
166
|
+
const dParam = designParam(theD.pDef);
|
|
167
|
+
try {
|
|
168
|
+
dParam.applyParamVal(readParams(paramPath, printLog));
|
|
169
|
+
dParam.applyParamVal(parseModif(modif, printLog));
|
|
170
|
+
} catch (emsg) {
|
|
171
|
+
console.log("err271: error while applying new parameters");
|
|
172
|
+
console.log(emsg);
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
const simtime = 0;
|
|
176
|
+
const dGeom = theD.pGeom(simtime, dParam.getParamVal());
|
|
177
|
+
rlog += prefixLog(dGeom.logstr, dParam.partName);
|
|
178
|
+
if (dGeom.calcErr) {
|
|
179
|
+
rlog += `err907: Error while computing ${theD.pDef.partName}
|
|
180
|
+
`;
|
|
181
|
+
console.log(rlog);
|
|
182
|
+
process.exit(1);
|
|
183
|
+
} else {
|
|
184
|
+
rlog += `${theD.pDef.partName} successfully computed
|
|
185
|
+
`;
|
|
186
|
+
}
|
|
187
|
+
if (printLog) {
|
|
188
|
+
console.log(rlog);
|
|
189
|
+
}
|
|
190
|
+
return dGeom;
|
|
191
|
+
}
|
|
192
|
+
function get_figure_array(dList, selD, paramPath, modif) {
|
|
193
|
+
const dGeom = computeGeom(dList, selD, paramPath, modif, false);
|
|
194
|
+
const rfigN = Object.keys(dGeom.fig);
|
|
195
|
+
return rfigN;
|
|
196
|
+
}
|
|
197
|
+
function get_subdesign_array(dList, selD, paramPath, modif) {
|
|
198
|
+
const dGeom = computeGeom(dList, selD, paramPath, modif, false);
|
|
199
|
+
const subd = dGeom.sub;
|
|
200
|
+
return subd;
|
|
201
|
+
}
|
|
202
|
+
function get_subd(dList, selD, subdN, paramPath, modif, printLog) {
|
|
203
|
+
const theD = selectDesign(dList, selD);
|
|
204
|
+
const dGeom = computeGeom(dList, selD, paramPath, modif, printLog);
|
|
205
|
+
if (!Object.keys(dGeom.sub).includes(subdN)) {
|
|
206
|
+
console.log(`err207: sub-design ${subdN} not defined in partName ${theD.pDef.partName}`);
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
const rSubd = dGeom.sub[subdN];
|
|
210
|
+
if (printLog) {
|
|
211
|
+
const rlog = `Subdesign ${subdN} (${rSubd.partName}) of ${selD} (${theD.pDef.partName}):
|
|
212
|
+
`;
|
|
213
|
+
console.log(rlog);
|
|
214
|
+
}
|
|
215
|
+
return rSubd;
|
|
216
|
+
}
|
|
217
|
+
var c_fileFormat = [
|
|
218
|
+
"json_param",
|
|
219
|
+
"svg_all_figures",
|
|
220
|
+
"dxf_all_figures",
|
|
221
|
+
"pax_all",
|
|
222
|
+
"scad_3d_openscad",
|
|
223
|
+
"js_3d_openjscad",
|
|
224
|
+
"zip_all"
|
|
225
|
+
];
|
|
226
|
+
function get_outopt_array(dList, selD, paramPath, modif) {
|
|
227
|
+
const rOutOpt = [];
|
|
228
|
+
const figN = get_figure_array(dList, selD, paramPath, modif);
|
|
229
|
+
const subdN = Object.keys(get_subdesign_array(dList, selD, paramPath, modif));
|
|
230
|
+
for (const figNi of figN) {
|
|
231
|
+
rOutOpt.push(`svg__${figNi}`);
|
|
232
|
+
}
|
|
233
|
+
for (const figNi of figN) {
|
|
234
|
+
rOutOpt.push(`dxf__${figNi}`);
|
|
235
|
+
}
|
|
236
|
+
for (const subdNi of subdN) {
|
|
237
|
+
rOutOpt.push(`json_sub_param_${subdNi}`);
|
|
238
|
+
}
|
|
239
|
+
for (const ffi of c_fileFormat) {
|
|
240
|
+
rOutOpt.push(`${ffi}`);
|
|
241
|
+
}
|
|
242
|
+
return rOutOpt;
|
|
243
|
+
}
|
|
244
|
+
function decompose_outopt(outopt) {
|
|
245
|
+
let rWrite = 2 /* eOTHERS */;
|
|
246
|
+
let rFormat = EFormat2.ePAX;
|
|
247
|
+
let rFace = "all";
|
|
248
|
+
let rSubD = "";
|
|
249
|
+
const reSvg = /^svg__/;
|
|
250
|
+
const reDxf = /^dxf__/;
|
|
251
|
+
const reSubP = /^json_sub_param_/;
|
|
252
|
+
if (outopt.match(reSvg)) {
|
|
253
|
+
rFace = outopt.replace(reSvg, "");
|
|
254
|
+
rFormat = EFormat2.eSVG;
|
|
255
|
+
rWrite = 2 /* eOTHERS */;
|
|
256
|
+
} else if (outopt.match(reDxf)) {
|
|
257
|
+
rFace = outopt.replace(reDxf, "");
|
|
258
|
+
rFormat = EFormat2.eDXF;
|
|
259
|
+
rWrite = 2 /* eOTHERS */;
|
|
260
|
+
} else if (outopt.match(reSubP)) {
|
|
261
|
+
rSubD = outopt.replace(reSubP, "");
|
|
262
|
+
rWrite = 1 /* eSUBDPARAMS */;
|
|
263
|
+
} else {
|
|
264
|
+
switch (outopt) {
|
|
265
|
+
case "json_param":
|
|
266
|
+
rWrite = 0 /* eEGOPARAMS */;
|
|
267
|
+
break;
|
|
268
|
+
case "svg_all_figures":
|
|
269
|
+
rFormat = EFormat2.eSVGALL;
|
|
270
|
+
rWrite = 2 /* eOTHERS */;
|
|
271
|
+
break;
|
|
272
|
+
case "dxf_all_figures":
|
|
273
|
+
rFormat = EFormat2.eDXFALL;
|
|
274
|
+
rWrite = 2 /* eOTHERS */;
|
|
275
|
+
break;
|
|
276
|
+
case "pax_all":
|
|
277
|
+
rFormat = EFormat2.ePAX;
|
|
278
|
+
rWrite = 2 /* eOTHERS */;
|
|
279
|
+
break;
|
|
280
|
+
case "scad_3d_openscad":
|
|
281
|
+
rFormat = EFormat2.eOPENSCAD;
|
|
282
|
+
rWrite = 2 /* eOTHERS */;
|
|
283
|
+
break;
|
|
284
|
+
case "js_3d_openjscad":
|
|
285
|
+
rFormat = EFormat2.eJSCAD;
|
|
286
|
+
rWrite = 2 /* eOTHERS */;
|
|
287
|
+
break;
|
|
288
|
+
case "zip_all":
|
|
289
|
+
rFormat = EFormat2.eZIP;
|
|
290
|
+
rWrite = 2 /* eOTHERS */;
|
|
291
|
+
break;
|
|
292
|
+
default:
|
|
293
|
+
rFormat = EFormat2.ePAX;
|
|
294
|
+
rWrite = 2 /* eOTHERS */;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const eFormat = { eWrite: rWrite, eFormat: rFormat, eFace: rFace, eSubdesign: rSubD };
|
|
298
|
+
return eFormat;
|
|
299
|
+
}
|
|
300
|
+
function list_designs(dList, detail) {
|
|
301
|
+
let rlog = "List of available designs:\n";
|
|
302
|
+
for (const [idx, dname] of get_design_array(dList).entries()) {
|
|
303
|
+
rlog += `${(idx + 1).toString().padStart(4, " ")} : ${dname}
|
|
304
|
+
`;
|
|
305
|
+
if (detail) {
|
|
306
|
+
rlog += ` ${dList[dname].pDef.partName}
|
|
307
|
+
`;
|
|
308
|
+
rlog += ` ${dList[dname].pTitle}
|
|
309
|
+
`;
|
|
310
|
+
rlog += ` ${dList[dname].pDescription}
|
|
311
|
+
`;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
console.log(rlog);
|
|
315
|
+
}
|
|
316
|
+
function list_parameters(dList, selD, paramPath, modif) {
|
|
317
|
+
const theD = selectDesign(dList, selD);
|
|
318
|
+
let rlog = `List of parameters of the design ${selD} (${theD.pDef.partName}):
|
|
319
|
+
`;
|
|
320
|
+
const dParam = designParam(theD.pDef);
|
|
321
|
+
try {
|
|
322
|
+
dParam.applyParamVal(readParams(paramPath, true));
|
|
323
|
+
dParam.applyParamVal(parseModif(modif, true));
|
|
324
|
+
} catch (emsg) {
|
|
325
|
+
console.log("err272: error while applying new parameters");
|
|
326
|
+
console.log(emsg);
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
const paramVal = dParam.getParamVal();
|
|
330
|
+
const nameLength = 20;
|
|
331
|
+
const unitLength = 8;
|
|
332
|
+
const nameLabel = "name".padEnd(nameLength, " ");
|
|
333
|
+
const unitLabel = "unit".padEnd(unitLength, " ");
|
|
334
|
+
rlog += ` # : ${nameLabel} current ${unitLabel} init min max step
|
|
335
|
+
`;
|
|
336
|
+
for (const [idx, pa] of theD.pDef.params.entries()) {
|
|
337
|
+
const idx2 = (idx + 1).toString().padStart(4, " ");
|
|
338
|
+
const pname = pa.name.padEnd(nameLength, " ");
|
|
339
|
+
const pcurr = paramVal[pa.name];
|
|
340
|
+
const pcurrP = pcurr.toString().padStart(6, " ");
|
|
341
|
+
const punit = pa.unit.padEnd(unitLength, " ");
|
|
342
|
+
const pinit = pa.init.toString().padStart(6, " ");
|
|
343
|
+
switch (pa.pType) {
|
|
344
|
+
case PType.eCheckbox:
|
|
345
|
+
rlog += `${idx2} : ${pname} checkbox ${pcurr} ${pa.init}
|
|
346
|
+
`;
|
|
347
|
+
break;
|
|
348
|
+
case PType.eDropdown:
|
|
349
|
+
rlog += `${idx2} : ${pname} ${pcurr} ${pa.init}`;
|
|
350
|
+
for (const [optI, optN] of pa.dropdown.entries()) {
|
|
351
|
+
rlog += ` ${optI}:${optN}`;
|
|
352
|
+
}
|
|
353
|
+
rlog += "\n";
|
|
354
|
+
break;
|
|
355
|
+
default:
|
|
356
|
+
rlog += `${idx2} : ${pname} ${pcurrP} ${punit} ${pinit} ${pa.min} ${pa.max} ${pa.step}
|
|
357
|
+
`;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
console.log(rlog);
|
|
361
|
+
}
|
|
362
|
+
function list_figures(dList, selD, paramPath, modif) {
|
|
363
|
+
const dPartName = selectDesignN(dList, selD);
|
|
364
|
+
const figN = get_figure_array(dList, selD, paramPath, modif);
|
|
365
|
+
let rlog = `List of figures of the design ${selD} (${dPartName}):
|
|
366
|
+
`;
|
|
367
|
+
for (const [idx, figNi] of figN.entries()) {
|
|
368
|
+
const idx2 = (idx + 1).toString().padStart(4, " ");
|
|
369
|
+
rlog += `${idx2} : ${figNi}
|
|
370
|
+
`;
|
|
371
|
+
}
|
|
372
|
+
console.log(rlog);
|
|
373
|
+
}
|
|
374
|
+
function list_subdesigns(dList, selD, paramPath, modif) {
|
|
375
|
+
const dPartName = selectDesignN(dList, selD);
|
|
376
|
+
const subdA = get_subdesign_array(dList, selD, paramPath, modif);
|
|
377
|
+
const subdN = Object.keys(subdA);
|
|
378
|
+
let rlog = `List of sub-designs of the design ${selD} (${dPartName}):
|
|
379
|
+
`;
|
|
380
|
+
for (const [idx, subdNi] of subdN.entries()) {
|
|
381
|
+
const idx2 = (idx + 1).toString().padStart(4, " ");
|
|
382
|
+
const subd = subdA[subdNi];
|
|
383
|
+
const ori = `[ ${subd.orientation[0]}, ${subd.orientation[1]}, ${subd.orientation[2]}]`;
|
|
384
|
+
const pos = `[ ${subd.position[0]}, ${subd.position[1]}, ${subd.position[2]}]`;
|
|
385
|
+
const subdNp = subdNi.padEnd(15, " ");
|
|
386
|
+
const subdPp = subd.partName.padEnd(15, " ");
|
|
387
|
+
rlog += `${idx2} : ${subdNp} ${subdPp} orientation: ${ori} position: ${pos}
|
|
388
|
+
`;
|
|
389
|
+
}
|
|
390
|
+
console.log(rlog);
|
|
391
|
+
}
|
|
392
|
+
function list_subd_parameters(dList, selD, subdN, paramPath, modif) {
|
|
393
|
+
const subdParam = get_subd(dList, selD, subdN, paramPath, modif, true).dparam;
|
|
394
|
+
const nameLength = 20;
|
|
395
|
+
const nameLabel = "name".padEnd(nameLength, " ");
|
|
396
|
+
let rlog = ` # : ${nameLabel} value init changed
|
|
397
|
+
`;
|
|
398
|
+
for (const [idx, ipaN] of Object.keys(subdParam).entries()) {
|
|
399
|
+
const idx2 = (idx + 1).toString().padStart(4, " ");
|
|
400
|
+
const paN = ipaN.padEnd(nameLength, " ");
|
|
401
|
+
const pa = subdParam[ipaN];
|
|
402
|
+
const paVal = pa.val.toString().padStart(6, " ");
|
|
403
|
+
const paInit = pa.init.toString().padStart(6, " ");
|
|
404
|
+
rlog += `${idx2} : ${paN} ${paVal} ${paInit} ${pa.chg ? "changed" : ""}
|
|
405
|
+
`;
|
|
406
|
+
}
|
|
407
|
+
console.log(rlog);
|
|
408
|
+
}
|
|
409
|
+
function list_outopt(dList, selD, paramPath, modif) {
|
|
410
|
+
const dPartName = selectDesignN(dList, selD);
|
|
411
|
+
let rlog = `List of outputs of the design ${selD} (${dPartName}):
|
|
412
|
+
`;
|
|
413
|
+
const outOpt = get_outopt_array(dList, selD, paramPath, modif);
|
|
414
|
+
for (const [idx, oneOpt] of outOpt.entries()) {
|
|
415
|
+
const idx2 = (idx + 1).toString().padStart(4, " ");
|
|
416
|
+
rlog += `${idx2} : ${oneOpt}
|
|
417
|
+
`;
|
|
418
|
+
}
|
|
419
|
+
console.log(rlog);
|
|
420
|
+
}
|
|
421
|
+
var cmd_write = false;
|
|
422
|
+
async function geom_cli(iArgs, dList, outDir = "output") {
|
|
423
|
+
const argv = yargs(hideBin(iArgs)).scriptName("geom_cli").version(version).usage("Usage: $0 <global-options> command <command-argument>").example([
|
|
424
|
+
["$0 list-designs", "list the available designs"],
|
|
425
|
+
["$0 list-designs-detailed", "list the available designs with detailed information"],
|
|
426
|
+
["$0 -d heliostat/rake compute-log", "compute and print the log"],
|
|
427
|
+
["$0 -d heliostat/swing list-outopt", "list possible output-format-options"],
|
|
428
|
+
["$0 -d heliostat/rod write zip_all", "write a zip file"]
|
|
429
|
+
]).option("design", {
|
|
430
|
+
alias: "d",
|
|
431
|
+
type: "string",
|
|
432
|
+
description: "design to be used by the command",
|
|
433
|
+
default: ""
|
|
434
|
+
}).option("param", {
|
|
435
|
+
alias: "p",
|
|
436
|
+
type: "string",
|
|
437
|
+
array: false,
|
|
438
|
+
description: "path to the input parameter file",
|
|
439
|
+
default: ""
|
|
440
|
+
}).option("modif", {
|
|
441
|
+
alias: "m",
|
|
442
|
+
nargs: 2,
|
|
443
|
+
type: "string",
|
|
444
|
+
description: "modify parameter values <paramName> <paramValue>",
|
|
445
|
+
default: ""
|
|
446
|
+
}).option("outDir", {
|
|
447
|
+
alias: "o",
|
|
448
|
+
type: "string",
|
|
449
|
+
description: "the path of the directory where to write the output files",
|
|
450
|
+
default: outDir
|
|
451
|
+
}).option("outFileName", {
|
|
452
|
+
type: "string",
|
|
453
|
+
description: "Rename the output filename",
|
|
454
|
+
default: ""
|
|
455
|
+
}).command(["list-designs", "list"], "list the available designs", {}, () => {
|
|
456
|
+
list_designs(dList, false);
|
|
457
|
+
}).command("list-designs-detailed", "list the available designs with details", {}, () => {
|
|
458
|
+
list_designs(dList, true);
|
|
459
|
+
}).command("list-parameters", "list the parameters of the selected design", {}, (argv2) => {
|
|
460
|
+
list_parameters(
|
|
461
|
+
dList,
|
|
462
|
+
argv2.design,
|
|
463
|
+
argv2.param,
|
|
464
|
+
argv2.modif
|
|
465
|
+
);
|
|
466
|
+
}).command("list-figures", "list the figures of the selected design", {}, (argv2) => {
|
|
467
|
+
list_figures(
|
|
468
|
+
dList,
|
|
469
|
+
argv2.design,
|
|
470
|
+
argv2.param,
|
|
471
|
+
argv2.modif
|
|
472
|
+
);
|
|
473
|
+
}).command("list-subdesigns", "list the subdesigns of the selected design", {}, (argv2) => {
|
|
474
|
+
list_subdesigns(
|
|
475
|
+
dList,
|
|
476
|
+
argv2.design,
|
|
477
|
+
argv2.param,
|
|
478
|
+
argv2.modif
|
|
479
|
+
);
|
|
480
|
+
}).command(
|
|
481
|
+
"list-subd-parameters <subdN>",
|
|
482
|
+
"list the parameters of subdesigns",
|
|
483
|
+
{},
|
|
484
|
+
(argv2) => {
|
|
485
|
+
list_subd_parameters(
|
|
486
|
+
dList,
|
|
487
|
+
argv2.design,
|
|
488
|
+
argv2.subdN,
|
|
489
|
+
argv2.param,
|
|
490
|
+
argv2.modif
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
).command("compute-log", "Compute and print the log without writing file", {}, (argv2) => {
|
|
494
|
+
computeGeom(
|
|
495
|
+
dList,
|
|
496
|
+
argv2.design,
|
|
497
|
+
argv2.param,
|
|
498
|
+
argv2.modif,
|
|
499
|
+
true
|
|
500
|
+
);
|
|
501
|
+
}).command(
|
|
502
|
+
"list-outopt",
|
|
503
|
+
"list the possible output format options of the selected design",
|
|
504
|
+
{},
|
|
505
|
+
(argv2) => {
|
|
506
|
+
list_outopt(
|
|
507
|
+
dList,
|
|
508
|
+
argv2.design,
|
|
509
|
+
argv2.param,
|
|
510
|
+
argv2.modif
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
).command("write <outopt>", "write the output format file", {}, () => {
|
|
514
|
+
cmd_write = true;
|
|
515
|
+
}).demandCommand(1).help().strict().parseSync();
|
|
516
|
+
if (cmd_write) {
|
|
517
|
+
const iOutDir = argv.outDir;
|
|
518
|
+
if (iOutDir === "") {
|
|
519
|
+
console.log("err638: option 'outDir' is set to empty string. Nothing written!");
|
|
520
|
+
process.exit(1);
|
|
521
|
+
}
|
|
522
|
+
const selD = argv.design;
|
|
523
|
+
const outopt = argv.outopt;
|
|
524
|
+
const paramPath = argv.param;
|
|
525
|
+
const paramModif = argv.modif;
|
|
526
|
+
const theD = selectDesign(dList, selD);
|
|
527
|
+
const outOpt = get_outopt_array(dList, selD, paramPath, paramModif);
|
|
528
|
+
if (!outOpt.includes(outopt)) {
|
|
529
|
+
console.log(`err639: outopt ${outopt} is not a valid option`);
|
|
530
|
+
process.exit(1);
|
|
531
|
+
}
|
|
532
|
+
let rlog = "";
|
|
533
|
+
const oOpt = decompose_outopt(outopt);
|
|
534
|
+
const dParam = designParam(theD.pDef);
|
|
535
|
+
try {
|
|
536
|
+
dParam.applyParamVal(readParams(paramPath, false));
|
|
537
|
+
dParam.applyParamVal(parseModif(paramModif, false));
|
|
538
|
+
} catch (emsg) {
|
|
539
|
+
console.log("err273: error while applying new parameters");
|
|
540
|
+
console.log(emsg);
|
|
541
|
+
process.exit(1);
|
|
542
|
+
}
|
|
543
|
+
computeGeom(dList, selD, paramPath, paramModif, true);
|
|
544
|
+
try {
|
|
545
|
+
if (oOpt.eWrite === 0 /* eEGOPARAMS */) {
|
|
546
|
+
rlog += writeParams(
|
|
547
|
+
dParam.partName,
|
|
548
|
+
dParam.getParamVal(),
|
|
549
|
+
iOutDir,
|
|
550
|
+
argv.outFileName
|
|
551
|
+
);
|
|
552
|
+
} else if (oOpt.eWrite === 1 /* eSUBDPARAMS */) {
|
|
553
|
+
const subD = get_subd(dList, selD, oOpt.eSubdesign, paramPath, paramModif, false);
|
|
554
|
+
rlog += writeParams(
|
|
555
|
+
subD.partName,
|
|
556
|
+
paramListToVal(subD.dparam),
|
|
557
|
+
iOutDir,
|
|
558
|
+
argv.outFileName
|
|
559
|
+
);
|
|
560
|
+
} else {
|
|
561
|
+
const simtime = 0;
|
|
562
|
+
rlog += await geom_write(
|
|
563
|
+
dParam.partName,
|
|
564
|
+
theD.pGeom,
|
|
565
|
+
simtime,
|
|
566
|
+
dParam.getParamVal(),
|
|
567
|
+
oOpt.eFormat,
|
|
568
|
+
// output-format
|
|
569
|
+
//EFormat.eSVG,
|
|
570
|
+
//EFormat.eDXF,
|
|
571
|
+
//EFormat.ePAX,
|
|
572
|
+
//EFormat.eOPENSCAD,
|
|
573
|
+
//EFormat.eJSCAD,
|
|
574
|
+
//EFormat.eZIP,
|
|
575
|
+
oOpt.eFace,
|
|
576
|
+
// selected-2d-face
|
|
577
|
+
iOutDir,
|
|
578
|
+
// output-directory
|
|
579
|
+
argv.outFileName
|
|
580
|
+
// output-filename
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
} catch (emsg) {
|
|
584
|
+
console.log("err279: error while writing file");
|
|
585
|
+
console.log(emsg);
|
|
586
|
+
process.exit(1);
|
|
587
|
+
}
|
|
588
|
+
console.log(rlog);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
export {
|
|
592
|
+
geom_cli,
|
|
593
|
+
geom_write
|
|
594
|
+
};
|
|
595
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "geomcli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.15",
|
|
4
4
|
"description": "the nodejs companion library of geometrix",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -63,6 +63,12 @@
|
|
|
63
63
|
"default": "./dist/index.js"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
+
"files": [
|
|
67
|
+
"dist",
|
|
68
|
+
"!dist/**/*.map",
|
|
69
|
+
"!dist/**/*.test.*",
|
|
70
|
+
"!dist/**/*.spec.*"
|
|
71
|
+
],
|
|
66
72
|
"types": "./dist/index.d.ts",
|
|
67
73
|
"type": "module"
|
|
68
74
|
}
|
package/.eslintignore
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
.DS_Store
|
|
2
|
-
node_modules
|
|
3
|
-
/build
|
|
4
|
-
/.svelte-kit
|
|
5
|
-
/package
|
|
6
|
-
.env
|
|
7
|
-
.env.*
|
|
8
|
-
!.env.example
|
|
9
|
-
|
|
10
|
-
# Ignore files for PNPM, NPM and YARN
|
|
11
|
-
pnpm-lock.yaml
|
|
12
|
-
package-lock.json
|
|
13
|
-
yarn.lock
|
|
14
|
-
|
|
15
|
-
# ignore recommended by eslint
|
|
16
|
-
vitest.config.ts
|
|
17
|
-
dist/
|
package/.eslintrc.cjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: [
|
|
3
|
-
'eslint:recommended',
|
|
4
|
-
'plugin:@typescript-eslint/recommended-type-checked',
|
|
5
|
-
//'plugin:@typescript-eslint/strict-type-checked',
|
|
6
|
-
'plugin:@typescript-eslint/stylistic-type-checked',
|
|
7
|
-
'prettier'
|
|
8
|
-
],
|
|
9
|
-
plugins: ['@typescript-eslint'],
|
|
10
|
-
parser: '@typescript-eslint/parser',
|
|
11
|
-
parserOptions: {
|
|
12
|
-
//sourceType: 'module',
|
|
13
|
-
//ecmaVersion: 2020,
|
|
14
|
-
project: true,
|
|
15
|
-
tsconfigRootDir: __dirname
|
|
16
|
-
},
|
|
17
|
-
root: true
|
|
18
|
-
//env: {
|
|
19
|
-
// browser: true,
|
|
20
|
-
// es2021: true,
|
|
21
|
-
// node: true
|
|
22
|
-
//},
|
|
23
|
-
//ignorePatterns: ['*.cjs'],
|
|
24
|
-
};
|
package/.prettierignore
DELETED