@catladder/cli 1.102.0 → 1.103.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/catenv/catenv.d.ts +2 -4
- package/dist/apps/catenv/catenv.js +8 -89
- package/dist/apps/catenv/catenv.js.map +1 -1
- package/dist/apps/catenv/printVariables.d.ts +3 -0
- package/dist/apps/catenv/printVariables.js +111 -0
- package/dist/apps/catenv/printVariables.js.map +1 -0
- package/dist/apps/catenv/types.d.ts +5 -0
- package/dist/apps/catenv/types.js +3 -0
- package/dist/apps/catenv/types.js.map +1 -0
- package/dist/apps/catenv/utils.d.ts +12 -0
- package/dist/apps/catenv/utils.js +108 -0
- package/dist/apps/catenv/utils.js.map +1 -0
- package/dist/apps/catenv/writeDotEnvFiles.d.ts +3 -0
- package/dist/apps/catenv/writeDotEnvFiles.js +93 -0
- package/dist/apps/catenv/writeDotEnvFiles.js.map +1 -0
- package/dist/bundles/catenv/index.js +3 -3
- package/dist/bundles/cli/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/apps/catenv/catenv.ts +8 -65
- package/src/apps/catenv/printVariables.ts +51 -0
- package/src/apps/catenv/types.ts +6 -0
- package/src/apps/catenv/utils.ts +49 -0
- package/src/apps/catenv/writeDotEnvFiles.ts +45 -0
- package/tsconfig.json +1 -1
|
@@ -1,15 +1,4 @@
|
|
|
1
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
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -48,77 +37,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
37
|
};
|
|
49
38
|
exports.__esModule = true;
|
|
50
39
|
var getProjectConfig_1 = require("../../config/getProjectConfig");
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var getCurrentComponentName = function (components) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
-
var gitRoot, currentDir;
|
|
55
|
-
return __generator(this, function (_a) {
|
|
56
|
-
switch (_a.label) {
|
|
57
|
-
case 0: return [4 /*yield*/, (0, projects_1.getGitRoot)()];
|
|
58
|
-
case 1:
|
|
59
|
-
gitRoot = _a.sent();
|
|
60
|
-
currentDir = process.cwd();
|
|
61
|
-
return [2 /*return*/, Object.keys(components).find(function (c) {
|
|
62
|
-
return currentDir.startsWith((0, path_1.join)(gitRoot, components[c].dir));
|
|
63
|
-
})];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}); };
|
|
67
|
-
var sanitizeEnvVarName = function (name) { return name.replace(/[\s\-.]+/g, "_"); };
|
|
68
|
-
var getAllVariablesToPrint = function (config, choice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
-
var env, components, currentComponent, _a, variables;
|
|
70
|
-
var _b, _c;
|
|
71
|
-
return __generator(this, function (_d) {
|
|
72
|
-
switch (_d.label) {
|
|
73
|
-
case 0:
|
|
74
|
-
env = (_b = choice === null || choice === void 0 ? void 0 : choice.env) !== null && _b !== void 0 ? _b : "local";
|
|
75
|
-
components = config.components;
|
|
76
|
-
if (!((_c = choice === null || choice === void 0 ? void 0 : choice.componentName) !== null && _c !== void 0)) return [3 /*break*/, 1];
|
|
77
|
-
_a = _c;
|
|
78
|
-
return [3 /*break*/, 3];
|
|
79
|
-
case 1: return [4 /*yield*/, getCurrentComponentName(components)];
|
|
80
|
-
case 2:
|
|
81
|
-
_a = (_d.sent());
|
|
82
|
-
_d.label = 3;
|
|
83
|
-
case 3:
|
|
84
|
-
currentComponent = _a;
|
|
85
|
-
variables = {};
|
|
86
|
-
if (!currentComponent) return [3 /*break*/, 5];
|
|
87
|
-
return [4 /*yield*/, (0, getProjectConfig_1.getEnvVarsResolved)(null, env, currentComponent)];
|
|
88
|
-
case 4:
|
|
89
|
-
variables = _d.sent();
|
|
90
|
-
return [3 /*break*/, 7];
|
|
91
|
-
case 5: return [4 /*yield*/, Object.keys(components).reduce(function (acc, componentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
92
|
-
var subappvars, _a;
|
|
93
|
-
return __generator(this, function (_b) {
|
|
94
|
-
switch (_b.label) {
|
|
95
|
-
case 0: return [4 /*yield*/, (0, getProjectConfig_1.getEnvVarsResolved)(null, env, componentName)];
|
|
96
|
-
case 1:
|
|
97
|
-
subappvars = _b.sent();
|
|
98
|
-
_a = [{}];
|
|
99
|
-
return [4 /*yield*/, acc];
|
|
100
|
-
case 2: return [2 /*return*/, __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), subappvars]), Object.fromEntries(Object.entries(subappvars).map(function (_a) {
|
|
101
|
-
var key = _a[0], value = _a[1];
|
|
102
|
-
return [
|
|
103
|
-
"".concat(sanitizeEnvVarName(componentName.toUpperCase()), "_").concat(key),
|
|
104
|
-
value,
|
|
105
|
-
];
|
|
106
|
-
}))])];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}); }, {})];
|
|
110
|
-
case 6:
|
|
111
|
-
// when in a monorep and not in a subapp, merge all env vars.
|
|
112
|
-
// this is not 100% correct, but better than not exporting any vars at all
|
|
113
|
-
// so we also add prefixed variants
|
|
114
|
-
variables = _d.sent();
|
|
115
|
-
_d.label = 7;
|
|
116
|
-
case 7: return [2 /*return*/, variables];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}); };
|
|
40
|
+
var printVariables_1 = require("./printVariables");
|
|
41
|
+
var writeDotEnvFiles_1 = require("./writeDotEnvFiles");
|
|
120
42
|
exports["default"] = (function (choice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
121
|
-
var config
|
|
43
|
+
var config;
|
|
122
44
|
return __generator(this, function (_a) {
|
|
123
45
|
switch (_a.label) {
|
|
124
46
|
case 0: return [4 /*yield*/, (0, getProjectConfig_1.getProjectConfig)()];
|
|
@@ -127,15 +49,12 @@ exports["default"] = (function (choice) { return __awaiter(void 0, void 0, void
|
|
|
127
49
|
if (!config) {
|
|
128
50
|
return [2 /*return*/];
|
|
129
51
|
}
|
|
130
|
-
return [4 /*yield*/,
|
|
52
|
+
return [4 /*yield*/, (0, printVariables_1.printVariables)(config, choice)];
|
|
131
53
|
case 2:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return "export ".concat(key, "='").concat(value, "'");
|
|
137
|
-
})
|
|
138
|
-
.join("\n"));
|
|
54
|
+
_a.sent();
|
|
55
|
+
return [4 /*yield*/, (0, writeDotEnvFiles_1.writeDotEnvFiles)(config, choice)];
|
|
56
|
+
case 3:
|
|
57
|
+
_a.sent();
|
|
139
58
|
return [2 /*return*/];
|
|
140
59
|
}
|
|
141
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catenv.js","sourceRoot":"","sources":["../../../src/apps/catenv/catenv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"catenv.js","sourceRoot":"","sources":["../../../src/apps/catenv/catenv.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kEAAiE;AACjE,mDAAkD;AAElD,uDAAsD;AAEtD,sBAAe,UAAO,MAAe;;;;oBACpB,qBAAM,IAAA,mCAAgB,GAAE,EAAA;;gBAAjC,MAAM,GAAG,SAAwB;gBACvC,IAAI,CAAC,MAAM,EAAE;oBACX,sBAAO;iBACR;gBAED,qBAAM,IAAA,+BAAc,EAAC,MAAM,EAAE,MAAM,CAAC,EAAA;;gBAApC,SAAoC,CAAC;gBAErC,qBAAM,IAAA,mCAAgB,EAAC,MAAM,EAAE,MAAM,CAAC,EAAA;;gBAAtC,SAAsC,CAAC;;;;KACxC,EAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.__esModule = true;
|
|
50
|
+
exports.printVariables = void 0;
|
|
51
|
+
var getProjectConfig_1 = require("../../config/getProjectConfig");
|
|
52
|
+
var utils_1 = require("./utils");
|
|
53
|
+
var getAllVariablesToPrint = function (config, choice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
+
var _a, env, currentComponent, variables;
|
|
55
|
+
return __generator(this, function (_b) {
|
|
56
|
+
switch (_b.label) {
|
|
57
|
+
case 0: return [4 /*yield*/, (0, utils_1.getCurrentComponentAndEnvFromChoice)(config, choice)];
|
|
58
|
+
case 1:
|
|
59
|
+
_a = _b.sent(), env = _a.env, currentComponent = _a.currentComponent;
|
|
60
|
+
variables = {};
|
|
61
|
+
if (!currentComponent) return [3 /*break*/, 3];
|
|
62
|
+
return [4 /*yield*/, (0, getProjectConfig_1.getEnvVarsResolved)(null, env, currentComponent)];
|
|
63
|
+
case 2:
|
|
64
|
+
variables = _b.sent();
|
|
65
|
+
return [3 /*break*/, 5];
|
|
66
|
+
case 3: return [4 /*yield*/, Object.keys(config.components).reduce(function (acc, componentName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
+
var subappvars, _a;
|
|
68
|
+
return __generator(this, function (_b) {
|
|
69
|
+
switch (_b.label) {
|
|
70
|
+
case 0: return [4 /*yield*/, (0, getProjectConfig_1.getEnvVarsResolved)(null, env, componentName)];
|
|
71
|
+
case 1:
|
|
72
|
+
subappvars = _b.sent();
|
|
73
|
+
_a = [{}];
|
|
74
|
+
return [4 /*yield*/, acc];
|
|
75
|
+
case 2: return [2 /*return*/, __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _a.concat([(_b.sent())])), subappvars]), Object.fromEntries(Object.entries(subappvars).map(function (_a) {
|
|
76
|
+
var key = _a[0], value = _a[1];
|
|
77
|
+
return [
|
|
78
|
+
"".concat((0, utils_1.sanitizeEnvVarName)(componentName.toUpperCase()), "_").concat(key),
|
|
79
|
+
value,
|
|
80
|
+
];
|
|
81
|
+
}))])];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); }, {})];
|
|
85
|
+
case 4:
|
|
86
|
+
// when in a monorep and not in a subapp, merge all env vars.
|
|
87
|
+
// this is not 100% correct, but better than not exporting any vars at all
|
|
88
|
+
// so we also add prefixed variants
|
|
89
|
+
variables = _b.sent();
|
|
90
|
+
_b.label = 5;
|
|
91
|
+
case 5: return [2 /*return*/, variables];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}); };
|
|
95
|
+
var printVariables = function (config, choice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
+
var variables;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0: return [4 /*yield*/, getAllVariablesToPrint(config, choice)];
|
|
100
|
+
case 1:
|
|
101
|
+
variables = _a.sent();
|
|
102
|
+
console.log(makeExportKeyValuestring(variables));
|
|
103
|
+
return [2 /*return*/];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}); };
|
|
107
|
+
exports.printVariables = printVariables;
|
|
108
|
+
var makeExportKeyValuestring = function (variables) {
|
|
109
|
+
return (0, utils_1.makeKeyValueString)(variables, "export ");
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=printVariables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printVariables.js","sourceRoot":"","sources":["../../../src/apps/catenv/printVariables.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kEAAmE;AAEnE,iCAIiB;AAEjB,IAAM,sBAAsB,GAAG,UAAO,MAAc,EAAE,MAAe;;;;oBACjC,qBAAM,IAAA,2CAAmC,EACzE,MAAM,EACN,MAAM,CACP,EAAA;;gBAHK,KAA4B,SAGjC,EAHO,GAAG,SAAA,EAAE,gBAAgB,sBAAA;gBAKzB,SAAS,GAAG,EAAE,CAAC;qBACf,gBAAgB,EAAhB,wBAAgB;gBACN,qBAAM,IAAA,qCAAkB,EAAC,IAAI,EAAE,GAAG,EAAE,gBAAgB,CAAC,EAAA;;gBAAjE,SAAS,GAAG,SAAqD,CAAC;;oBAKtD,qBAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CACrD,UAAO,GAAG,EAAE,aAAa;;;;oCACJ,qBAAM,IAAA,qCAAkB,EAAC,IAAI,EAAE,GAAG,EAAE,aAAa,CAAC,EAAA;;gCAA/D,UAAU,GAAG,SAAkD;;gCAE/D,qBAAM,GAAG,EAAA;oCADf,wGACK,CAAC,SAAS,CAAC,KACX,UAAU,IAEV,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,UAAC,EAAY;4CAAX,GAAG,QAAA,EAAE,KAAK,QAAA;wCAAM,OAAA;4CAC/C,UAAG,IAAA,0BAAkB,EAAC,aAAa,CAAC,WAAW,EAAE,CAAC,cAAI,GAAG,CAAE;4CAC3D,KAAK;yCACN;oCAHgD,CAGhD,CAAC,CACH,IACD;;;qBACH,EACD,EAAE,CACH,EAAA;;gBAnBD,6DAA6D;gBAC7D,0EAA0E;gBAC1E,mCAAmC;gBACnC,SAAS,GAAG,SAgBX,CAAC;;oBAEJ,sBAAO,SAAS,EAAC;;;KAClB,CAAC;AAEK,IAAM,cAAc,GAAG,UAAO,MAAc,EAAE,MAAe;;;;oBAChD,qBAAM,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,EAAA;;gBAAxD,SAAS,GAAG,SAA4C;gBAE9D,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC,CAAC;;;;KAClD,CAAC;AAJW,QAAA,cAAc,kBAIzB;AAEF,IAAM,wBAAwB,GAAG,UAAC,SAAoB;IACpD,OAAA,IAAA,0BAAkB,EAAC,SAAS,EAAE,SAAS,CAAC;AAAxC,CAAwC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/apps/catenv/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config } from "@catladder/pipeline";
|
|
2
|
+
import type { Choice, Variables } from "./types";
|
|
3
|
+
export declare const getComponentFullPath: (gitRoot: string, config: Config, componentName: string) => string;
|
|
4
|
+
export declare const getCurrentComponentAndEnvFromChoice: (config: Config, choice?: Choice) => Promise<{
|
|
5
|
+
currentComponent: string;
|
|
6
|
+
env: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const makeKeyValueString: (variables: Variables, keyPrefix?: string) => string;
|
|
9
|
+
export declare const sanitizeMultiLine: (variables: Variables) => {
|
|
10
|
+
[k: string]: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const sanitizeEnvVarName: (name: string) => string;
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
exports.__esModule = true;
|
|
39
|
+
exports.sanitizeEnvVarName = exports.sanitizeMultiLine = exports.makeKeyValueString = exports.getCurrentComponentAndEnvFromChoice = exports.getComponentFullPath = void 0;
|
|
40
|
+
var path_1 = require("path");
|
|
41
|
+
var projects_1 = require("../../utils/projects");
|
|
42
|
+
var getComponentFullPath = function (gitRoot, config, componentName) {
|
|
43
|
+
return (0, path_1.join)(gitRoot, config.components[componentName].dir);
|
|
44
|
+
};
|
|
45
|
+
exports.getComponentFullPath = getComponentFullPath;
|
|
46
|
+
var getCurrentComponentName = function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
var gitRoot, currentDir;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0: return [4 /*yield*/, (0, projects_1.getGitRoot)()];
|
|
51
|
+
case 1:
|
|
52
|
+
gitRoot = _a.sent();
|
|
53
|
+
currentDir = process.cwd();
|
|
54
|
+
return [2 /*return*/, Object.keys(config.components).find(function (c) {
|
|
55
|
+
return currentDir.startsWith((0, exports.getComponentFullPath)(gitRoot, config, c));
|
|
56
|
+
})];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); };
|
|
60
|
+
var getCurrentComponentAndEnvFromChoice = function (config, choice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
61
|
+
var env, currentComponent, _a;
|
|
62
|
+
var _b, _c;
|
|
63
|
+
return __generator(this, function (_d) {
|
|
64
|
+
switch (_d.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
env = (_b = choice === null || choice === void 0 ? void 0 : choice.env) !== null && _b !== void 0 ? _b : "local";
|
|
67
|
+
if (!((_c = choice === null || choice === void 0 ? void 0 : choice.componentName) !== null && _c !== void 0)) return [3 /*break*/, 1];
|
|
68
|
+
_a = _c;
|
|
69
|
+
return [3 /*break*/, 3];
|
|
70
|
+
case 1: return [4 /*yield*/, getCurrentComponentName(config)];
|
|
71
|
+
case 2:
|
|
72
|
+
_a = (_d.sent());
|
|
73
|
+
_d.label = 3;
|
|
74
|
+
case 3:
|
|
75
|
+
currentComponent = _a;
|
|
76
|
+
return [2 /*return*/, {
|
|
77
|
+
currentComponent: currentComponent,
|
|
78
|
+
env: env
|
|
79
|
+
}];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); };
|
|
83
|
+
exports.getCurrentComponentAndEnvFromChoice = getCurrentComponentAndEnvFromChoice;
|
|
84
|
+
var makeKeyValueString = function (variables, keyPrefix) {
|
|
85
|
+
if (keyPrefix === void 0) { keyPrefix = ""; }
|
|
86
|
+
return Object.entries(variables)
|
|
87
|
+
.map(function (_a) {
|
|
88
|
+
var key = _a[0], value = _a[1];
|
|
89
|
+
return "".concat(keyPrefix).concat(key, "='").concat(value, "'");
|
|
90
|
+
})
|
|
91
|
+
.join("\n");
|
|
92
|
+
};
|
|
93
|
+
exports.makeKeyValueString = makeKeyValueString;
|
|
94
|
+
var sanitizeMultiLine = function (variables) {
|
|
95
|
+
return Object.fromEntries(Object.entries(variables).map(function (_a) {
|
|
96
|
+
var key = _a[0], value = _a[1];
|
|
97
|
+
return [
|
|
98
|
+
key,
|
|
99
|
+
value.replaceAll("\n", "\\n"),
|
|
100
|
+
];
|
|
101
|
+
}));
|
|
102
|
+
};
|
|
103
|
+
exports.sanitizeMultiLine = sanitizeMultiLine;
|
|
104
|
+
var sanitizeEnvVarName = function (name) {
|
|
105
|
+
return name.replace(/[\s\-.]+/g, "_");
|
|
106
|
+
};
|
|
107
|
+
exports.sanitizeEnvVarName = sanitizeEnvVarName;
|
|
108
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/apps/catenv/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6BAA4B;AAC5B,iDAAkD;AAE3C,IAAM,oBAAoB,GAAG,UAClC,OAAe,EACf,MAAc,EACd,aAAqB;IAErB,OAAO,IAAA,WAAI,EAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7D,CAAC,CAAC;AANW,QAAA,oBAAoB,wBAM/B;AACF,IAAM,uBAAuB,GAAG,UAAO,MAAc;;;;oBACnC,qBAAM,IAAA,qBAAU,GAAE,EAAA;;gBAA5B,OAAO,GAAG,SAAkB;gBAC5B,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;gBACjC,sBAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC;wBAC3C,OAAA,UAAU,CAAC,UAAU,CAAC,IAAA,4BAAoB,EAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;oBAA/D,CAA+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AA9B,CAA8B,CAAC;AADpB,QAAA,kBAAkB,sBACE"}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
exports.__esModule = true;
|
|
39
|
+
exports.writeDotEnvFiles = void 0;
|
|
40
|
+
var fs_extra_1 = require("fs-extra");
|
|
41
|
+
var path_1 = require("path");
|
|
42
|
+
var getProjectConfig_1 = require("../../config/getProjectConfig");
|
|
43
|
+
var projects_1 = require("../../utils/projects");
|
|
44
|
+
var utils_1 = require("./utils");
|
|
45
|
+
var writeDotEnvFiles = function (config, choice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
+
var _a, env, currentComponent, componentsWithEnabledDotEnvWrite, componentsToActuallyWriteDotEnvNow, gitRoot, _i, componentsToActuallyWriteDotEnvNow_1, componentName, variables, componentDir, filePath, variablesSanitized;
|
|
47
|
+
return __generator(this, function (_b) {
|
|
48
|
+
switch (_b.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, (0, utils_1.getCurrentComponentAndEnvFromChoice)(config, choice)];
|
|
50
|
+
case 1:
|
|
51
|
+
_a = _b.sent(), env = _a.env, currentComponent = _a.currentComponent;
|
|
52
|
+
componentsWithEnabledDotEnvWrite = Object.entries(config.components)
|
|
53
|
+
.filter(function (_a) {
|
|
54
|
+
var component = _a[1];
|
|
55
|
+
return component === null || component === void 0 ? void 0 : component.dotEnv;
|
|
56
|
+
})
|
|
57
|
+
.map(function (_a) {
|
|
58
|
+
var componentName = _a[0];
|
|
59
|
+
return componentName;
|
|
60
|
+
});
|
|
61
|
+
componentsToActuallyWriteDotEnvNow = currentComponent
|
|
62
|
+
? componentsWithEnabledDotEnvWrite.includes(currentComponent)
|
|
63
|
+
? [currentComponent]
|
|
64
|
+
: []
|
|
65
|
+
: componentsWithEnabledDotEnvWrite;
|
|
66
|
+
return [4 /*yield*/, (0, projects_1.getGitRoot)()];
|
|
67
|
+
case 2:
|
|
68
|
+
gitRoot = _b.sent();
|
|
69
|
+
_i = 0, componentsToActuallyWriteDotEnvNow_1 = componentsToActuallyWriteDotEnvNow;
|
|
70
|
+
_b.label = 3;
|
|
71
|
+
case 3:
|
|
72
|
+
if (!(_i < componentsToActuallyWriteDotEnvNow_1.length)) return [3 /*break*/, 7];
|
|
73
|
+
componentName = componentsToActuallyWriteDotEnvNow_1[_i];
|
|
74
|
+
return [4 /*yield*/, (0, getProjectConfig_1.getEnvVarsResolved)(null, env, componentName)];
|
|
75
|
+
case 4:
|
|
76
|
+
variables = _b.sent();
|
|
77
|
+
componentDir = (0, utils_1.getComponentFullPath)(gitRoot, config, componentName);
|
|
78
|
+
filePath = (0, path_1.join)(componentDir, ".env");
|
|
79
|
+
variablesSanitized = (0, utils_1.sanitizeMultiLine)(variables);
|
|
80
|
+
return [4 /*yield*/, (0, fs_extra_1.writeFile)(filePath, "# automatically created by catladder. Do not modify!\n\n" +
|
|
81
|
+
(0, utils_1.makeKeyValueString)(variablesSanitized))];
|
|
82
|
+
case 5:
|
|
83
|
+
_b.sent();
|
|
84
|
+
_b.label = 6;
|
|
85
|
+
case 6:
|
|
86
|
+
_i++;
|
|
87
|
+
return [3 /*break*/, 3];
|
|
88
|
+
case 7: return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); };
|
|
92
|
+
exports.writeDotEnvFiles = writeDotEnvFiles;
|
|
93
|
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