@dextinity/cli 2.0.0-canary-20260729062014

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.
@@ -0,0 +1,272 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
47
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48
+ return new (P || (P = Promise))(function (resolve, reject) {
49
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
50
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
51
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
52
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
53
+ });
54
+ };
55
+ var __generator = (this && this.__generator) || function (thisArg, body) {
56
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
57
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
58
+ function verb(n) { return function (v) { return step([n, v]); }; }
59
+ function step(op) {
60
+ if (f) throw new TypeError("Generator is already executing.");
61
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
62
+ 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;
63
+ if (y = 0, t) op = [op[0] & 2, t.value];
64
+ switch (op[0]) {
65
+ case 0: case 1: t = op; break;
66
+ case 4: _.label++; return { value: op[1], done: false };
67
+ case 5: _.label++; y = op[1]; op = [0]; continue;
68
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
69
+ default:
70
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
71
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
72
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
73
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74
+ if (t[2]) _.ops.pop();
75
+ _.trys.pop(); continue;
76
+ }
77
+ op = body.call(thisArg, _);
78
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
79
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
80
+ }
81
+ };
82
+ var __rest = (this && this.__rest) || function (s, e) {
83
+ var t = {};
84
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
85
+ t[p] = s[p];
86
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
87
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
88
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
89
+ t[p[i]] = s[p[i]];
90
+ }
91
+ return t;
92
+ };
93
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
94
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
95
+ if (ar || !(i in from)) {
96
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
97
+ ar[i] = from[i];
98
+ }
99
+ }
100
+ return to.concat(ar || Array.prototype.slice.call(from));
101
+ };
102
+ var __importDefault = (this && this.__importDefault) || function (mod) {
103
+ return (mod && mod.__esModule) ? mod : { "default": mod };
104
+ };
105
+ Object.defineProperty(exports, "__esModule", { value: true });
106
+ exports.resolveOpReferences = exports.injectSiteConfigsCommand = void 0;
107
+ /* eslint-disable no-console */
108
+ var child_process_1 = require("child_process");
109
+ var commander_1 = require("commander");
110
+ var fs_1 = __importDefault(require("fs"));
111
+ var path_1 = require("path");
112
+ exports.injectSiteConfigsCommand = new commander_1.Command("inject-site-configs")
113
+ .description("Inject site-configs into a file")
114
+ .requiredOption("-i, --in-file <file>", "The filename of a template file to inject.")
115
+ .requiredOption("-o, --out-file <file>", "Write the injected template to a file.")
116
+ .option("--base64", "use base64 encoding")
117
+ .option("-f, --site-config-file <file>", "Path to ts-file which provides a default export with (env: string) => SiteConfig[]")
118
+ .action(function (options) { return __awaiter(void 0, void 0, void 0, function () {
119
+ var configFile, getSiteConfigs, siteConfigsCache, getCachedSiteConfigs, str, getUrlFromDomain, replacerFunctions;
120
+ return __generator(this, function (_a) {
121
+ switch (_a.label) {
122
+ case 0:
123
+ configFile = "".concat(process.cwd(), "/").concat(options.siteConfigFile || "site-configs.ts");
124
+ return [4 /*yield*/, Promise.resolve("".concat(configFile)).then(function (s) { return __importStar(require(s)); })];
125
+ case 1:
126
+ getSiteConfigs = (_a.sent()).default;
127
+ siteConfigsCache = new Map();
128
+ getCachedSiteConfigs = function (env) { return __awaiter(void 0, void 0, void 0, function () {
129
+ var cached;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ cached = siteConfigsCache.get(env);
134
+ if (!!cached) return [3 /*break*/, 2];
135
+ return [4 /*yield*/, getSiteConfigs(env)];
136
+ case 1:
137
+ cached = _a.sent();
138
+ siteConfigsCache.set(env, cached);
139
+ _a.label = 2;
140
+ case 2: return [2 /*return*/, cached];
141
+ }
142
+ });
143
+ }); };
144
+ console.log("inject-site-configs: Replace site-configs in ".concat(options.inFile));
145
+ str = fs_1.default.readFileSync((0, path_1.resolve)(process.cwd(), options.inFile)).toString();
146
+ getUrlFromDomain = function (domain) {
147
+ return domain.includes("localhost") ? "http://".concat(domain) : "https://".concat(domain);
148
+ };
149
+ replacerFunctions = {
150
+ private: function (siteConfigs, env) {
151
+ return siteConfigs.map(function (siteConfig) {
152
+ return (function (_a) {
153
+ var _b, _c;
154
+ var publicVars = _a.public, rest = __rest(_a, ["public"]);
155
+ return (__assign(__assign(__assign({}, publicVars), rest), { url: getUrlFromDomain((_b = siteConfig.domains.preliminary) !== null && _b !== void 0 ? _b : siteConfig.domains.main), preloginEnabled: (_c = siteConfig.preloginEnabled) !== null && _c !== void 0 ? _c : !["prod", "local"].includes(env) }));
156
+ })(siteConfig);
157
+ });
158
+ },
159
+ public: function (siteConfigs) {
160
+ return siteConfigs.map(function (siteConfig) {
161
+ var _a;
162
+ return (__assign(__assign({}, siteConfig.public), { name: siteConfig.name, domains: siteConfig.domains, preloginEnabled: siteConfig.preloginEnabled || false, url: getUrlFromDomain((_a = siteConfig.domains.preliminary) !== null && _a !== void 0 ? _a : siteConfig.domains.main) }));
163
+ });
164
+ },
165
+ };
166
+ str = str.replace(/"({{ site:\/\/configs\/.*\/.* }})"/g, "'$1'"); // convert to single quotes
167
+ return [4 /*yield*/, replaceAsync(str, RegExp("{{ site://configs/(.*)/(.*) }}", "g"), function (substr, type, env) { return __awaiter(void 0, void 0, void 0, function () {
168
+ var siteConfigs, ret;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0: return [4 /*yield*/, getCachedSiteConfigs(env)];
172
+ case 1:
173
+ siteConfigs = _a.sent();
174
+ console.log("inject-site-configs: - ".concat(substr, " (").concat(siteConfigs.length, " sites)"));
175
+ if (replacerFunctions[type] == undefined) {
176
+ console.error("inject-site-configs: ERROR: type must be ".concat(Object.keys(replacerFunctions).join("|"), " (got ").concat(type, ")"));
177
+ return [2 /*return*/, substr];
178
+ }
179
+ ret = JSON.stringify(replacerFunctions[type](siteConfigs, env));
180
+ ret = (0, exports.resolveOpReferences)(ret);
181
+ if (options.base64) {
182
+ return [2 /*return*/, Buffer.from(ret).toString("base64")];
183
+ }
184
+ return [2 /*return*/, ret.replace(/\\/g, "\\\\")];
185
+ }
186
+ });
187
+ }); })];
188
+ case 2:
189
+ str = _a.sent();
190
+ str = str.replace(/"({{ site:\/\/domains\/.*\/.* }})"/g, "$1"); // remove quotes in array
191
+ return [4 /*yield*/, replaceAsync(str, /{{ site:\/\/domains\/(site|prelogin)\/(.*) }}/g, function (substr, type, env) { return __awaiter(void 0, void 0, void 0, function () {
192
+ var siteConfigs, filteredSiteConfigs;
193
+ return __generator(this, function (_a) {
194
+ switch (_a.label) {
195
+ case 0: return [4 /*yield*/, getCachedSiteConfigs(env)];
196
+ case 1:
197
+ siteConfigs = _a.sent();
198
+ console.log("inject-site-domains: - ".concat(substr, " (").concat(siteConfigs.length, " sites)"));
199
+ if (type === "site") {
200
+ filteredSiteConfigs = siteConfigs.filter(function (d) { return !d.preloginEnabled; });
201
+ return [2 /*return*/, JSON.stringify(__spreadArray(__spreadArray([], filteredSiteConfigs.map(function (d) { return d.domains.main; }), true), filteredSiteConfigs.filter(function (d) { return d.domains.additional; }).flatMap(function (d) { return d.domains.additional; }), true))];
202
+ }
203
+ else if (type === "prelogin") {
204
+ return [2 /*return*/, JSON.stringify(__spreadArray(__spreadArray([], siteConfigs.filter(function (d) { return d.preloginEnabled; }).map(function (d) { return d.domains.main; }), true), siteConfigs.filter(function (d) { return d.domains.preliminary; }).map(function (d) { return d.domains.preliminary; }), true))];
205
+ }
206
+ throw new Error('type must be "site", "prelogin"');
207
+ }
208
+ });
209
+ }); })];
210
+ case 3:
211
+ str = _a.sent();
212
+ fs_1.default.writeFileSync((0, path_1.resolve)(process.cwd(), options.outFile), str);
213
+ return [2 /*return*/];
214
+ }
215
+ });
216
+ }); });
217
+ var resolveOpReferences = function (input) {
218
+ var opRefs = input.match(/\{\{ op:\/\/[^ }]+ \}\}/g);
219
+ if (!opRefs) {
220
+ return input;
221
+ }
222
+ try {
223
+ (0, child_process_1.execSync)("op --version", { stdio: "ignore" });
224
+ }
225
+ catch (_a) {
226
+ throw new Error("inject-site-configs: Config contains 1Password references (op://) but the 1Password CLI (op) is not installed. " +
227
+ "Install from https://developer.1password.com/docs/cli/");
228
+ }
229
+ var opCache = new Map();
230
+ var result = input;
231
+ for (var _i = 0, opRefs_1 = opRefs; _i < opRefs_1.length; _i++) {
232
+ var ref = opRefs_1[_i];
233
+ var opUri = ref.replace("{{ ", "").replace(" }}", "");
234
+ try {
235
+ var secret = opCache.get(opUri);
236
+ if (!secret) {
237
+ secret = (0, child_process_1.execSync)("op read \"".concat(opUri, "\""), { encoding: "utf-8" }).trim();
238
+ opCache.set(opUri, secret);
239
+ }
240
+ console.log("inject-site-configs: - Resolved ".concat(ref));
241
+ result = result.replace(ref, secret);
242
+ }
243
+ catch (e) {
244
+ throw new Error("inject-site-configs: Failed to resolve 1Password reference ".concat(ref, ": ").concat(e));
245
+ }
246
+ }
247
+ return result;
248
+ };
249
+ exports.resolveOpReferences = resolveOpReferences;
250
+ // https://stackoverflow.com/a/75205316
251
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
252
+ var replaceAsync = function (str, regex, asyncFn) { return __awaiter(void 0, void 0, void 0, function () {
253
+ var promises, data;
254
+ return __generator(this, function (_a) {
255
+ switch (_a.label) {
256
+ case 0:
257
+ promises = [];
258
+ str.replace(regex, function (match) {
259
+ var args = [];
260
+ for (var _i = 1; _i < arguments.length; _i++) {
261
+ args[_i - 1] = arguments[_i];
262
+ }
263
+ promises.push(asyncFn.apply(void 0, __spreadArray([match], args, false)));
264
+ return match;
265
+ });
266
+ return [4 /*yield*/, Promise.all(promises)];
267
+ case 1:
268
+ data = _a.sent();
269
+ return [2 /*return*/, str.replace(regex, function () { return data.shift(); })];
270
+ }
271
+ });
272
+ }); };
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { BaseSiteConfig, ExtractPrivateSiteConfig, ExtractPublicSiteConfig } from "./site-configs.types";
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ export type BaseSiteConfig = {
2
+ name: string;
3
+ domains: {
4
+ main: string;
5
+ preliminary?: string;
6
+ pattern?: string;
7
+ additional?: string[];
8
+ };
9
+ preloginEnabled?: boolean;
10
+ public?: Record<string, unknown>;
11
+ };
12
+ export type ExtractPrivateSiteConfig<S extends BaseSiteConfig> = S["public"] & Omit<S, "public"> & {
13
+ url: string;
14
+ };
15
+ export type ExtractPublicSiteConfig<S extends BaseSiteConfig> = S["public"] & Pick<S, "name" | "domains" | "preloginEnabled"> & {
16
+ url: string;
17
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@dextinity/cli",
3
+ "version": "2.0.0-canary-20260729062014",
4
+ "description": "A collection of CLI tools for Comet projects",
5
+ "repository": {
6
+ "directory": "packages/cli",
7
+ "type": "git",
8
+ "url": "https://github.com/vivid-planet/comet"
9
+ },
10
+ "license": "BSD-2-Clause",
11
+ "type": "commonjs",
12
+ "main": "lib/index.js",
13
+ "typings": "lib/index.d.ts",
14
+ "bin": {
15
+ "comet": "bin/comet.js"
16
+ },
17
+ "sideEffects": false,
18
+ "files": [
19
+ "bin/**/*.js",
20
+ "lib/*"
21
+ ],
22
+ "dependencies": {
23
+ "commander": "^9.5.0",
24
+ "js-yaml": "^4.1.1",
25
+ "prettier": "^3.6.2",
26
+ "ts-node": "^10.9.2"
27
+ },
28
+ "devDependencies": {
29
+ "@types/js-yaml": "^4.0.9",
30
+ "@types/node": "^24.12.4",
31
+ "eslint": "^9.39.4",
32
+ "npm-run-all2": "^8.0.4",
33
+ "rimraf": "^6.1.2",
34
+ "typescript": "^5.9.3",
35
+ "vitest": "^4.1.8",
36
+ "@dextinity/eslint-config": "2.0.0-canary-20260729062014"
37
+ },
38
+ "engines": {
39
+ "node": ">=22.0.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "registry": "https://registry.npmjs.org"
44
+ },
45
+ "scripts": {
46
+ "build": "pnpm run clean && tsc -p tsconfig.build.json",
47
+ "clean": "rimraf lib",
48
+ "dev": "tsc --watch",
49
+ "lint": "run-p lint:prettier lint:eslint lint:tsc",
50
+ "lint:ci": "pnpm run lint",
51
+ "lint:eslint": "eslint --max-warnings 0 src/ '**/*.json' --no-warn-ignored",
52
+ "lint:fix": "run-p lint:fix:eslint lint:fix:prettier",
53
+ "lint:fix:eslint": "pnpm run lint:eslint --fix",
54
+ "lint:fix:prettier": "pnpm run lint:prettier --write",
55
+ "lint:prettier": "pnpm exec prettier --check '*.{ts,js,json,md,yml,yaml}'",
56
+ "lint:tsc": "tsc",
57
+ "test": "pnpm run test:unit",
58
+ "test:unit": "vitest --run",
59
+ "test:watch": "vitest --watch"
60
+ }
61
+ }