base-queue 1.0.2 → 1.0.4
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/README.md +1 -0
- package/appenders/base.js +1 -1
- package/appenders/version.js +0 -8
- package/package.json +4 -3
- package/test/package.js +4 -3
- package/tests/json.js +119 -0
package/README.md
CHANGED
package/appenders/base.js
CHANGED
package/appenders/version.js
CHANGED
|
@@ -50,14 +50,6 @@ exports = module.exports = class version extends base {
|
|
|
50
50
|
dat = { props: { id: (i + 1), log: t.parent.logMsg } }
|
|
51
51
|
obj = t.get_objects_to_process()[i]
|
|
52
52
|
t.common_code.init({ obj: obj, dat: dat })
|
|
53
|
-
|
|
54
|
-
// is = t.get_include_version() jrm debug 2/23
|
|
55
|
-
// obj_a = new obj(dat.props)
|
|
56
|
-
// if (typeof obj_a != "undefined" &&
|
|
57
|
-
// typeof obj_a.version != "undefined" &&
|
|
58
|
-
// is.indexOf(obj_a.version) > -1) {
|
|
59
|
-
// t.main_process_objects.push(new obj(dat.props))
|
|
60
|
-
// }
|
|
61
53
|
})
|
|
62
54
|
|
|
63
55
|
super.init(props)
|
package/package.json
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
"author": {
|
|
3
3
|
"name": "Jim Manton"
|
|
4
4
|
},
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.4",
|
|
6
6
|
"bundleDependencies": [],
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"chai": "^4.3.7",
|
|
9
9
|
"colors": "^1.4.0",
|
|
10
10
|
"diffler": "^2.0.4",
|
|
11
11
|
"fs": "^0.0.1-security",
|
|
12
|
-
"log-queue": "^2.0
|
|
12
|
+
"log-queue": "^2.1.0",
|
|
13
13
|
"mocha": "^10.2.0",
|
|
14
14
|
"valid-path": "^2.1.0"
|
|
15
15
|
},
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"start": "node app.ts",
|
|
18
18
|
"test": "mocha",
|
|
19
19
|
"ditched": "ditched -a",
|
|
20
|
-
"test_base": "node ./tests/base"
|
|
20
|
+
"test_base": "node ./tests/base",
|
|
21
|
+
"json_base": "node ./tests/json"
|
|
21
22
|
},
|
|
22
23
|
"keywords": [
|
|
23
24
|
"queue",
|
package/test/package.js
CHANGED
|
@@ -6,14 +6,14 @@ const packageMock = {
|
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Jim Manton"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.4",
|
|
10
10
|
"bundleDependencies": [],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chai": "^4.3.7",
|
|
13
13
|
"colors": "^1.4.0",
|
|
14
14
|
"diffler": "^2.0.4",
|
|
15
15
|
"fs": "^0.0.1-security",
|
|
16
|
-
"log-queue": "^2.0
|
|
16
|
+
"log-queue": "^2.1.0",
|
|
17
17
|
"mocha": "^10.2.0",
|
|
18
18
|
"valid-path": "^2.1.0"
|
|
19
19
|
},
|
|
@@ -21,7 +21,8 @@ const packageMock = {
|
|
|
21
21
|
"start": "node app.ts",
|
|
22
22
|
"test": "mocha",
|
|
23
23
|
"ditched": "ditched -a",
|
|
24
|
-
"test_base": "node ./tests/base"
|
|
24
|
+
"test_base": "node ./tests/base",
|
|
25
|
+
"json_base": "node ./tests/json"
|
|
25
26
|
},
|
|
26
27
|
"keywords": [
|
|
27
28
|
"queue",
|
package/tests/json.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var file_data = [
|
|
2
|
+
{ props: { id: 100, name: "all", absolute_path: __filename, check: false } },
|
|
3
|
+
{ props: { id: 101, name: "func_all", absolute_path: __filename, check: false } },
|
|
4
|
+
{ props: { id: 102, name: "top_one", absolute_path: __filename, check: false } },
|
|
5
|
+
{ props: { id: 103, name: "bottom_one", absolute_path: __filename, check: false } },
|
|
6
|
+
{ props: { id: 104, name: "sync_all", absolute_path: __filename, check: false } },
|
|
7
|
+
{ props: { id: 105, name: "status", absolute_path: __filename, check: false } },
|
|
8
|
+
{ props: { id: 106, name: "name", absolute_path: __filename, check: false } },
|
|
9
|
+
{ props: { id: 107, name: "version", absolute_path: __filename, check: false } }
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
var file_object = class file_obj {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
let t = this, fname = "file_obj.constructor"
|
|
15
|
+
try {
|
|
16
|
+
t.id = props.id
|
|
17
|
+
t.log = props.log
|
|
18
|
+
t.name = props.name
|
|
19
|
+
t.path = props.relative_path
|
|
20
|
+
t.absolute_path = props.absolute_path
|
|
21
|
+
t.status = 'init'
|
|
22
|
+
t.errors = false
|
|
23
|
+
t.error_msg = 'none'
|
|
24
|
+
|
|
25
|
+
// if (t.id == 104) {
|
|
26
|
+
// t.errors = true
|
|
27
|
+
// t.error_msg = `some sort of error here`
|
|
28
|
+
// }
|
|
29
|
+
|
|
30
|
+
t.process = t.process.bind(t)
|
|
31
|
+
t.do_checks = t.do_checks.bind(t)
|
|
32
|
+
|
|
33
|
+
if (props.check) {
|
|
34
|
+
t.do_checks()
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
e.message = `${fname} error: ${e.message}`
|
|
38
|
+
throw e
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return t
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
do_checks() {
|
|
45
|
+
let t = this, path_to_check,
|
|
46
|
+
last_item = t.absolute_path.split("\\").pop(),
|
|
47
|
+
check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
|
|
48
|
+
|
|
49
|
+
check_file = check_file.replace(/\\/g, "/");
|
|
50
|
+
path_to_check = validPath(t.path);
|
|
51
|
+
|
|
52
|
+
if (!path_to_check.valid) {
|
|
53
|
+
t.errors = true
|
|
54
|
+
t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
check_path.map((dat, i) => {
|
|
58
|
+
if (/^[a-zA-Z._]+$/.test(dat)) {
|
|
59
|
+
if (dat != '.')
|
|
60
|
+
check_file += dat + '/'
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
check_file = check_file.slice(0, -1)
|
|
64
|
+
try {
|
|
65
|
+
if (!fs.existsSync(check_file)) {
|
|
66
|
+
t.errors = true
|
|
67
|
+
t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
e.message = "file_obj do_checks error: " + e.message
|
|
71
|
+
throw (e)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
process(callback) {
|
|
76
|
+
let t = this
|
|
77
|
+
t.log({ msg: `processing object id ${t.id}. Do a bunch of stuff here.`.silly, type: "silly" })
|
|
78
|
+
if (t.errors)
|
|
79
|
+
callback({ error: { msg: t.error_msg } })
|
|
80
|
+
else
|
|
81
|
+
callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var lq = require("log-queue"),
|
|
86
|
+
log = new lq({
|
|
87
|
+
exclude_logMsg: ["debug"], /* example ["debug", "info"] */
|
|
88
|
+
}).init({appender: "console"}),
|
|
89
|
+
a_resolve, a_reject,
|
|
90
|
+
promise = new Promise((resolve, reject) => {
|
|
91
|
+
a_resolve = resolve
|
|
92
|
+
a_reject = reject
|
|
93
|
+
}),
|
|
94
|
+
bb = require("../app.js"),
|
|
95
|
+
base_queue = new bb({
|
|
96
|
+
parent: null,
|
|
97
|
+
relative_path: "./appenders/",
|
|
98
|
+
logMsg: log.logMsg,
|
|
99
|
+
resolve: a_resolve,
|
|
100
|
+
reject: a_reject
|
|
101
|
+
}).load({
|
|
102
|
+
appender: "json_all",
|
|
103
|
+
exclude_logMsg: ["debug", "silly", "info"], /* default [] */
|
|
104
|
+
process_objects: [file_object],
|
|
105
|
+
data_to_process_array: file_data
|
|
106
|
+
}).process()
|
|
107
|
+
|
|
108
|
+
promise.then((success) => {
|
|
109
|
+
log.logMsg({ msg: `Json all object processed successfully`.success.italic.bold, type: "success" })
|
|
110
|
+
}, (error) => {
|
|
111
|
+
if (typeof error == "string") {
|
|
112
|
+
log.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
113
|
+
} else {
|
|
114
|
+
let add_s = (error.error_count > 1) ? 's' : ''
|
|
115
|
+
log.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
|