@catladder/cli 1.105.2 → 1.106.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/apps/cli/commands/cloudSQL/commandRestoreDb.js +10 -22
- package/dist/apps/cli/commands/cloudSQL/commandRestoreDb.js.map +1 -1
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js +4 -4
- package/dist/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -1
- package/dist/bundles/catenv/index.js +1 -1
- package/dist/bundles/cli/index.js +2 -2
- package/dist/gcloud/cloudSql/startProxy.d.ts +10 -0
- package/dist/gcloud/cloudSql/startProxy.js +121 -0
- package/dist/gcloud/cloudSql/startProxy.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/apps/cli/commands/cloudSQL/commandRestoreDb.ts +14 -29
- package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +6 -9
- package/src/gcloud/cloudSql/startProxy.ts +74 -0
- package/src/types/child-process-promise.d.ts +2 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const ERROR_NOT_INSTALLED = "cloud-sql-proxy not installed";
|
|
2
|
+
export declare type CloudSqlBackgroundProxy = {
|
|
3
|
+
stop: () => void;
|
|
4
|
+
};
|
|
5
|
+
export declare type CloudSqlProxyOptions = {
|
|
6
|
+
instanceName: string;
|
|
7
|
+
localPort: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const startCloudSqlProxyInCurrentShell: (opts: CloudSqlProxyOptions) => Promise<void>;
|
|
10
|
+
export declare const startCloudSqlProxyInBackground: (opts: CloudSqlProxyOptions) => Promise<CloudSqlBackgroundProxy>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
exports.__esModule = true;
|
|
42
|
+
exports.startCloudSqlProxyInBackground = exports.startCloudSqlProxyInCurrentShell = exports.ERROR_NOT_INSTALLED = void 0;
|
|
43
|
+
var child_process_promise_1 = require("child-process-promise");
|
|
44
|
+
var command_exists_promise_1 = __importDefault(require("command-exists-promise"));
|
|
45
|
+
exports.ERROR_NOT_INSTALLED = "cloud-sql-proxy not installed";
|
|
46
|
+
var getProxyCommandSpawnArgs = function (_a) {
|
|
47
|
+
var localPort = _a.localPort, instanceName = _a.instanceName;
|
|
48
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
var commandString, _b, _c, cmd, args;
|
|
50
|
+
return __generator(this, function (_d) {
|
|
51
|
+
switch (_d.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, (0, command_exists_promise_1["default"])("cloud-sql-proxy")];
|
|
53
|
+
case 1:
|
|
54
|
+
if (!(_d.sent())) return [3 /*break*/, 2];
|
|
55
|
+
_b = "cloud-sql-proxy --port ".concat(localPort, " ").concat(instanceName);
|
|
56
|
+
return [3 /*break*/, 4];
|
|
57
|
+
case 2: return [4 /*yield*/, (0, command_exists_promise_1["default"])("cloud_sql_proxy" // v1
|
|
58
|
+
)];
|
|
59
|
+
case 3:
|
|
60
|
+
_b = (_d.sent())
|
|
61
|
+
? "cloud_sql_proxy -instances ".concat(instanceName, "=tcp:").concat(localPort)
|
|
62
|
+
: null;
|
|
63
|
+
_d.label = 4;
|
|
64
|
+
case 4:
|
|
65
|
+
commandString = _b;
|
|
66
|
+
if (!commandString) {
|
|
67
|
+
throw new Error(exports.ERROR_NOT_INSTALLED);
|
|
68
|
+
}
|
|
69
|
+
_c = commandString.split(" "), cmd = _c[0], args = _c.slice(1);
|
|
70
|
+
return [2 /*return*/, { cmd: cmd, args: args }];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var startCloudSqlProxyInCurrentShell = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
76
|
+
var _a, cmd, args;
|
|
77
|
+
return __generator(this, function (_b) {
|
|
78
|
+
switch (_b.label) {
|
|
79
|
+
case 0: return [4 /*yield*/, getProxyCommandSpawnArgs(opts)];
|
|
80
|
+
case 1:
|
|
81
|
+
_a = _b.sent(), cmd = _a.cmd, args = _a.args;
|
|
82
|
+
return [4 /*yield*/, (0, child_process_promise_1.spawn)(cmd, args, {
|
|
83
|
+
stdio: "inherit",
|
|
84
|
+
shell: true
|
|
85
|
+
})];
|
|
86
|
+
case 2:
|
|
87
|
+
_b.sent();
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); };
|
|
92
|
+
exports.startCloudSqlProxyInCurrentShell = startCloudSqlProxyInCurrentShell;
|
|
93
|
+
var startCloudSqlProxyInBackground = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
94
|
+
var _a, cmd, args, proxyPromise, stop;
|
|
95
|
+
return __generator(this, function (_b) {
|
|
96
|
+
switch (_b.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, getProxyCommandSpawnArgs(opts)];
|
|
98
|
+
case 1:
|
|
99
|
+
_a = _b.sent(), cmd = _a.cmd, args = _a.args;
|
|
100
|
+
proxyPromise = (0, child_process_promise_1.spawn)(cmd, args, { shell: "bash" });
|
|
101
|
+
// wait until it starts
|
|
102
|
+
return [4 /*yield*/, (0, child_process_promise_1.spawn)("echo -n \"Waiting for proxy\"\n until echo > /dev/tcp/localhost/".concat(opts.localPort, "; do\n sleep 0.2\n echo -n \".\"\n done 2>/dev/null"), [], { shell: "bash" })];
|
|
103
|
+
case 2:
|
|
104
|
+
// wait until it starts
|
|
105
|
+
_b.sent();
|
|
106
|
+
stop = function () {
|
|
107
|
+
proxyPromise["catch"](function () {
|
|
108
|
+
// ignore
|
|
109
|
+
});
|
|
110
|
+
proxyPromise.childProcess.kill();
|
|
111
|
+
};
|
|
112
|
+
// stop if catladder i stopped
|
|
113
|
+
process.on("beforeExit", stop);
|
|
114
|
+
return [2 /*return*/, {
|
|
115
|
+
stop: stop
|
|
116
|
+
}];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}); };
|
|
120
|
+
exports.startCloudSqlProxyInBackground = startCloudSqlProxyInBackground;
|
|
121
|
+
//# sourceMappingURL=startProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startProxy.js","sourceRoot":"","sources":["../../../src/gcloud/cloudSql/startProxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA8C;AAC9C,kFAAmD;AAEtC,QAAA,mBAAmB,GAAG,+BAA+B,CAAC;AAWnE,IAAM,wBAAwB,GAAG,UAAO,EAGjB;QAFrB,SAAS,eAAA,EACT,YAAY,kBAAA;;;;;wBAEW,qBAAM,IAAA,mCAAa,EAAC,iBAAiB,CAAC,EAAA;;yBAAvC,CAAC,SAAsC,CAAC,EAAxC,wBAAwC;oBAC1D,KAAA,iCAA0B,SAAS,cAAI,YAAY,CAAE,CAAA;;wBACpD,qBAAM,IAAA,mCAAa,EAClB,iBAAiB,CAAC,KAAK;qBACxB,EAAA;;oBAFD,KAAA,CAAC,SAEA,CAAC;wBACJ,CAAC,CAAC,qCAA8B,YAAY,kBAAQ,SAAS,CAAE;wBAC/D,CAAC,CAAC,IAAI,CAAA;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