1 | "use strict";
|
2 | var __assign = (this && this.__assign) || function () {
|
3 | __assign = Object.assign || function(t) {
|
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5 | s = arguments[i];
|
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7 | t[p] = s[p];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | return __assign.apply(this, arguments);
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | var child_process = require("child_process");
|
15 | var dump_1 = require("./dump");
|
16 | var git_1 = require("./git");
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | var callTortillaFn = function (fnName) {
|
23 | var args = [];
|
24 | for (var _i = 1; _i < arguments.length; _i++) {
|
25 | args[_i - 1] = arguments[_i];
|
26 | }
|
27 | return new Promise(function (resolve, reject) {
|
28 |
|
29 |
|
30 | var worker = child_process.fork(__filename, [], {
|
31 | env: __assign({}, process.env, { TORTILLA_WORKER: 1 })
|
32 | });
|
33 | worker.send({
|
34 | op: 'exec',
|
35 | fn: fnName,
|
36 | args: args,
|
37 | });
|
38 |
|
39 | worker.on('message', function (msg) {
|
40 | if (typeof msg !== 'object') {
|
41 | return;
|
42 | }
|
43 | if (msg.op !== 'result') {
|
44 | return;
|
45 | }
|
46 | if (msg.fn !== fnName) {
|
47 | return;
|
48 | }
|
49 | resolve(msg.payload);
|
50 | });
|
51 |
|
52 | worker.on('message', function (msg) {
|
53 | if (typeof msg !== 'object') {
|
54 | return;
|
55 | }
|
56 | if (msg.op !== 'error') {
|
57 | return;
|
58 | }
|
59 | if (msg.fn !== fnName) {
|
60 | return;
|
61 | }
|
62 | reject(msg.payload);
|
63 | });
|
64 | });
|
65 | };
|
66 |
|
67 | var withUser = function (fn) { return function () {
|
68 | var args = [];
|
69 | for (var _i = 0; _i < arguments.length; _i++) {
|
70 | args[_i] = arguments[_i];
|
71 | }
|
72 | var result = '';
|
73 | var nameExists = false;
|
74 | var emailExists = false;
|
75 |
|
76 | try {
|
77 |
|
78 | try {
|
79 | git_1.Git(['config', '--global', 'user.name']);
|
80 | nameExists = true;
|
81 | }
|
82 | catch (e) {
|
83 | git_1.Git(['config', '--global', 'user.name', 'tortilla']);
|
84 | }
|
85 |
|
86 | try {
|
87 | git_1.Git(['config', '--global', 'user.email']);
|
88 | emailExists = true;
|
89 | }
|
90 | catch (e) {
|
91 | git_1.Git(['config', '--global', 'user.email', 'tortilla@tortilla.academy']);
|
92 | }
|
93 | result = fn.apply(void 0, args);
|
94 | }
|
95 | finally {
|
96 | if (!nameExists) {
|
97 | git_1.Git(['config', '--global', '--unset', 'user.name']);
|
98 | }
|
99 | if (!emailExists) {
|
100 | git_1.Git(['config', '--global', '--unset', 'user.email']);
|
101 | }
|
102 | }
|
103 | return result;
|
104 | }; };
|
105 | exports.diffReleases = withUser(function (dump, srcRelease, destRelease) {
|
106 | return dump_1.Dump.diffReleases(dump, srcRelease, destRelease);
|
107 | });
|
108 |
|
109 | if (!process.env.TORTILLA_WORKER) {
|
110 |
|
111 | process.on('message', function (msg) {
|
112 | if (msg.op !== 'exec') {
|
113 | return;
|
114 | }
|
115 | var handler;
|
116 | switch (msg.fn) {
|
117 | case 'diffReleases': {
|
118 | handler = exports.diffReleases;
|
119 | break;
|
120 | }
|
121 |
|
122 | default: return;
|
123 | }
|
124 | try {
|
125 | var result = handler.apply(void 0, msg.args);
|
126 | process.send({
|
127 | op: 'result',
|
128 | fn: msg.fn,
|
129 | id: msg.id,
|
130 | payload: result,
|
131 | });
|
132 | }
|
133 | catch (e) {
|
134 | process.send({
|
135 | op: 'error',
|
136 | fn: msg.fn,
|
137 | id: msg.id,
|
138 | payload: e,
|
139 | });
|
140 | }
|
141 | });
|
142 | }
|
143 |
|
\ | No newline at end of file |