file-obj-queue 3.0.0 → 3.0.1
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/.github/workflows/{github-actions.yml → github-actions-demo.yml} +1 -1
- package/.github/workflows/node.js.yml +0 -1
- package/LICENSE +1 -1
- package/README.md +7 -132
- package/app.js +40 -155
- package/base_queue/app.js +146 -0
- package/base_queue/appenders/base.js +77 -0
- package/base_queue/appenders/json_all.js +70 -0
- package/package.json +7 -28
- package/test/app.js +1 -5
- package/test/package.js +7 -28
- package/tests/appenders/all.js +1 -1
- package/tests/appenders/base.js +1 -1
- package/tests/appenders/bottom_one.js +1 -1
- package/tests/appenders/func_all.js +1 -1
- package/tests/appenders/sync.js +1 -1
- package/tests/appenders/sync_all.js +1 -1
- package/tests/appenders/top_one.js +1 -1
- package/tests/appenders/version.js +1 -1
- package/tests/files.js +32 -50
- package/lib/appenders/all.js +0 -17
- package/lib/appenders/base.js +0 -189
- package/lib/appenders/bottom_one.js +0 -17
- package/lib/appenders/func_all.js +0 -17
- package/lib/appenders/name.js +0 -17
- package/lib/appenders/status.js +0 -17
- package/lib/appenders/sync.js +0 -17
- package/lib/appenders/sync_all.js +0 -17
- package/lib/appenders/top_one.js +0 -17
- package/lib/appenders/version.js +0 -17
- package/tests/all.js +0 -85
- package/tests/bottom_one.js +0 -86
- package/tests/func_all.js +0 -94
- package/tests/json_all.js +0 -107
- package/tests/json_bottom_one.js +0 -108
- package/tests/json_func_all.js +0 -109
- package/tests/json_name_matching.js +0 -109
- package/tests/json_name_non_matching.js +0 -109
- package/tests/json_status_matching.js +0 -110
- package/tests/json_status_non_matching.js +0 -110
- package/tests/json_top_one.js +0 -108
- package/tests/json_version_matching.js +0 -110
- package/tests/json_version_non_matching.js +0 -110
- package/tests/name_matching.js +0 -90
- package/tests/name_non_matching.js +0 -90
- package/tests/status_matching.js +0 -90
- package/tests/status_non_matching.js +0 -90
- package/tests/top_one.js +0 -85
- package/tests/version_matching.js +0 -90
- package/tests/version_non_matching.js +0 -90
package/lib/appenders/version.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
-
* @since 2023-2-5
|
|
4
|
-
* lib/appenders/status.js
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var base = require('./base.js')
|
|
8
|
-
|
|
9
|
-
exports = module.exports = class version extends base {
|
|
10
|
-
constructor(props) {
|
|
11
|
-
super(props)
|
|
12
|
-
var t = this
|
|
13
|
-
t.aname = 'version'
|
|
14
|
-
t.pro_types = ['version']
|
|
15
|
-
return t
|
|
16
|
-
}
|
|
17
|
-
}
|
package/tests/all.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
var queue = require("../app.js")
|
|
2
|
-
|
|
3
|
-
var tst1 = class test1 {
|
|
4
|
-
constructor(props) {
|
|
5
|
-
let t = this, fname = "test_all.test1.constructor"
|
|
6
|
-
t.log = props.log
|
|
7
|
-
t.id = props.id
|
|
8
|
-
|
|
9
|
-
t.process = t.process.bind(t)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
process(callback) {
|
|
13
|
-
let t = this, fname = "test_all.test1.process"
|
|
14
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
15
|
-
callback({ success: { msg: `processing all test1` } })
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var tst2 = class test2 {
|
|
20
|
-
constructor(props) {
|
|
21
|
-
let t = this, fname = "test_all.test2.constructor"
|
|
22
|
-
t.log = props.log
|
|
23
|
-
t.id = props.id
|
|
24
|
-
|
|
25
|
-
t.process = t.process.bind(t)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
process(callback) {
|
|
29
|
-
let t = this, fname = "test_all.test2.process"
|
|
30
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
callback({ success: { msg: `processing all test2` } })
|
|
33
|
-
}, 4000)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var tst3 = class test3 {
|
|
38
|
-
constructor(props) {
|
|
39
|
-
let t = this, fname = "test_all.test3.constructor"
|
|
40
|
-
t.log = props.log
|
|
41
|
-
t.id = props.id
|
|
42
|
-
|
|
43
|
-
t.process = t.process.bind(t)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
process(callback) {
|
|
47
|
-
let t = this, fname = "test_all.test3.process"
|
|
48
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
49
|
-
// callback({success: { msg: `processing all test3` }})
|
|
50
|
-
callback({ error: { msg: `there is some problem thrown here on test3` } })
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var tst4 = class test4 {
|
|
55
|
-
constructor(props) {
|
|
56
|
-
let t = this, fname = "test_all.test4.constructor"
|
|
57
|
-
t.log = props.log
|
|
58
|
-
t.id = props.id
|
|
59
|
-
|
|
60
|
-
t.process = t.process.bind(t)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
process(callback) {
|
|
64
|
-
let t = this, fname = "test_all.test4.process"
|
|
65
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
66
|
-
callback({ success: { msg: `processing all test4` } })
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
var qObj = new queue()
|
|
71
|
-
|
|
72
|
-
qObj.init().process({
|
|
73
|
-
appender: "all",
|
|
74
|
-
exclude_logMsg: ["debug"], /* example ["debug", "info"] */
|
|
75
|
-
process_objects: [tst1, tst2, tst3, tst4]
|
|
76
|
-
}).then((success) => {
|
|
77
|
-
qObj.logMsg({ msg: `test success: {msg: "all objects processed with no errors"}`.success.italic.bold, type: "success" })
|
|
78
|
-
}, (error) => {
|
|
79
|
-
if (typeof error == "string") {
|
|
80
|
-
qObj.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
81
|
-
} else {
|
|
82
|
-
let add_s = (error.error_count > 1) ? 's' : ''
|
|
83
|
-
qObj.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
84
|
-
}
|
|
85
|
-
})
|
package/tests/bottom_one.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
var queue = require("../app.js")
|
|
2
|
-
|
|
3
|
-
var tst1 = class test1 {
|
|
4
|
-
constructor(props) {
|
|
5
|
-
let t = this, fname = "test_bottom_one.test1.constructor"
|
|
6
|
-
t.log = props.log
|
|
7
|
-
t.id = props.id
|
|
8
|
-
|
|
9
|
-
t.process = t.process.bind(t)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
process(callback) {
|
|
13
|
-
let t = this, fname = "test_bottom_one.test1.process"
|
|
14
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
15
|
-
callback({ success: { msg: `processing all test1` } })
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var tst2 = class test2 {
|
|
20
|
-
constructor(props) {
|
|
21
|
-
let t = this, fname = "test_bottom_one.test2.constructor"
|
|
22
|
-
t.log = props.log
|
|
23
|
-
t.id = props.id
|
|
24
|
-
|
|
25
|
-
t.process = t.process.bind(t)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
process(callback) {
|
|
29
|
-
let t = this, fname = "test_bottom_one.test2.process"
|
|
30
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
callback({ success: { msg: `processing all test2` } })
|
|
33
|
-
}, 4000)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var tst3 = class test3 {
|
|
38
|
-
constructor(props) {
|
|
39
|
-
let t = this, fname = "test_bottom_one.test3.constructor"
|
|
40
|
-
t.log = props.log
|
|
41
|
-
t.id = props.id
|
|
42
|
-
|
|
43
|
-
t.process = t.process.bind(t)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
process(callback) {
|
|
47
|
-
let t = this, fname = "test_bottom_one.test3.process"
|
|
48
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
49
|
-
// callback({success: { msg: `processing all test3` }})
|
|
50
|
-
callback({ error: { msg: `there is some problem thrown here on test3` } })
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var tst4 = class test4 {
|
|
55
|
-
constructor(props) {
|
|
56
|
-
let t = this, fname = "test_bottom_one.test4.constructor"
|
|
57
|
-
t.log = props.log
|
|
58
|
-
t.id = props.id
|
|
59
|
-
|
|
60
|
-
t.process = t.process.bind(t)
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
process(callback) {
|
|
65
|
-
let t = this, fname = "test_bottom_one.test4.process"
|
|
66
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
67
|
-
callback({ success: { msg: `processing all test4` } })
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
var qObj = new queue()
|
|
72
|
-
|
|
73
|
-
qObj.init().process({
|
|
74
|
-
appender: "bottom_one",
|
|
75
|
-
exclude_logMsg: ["debug"], /* example ["debug", "info"] */
|
|
76
|
-
process_objects: [tst1, tst2, tst3, tst4]
|
|
77
|
-
}).then((success) => {
|
|
78
|
-
qObj.logMsg({ msg: `test success: {msg: "bottom_one object processed with no errors"}`.success.italic.bold, type: "success" })
|
|
79
|
-
}, (error) => {
|
|
80
|
-
if (typeof error == "string") {
|
|
81
|
-
qObj.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
82
|
-
} else {
|
|
83
|
-
let add_s = (error.error_count > 1) ? 's' : ''
|
|
84
|
-
qObj.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
85
|
-
}
|
|
86
|
-
})
|
package/tests/func_all.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
var queue = require("../app.js")
|
|
2
|
-
|
|
3
|
-
var tst1 = class test1 {
|
|
4
|
-
constructor(props) {
|
|
5
|
-
let t = this, fname = "test_all.test1.constructor"
|
|
6
|
-
t.log = props.log
|
|
7
|
-
t.id = props.id
|
|
8
|
-
t.base_queue_process_function = t.custom_function
|
|
9
|
-
|
|
10
|
-
t.custom_function = t.custom_function.bind(t)
|
|
11
|
-
t.base_queue_process_function = t.base_queue_process_function.bind(t)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
custom_function(callback) {
|
|
15
|
-
let t = this, fname = "test_all.test1.custom_function"
|
|
16
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
17
|
-
callback({ success: { msg: `processing all test1` } })
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
var tst2 = class test2 {
|
|
22
|
-
constructor(props) {
|
|
23
|
-
let t = this, fname = "test_all.test2.constructor"
|
|
24
|
-
t.log = props.log
|
|
25
|
-
t.id = props.id
|
|
26
|
-
t.base_queue_process_function = t.another_function
|
|
27
|
-
|
|
28
|
-
t.another_function = t.another_function.bind(t)
|
|
29
|
-
t.base_queue_process_function = t.base_queue_process_function.bind(t)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
another_function(callback) {
|
|
33
|
-
let t = this, fname = "test_all.test2.another_function"
|
|
34
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
35
|
-
// callback({ success: { msg: `processing all test2` } })
|
|
36
|
-
setTimeout(() => {
|
|
37
|
-
callback({ success: { msg: `processing all test2` } })
|
|
38
|
-
}, 4000)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var tst3 = class test3 {
|
|
43
|
-
constructor(props) {
|
|
44
|
-
let t = this, fname = "test_all.test3.constructor"
|
|
45
|
-
t.log = props.log
|
|
46
|
-
t.id = props.id
|
|
47
|
-
t.base_queue_process_function = t.third_test
|
|
48
|
-
|
|
49
|
-
t.third_test = t.third_test.bind(t)
|
|
50
|
-
t.base_queue_process_function = t.base_queue_process_function.bind(t)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
third_test(callback) {
|
|
54
|
-
let t = this, fname = "test_all.test3.third_test"
|
|
55
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
56
|
-
// callback({success: { msg: `processing all test3` }})
|
|
57
|
-
callback({ error: { msg: `there is some problem thrown here on test3` } })
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var tst4 = class test4 {
|
|
62
|
-
constructor(props) {
|
|
63
|
-
let t = this, fname = "test_all.test4.constructor"
|
|
64
|
-
t.log = props.log
|
|
65
|
-
t.id = props.id
|
|
66
|
-
t.base_queue_process_function = t.last_shot
|
|
67
|
-
|
|
68
|
-
t.last_shot = t.last_shot.bind(t)
|
|
69
|
-
t.base_queue_process_function = t.base_queue_process_function.bind(t)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
last_shot(callback) {
|
|
73
|
-
let t = this, fname = "test_all.test4.process"
|
|
74
|
-
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
75
|
-
callback({ success: { msg: `processing all test4` } })
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var qObj = new queue()
|
|
80
|
-
|
|
81
|
-
qObj.init().process({
|
|
82
|
-
appender: "func_all",
|
|
83
|
-
exclude_logMsg: ["debug"], /* example ["debug", "info"] */
|
|
84
|
-
process_objects: [tst1, tst2, tst3, tst4],
|
|
85
|
-
}).then((success) => {
|
|
86
|
-
qObj.logMsg({ msg: `test success: {msg: "func_all objects processed with no errors"}`.success.italic.bold, type: "success" })
|
|
87
|
-
}, (error) => {
|
|
88
|
-
if (typeof error == "string") {
|
|
89
|
-
qObj.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
90
|
-
} else {
|
|
91
|
-
let add_s = (error.error_count > 1) ? 's' : ''
|
|
92
|
-
qObj.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
93
|
-
}
|
|
94
|
-
})
|
package/tests/json_all.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
var file_queue = require("../app.js"),
|
|
2
|
-
fs = require('fs'),
|
|
3
|
-
validPath = require('valid-path')
|
|
4
|
-
|
|
5
|
-
var file_data = [
|
|
6
|
-
{ props: { id: 100, name: "all", absolute_path: __filename, check: true } },
|
|
7
|
-
{ props: { id: 101, name: "func_all", absolute_path: __filename, check: true } },
|
|
8
|
-
{ props: { id: 102, name: "top_one", absolute_path: __filename, check: true } },
|
|
9
|
-
{ props: { id: 103, name: "bottom_one", absolute_path: __filename, check: true } },
|
|
10
|
-
{ props: { id: 104, name: "sync_all", absolute_path: __filename, check: true } },
|
|
11
|
-
{ props: { id: 105, name: "status", absolute_path: __filename, check: true } },
|
|
12
|
-
{ props: { id: 106, name: "name", absolute_path: __filename, check: true } },
|
|
13
|
-
{ props: { id: 107, name: "version", absolute_path: __filename, check: true } }
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
var file_object = class file_obj {
|
|
17
|
-
constructor(props) {
|
|
18
|
-
let t = this, fname = "file_obj.constructor"
|
|
19
|
-
try {
|
|
20
|
-
t.id = props.id
|
|
21
|
-
t.log = props.log
|
|
22
|
-
t.name = props.name
|
|
23
|
-
t.path = props.relative_path
|
|
24
|
-
t.absolute_path = props.absolute_path
|
|
25
|
-
t.status = 'init'
|
|
26
|
-
t.errors = false
|
|
27
|
-
t.error_msg = 'none'
|
|
28
|
-
|
|
29
|
-
// if (t.id == 104) {
|
|
30
|
-
// t.errors = true
|
|
31
|
-
// t.error_msg = `some sort of error here`
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
t.process = t.process.bind(t)
|
|
35
|
-
t.do_checks = t.do_checks.bind(t)
|
|
36
|
-
|
|
37
|
-
if (props.check) {
|
|
38
|
-
t.do_checks()
|
|
39
|
-
}
|
|
40
|
-
} catch (e) {
|
|
41
|
-
e.message = `${fname} error: ${e.message}`
|
|
42
|
-
throw e
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return t
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
do_checks() {
|
|
49
|
-
let t = this, path_to_check,
|
|
50
|
-
last_item = t.absolute_path.split("\\").pop(),
|
|
51
|
-
check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
|
|
52
|
-
|
|
53
|
-
check_file = check_file.replace(/\\/g, "/");
|
|
54
|
-
path_to_check = validPath(t.path);
|
|
55
|
-
|
|
56
|
-
if (!path_to_check.valid) {
|
|
57
|
-
t.errors = true
|
|
58
|
-
t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
check_path.map((dat, i) => {
|
|
62
|
-
if (/^[a-zA-Z._]+$/.test(dat)) {
|
|
63
|
-
if (dat != '.')
|
|
64
|
-
check_file += dat + '/'
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
check_file = check_file.slice(0, -1)
|
|
68
|
-
try {
|
|
69
|
-
if (!fs.existsSync(check_file)) {
|
|
70
|
-
t.errors = true
|
|
71
|
-
t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
|
|
72
|
-
}
|
|
73
|
-
} catch (e) {
|
|
74
|
-
e.message = "file_obj do_checks error: " + e.message
|
|
75
|
-
throw (e)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
process(callback) {
|
|
80
|
-
let t = this
|
|
81
|
-
t.log({ msg: `processing object id ${t.id}. Do a bunch of stuff here.`.silly, type: "silly" })
|
|
82
|
-
if (t.errors)
|
|
83
|
-
callback({ error: { msg: t.error_msg } })
|
|
84
|
-
else
|
|
85
|
-
callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
var qRequire = new file_queue()
|
|
90
|
-
|
|
91
|
-
qRequire.init().process({
|
|
92
|
-
appender: "json_all",
|
|
93
|
-
exclude_logMsg: ["debug", "silly", "info"], /* default [] */
|
|
94
|
-
process_objects: [file_object],
|
|
95
|
-
data_to_process_array: file_data
|
|
96
|
-
}).then((success) => {
|
|
97
|
-
qRequire.logMsg({ msg: `test success: json_all objects processed with no errors`.success.italic.bold, type: "success" })
|
|
98
|
-
}, (error) => {
|
|
99
|
-
if (typeof error == "string") {
|
|
100
|
-
qRequire.logMsg({msg: `error: ${error}`.error.italic.bold, type: "error"})
|
|
101
|
-
|
|
102
|
-
} else {
|
|
103
|
-
let add_s = (error.error_count > 1) ? 's' : ''
|
|
104
|
-
qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
|
package/tests/json_bottom_one.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
var file_queue = require("../app.js"),
|
|
2
|
-
fs = require('fs'),
|
|
3
|
-
validPath = require('valid-path')
|
|
4
|
-
|
|
5
|
-
var file_data = [
|
|
6
|
-
{ props: { id: 100, name: "all", absolute_path: __filename, check: true } },
|
|
7
|
-
{ props: { id: 101, name: "func_all", absolute_path: __filename, check: true } },
|
|
8
|
-
{ props: { id: 102, name: "top_one", absolute_path: __filename, check: true } },
|
|
9
|
-
{ props: { id: 103, name: "bottom_one", absolute_path: __filename, check: true } },
|
|
10
|
-
{ props: { id: 104, name: "sync_all", absolute_path: __filename, check: true } },
|
|
11
|
-
{ props: { id: 105, name: "status", absolute_path: __filename, check: true } },
|
|
12
|
-
{ props: { id: 106, name: "name", absolute_path: __filename, check: true } },
|
|
13
|
-
{ props: { id: 107, name: "version", absolute_path: __filename, check: true } }
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
var file_object = class file_obj {
|
|
17
|
-
constructor(props) {
|
|
18
|
-
let t = this, fname = "file_obj.constructor"
|
|
19
|
-
try {
|
|
20
|
-
t.id = props.id
|
|
21
|
-
t.log = props.log
|
|
22
|
-
t.name = props.name
|
|
23
|
-
t.path = props.relative_path
|
|
24
|
-
t.absolute_path = props.absolute_path
|
|
25
|
-
t.status = 'init'
|
|
26
|
-
t.errors = false
|
|
27
|
-
t.error_msg = 'none'
|
|
28
|
-
|
|
29
|
-
// if (t.id == 104) {
|
|
30
|
-
// t.errors = true
|
|
31
|
-
// t.error_msg = `some sort of error here`
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
t.process = t.process.bind(t)
|
|
36
|
-
t.do_checks = t.do_checks.bind(t)
|
|
37
|
-
|
|
38
|
-
if (props.check) {
|
|
39
|
-
t.do_checks()
|
|
40
|
-
}
|
|
41
|
-
} catch (e) {
|
|
42
|
-
e.message = `${fname} error: ${e.message}`
|
|
43
|
-
throw e
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return t
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
do_checks() {
|
|
50
|
-
let t = this, path_to_check,
|
|
51
|
-
last_item = t.absolute_path.split("\\").pop(),
|
|
52
|
-
check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
|
|
53
|
-
|
|
54
|
-
check_file = check_file.replace(/\\/g, "/");
|
|
55
|
-
path_to_check = validPath(t.path);
|
|
56
|
-
|
|
57
|
-
if (!path_to_check.valid) {
|
|
58
|
-
t.errors = true
|
|
59
|
-
t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
check_path.map((dat, i) => {
|
|
63
|
-
if (/^[a-zA-Z._]+$/.test(dat)) {
|
|
64
|
-
if (dat != '.')
|
|
65
|
-
check_file += dat + '/'
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
check_file = check_file.slice(0, -1)
|
|
69
|
-
try {
|
|
70
|
-
if (!fs.existsSync(check_file)) {
|
|
71
|
-
t.errors = true
|
|
72
|
-
t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
|
|
73
|
-
}
|
|
74
|
-
} catch (e) {
|
|
75
|
-
e.message = "file_obj do_checks error: " + e.message
|
|
76
|
-
throw (e)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
process(callback) {
|
|
81
|
-
let t = this
|
|
82
|
-
t.log({ msg: `processing object id ${t.id} name: ${t.name}. Do a bunch of stuff here.`.silly, type: "silly" })
|
|
83
|
-
if (t.errors)
|
|
84
|
-
callback({ error: { msg: t.error_msg } })
|
|
85
|
-
else
|
|
86
|
-
callback({ success: { msg: `id: ${t.id} name: ${t.name}` } })
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var qRequire = new file_queue()
|
|
91
|
-
|
|
92
|
-
qRequire.init().process({
|
|
93
|
-
appender: "json_bottom_one",
|
|
94
|
-
exclude_logMsg: ["debug", "silly", "info"], /* default [] */
|
|
95
|
-
process_objects: [file_object],
|
|
96
|
-
data_to_process_array: file_data
|
|
97
|
-
}).then((success) => {
|
|
98
|
-
qRequire.logMsg({ msg: `test success: bottom_one file objects processed with no errors`.success.italic.bold, type: "success" })
|
|
99
|
-
}, (error) => {
|
|
100
|
-
if (typeof error == "string") {
|
|
101
|
-
qRequire.logMsg({msg: `error: ${error}`.error.italic.bold, type: "error"})
|
|
102
|
-
|
|
103
|
-
} else {
|
|
104
|
-
let add_s = (error.error_count > 1) ? 's' : ''
|
|
105
|
-
qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
|
package/tests/json_func_all.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
var file_queue = require("../app.js"),
|
|
2
|
-
fs = require('fs'),
|
|
3
|
-
validPath = require('valid-path')
|
|
4
|
-
|
|
5
|
-
var file_data = [
|
|
6
|
-
{ props: { id: 100, name: "all", absolute_path: __filename, check: true } },
|
|
7
|
-
{ props: { id: 101, name: "func_all", absolute_path: __filename, check: true } },
|
|
8
|
-
{ props: { id: 102, name: "top_one", absolute_path: __filename, check: true } },
|
|
9
|
-
{ props: { id: 103, name: "bottom_one", absolute_path: __filename, check: true } },
|
|
10
|
-
{ props: { id: 104, name: "sync_all", absolute_path: __filename, check: true } },
|
|
11
|
-
{ props: { id: 105, name: "status", absolute_path: __filename, check: true } },
|
|
12
|
-
{ props: { id: 106, name: "name", absolute_path: __filename, check: true } },
|
|
13
|
-
{ props: { id: 107, name: "version", absolute_path: __filename, check: true } }
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
var file_object = class file_obj {
|
|
17
|
-
constructor(props) {
|
|
18
|
-
let t = this, fname = "file_obj.constructor"
|
|
19
|
-
try {
|
|
20
|
-
t.id = props.id
|
|
21
|
-
t.log = props.log
|
|
22
|
-
t.name = props.name
|
|
23
|
-
t.path = props.relative_path
|
|
24
|
-
t.absolute_path = props.absolute_path
|
|
25
|
-
t.status = 'init'
|
|
26
|
-
t.errors = false
|
|
27
|
-
t.error_msg = 'none'
|
|
28
|
-
|
|
29
|
-
// if (t.id == 104) {
|
|
30
|
-
// t.errors = true
|
|
31
|
-
// t.error_msg = `some sort of error here`
|
|
32
|
-
// }
|
|
33
|
-
t.base_queue_process_function = t.a_cool_function
|
|
34
|
-
|
|
35
|
-
t.do_checks = t.do_checks.bind(t)
|
|
36
|
-
t.a_cool_function = t.a_cool_function.bind(t)
|
|
37
|
-
t.base_queue_process_function = t.base_queue_process_function.bind(t)
|
|
38
|
-
|
|
39
|
-
if (props.check) {
|
|
40
|
-
t.do_checks()
|
|
41
|
-
}
|
|
42
|
-
} catch (e) {
|
|
43
|
-
e.message = `${fname} error: ${e.message}`
|
|
44
|
-
throw e
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return t
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
do_checks() {
|
|
51
|
-
let t = this, path_to_check,
|
|
52
|
-
last_item = t.absolute_path.split("\\").pop(),
|
|
53
|
-
check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
|
|
54
|
-
|
|
55
|
-
check_file = check_file.replace(/\\/g, "/");
|
|
56
|
-
path_to_check = validPath(t.path);
|
|
57
|
-
|
|
58
|
-
if (!path_to_check.valid) {
|
|
59
|
-
t.errors = true
|
|
60
|
-
t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
check_path.map((dat, i) => {
|
|
64
|
-
if (/^[a-zA-Z._]+$/.test(dat)) {
|
|
65
|
-
if (dat != '.')
|
|
66
|
-
check_file += dat + '/'
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
check_file = check_file.slice(0, -1)
|
|
70
|
-
try {
|
|
71
|
-
if (!fs.existsSync(check_file)) {
|
|
72
|
-
t.errors = true
|
|
73
|
-
t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
|
|
74
|
-
}
|
|
75
|
-
} catch (e) {
|
|
76
|
-
e.message = "file_obj do_checks error: " + e.message
|
|
77
|
-
throw (e)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
a_cool_function(callback) {
|
|
82
|
-
let t = this
|
|
83
|
-
t.log({ msg: `processing object id ${t.id}. Do a bunch of stuff here.`.silly, type: "silly" })
|
|
84
|
-
if (t.errors)
|
|
85
|
-
callback({ error: { msg: t.error_msg } })
|
|
86
|
-
else
|
|
87
|
-
callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
var qRequire = new file_queue()
|
|
92
|
-
|
|
93
|
-
qRequire.init().process({
|
|
94
|
-
appender: "json_func_all",
|
|
95
|
-
exclude_logMsg: ["debug", "silly", "info"], /* default [] */
|
|
96
|
-
process_objects: [file_object],
|
|
97
|
-
data_to_process_array: file_data
|
|
98
|
-
}).then((success) => {
|
|
99
|
-
qRequire.logMsg({ msg: `test success: json_func_all objects processed with no errors`.success.italic.bold, type: "success" })
|
|
100
|
-
}, (error) => {
|
|
101
|
-
if (typeof error == "string") {
|
|
102
|
-
qRequire.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
103
|
-
|
|
104
|
-
} else {
|
|
105
|
-
let add_s = (error.error_count > 1) ? 's' : ''
|
|
106
|
-
qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
|