@oliasoft-open-source/node-json-migrator 2.3.0 → 2.3.1-beta-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/dist/git/git.js +72 -12
- package/package.json +1 -1
- package/release-notes.md +4 -0
- package/scripts/send-mattermost-message.sh +0 -0
package/dist/git/git.js
CHANGED
|
@@ -3,14 +3,68 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getPlanRevisionsFromGit = exports.getPlanFromGit = exports.getHistoricalPlansFromGit = exports.exec = void 0;
|
|
6
|
+
exports.terminals = exports.isWindows = exports.gitAvailable = exports.getTerminal = exports.getPlanRevisionsFromGit = exports.getPlanFromGit = exports.getHistoricalPlansFromGit = exports.exec = exports.commandAvailable = exports.cmdAvailable = exports.bashAvailable = void 0;
|
|
7
7
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
|
+
var _process = _interopRequireDefault(require("process"));
|
|
8
9
|
var _child_process = require("child_process");
|
|
9
10
|
var _hash = require("../hash/hash");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const {
|
|
13
|
+
platform
|
|
14
|
+
} = _process.default;
|
|
15
|
+
const isWindows = platform === 'win32';
|
|
16
|
+
exports.isWindows = isWindows;
|
|
17
|
+
const terminals = Object.freeze({
|
|
18
|
+
bash: 'bash',
|
|
19
|
+
cmd: 'cmd'
|
|
20
|
+
});
|
|
21
|
+
exports.terminals = terminals;
|
|
22
|
+
const historyError = `Unable to fetch git history. Possible reasons:
|
|
23
|
+
- Have you merged latest master branch into your environment (pull latest migrations)?
|
|
24
|
+
- Are you trying to downgrade data (not allowed), e.g. newer data into an older environment?
|
|
25
|
+
- Not allowed to export from TEST and import to PROD
|
|
26
|
+
- Not allowed to export datasets generated from migration feature branches into TEST, PROD or master ENVs
|
|
27
|
+
- On Windows? Do you have git and a terminal (bash or cmd) in your PATH? Try cmder.app, gitforwindows.org, or WSL
|
|
28
|
+
`;
|
|
29
|
+
const commandAvailable = command => {
|
|
30
|
+
try {
|
|
31
|
+
const exists = isWindows ? 'where' : 'which';
|
|
32
|
+
(0, _child_process.execSync)(`${exists} ${command}`);
|
|
33
|
+
return true;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.commandAvailable = commandAvailable;
|
|
39
|
+
const gitAvailable = () => commandAvailable('git');
|
|
40
|
+
exports.gitAvailable = gitAvailable;
|
|
41
|
+
const cmdAvailable = () => isWindows && commandAvailable('cmd');
|
|
42
|
+
exports.cmdAvailable = cmdAvailable;
|
|
43
|
+
const bashAvailable = () => {
|
|
44
|
+
if (commandAvailable('bash')) {
|
|
45
|
+
try {
|
|
46
|
+
const response = (0, _child_process.execSync)('bash --version').toString();
|
|
47
|
+
return response.includes('version');
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
};
|
|
54
|
+
exports.bashAvailable = bashAvailable;
|
|
55
|
+
const getTerminal = () => {
|
|
56
|
+
const bashActive = bashAvailable();
|
|
57
|
+
const cmdActive = cmdAvailable();
|
|
58
|
+
if (!(bashActive || cmdActive)) {
|
|
59
|
+
throw new Error('bash terminal (or cmd.exe on Windows) must be installed and in PATH');
|
|
60
|
+
}
|
|
61
|
+
return isWindows && !bashActive ? terminals.cmd : terminals.bash;
|
|
62
|
+
};
|
|
63
|
+
exports.getTerminal = getTerminal;
|
|
64
|
+
const exec = (command, terminal) => new Promise((resolve, reject) => {
|
|
65
|
+
const useWinCmd = terminal === terminals.cmd;
|
|
66
|
+
const args = useWinCmd ? ['/c', command] : ['-c', command];
|
|
67
|
+
const thread = (0, _child_process.spawn)(terminal, args, {
|
|
14
68
|
stdio: ['inherit', 'pipe', 'pipe']
|
|
15
69
|
});
|
|
16
70
|
const stdOut = [];
|
|
@@ -24,15 +78,15 @@ const exec = command => new Promise((resolve, reject) => {
|
|
|
24
78
|
thread.on('close', () => {
|
|
25
79
|
if (stdErr.length) {
|
|
26
80
|
reject(stdErr.join(''));
|
|
27
|
-
return;
|
|
28
81
|
}
|
|
29
82
|
resolve(stdOut.join(''));
|
|
30
83
|
});
|
|
31
84
|
});
|
|
32
85
|
exports.exec = exec;
|
|
33
|
-
const getPlanRevisionsFromGit = async planFilePath => {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
86
|
+
const getPlanRevisionsFromGit = async (planFilePath, terminal) => {
|
|
87
|
+
const command = terminal === terminals.bash ? `git rev-list --pretty="format:%H|%ad" HEAD ${planFilePath}` : `git rev-list --pretty="%H|%ad" HEAD ${planFilePath}`;
|
|
88
|
+
const stdOut = await exec(command, terminal);
|
|
89
|
+
const lines = stdOut.split(/\r\n|\r|\n/).filter(r => r?.includes('|')).map(r => r?.replace(/"/g, '')); //trim extra double quotes in Windows output
|
|
36
90
|
return lines.map(line => {
|
|
37
91
|
const [version, timeStamp] = line.split('|');
|
|
38
92
|
const utcTimeStamp = new Date(timeStamp).toISOString();
|
|
@@ -43,15 +97,20 @@ const getPlanRevisionsFromGit = async planFilePath => {
|
|
|
43
97
|
});
|
|
44
98
|
};
|
|
45
99
|
exports.getPlanRevisionsFromGit = getPlanRevisionsFromGit;
|
|
46
|
-
const getPlanFromGit = async (planFilePath, revision) => {
|
|
47
|
-
return exec(`git show ${revision}:${planFilePath}
|
|
100
|
+
const getPlanFromGit = async (planFilePath, revision, terminal) => {
|
|
101
|
+
return exec(`git show ${revision}:${planFilePath}`, terminal);
|
|
48
102
|
};
|
|
49
103
|
exports.getPlanFromGit = getPlanFromGit;
|
|
50
104
|
const getHistoricalPlansFromGit = async planFilePath => {
|
|
51
105
|
try {
|
|
52
|
-
const
|
|
106
|
+
const gitActive = gitAvailable();
|
|
107
|
+
if (!gitActive) {
|
|
108
|
+
throw new Error('git must be installed and in PATH');
|
|
109
|
+
}
|
|
110
|
+
const terminal = getTerminal();
|
|
111
|
+
const revisions = await getPlanRevisionsFromGit(planFilePath, terminal);
|
|
53
112
|
const historicalPlans = await Promise.all(revisions.map(async revision => {
|
|
54
|
-
const plan = await getPlanFromGit(planFilePath, revision.version);
|
|
113
|
+
const plan = await getPlanFromGit(planFilePath, revision.version, terminal);
|
|
55
114
|
const version = (0, _hash.hash)(plan);
|
|
56
115
|
return {
|
|
57
116
|
revision,
|
|
@@ -64,6 +123,7 @@ const getHistoricalPlansFromGit = async planFilePath => {
|
|
|
64
123
|
};
|
|
65
124
|
} catch (error) {
|
|
66
125
|
console.error(_chalk.default.red(error));
|
|
126
|
+
console.error(historyError);
|
|
67
127
|
throw new Error('Unable to fetch plan.json history from git');
|
|
68
128
|
}
|
|
69
129
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/node-json-migrator",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1-beta-1",
|
|
4
4
|
"description": "A library for JSON migrations",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npx babel src --ignore 'src/**/*.test.js' --out-dir dist --copy-files --no-copy-ignored",
|
package/release-notes.md
CHANGED
|
File without changes
|