@axinom/mosaic-cli 0.49.0-rc.7 → 0.49.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/dist/commands/pg-dump/generate.js +48 -10
- package/dist/commands/pg-dump/generate.js.map +1 -1
- package/dist/commands/pg-dump/index.js +6 -1
- package/dist/commands/pg-dump/index.js.map +1 -1
- package/dist/commands/pg-dump/pg-dump-options.d.ts +1 -0
- package/package.json +4 -4
- package/src/commands/pg-dump/generate.ts +73 -14
- package/src/commands/pg-dump/index.ts +7 -1
- package/src/commands/pg-dump/pg-dump-options.ts +1 -0
|
@@ -7,6 +7,16 @@ const child_process_1 = require("child_process");
|
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const common_1 = require("../../common");
|
|
10
|
+
/**
|
|
11
|
+
* Convert absolute path to ComposePathResult
|
|
12
|
+
* dirName would be relative to the current working directory
|
|
13
|
+
*/
|
|
14
|
+
const absolutePathToRelativeDirNameAndFileName = (absPath) => {
|
|
15
|
+
return {
|
|
16
|
+
dirName: (0, path_1.dirname)((0, path_1.relative)(process.cwd(), absPath)),
|
|
17
|
+
fileName: (0, path_1.basename)(absPath),
|
|
18
|
+
};
|
|
19
|
+
};
|
|
10
20
|
/**
|
|
11
21
|
* Calculates a path to `docker-compose.yaml` file based on initial path.
|
|
12
22
|
* For example, if `scripts/infra` is provided as initial path, it will look for `scripts/infra/docker-compose.yml` in current folder, then in folder one hierarchy level up, traversing directories towards root.
|
|
@@ -14,21 +24,41 @@ const common_1 = require("../../common");
|
|
|
14
24
|
* Eliminates the need to calculate how many `..` you must have in the path to docker compose file which is passed as a cli parameter.
|
|
15
25
|
*/
|
|
16
26
|
const findComposePath = (initialPath) => {
|
|
27
|
+
const supportedComposeFiles = ['docker-compose.yml', 'docker-compose.yaml'];
|
|
17
28
|
let startPath = process.cwd();
|
|
18
29
|
let lastPath = '';
|
|
19
30
|
while (lastPath !== startPath) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
for (const file of supportedComposeFiles) {
|
|
32
|
+
const lookupPath = (0, path_1.join)(startPath, initialPath, file);
|
|
33
|
+
if ((0, fs_1.existsSync)(lookupPath)) {
|
|
34
|
+
return absolutePathToRelativeDirNameAndFileName(lookupPath);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Preserve currently checked path for while condition comparison
|
|
38
|
+
lastPath = startPath;
|
|
39
|
+
// Remove last segment from path, move to directory closer to root
|
|
40
|
+
startPath = (0, path_1.normalize)((0, path_1.join)(startPath, '..'));
|
|
41
|
+
}
|
|
42
|
+
throw Error(`'${initialPath}/docker-compose.y(a)ml' file not found. Please make sure that correct composeFolderPath parameter is provided.`);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* checks if the given path to file exists. and returns the directory path and file name of the file
|
|
46
|
+
*/
|
|
47
|
+
const findComposeFilePath = (initialPath) => {
|
|
48
|
+
const isAbs = (0, path_1.isAbsolute)(initialPath);
|
|
49
|
+
const lookupPath = isAbs ? initialPath : (0, path_1.join)(process.cwd(), initialPath);
|
|
50
|
+
try {
|
|
51
|
+
const fileStats = (0, fs_1.statSync)(lookupPath);
|
|
52
|
+
if (fileStats.isFile()) {
|
|
53
|
+
return absolutePathToRelativeDirNameAndFileName(lookupPath);
|
|
23
54
|
}
|
|
24
55
|
else {
|
|
25
|
-
|
|
26
|
-
lastPath = startPath;
|
|
27
|
-
// Remove last segment from path, move to directory closer to root
|
|
28
|
-
startPath = (0, path_1.normalize)((0, path_1.join)(startPath, '..'));
|
|
56
|
+
throw Error(`'${initialPath}' is not a file. Please make sure that correct composeFilePath parameter is provided.`);
|
|
29
57
|
}
|
|
30
58
|
}
|
|
31
|
-
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw Error(`'${initialPath}' file not found. Please make sure that correct composeFilePath parameter is provided.`);
|
|
61
|
+
}
|
|
32
62
|
};
|
|
33
63
|
/**
|
|
34
64
|
* Loads and validates all required environment variables that are used to create a shadow database connection string.
|
|
@@ -65,7 +95,15 @@ const ensureDumpDirectoryExist = (targetPath) => {
|
|
|
65
95
|
const generate = (options) => {
|
|
66
96
|
try {
|
|
67
97
|
console.log((0, common_1.getTimestamp)(), `Starting pg-dump command...`);
|
|
68
|
-
|
|
98
|
+
let composeDirPath = '';
|
|
99
|
+
let composeFileName = 'docker-compose.yml';
|
|
100
|
+
if (options.composeFilePath) {
|
|
101
|
+
({ dirName: composeDirPath, fileName: composeFileName } =
|
|
102
|
+
findComposeFilePath((0, path_1.normalize)(options.composeFilePath)));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
({ dirName: composeDirPath, fileName: composeFileName } = findComposePath((0, path_1.normalize)(options.composeFolderPath)));
|
|
106
|
+
}
|
|
69
107
|
const connectionString = getDumpDbConnectionString(options.connectionString);
|
|
70
108
|
const dumpPath = ensureDumpDirectoryExist(options.dumpPath);
|
|
71
109
|
const excludeSchemas = (0, mosaic_service_common_1.isNullOrWhitespace)(options.excludeSchemas)
|
|
@@ -80,7 +118,7 @@ const generate = (options) => {
|
|
|
80
118
|
...excludeSchemas,
|
|
81
119
|
connectionString,
|
|
82
120
|
].join(' ');
|
|
83
|
-
(0, child_process_1.exec)(`cd ${
|
|
121
|
+
(0, child_process_1.exec)(`cd "${composeDirPath}" && docker compose -f "${composeFileName}" exec -T postgres pg_dump ${dumpOptions} > "${dumpPath}"`, (_error, stdout, stderr) => {
|
|
84
122
|
if (stdout) {
|
|
85
123
|
console.log((0, common_1.getTimestamp)(), 'pg_dump info:', stdout);
|
|
86
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/commands/pg-dump/generate.ts"],"names":[],"mappings":";;;AAAA,yEAMuC;AACvC,+BAA+B;AAC/B,iDAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/commands/pg-dump/generate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compose.
|
|
12
|
+
describe: 'Relative path to docker-compose.y(a)ml file, e.g. `infra` or `scripts/infra`. Script will look for such directory starting from current project, traversing directories closer to root, so no need to specify a path like `../../../infra`',
|
|
13
|
+
string: true,
|
|
14
|
+
})
|
|
15
|
+
.option('composeFilePath', {
|
|
16
|
+
alias: 'f',
|
|
17
|
+
describe: 'Relative or Absolute file path to the y(a)ml file. This option would override any composeFolderPath setting.',
|
|
13
18
|
string: true,
|
|
14
19
|
})
|
|
15
20
|
.option('dumpPath', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/pg-dump/index.ts"],"names":[],"mappings":";;;AACA,yCAAsC;AAGzB,QAAA,MAAM,GAA0C;IAC3D,OAAO,EAAE,SAAS;IAClB,QAAQ,EACN,sKAAsK;IACxK,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CACjB,KAAK;SACF,MAAM,CAAC,mBAAmB,EAAE;QAC3B,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,OAAO;QAChB,QAAQ,EACN,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/pg-dump/index.ts"],"names":[],"mappings":";;;AACA,yCAAsC;AAGzB,QAAA,MAAM,GAA0C;IAC3D,OAAO,EAAE,SAAS;IAClB,QAAQ,EACN,sKAAsK;IACxK,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CACjB,KAAK;SACF,MAAM,CAAC,mBAAmB,EAAE;QAC3B,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,OAAO;QAChB,QAAQ,EACN,4OAA4O;QAC9O,MAAM,EAAE,IAAI;KACb,CAAC;SACD,MAAM,CAAC,iBAAiB,EAAE;QACzB,KAAK,EAAE,GAAG;QACV,QAAQ,EACN,8GAA8G;QAChH,MAAM,EAAE,IAAI;KACb,CAAC;SACD,MAAM,CAAC,UAAU,EAAE;QAClB,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,6BAA6B;QACtC,QAAQ,EACN,wIAAwI;QAC1I,MAAM,EAAE,IAAI;KACb,CAAC;SACD,MAAM,CAAC,gBAAgB,EAAE;QACxB,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,kCAAkC;QAC3C,QAAQ,EACN,sHAAsH;QACxH,MAAM,EAAE,IAAI;KACb,CAAC;SACD,MAAM,CAAC,kBAAkB,EAAE;QAC1B,KAAK,EAAE,GAAG;QACV,QAAQ,EACN,gJAAgJ;QAClJ,MAAM,EAAE,IAAI;KACb,CAAC;IACN,OAAO,EAAE,mBAAQ;CAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-cli",
|
|
3
|
-
"version": "0.49.0
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "The Axinom Mosaic CLI",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@asyncapi/diff": "^0.4.1",
|
|
35
35
|
"@asyncapi/modelina": "^1.8.4",
|
|
36
36
|
"@asyncapi/parser": "^2.0.2",
|
|
37
|
-
"@axinom/mosaic-id-link-be": "^0.32.0
|
|
38
|
-
"@axinom/mosaic-service-common": "^0.62.0
|
|
37
|
+
"@axinom/mosaic-id-link-be": "^0.32.0",
|
|
38
|
+
"@axinom/mosaic-service-common": "^0.62.0",
|
|
39
39
|
"@graphql-inspector/core": "^3.1.2",
|
|
40
40
|
"@inquirer/prompts": "^4.3.0",
|
|
41
41
|
"@stoplight/spectral-core": "^1.18.3",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "53c1540262d00a496b37c1518bab28141474da9a"
|
|
81
81
|
}
|
|
@@ -7,37 +7,85 @@ import {
|
|
|
7
7
|
} from '@axinom/mosaic-service-common';
|
|
8
8
|
import * as chalk from 'chalk';
|
|
9
9
|
import { ExecException, exec } from 'child_process';
|
|
10
|
-
import { existsSync, mkdirSync } from 'fs';
|
|
11
|
-
import { dirname, join, normalize, relative } from 'path';
|
|
10
|
+
import { existsSync, mkdirSync, statSync } from 'fs';
|
|
11
|
+
import { basename, dirname, isAbsolute, join, normalize, relative } from 'path';
|
|
12
12
|
import { exitCode, getTimestamp } from '../../common';
|
|
13
13
|
import { PgDumpOptions } from './pg-dump-options';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Type needed for findCompose functions
|
|
17
|
+
*/
|
|
18
|
+
interface ComposePathResult {
|
|
19
|
+
dirName: string;
|
|
20
|
+
fileName: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Convert absolute path to ComposePathResult
|
|
25
|
+
* dirName would be relative to the current working directory
|
|
26
|
+
*/
|
|
27
|
+
const absolutePathToRelativeDirNameAndFileName = (
|
|
28
|
+
absPath: string,
|
|
29
|
+
): ComposePathResult => {
|
|
30
|
+
return {
|
|
31
|
+
dirName: dirname(relative(process.cwd(), absPath)),
|
|
32
|
+
fileName: basename(absPath),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
15
36
|
/**
|
|
16
37
|
* Calculates a path to `docker-compose.yaml` file based on initial path.
|
|
17
38
|
* For example, if `scripts/infra` is provided as initial path, it will look for `scripts/infra/docker-compose.yml` in current folder, then in folder one hierarchy level up, traversing directories towards root.
|
|
18
39
|
* Returns a value like `../../../scripts/infra` or throws an error.
|
|
19
40
|
* Eliminates the need to calculate how many `..` you must have in the path to docker compose file which is passed as a cli parameter.
|
|
20
41
|
*/
|
|
21
|
-
const findComposePath = (initialPath: string):
|
|
42
|
+
const findComposePath = (initialPath: string): ComposePathResult => {
|
|
43
|
+
const supportedComposeFiles = ['docker-compose.yml', 'docker-compose.yaml'];
|
|
22
44
|
let startPath = process.cwd();
|
|
23
45
|
let lastPath = '';
|
|
24
46
|
|
|
25
47
|
while (lastPath !== startPath) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
lastPath = startPath;
|
|
32
|
-
// Remove last segment from path, move to directory closer to root
|
|
33
|
-
startPath = normalize(join(startPath, '..'));
|
|
48
|
+
for (const file of supportedComposeFiles) {
|
|
49
|
+
const lookupPath = join(startPath, initialPath, file);
|
|
50
|
+
if (existsSync(lookupPath)) {
|
|
51
|
+
return absolutePathToRelativeDirNameAndFileName(lookupPath);
|
|
52
|
+
}
|
|
34
53
|
}
|
|
54
|
+
|
|
55
|
+
// Preserve currently checked path for while condition comparison
|
|
56
|
+
lastPath = startPath;
|
|
57
|
+
// Remove last segment from path, move to directory closer to root
|
|
58
|
+
startPath = normalize(join(startPath, '..'));
|
|
35
59
|
}
|
|
36
60
|
throw Error(
|
|
37
|
-
`'${initialPath}/docker-compose.
|
|
61
|
+
`'${initialPath}/docker-compose.y(a)ml' file not found. Please make sure that correct composeFolderPath parameter is provided.`,
|
|
38
62
|
);
|
|
39
63
|
};
|
|
40
64
|
|
|
65
|
+
/**
|
|
66
|
+
* checks if the given path to file exists. and returns the directory path and file name of the file
|
|
67
|
+
*/
|
|
68
|
+
const findComposeFilePath = (initialPath: string): ComposePathResult => {
|
|
69
|
+
const isAbs = isAbsolute(initialPath);
|
|
70
|
+
const lookupPath = isAbs ? initialPath : join(process.cwd(), initialPath);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const fileStats = statSync(lookupPath);
|
|
74
|
+
|
|
75
|
+
if (fileStats.isFile()) {
|
|
76
|
+
return absolutePathToRelativeDirNameAndFileName(lookupPath);
|
|
77
|
+
} else {
|
|
78
|
+
throw Error(
|
|
79
|
+
`'${initialPath}' is not a file. Please make sure that correct composeFilePath parameter is provided.`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw Error(
|
|
84
|
+
`'${initialPath}' file not found. Please make sure that correct composeFilePath parameter is provided.`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
41
89
|
/**
|
|
42
90
|
* Loads and validates all required environment variables that are used to create a shadow database connection string.
|
|
43
91
|
* For this to work, CLI script must be called with pre-loaded variables. e.g.
|
|
@@ -87,7 +135,18 @@ const ensureDumpDirectoryExist = (targetPath: string): string => {
|
|
|
87
135
|
export const generate = (options: PgDumpOptions): void => {
|
|
88
136
|
try {
|
|
89
137
|
console.log(getTimestamp(), `Starting pg-dump command...`);
|
|
90
|
-
|
|
138
|
+
let composeDirPath = '';
|
|
139
|
+
let composeFileName = 'docker-compose.yml';
|
|
140
|
+
|
|
141
|
+
if (options.composeFilePath) {
|
|
142
|
+
({ dirName: composeDirPath, fileName: composeFileName } =
|
|
143
|
+
findComposeFilePath(normalize(options.composeFilePath)));
|
|
144
|
+
} else {
|
|
145
|
+
({ dirName: composeDirPath, fileName: composeFileName } = findComposePath(
|
|
146
|
+
normalize(options.composeFolderPath),
|
|
147
|
+
));
|
|
148
|
+
}
|
|
149
|
+
|
|
91
150
|
const connectionString = getDumpDbConnectionString(
|
|
92
151
|
options.connectionString,
|
|
93
152
|
);
|
|
@@ -106,7 +165,7 @@ export const generate = (options: PgDumpOptions): void => {
|
|
|
106
165
|
].join(' ');
|
|
107
166
|
|
|
108
167
|
exec(
|
|
109
|
-
`cd ${
|
|
168
|
+
`cd "${composeDirPath}" && docker compose -f "${composeFileName}" exec -T postgres pg_dump ${dumpOptions} > "${dumpPath}"`,
|
|
110
169
|
(_error: ExecException | null, stdout: string, stderr: string) => {
|
|
111
170
|
if (stdout) {
|
|
112
171
|
console.log(getTimestamp(), 'pg_dump info:', stdout);
|
|
@@ -12,7 +12,13 @@ export const pgDump: CommandModule<unknown, PgDumpOptions> = {
|
|
|
12
12
|
alias: 'c',
|
|
13
13
|
default: 'infra',
|
|
14
14
|
describe:
|
|
15
|
-
'Relative path to docker-compose.
|
|
15
|
+
'Relative path to docker-compose.y(a)ml file, e.g. `infra` or `scripts/infra`. Script will look for such directory starting from current project, traversing directories closer to root, so no need to specify a path like `../../../infra`',
|
|
16
|
+
string: true,
|
|
17
|
+
})
|
|
18
|
+
.option('composeFilePath', {
|
|
19
|
+
alias: 'f',
|
|
20
|
+
describe:
|
|
21
|
+
'Relative or Absolute file path to the y(a)ml file. This option would override any composeFolderPath setting.',
|
|
16
22
|
string: true,
|
|
17
23
|
})
|
|
18
24
|
.option('dumpPath', {
|