@data-fair/lib-node 2.3.0 → 2.3.2
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/package.json +1 -1
- package/upgrade-scripts.d.ts +1 -1
- package/upgrade-scripts.js +13 -11
package/package.json
CHANGED
package/upgrade-scripts.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export interface UpgradeScript {
|
|
|
5
5
|
description: string;
|
|
6
6
|
exec: (db: Db, debug: Debugger) => Promise<void>;
|
|
7
7
|
}
|
|
8
|
-
export default function (db: Db, locks: Locks, basePath?: string,
|
|
8
|
+
export default function (db: Db, locks: Locks, basePath?: string, isFresh?: () => Promise<boolean>): Promise<void>;
|
package/upgrade-scripts.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import semver from 'semver'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import { readdirSync, readFileSync } from 'fs'
|
|
3
|
+
import { readdirSync, readFileSync, statSync } from 'fs'
|
|
4
4
|
import Debug from 'debug'
|
|
5
5
|
const debug = Debug('upgrade')
|
|
6
6
|
// chose the proper scripts to execute, then run them
|
|
7
|
-
export default async function (db, locks, basePath = './',
|
|
7
|
+
export default async function (db, locks, basePath = './', isFresh) {
|
|
8
8
|
const ack = await locks.acquire('upgrade')
|
|
9
9
|
if (!ack) {
|
|
10
10
|
console.warn('upgrade scripts lock is already acquired, skip them')
|
|
@@ -15,13 +15,13 @@ export default async function (db, locks, basePath = './', bootstrap) {
|
|
|
15
15
|
// are not considered "up" and the previous versions keep running in the mean time
|
|
16
16
|
} else {
|
|
17
17
|
try {
|
|
18
|
-
await runScripts(db, basePath,
|
|
18
|
+
await runScripts(db, basePath, isFresh)
|
|
19
19
|
} finally {
|
|
20
20
|
await locks.release('upgrade')
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
async function runScripts (db, basePath,
|
|
24
|
+
async function runScripts (db, basePath, isFresh) {
|
|
25
25
|
const dir = path.resolve(basePath)
|
|
26
26
|
const pjsonPath = path.join(dir, 'package.json')
|
|
27
27
|
debug('read service info from ' + pjsonPath)
|
|
@@ -38,15 +38,15 @@ async function runScripts (db, basePath, bootstrap) {
|
|
|
38
38
|
} else {
|
|
39
39
|
debug('No service version found in database, this is the first time the upgrade system is run')
|
|
40
40
|
scripts = scripts.filter(scriptDef => scriptDef.version === 'init')
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
debug('Bootstrap function returned version %s', previousPersion)
|
|
41
|
+
if (isFresh) {
|
|
42
|
+
if (await isFresh()) {
|
|
43
|
+
debug('isFresh function returned true, this is a fresh install, do not run any script')
|
|
45
44
|
} else {
|
|
46
|
-
debug('
|
|
45
|
+
debug('isFresh function returned false, this is not a fresh install, run all init scripts')
|
|
46
|
+
previousPersion = '0.0.0'
|
|
47
47
|
}
|
|
48
48
|
} else {
|
|
49
|
-
debug('No
|
|
49
|
+
debug('No isFresh function, it could be a fresh install, do not run any script')
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
if (previousPersion) {
|
|
@@ -68,7 +68,9 @@ async function runScripts (db, basePath, bootstrap) {
|
|
|
68
68
|
}
|
|
69
69
|
// Walk the scripts directories
|
|
70
70
|
async function listScripts (scriptsRoot) {
|
|
71
|
-
const dirs = readdirSync(scriptsRoot)
|
|
71
|
+
const dirs = readdirSync(scriptsRoot)
|
|
72
|
+
.filter(dir => statSync(path.join(scriptsRoot, dir)).isDirectory())
|
|
73
|
+
.sort()
|
|
72
74
|
return dirs.map(dir => {
|
|
73
75
|
return {
|
|
74
76
|
version: dir,
|