adapt-migrations 1.2.0 → 1.4.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/lib/Logger.js CHANGED
@@ -1,91 +1,91 @@
1
- import chalk from 'chalk'
2
- import path from 'path'
3
- import fs from 'fs-extra'
4
-
5
- function padNum2(value) {
6
- return String(value).padStart(2, '0');
7
- }
8
-
9
- export default class Logger {
10
- constructor () {
11
- this.logArr = []
12
- this.config = {
13
- levels: {
14
- error: {
15
- colour: 'red'
16
- },
17
- warn: {
18
- colour: 'yellow'
19
- },
20
- info: {
21
- colour: 'cyan'
22
- },
23
- debug: {
24
- colour: 'grey'
25
- }
26
- }
27
- }
28
- }
29
-
30
- // getInstance used to allow import
31
- static getInstance () {
32
- if (Logger.instance === null) {
33
- Logger.instance = new Logger()
34
- }
35
- return Logger.instance
36
- }
37
-
38
- // Colour level string, easier to differentiate between info/error/warn/debug
39
- static colourise (str, colour) {
40
- const chalkFunc = chalk[colour]
41
- return chalkFunc ? chalkFunc(str) : str
42
- }
43
-
44
- // Use getDateStamp to return readable date/time string.
45
- static getDateStamp () {
46
- const d = new Date()
47
- const date = `${d.getFullYear().toString()}/${padNum2(d.getMonth() + 1)}/${padNum2(d.getDate())}`
48
- const time = `${padNum2(d.getHours())}:${padNum2(d.getMinutes())}:${padNum2(d.getSeconds())}.${padNum2(d.getMilliseconds())}`
49
- const str = `${date} ${time}`
50
- return str
51
- }
52
-
53
- // Add Success/Fail ?
54
- info (...args) {
55
- this.log('info', args)
56
- }
57
-
58
- error (...args) {
59
- this.log('error', args)
60
- }
61
-
62
- warn (...args) {
63
- this.log('warn', args)
64
- }
65
-
66
- debug (...args) {
67
- this.log('debug', args)
68
- }
69
-
70
- // Colour level for easy read, store log in this.logArr as string
71
- log (level, args) {
72
- const colour = this?.config?.levels[level]?.colour || 'grey'
73
- const logFunc = console[level] ?? console.log
74
- const dateStamp = Logger.getDateStamp()
75
- const argsStr = args.join(', ')
76
- logFunc(`(${dateStamp}) -- ${Logger.colourise(level, colour)} -- `, ...args)
77
- this.logArr.push(`[${dateStamp}] -- ${level} -- ${argsStr}`)
78
- }
79
-
80
- // Output this.logArr, 2 log outputs, capture & migrate
81
- output (dir, type) {
82
- const logPath = path.join(dir, './logs/')
83
- if (!fs.existsSync(logPath)) fs.mkdirSync(logPath)
84
-
85
- const outputName = `${type}_log`
86
- const outputFile = path.join(logPath, `${outputName}.json`)
87
- fs.writeJSONSync(outputFile, this.logArr, { replacer: null, spaces: 2 })
88
- }
89
- }
90
-
91
- Logger.instance = null
1
+ import chalk from 'chalk'
2
+ import path from 'path'
3
+ import fs from 'fs-extra'
4
+
5
+ function padNum2(value) {
6
+ return String(value).padStart(2, '0');
7
+ }
8
+
9
+ export default class Logger {
10
+ constructor () {
11
+ this.logArr = []
12
+ this.config = {
13
+ levels: {
14
+ error: {
15
+ colour: 'red'
16
+ },
17
+ warn: {
18
+ colour: 'yellow'
19
+ },
20
+ info: {
21
+ colour: 'cyan'
22
+ },
23
+ debug: {
24
+ colour: 'grey'
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ // getInstance used to allow import
31
+ static getInstance () {
32
+ if (Logger.instance === null) {
33
+ Logger.instance = new Logger()
34
+ }
35
+ return Logger.instance
36
+ }
37
+
38
+ // Colour level string, easier to differentiate between info/error/warn/debug
39
+ static colourise (str, colour) {
40
+ const chalkFunc = chalk[colour]
41
+ return chalkFunc ? chalkFunc(str) : str
42
+ }
43
+
44
+ // Use getDateStamp to return readable date/time string.
45
+ static getDateStamp () {
46
+ const d = new Date()
47
+ const date = `${d.getFullYear().toString()}/${padNum2(d.getMonth() + 1)}/${padNum2(d.getDate())}`
48
+ const time = `${padNum2(d.getHours())}:${padNum2(d.getMinutes())}:${padNum2(d.getSeconds())}.${padNum2(d.getMilliseconds())}`
49
+ const str = `${date} ${time}`
50
+ return str
51
+ }
52
+
53
+ // Add Success/Fail ?
54
+ info (...args) {
55
+ this.log('info', args)
56
+ }
57
+
58
+ error (...args) {
59
+ this.log('error', args)
60
+ }
61
+
62
+ warn (...args) {
63
+ this.log('warn', args)
64
+ }
65
+
66
+ debug (...args) {
67
+ this.log('debug', args)
68
+ }
69
+
70
+ // Colour level for easy read, store log in this.logArr as string
71
+ log (level, args) {
72
+ const colour = this?.config?.levels[level]?.colour || 'grey'
73
+ const logFunc = console[level] ?? console.log
74
+ const dateStamp = Logger.getDateStamp()
75
+ const argsStr = args.join(', ')
76
+ logFunc(`(${dateStamp}) -- ${Logger.colourise(level, colour)} -- `, ...args)
77
+ this.logArr.push(`[${dateStamp}] -- ${level} -- ${argsStr}`)
78
+ }
79
+
80
+ // Output this.logArr, 2 log outputs, capture & migrate
81
+ output (dir, type) {
82
+ const logPath = path.join(dir, './logs/')
83
+ if (!fs.existsSync(logPath)) fs.mkdirSync(logPath)
84
+
85
+ const outputName = `${type}_log`
86
+ const outputFile = path.join(logPath, `${outputName}.json`)
87
+ fs.writeJSONSync(outputFile, this.logArr, { replacer: null, spaces: 2 })
88
+ }
89
+ }
90
+
91
+ Logger.instance = null