adapt-migrations 1.0.0 → 1.2.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/.eslintignore +1 -1
- package/.eslintrc.json +14 -14
- package/README.md +106 -43
- package/api/commands.js +33 -33
- package/api/data.js +26 -26
- package/api/describe.js +12 -12
- package/api/errors.js +28 -28
- package/api/helpers.js +17 -0
- package/api/plugins.js +47 -44
- package/api/tests.js +57 -57
- package/api/where.js +46 -46
- package/examples/migrations.js +159 -159
- package/examples/script.js +78 -78
- package/index.js +70 -62
- package/lib/CacheManager.js +95 -95
- package/lib/Journal.js +303 -303
- package/lib/Logger.js +91 -91
- package/lib/Task.js +381 -381
- package/lib/TaskContext.js +27 -27
- package/lib/TaskTest.js +19 -19
- package/lib/lifecycle.js +50 -50
- package/package.json +18 -18
package/lib/TaskContext.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export default class TaskContext {
|
|
2
|
-
constructor ({
|
|
3
|
-
hasErrored = false,
|
|
4
|
-
hasStopped = false,
|
|
5
|
-
hasRun = false,
|
|
6
|
-
fromPlugins = null,
|
|
7
|
-
originalFromPlugins = null,
|
|
8
|
-
toPlugins = null,
|
|
9
|
-
content = null,
|
|
10
|
-
journal = null,
|
|
11
|
-
errors = []
|
|
12
|
-
} = {}) {
|
|
13
|
-
this.hasErrored = hasErrored
|
|
14
|
-
this.hasStopped = hasStopped
|
|
15
|
-
this.hasRun = hasRun
|
|
16
|
-
this.fromPlugins = fromPlugins
|
|
17
|
-
this.originalFromPlugins = originalFromPlugins
|
|
18
|
-
this.toPlugins = toPlugins
|
|
19
|
-
this.content = content
|
|
20
|
-
this.journal = journal
|
|
21
|
-
this.errors = errors
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get lastError () {
|
|
25
|
-
return this.errors[this.errors.length - 1]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
export default class TaskContext {
|
|
2
|
+
constructor ({
|
|
3
|
+
hasErrored = false,
|
|
4
|
+
hasStopped = false,
|
|
5
|
+
hasRun = false,
|
|
6
|
+
fromPlugins = null,
|
|
7
|
+
originalFromPlugins = null,
|
|
8
|
+
toPlugins = null,
|
|
9
|
+
content = null,
|
|
10
|
+
journal = null,
|
|
11
|
+
errors = []
|
|
12
|
+
} = {}) {
|
|
13
|
+
this.hasErrored = hasErrored
|
|
14
|
+
this.hasStopped = hasStopped
|
|
15
|
+
this.hasRun = hasRun
|
|
16
|
+
this.fromPlugins = fromPlugins
|
|
17
|
+
this.originalFromPlugins = originalFromPlugins
|
|
18
|
+
this.toPlugins = toPlugins
|
|
19
|
+
this.content = content
|
|
20
|
+
this.journal = journal
|
|
21
|
+
this.errors = errors
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get lastError () {
|
|
25
|
+
return this.errors[this.errors.length - 1]
|
|
26
|
+
}
|
|
27
|
+
}
|
package/lib/TaskTest.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export default class TaskTest {
|
|
2
|
-
constructor ({
|
|
3
|
-
description = '',
|
|
4
|
-
shouldStop = true,
|
|
5
|
-
shouldRun = false,
|
|
6
|
-
shouldError = true,
|
|
7
|
-
fromPlugins = [],
|
|
8
|
-
toPlugins = [],
|
|
9
|
-
content = []
|
|
10
|
-
} = {}) {
|
|
11
|
-
this.description = description
|
|
12
|
-
this.shouldStop = shouldStop
|
|
13
|
-
this.shouldRun = shouldRun
|
|
14
|
-
this.shouldError = shouldError
|
|
15
|
-
this.fromPlugins = fromPlugins
|
|
16
|
-
this.toPlugins = toPlugins
|
|
17
|
-
this.content = content
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
export default class TaskTest {
|
|
2
|
+
constructor ({
|
|
3
|
+
description = '',
|
|
4
|
+
shouldStop = true,
|
|
5
|
+
shouldRun = false,
|
|
6
|
+
shouldError = true,
|
|
7
|
+
fromPlugins = [],
|
|
8
|
+
toPlugins = [],
|
|
9
|
+
content = []
|
|
10
|
+
} = {}) {
|
|
11
|
+
this.description = description
|
|
12
|
+
this.shouldStop = shouldStop
|
|
13
|
+
this.shouldRun = shouldRun
|
|
14
|
+
this.shouldError = shouldError
|
|
15
|
+
this.fromPlugins = fromPlugins
|
|
16
|
+
this.toPlugins = toPlugins
|
|
17
|
+
this.content = content
|
|
18
|
+
}
|
|
19
|
+
}
|
package/lib/lifecycle.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import Task from './Task.js'
|
|
2
|
-
import Logger from './Logger.js'
|
|
3
|
-
|
|
4
|
-
const logger = Logger.getInstance()
|
|
5
|
-
|
|
6
|
-
function getCalleeName (step = 0) {
|
|
7
|
-
const e = new Error('dummy')
|
|
8
|
-
const name = e.stack
|
|
9
|
-
.split('\n')[step]
|
|
10
|
-
// " at functionName ( ..." => "functionName"
|
|
11
|
-
.replace(/^\s+at\s+(.+?)\s.+/g, '$1')
|
|
12
|
-
return name
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function deferOrRunWrap (callback, options) {
|
|
16
|
-
const unwrapped = callback
|
|
17
|
-
if (!Task.isRunning) {
|
|
18
|
-
callback = function deferred (context) { return unwrapped(context) }
|
|
19
|
-
if (!Task.current) {
|
|
20
|
-
logger.error(`Cannot run ${getCalleeName(3)} out of task context`)
|
|
21
|
-
throw new Error()
|
|
22
|
-
}
|
|
23
|
-
Task.current[options.type === 'test' ? 'tests' : 'steps'].push(callback)
|
|
24
|
-
}
|
|
25
|
-
if (options) Object.assign(callback, options)
|
|
26
|
-
return Task.isRunning
|
|
27
|
-
? callback(Task.current.context)
|
|
28
|
-
: callback
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export async function successStopOrErrorWrap (taskName, description, callback) {
|
|
32
|
-
let successOrStop
|
|
33
|
-
let error
|
|
34
|
-
try {
|
|
35
|
-
successOrStop = await callback()
|
|
36
|
-
} catch (err) {
|
|
37
|
-
error = err
|
|
38
|
-
logger.error(`${taskName} -- ${description}`, `${error}`)
|
|
39
|
-
error.stack = Object.entries(Task.mapCacheToSource).reduce((stack, [cache, source]) => {
|
|
40
|
-
return stack.replaceAll(cache, source)
|
|
41
|
-
}, error.stack)
|
|
42
|
-
}
|
|
43
|
-
if (error) {
|
|
44
|
-
logger.error(`${taskName} -- ${description} -- (errored - ${error.message})`)
|
|
45
|
-
logger.error(error)
|
|
46
|
-
throw error
|
|
47
|
-
}
|
|
48
|
-
logger.info(`${taskName} -- ${description} -- (${successOrStop ? 'success' : 'stopped'})`)
|
|
49
|
-
return successOrStop
|
|
50
|
-
}
|
|
1
|
+
import Task from './Task.js'
|
|
2
|
+
import Logger from './Logger.js'
|
|
3
|
+
|
|
4
|
+
const logger = Logger.getInstance()
|
|
5
|
+
|
|
6
|
+
function getCalleeName (step = 0) {
|
|
7
|
+
const e = new Error('dummy')
|
|
8
|
+
const name = e.stack
|
|
9
|
+
.split('\n')[step]
|
|
10
|
+
// " at functionName ( ..." => "functionName"
|
|
11
|
+
.replace(/^\s+at\s+(.+?)\s.+/g, '$1')
|
|
12
|
+
return name
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function deferOrRunWrap (callback, options) {
|
|
16
|
+
const unwrapped = callback
|
|
17
|
+
if (!Task.isRunning) {
|
|
18
|
+
callback = function deferred (context) { return unwrapped(context) }
|
|
19
|
+
if (!Task.current) {
|
|
20
|
+
logger.error(`Cannot run ${getCalleeName(3)} out of task context`)
|
|
21
|
+
throw new Error()
|
|
22
|
+
}
|
|
23
|
+
Task.current[options.type === 'test' ? 'tests' : 'steps'].push(callback)
|
|
24
|
+
}
|
|
25
|
+
if (options) Object.assign(callback, options)
|
|
26
|
+
return Task.isRunning
|
|
27
|
+
? callback(Task.current.context)
|
|
28
|
+
: callback
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export async function successStopOrErrorWrap (taskName, description, callback) {
|
|
32
|
+
let successOrStop
|
|
33
|
+
let error
|
|
34
|
+
try {
|
|
35
|
+
successOrStop = await callback()
|
|
36
|
+
} catch (err) {
|
|
37
|
+
error = err
|
|
38
|
+
logger.error(`${taskName} -- ${description}`, `${error}`)
|
|
39
|
+
error.stack = Object.entries(Task.mapCacheToSource).reduce((stack, [cache, source]) => {
|
|
40
|
+
return stack.replaceAll(cache, source)
|
|
41
|
+
}, error.stack)
|
|
42
|
+
}
|
|
43
|
+
if (error) {
|
|
44
|
+
logger.error(`${taskName} -- ${description} -- (errored - ${error.message})`)
|
|
45
|
+
logger.error(error)
|
|
46
|
+
throw error
|
|
47
|
+
}
|
|
48
|
+
logger.info(`${taskName} -- ${description} -- (${successOrStop ? 'success' : 'stopped'})`)
|
|
49
|
+
return successOrStop
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "adapt-migrations",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"main": "index.js",
|
|
5
|
-
"version": "1.
|
|
6
|
-
"devDependencies": {
|
|
7
|
-
"eslint": "^8.42.0",
|
|
8
|
-
"eslint-config-standard": "^17.1.0",
|
|
9
|
-
"eslint-plugin-import": "^2.27.5",
|
|
10
|
-
"eslint-plugin-node": "^11.1.0",
|
|
11
|
-
"eslint-plugin-promise": "^6.1.1"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"fs-extra": "^11.1.1",
|
|
15
|
-
"globs": "^0.1.4",
|
|
16
|
-
"semver": "^7.5.4"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "adapt-migrations",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"version": "1.2.0",
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"eslint": "^8.42.0",
|
|
8
|
+
"eslint-config-standard": "^17.1.0",
|
|
9
|
+
"eslint-plugin-import": "^2.27.5",
|
|
10
|
+
"eslint-plugin-node": "^11.1.0",
|
|
11
|
+
"eslint-plugin-promise": "^6.1.1"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"fs-extra": "^11.1.1",
|
|
15
|
+
"globs": "^0.1.4",
|
|
16
|
+
"semver": "^7.5.4"
|
|
17
|
+
}
|
|
18
|
+
}
|