nv-cli-creat-mach-proj 1.0.0
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/creat-input.js +50 -0
- package/index.js +16 -0
- package/load-acts-from-dir.js +32 -0
- package/load-handles-from-dir.js +33 -0
- package/make-cfg.js +16 -0
- package/make-one-stt-subdir.js +36 -0
- package/package.json +17 -0
package/creat-input.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const load_acts_code = require("./load-acts-from-dir");
|
|
2
|
+
const load_handles_code = require("./load-handles-from-dir");
|
|
3
|
+
const creat_sttsw = require("nv-cli-creat-mach-proj-cmmn").cr_stt_sw;
|
|
4
|
+
const _ison = require("nvison-bw");
|
|
5
|
+
const _fs = require("fs");
|
|
6
|
+
const _path = require("path");
|
|
7
|
+
|
|
8
|
+
module.exports = (
|
|
9
|
+
INPUT_TMPL_FILE_OR_INPUT_TMPL,
|
|
10
|
+
STTENUM_FILE_OR_STTENUM,
|
|
11
|
+
HIENUM_FILE_OR_HIENUM,
|
|
12
|
+
ACT_DIR_OR_ACTS,
|
|
13
|
+
HANDLE_DIR_OR_HANDLES,
|
|
14
|
+
ncfg,
|
|
15
|
+
depth=2
|
|
16
|
+
) => {
|
|
17
|
+
let STTENUM;
|
|
18
|
+
if(typeof(STTENUM_FILE_OR_STTENUM) === "string") {
|
|
19
|
+
STTENUM = _ison.parse_from_str(_fs.readFileSync(_path.resolve(STTENUM_FILE_OR_STTENUM)).toString());
|
|
20
|
+
} else {
|
|
21
|
+
STTENUM = STTENUM_FILE_OR_STTENUM;
|
|
22
|
+
}
|
|
23
|
+
let HIENUM;
|
|
24
|
+
if(typeof(HIENUM_FILE_OR_HIENUM) === "string") {
|
|
25
|
+
HIENUM = _ison.parse_from_str(_fs.readFileSync(_path.resolve(HIENUM_FILE_OR_HIENUM)).toString());
|
|
26
|
+
} else {
|
|
27
|
+
HIENUM = HIENUM_FILE_OR_HIENUM;
|
|
28
|
+
}
|
|
29
|
+
let ACTS;
|
|
30
|
+
if(typeof(ACT_DIR_OR_ACTS) === "string") {
|
|
31
|
+
ACTS = JSON.parse(load_acts_code(STTENUM,HIENUM,ncfg,ACT_DIR_OR_ACTS))
|
|
32
|
+
} else {
|
|
33
|
+
ACTS = ACT_DIR_OR_ACTS;
|
|
34
|
+
}
|
|
35
|
+
let HANDLES;
|
|
36
|
+
if(typeof(HANDLE_DIR_OR_HANDLES) === "string") {
|
|
37
|
+
HANDLES = JSON.parse(load_handles_code(HANDLE_DIR_OR_HANDLES))
|
|
38
|
+
} else {
|
|
39
|
+
HANDLES = HANDLE_DIR_OR_HANDLES;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let sw = creat_sttsw(STTENUM,HIENUM,ACTS,HANDLES,ncfg,depth);
|
|
43
|
+
let TMPL;
|
|
44
|
+
if(_fs.existsSync(INPUT_TMPL_FILE_OR_INPUT_TMPL)) {
|
|
45
|
+
TMPL = _fs.readFileSync(_path.resolve(INPUT_TMPL_FILE_OR_INPUT_TMPL)).toString();
|
|
46
|
+
} else {
|
|
47
|
+
TMPL= INPUT_TMPL_FILE_OR_INPUT_TMPL;
|
|
48
|
+
}
|
|
49
|
+
return TMPL.replace("@SW@",sw);
|
|
50
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const mkcfg = require("./make-cfg");
|
|
2
|
+
const mk_one_stt_dir = require("./make-one-stt-subdir");
|
|
3
|
+
|
|
4
|
+
const creat_input = require("./creat-input");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module.exports = ({input,stt,hi,acts,handles,cfg,depth})=> {
|
|
8
|
+
depth = depth??2;
|
|
9
|
+
return creat_input(input,stt,hi,acts,handles,cfg,depth);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
module.exports.mkcfg = mkcfg;
|
|
14
|
+
module.exports.mk_one_stt_dir = mk_one_stt_dir;
|
|
15
|
+
module.exports.creat_input = creat_input;
|
|
16
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const _fs = require("fs");
|
|
2
|
+
const _path = require("path");
|
|
3
|
+
const {apend_fmt_sary} = require("nv-string-basic");
|
|
4
|
+
const {simple_all_files} = require("nv-file-sync-reader");
|
|
5
|
+
const creat_one_act = require("nv-cli-creat-mach-proj-cmmn").cr_one_act;
|
|
6
|
+
|
|
7
|
+
module.exports = (STTENUM,HIENUM,ncfg,dir="./")=>{
|
|
8
|
+
let actsdir = _path.resolve(dir);
|
|
9
|
+
let fns = simple_all_files(actsdir);
|
|
10
|
+
let ks = [];
|
|
11
|
+
let vs = [];
|
|
12
|
+
for(let e of fns) {
|
|
13
|
+
let key = e.name;
|
|
14
|
+
if(key !== "package") {
|
|
15
|
+
let code = _fs.readFileSync(e.path).toString().trim();
|
|
16
|
+
code = creat_one_act(STTENUM,HIENUM,ncfg,code);
|
|
17
|
+
vs.push(JSON.stringify(code));
|
|
18
|
+
ks.push(" "+JSON.stringify(key))
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
ks = apend_fmt_sary(ks);
|
|
22
|
+
let codes = ["{"];
|
|
23
|
+
for(let i=0;i<ks.length-1;++i) {
|
|
24
|
+
codes.push(`${ks[i]} : ${vs[i]},`)
|
|
25
|
+
}
|
|
26
|
+
if(ks.length>0){
|
|
27
|
+
codes.push(`${ks[ks.length-1]} : ${vs[ks.length-1]}`)
|
|
28
|
+
}
|
|
29
|
+
codes.push("}");
|
|
30
|
+
return codes.join("\n")+"\n";
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const _fs = require("fs");
|
|
2
|
+
const _path = require("path");
|
|
3
|
+
const {simple_all_files,simple_all_dirs} = require("nv-file-sync-reader");
|
|
4
|
+
const _ison = require("nvison-bw");
|
|
5
|
+
|
|
6
|
+
module.exports = (dir="./")=>{
|
|
7
|
+
dir = _path.resolve(dir);
|
|
8
|
+
let fns = simple_all_dirs(dir);
|
|
9
|
+
fns.shift();
|
|
10
|
+
let d = {};
|
|
11
|
+
for(let e of fns) {
|
|
12
|
+
let stt = e.name;
|
|
13
|
+
let his = {};
|
|
14
|
+
d[stt] = his;
|
|
15
|
+
let all = simple_all_files(e.path);
|
|
16
|
+
for(let ee of all) {
|
|
17
|
+
let hinm = ee.name;
|
|
18
|
+
let cfg = _fs.readFileSync(ee.path).toString().trim();
|
|
19
|
+
his[hinm] = _ison.parse_from_str(cfg);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let dflt = _path.join(dir,"default.js");
|
|
23
|
+
if(_fs.existsSync(dflt)) {
|
|
24
|
+
d["default"] = _ison.parse_from_str(_fs.readFileSync(dflt).toString().trim())
|
|
25
|
+
}
|
|
26
|
+
return JSON.stringify(d,null,2);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if(module.id === ".") {
|
|
30
|
+
let dir = _path.resolve(process.argv[2]??"./");
|
|
31
|
+
console.log(module.exports(dir));
|
|
32
|
+
} else {
|
|
33
|
+
}
|
package/make-cfg.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const _fs = require("fs");
|
|
2
|
+
const _path = require("path");
|
|
3
|
+
|
|
4
|
+
const DFLT = JSON.stringify({
|
|
5
|
+
SELF : "this",
|
|
6
|
+
REF : "ref_str",
|
|
7
|
+
HA : "ha",
|
|
8
|
+
I : "i",
|
|
9
|
+
CD : "cd",
|
|
10
|
+
},null,2);
|
|
11
|
+
|
|
12
|
+
module.exports= (dir="./")=>{
|
|
13
|
+
dir = _path.resolve(dir);
|
|
14
|
+
let fn = _path.join(dir,"cfg.json");
|
|
15
|
+
_fs.writeFileSync(fn,DFLT)
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const _fs = require("fs");
|
|
2
|
+
const _path = require("path");
|
|
3
|
+
|
|
4
|
+
module.exports = (sttnm,HIENUM_FILE_OR_HIENUM,dir="./")=> {
|
|
5
|
+
|
|
6
|
+
let HIENUM;
|
|
7
|
+
if(typeof(HIENUM_FILE_OR_STTENUM) === "string") {
|
|
8
|
+
HIENUM = _ison.parse_from_str(_fs.readFileSync(_path.resolve(HIENUM_FILE_OR_STTENUM)).toString());
|
|
9
|
+
} else {
|
|
10
|
+
HIENUM = HIENUM_FILE_OR_STTENUM;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let sttdir = _path.join(_path.resolve(dir),sttnm);
|
|
14
|
+
if(_fs.existsSync(sttdir)) {
|
|
15
|
+
} else {
|
|
16
|
+
_fs.mkdirSync(sttdir,{recursive:true});
|
|
17
|
+
}
|
|
18
|
+
for(let nm in HIENUM) {
|
|
19
|
+
let fn = _path.join(sttdir,nm+".js");
|
|
20
|
+
if(_fs.existsSync(fn)) {
|
|
21
|
+
console.warn(`${fn} ALREADY EXISTS`);
|
|
22
|
+
} else {
|
|
23
|
+
let content = {acts:[],nstt:null,adv:1}
|
|
24
|
+
_fs.writeFileSync(fn,JSON.stringify(content,null,2));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
{
|
|
28
|
+
let fn = _path.join(sttdir,"default.js");
|
|
29
|
+
if(_fs.existsSync(fn)) {
|
|
30
|
+
console.warn(`${fn} ALREADY EXISTS`);
|
|
31
|
+
} else {
|
|
32
|
+
let content = {acts:[],nstt:null,adv:1}
|
|
33
|
+
_fs.writeFileSync(fn,JSON.stringify(content,null,2));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nv-cli-creat-mach-proj",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"description": "",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"nv-cli-creat-mach-proj-cmmn": "^1.0.0",
|
|
13
|
+
"nv-file-sync-reader": "^1.0.17",
|
|
14
|
+
"nv-string-basic": "^1.0.56",
|
|
15
|
+
"nvison-bw": "^1.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|