tthr 0.3.6 → 0.3.7
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/index.js +62 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1224,8 +1224,8 @@ PUBLIC_TETHER_PROJECT_ID=\${TETHER_PROJECT_ID}
|
|
|
1224
1224
|
}
|
|
1225
1225
|
}
|
|
1226
1226
|
}
|
|
1227
|
-
function getInstallCommand(pm,
|
|
1228
|
-
const devFlag =
|
|
1227
|
+
function getInstallCommand(pm, isDev7 = false) {
|
|
1228
|
+
const devFlag = isDev7 ? pm === "npm" ? "-D" : pm === "yarn" ? "-D" : pm === "pnpm" ? "-D" : "-d" : "";
|
|
1229
1229
|
return `${pm} ${pm === "npm" ? "install" : "add"} ${devFlag}`.trim();
|
|
1230
1230
|
}
|
|
1231
1231
|
async function installTetherPackages(projectPath, template, packageManager) {
|
|
@@ -1670,9 +1670,12 @@ import fs3 from "fs-extra";
|
|
|
1670
1670
|
import path3 from "path";
|
|
1671
1671
|
import { spawn } from "child_process";
|
|
1672
1672
|
import { watch } from "chokidar";
|
|
1673
|
+
var isDev3 = process.env.NODE_ENV === "development" || process.env.TETHER_DEV === "true";
|
|
1674
|
+
var API_BASE = isDev3 ? "http://localhost:3001" : "https://tether-api.strands.gg";
|
|
1673
1675
|
var frameworkProcess = null;
|
|
1674
1676
|
var schemaWatcher = null;
|
|
1675
1677
|
var functionsWatcher = null;
|
|
1678
|
+
var envWs = null;
|
|
1676
1679
|
var isGenerating = false;
|
|
1677
1680
|
var pendingGenerate = false;
|
|
1678
1681
|
var isDeploying = false;
|
|
@@ -1791,6 +1794,44 @@ async function validateFunctions(functionsDir) {
|
|
|
1791
1794
|
}
|
|
1792
1795
|
return { valid: errors.length === 0, errors };
|
|
1793
1796
|
}
|
|
1797
|
+
function connectToEnvironment(projectId, environment, token, spinner) {
|
|
1798
|
+
const wsBase = API_BASE.replace("https://", "wss://").replace("http://", "ws://");
|
|
1799
|
+
const wsUrl = environment && environment !== "production" ? `${wsBase}/ws/${projectId}/${environment}?token=${encodeURIComponent(token)}` : `${wsBase}/ws/${projectId}?token=${encodeURIComponent(token)}`;
|
|
1800
|
+
let reconnectAttempts = 0;
|
|
1801
|
+
const maxReconnectAttempts = 10;
|
|
1802
|
+
function connect() {
|
|
1803
|
+
try {
|
|
1804
|
+
envWs = new WebSocket(wsUrl);
|
|
1805
|
+
} catch {
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
envWs.onopen = () => {
|
|
1809
|
+
reconnectAttempts = 0;
|
|
1810
|
+
};
|
|
1811
|
+
envWs.onmessage = async (event) => {
|
|
1812
|
+
try {
|
|
1813
|
+
const data = JSON.parse(typeof event.data === "string" ? event.data : event.data.toString());
|
|
1814
|
+
if (data.type === "env_change") {
|
|
1815
|
+
console.log(chalk3.cyan(`
|
|
1816
|
+
Environment variable ${data.action}: ${data.key}`));
|
|
1817
|
+
await runGenerate(spinner);
|
|
1818
|
+
}
|
|
1819
|
+
} catch {
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
envWs.onclose = () => {
|
|
1823
|
+
envWs = null;
|
|
1824
|
+
if (reconnectAttempts < maxReconnectAttempts) {
|
|
1825
|
+
reconnectAttempts++;
|
|
1826
|
+
const delay = Math.min(1e3 * Math.pow(2, reconnectAttempts - 1), 3e4);
|
|
1827
|
+
setTimeout(connect, delay);
|
|
1828
|
+
}
|
|
1829
|
+
};
|
|
1830
|
+
envWs.onerror = () => {
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
connect();
|
|
1834
|
+
}
|
|
1794
1835
|
function startFrameworkDev(command, port, spinner, extraArgs = []) {
|
|
1795
1836
|
const [cmd, ...args] = command.split(" ");
|
|
1796
1837
|
const portArgs = ["--port", port];
|
|
@@ -1845,6 +1886,10 @@ function cleanup() {
|
|
|
1845
1886
|
functionsWatcher.close();
|
|
1846
1887
|
functionsWatcher = null;
|
|
1847
1888
|
}
|
|
1889
|
+
if (envWs) {
|
|
1890
|
+
envWs.close();
|
|
1891
|
+
envWs = null;
|
|
1892
|
+
}
|
|
1848
1893
|
}
|
|
1849
1894
|
async function devCommand(options) {
|
|
1850
1895
|
const credentials = await requireAuth();
|
|
@@ -1960,6 +2005,9 @@ async function devCommand(options) {
|
|
|
1960
2005
|
});
|
|
1961
2006
|
}
|
|
1962
2007
|
spinner.succeed("File watchers ready");
|
|
2008
|
+
if (config.projectId) {
|
|
2009
|
+
connectToEnvironment(config.projectId, environment, credentials.accessToken, spinner);
|
|
2010
|
+
}
|
|
1963
2011
|
if (devCmd && !options.skipFramework) {
|
|
1964
2012
|
spinner.start(`Starting ${framework} dev server...`);
|
|
1965
2013
|
frameworkProcess = startFrameworkDev(devCmd, port, spinner, options.extraArgs || []);
|
|
@@ -1986,9 +2034,9 @@ import ora4 from "ora";
|
|
|
1986
2034
|
import os from "os";
|
|
1987
2035
|
import { exec } from "child_process";
|
|
1988
2036
|
import readline from "readline";
|
|
1989
|
-
var
|
|
1990
|
-
var API_URL4 =
|
|
1991
|
-
var AUTH_URL =
|
|
2037
|
+
var isDev4 = process.env.NODE_ENV === "development" || process.env.TETHER_DEV === "true";
|
|
2038
|
+
var API_URL4 = isDev4 ? "http://localhost:3001/api/v1" : "https://tether-api.strands.gg/api/v1";
|
|
2039
|
+
var AUTH_URL = isDev4 ? "http://localhost:3000/cli" : "https://tthr.io/cli";
|
|
1992
2040
|
async function loginCommand() {
|
|
1993
2041
|
console.log(chalk4.bold("\u26A1 Login to Tether\n"));
|
|
1994
2042
|
const existing = await getCredentials();
|
|
@@ -2203,18 +2251,18 @@ function detectPackageManager() {
|
|
|
2203
2251
|
}
|
|
2204
2252
|
return "npm";
|
|
2205
2253
|
}
|
|
2206
|
-
function getInstallCommand2(pm, packages,
|
|
2254
|
+
function getInstallCommand2(pm, packages, isDev7) {
|
|
2207
2255
|
const packagesStr = packages.join(" ");
|
|
2208
2256
|
switch (pm) {
|
|
2209
2257
|
case "bun":
|
|
2210
|
-
return
|
|
2258
|
+
return isDev7 ? `bun add -d ${packagesStr}` : `bun add ${packagesStr}`;
|
|
2211
2259
|
case "pnpm":
|
|
2212
|
-
return
|
|
2260
|
+
return isDev7 ? `pnpm add -D ${packagesStr}` : `pnpm add ${packagesStr}`;
|
|
2213
2261
|
case "yarn":
|
|
2214
|
-
return
|
|
2262
|
+
return isDev7 ? `yarn add -D ${packagesStr}` : `yarn add ${packagesStr}`;
|
|
2215
2263
|
case "npm":
|
|
2216
2264
|
default:
|
|
2217
|
-
return
|
|
2265
|
+
return isDev7 ? `npm install -D ${packagesStr}` : `npm install ${packagesStr}`;
|
|
2218
2266
|
}
|
|
2219
2267
|
}
|
|
2220
2268
|
async function getLatestVersion2(packageName) {
|
|
@@ -2323,8 +2371,8 @@ import chalk6 from "chalk";
|
|
|
2323
2371
|
import ora6 from "ora";
|
|
2324
2372
|
import fs5 from "fs-extra";
|
|
2325
2373
|
import path5 from "path";
|
|
2326
|
-
var
|
|
2327
|
-
var API_URL5 =
|
|
2374
|
+
var isDev5 = process.env.NODE_ENV === "development" || process.env.TETHER_DEV === "true";
|
|
2375
|
+
var API_URL5 = isDev5 ? "http://localhost:3001/api/v1" : "https://tether-api.strands.gg/api/v1";
|
|
2328
2376
|
async function execCommand(sql) {
|
|
2329
2377
|
if (!sql || sql.trim() === "") {
|
|
2330
2378
|
console.log(chalk6.red("\nError: SQL query required"));
|
|
@@ -2396,8 +2444,8 @@ import chalk7 from "chalk";
|
|
|
2396
2444
|
import ora7 from "ora";
|
|
2397
2445
|
import fs6 from "fs-extra";
|
|
2398
2446
|
import path6 from "path";
|
|
2399
|
-
var
|
|
2400
|
-
var API_URL6 =
|
|
2447
|
+
var isDev6 = process.env.NODE_ENV === "development" || process.env.TETHER_DEV === "true";
|
|
2448
|
+
var API_URL6 = isDev6 ? "http://localhost:3001/api/v1" : "https://tether-api.strands.gg/api/v1";
|
|
2401
2449
|
async function getProjectId() {
|
|
2402
2450
|
const envPath = path6.resolve(process.cwd(), ".env");
|
|
2403
2451
|
let projectId;
|