@insforge/cli 0.1.23 → 0.1.24
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 +69 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { readFileSync as readFileSync6 } from "fs";
|
|
5
|
-
import { join as
|
|
5
|
+
import { join as join7, dirname } from "path";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
import * as clack14 from "@clack/prompts";
|
|
@@ -360,7 +360,7 @@ async function refreshAccessToken(apiUrl) {
|
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
// src/lib/api/platform.ts
|
|
363
|
-
async function platformFetch(
|
|
363
|
+
async function platformFetch(path4, options = {}, apiUrl) {
|
|
364
364
|
const baseUrl = getPlatformApiUrl(apiUrl);
|
|
365
365
|
const token = getAccessToken();
|
|
366
366
|
if (!token) {
|
|
@@ -371,11 +371,11 @@ async function platformFetch(path3, options = {}, apiUrl) {
|
|
|
371
371
|
Authorization: `Bearer ${token}`,
|
|
372
372
|
...options.headers ?? {}
|
|
373
373
|
};
|
|
374
|
-
const res = await fetch(`${baseUrl}${
|
|
374
|
+
const res = await fetch(`${baseUrl}${path4}`, { ...options, headers });
|
|
375
375
|
if (res.status === 401) {
|
|
376
376
|
const newToken = await refreshAccessToken(apiUrl);
|
|
377
377
|
headers.Authorization = `Bearer ${newToken}`;
|
|
378
|
-
const retryRes = await fetch(`${baseUrl}${
|
|
378
|
+
const retryRes = await fetch(`${baseUrl}${path4}`, { ...options, headers });
|
|
379
379
|
if (!retryRes.ok) {
|
|
380
380
|
const err = await retryRes.json().catch(() => ({}));
|
|
381
381
|
throw new CLIError(err.error ?? `Request failed: ${retryRes.status}`, retryRes.status === 403 ? 5 : 1);
|
|
@@ -866,14 +866,14 @@ async function getAnonKey() {
|
|
|
866
866
|
const data = await res.json();
|
|
867
867
|
return data.accessToken;
|
|
868
868
|
}
|
|
869
|
-
async function ossFetch(
|
|
869
|
+
async function ossFetch(path4, options = {}) {
|
|
870
870
|
const config = requireProjectConfig();
|
|
871
871
|
const headers = {
|
|
872
872
|
"Content-Type": "application/json",
|
|
873
873
|
Authorization: `Bearer ${config.api_key}`,
|
|
874
874
|
...options.headers ?? {}
|
|
875
875
|
};
|
|
876
|
-
const res = await fetch(`${config.oss_host}${
|
|
876
|
+
const res = await fetch(`${config.oss_host}${path4}`, { ...options, headers });
|
|
877
877
|
if (!res.ok) {
|
|
878
878
|
const err = await res.json().catch(() => ({}));
|
|
879
879
|
throw new CLIError(err.error ?? `OSS request failed: ${res.status}`);
|
|
@@ -1215,8 +1215,8 @@ function registerRecordsCommands(recordsCmd2) {
|
|
|
1215
1215
|
if (opts.limit) params.set("limit", String(opts.limit));
|
|
1216
1216
|
if (opts.offset) params.set("offset", String(opts.offset));
|
|
1217
1217
|
const query = params.toString();
|
|
1218
|
-
const
|
|
1219
|
-
const res = await ossFetch(
|
|
1218
|
+
const path4 = `/api/database/records/${encodeURIComponent(table)}${query ? `?${query}` : ""}`;
|
|
1219
|
+
const res = await ossFetch(path4);
|
|
1220
1220
|
const data = await res.json();
|
|
1221
1221
|
const records = data.data ?? [];
|
|
1222
1222
|
if (json) {
|
|
@@ -1779,13 +1779,38 @@ function registerStorageListObjectsCommand(storageCmd2) {
|
|
|
1779
1779
|
import { exec as exec2 } from "child_process";
|
|
1780
1780
|
import { tmpdir } from "os";
|
|
1781
1781
|
import { promisify as promisify2 } from "util";
|
|
1782
|
-
import * as
|
|
1783
|
-
import * as
|
|
1782
|
+
import * as fs3 from "fs/promises";
|
|
1783
|
+
import * as path3 from "path";
|
|
1784
1784
|
import * as clack10 from "@clack/prompts";
|
|
1785
1785
|
|
|
1786
|
-
// src/
|
|
1787
|
-
import * as path from "path";
|
|
1786
|
+
// src/lib/env.ts
|
|
1788
1787
|
import * as fs from "fs/promises";
|
|
1788
|
+
import * as path from "path";
|
|
1789
|
+
async function readEnvFile(cwd) {
|
|
1790
|
+
const candidates = [".env.local", ".env.production", ".env"];
|
|
1791
|
+
for (const name of candidates) {
|
|
1792
|
+
const filePath = path.join(cwd, name);
|
|
1793
|
+
const exists = await fs.stat(filePath).catch(() => null);
|
|
1794
|
+
if (!exists) continue;
|
|
1795
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
1796
|
+
const vars = [];
|
|
1797
|
+
for (const line of content.split("\n")) {
|
|
1798
|
+
const trimmed = line.trim();
|
|
1799
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
1800
|
+
const eqIndex = trimmed.indexOf("=");
|
|
1801
|
+
if (eqIndex === -1) continue;
|
|
1802
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
1803
|
+
const value = trimmed.slice(eqIndex + 1).trim();
|
|
1804
|
+
if (key) vars.push({ key, value });
|
|
1805
|
+
}
|
|
1806
|
+
return vars;
|
|
1807
|
+
}
|
|
1808
|
+
return [];
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
// src/commands/deployments/deploy.ts
|
|
1812
|
+
import * as path2 from "path";
|
|
1813
|
+
import * as fs2 from "fs/promises";
|
|
1789
1814
|
import * as clack9 from "@clack/prompts";
|
|
1790
1815
|
import archiver from "archiver";
|
|
1791
1816
|
var POLL_INTERVAL_MS = 5e3;
|
|
@@ -1885,8 +1910,8 @@ function registerDeploymentsDeployCommand(deploymentsCmd2) {
|
|
|
1885
1910
|
await requireAuth();
|
|
1886
1911
|
const config = getProjectConfig();
|
|
1887
1912
|
if (!config) throw new ProjectNotLinkedError();
|
|
1888
|
-
const sourceDir =
|
|
1889
|
-
const stats = await
|
|
1913
|
+
const sourceDir = path2.resolve(directory ?? ".");
|
|
1914
|
+
const stats = await fs2.stat(sourceDir).catch(() => null);
|
|
1890
1915
|
if (!stats?.isDirectory()) {
|
|
1891
1916
|
throw new CLIError(`"${sourceDir}" is not a valid directory.`);
|
|
1892
1917
|
}
|
|
@@ -1955,15 +1980,15 @@ async function waitForProjectActive(projectId, apiUrl, timeoutMs = 12e4) {
|
|
|
1955
1980
|
throw new CLIError("Project creation timed out. Check the dashboard for status.");
|
|
1956
1981
|
}
|
|
1957
1982
|
async function copyDir(src, dest) {
|
|
1958
|
-
const entries = await
|
|
1983
|
+
const entries = await fs3.readdir(src, { withFileTypes: true });
|
|
1959
1984
|
for (const entry of entries) {
|
|
1960
|
-
const srcPath =
|
|
1961
|
-
const destPath =
|
|
1985
|
+
const srcPath = path3.join(src, entry.name);
|
|
1986
|
+
const destPath = path3.join(dest, entry.name);
|
|
1962
1987
|
if (entry.isDirectory()) {
|
|
1963
|
-
await
|
|
1988
|
+
await fs3.mkdir(destPath, { recursive: true });
|
|
1964
1989
|
await copyDir(srcPath, destPath);
|
|
1965
1990
|
} else {
|
|
1966
|
-
await
|
|
1991
|
+
await fs3.copyFile(srcPath, destPath);
|
|
1967
1992
|
}
|
|
1968
1993
|
}
|
|
1969
1994
|
}
|
|
@@ -2072,9 +2097,15 @@ function registerCreateCommand(program2) {
|
|
|
2072
2097
|
});
|
|
2073
2098
|
if (!clack10.isCancel(shouldDeploy) && shouldDeploy) {
|
|
2074
2099
|
try {
|
|
2100
|
+
const envVars = await readEnvFile(process.cwd());
|
|
2101
|
+
const startBody = {};
|
|
2102
|
+
if (envVars.length > 0) {
|
|
2103
|
+
startBody.envVars = envVars;
|
|
2104
|
+
}
|
|
2075
2105
|
const deploySpinner = clack10.spinner();
|
|
2076
2106
|
const result = await deployProject({
|
|
2077
2107
|
sourceDir: process.cwd(),
|
|
2108
|
+
startBody,
|
|
2078
2109
|
spinner: deploySpinner
|
|
2079
2110
|
});
|
|
2080
2111
|
if (result.isReady) {
|
|
@@ -2124,9 +2155,9 @@ async function downloadTemplate(framework, projectConfig, projectName, json, _ap
|
|
|
2124
2155
|
}
|
|
2125
2156
|
const tempDir = tmpdir();
|
|
2126
2157
|
const targetDir = projectName;
|
|
2127
|
-
const templatePath =
|
|
2158
|
+
const templatePath = path3.join(tempDir, targetDir);
|
|
2128
2159
|
try {
|
|
2129
|
-
await
|
|
2160
|
+
await fs3.rm(templatePath, { recursive: true, force: true });
|
|
2130
2161
|
} catch {
|
|
2131
2162
|
}
|
|
2132
2163
|
const frame = framework === "nextjs" ? "nextjs" : "react";
|
|
@@ -2140,7 +2171,7 @@ async function downloadTemplate(framework, projectConfig, projectName, json, _ap
|
|
|
2140
2171
|
s?.message("Copying template files...");
|
|
2141
2172
|
const cwd = process.cwd();
|
|
2142
2173
|
await copyDir(templatePath, cwd);
|
|
2143
|
-
await
|
|
2174
|
+
await fs3.rm(templatePath, { recursive: true, force: true }).catch(() => {
|
|
2144
2175
|
});
|
|
2145
2176
|
s?.stop("Template files downloaded");
|
|
2146
2177
|
} catch (err) {
|
|
@@ -2154,26 +2185,26 @@ async function downloadTemplate(framework, projectConfig, projectName, json, _ap
|
|
|
2154
2185
|
async function downloadGitHubTemplate(templateName, projectConfig, json) {
|
|
2155
2186
|
const s = !json ? clack10.spinner() : null;
|
|
2156
2187
|
s?.start(`Downloading ${templateName} template...`);
|
|
2157
|
-
const tempDir =
|
|
2188
|
+
const tempDir = path3.join(tmpdir(), `insforge-template-${Date.now()}`);
|
|
2158
2189
|
try {
|
|
2159
|
-
await
|
|
2190
|
+
await fs3.mkdir(tempDir, { recursive: true });
|
|
2160
2191
|
await execAsync2(
|
|
2161
2192
|
"git clone --depth 1 https://github.com/InsForge/insforge-templates.git .",
|
|
2162
2193
|
{ cwd: tempDir, maxBuffer: 10 * 1024 * 1024, timeout: 6e4 }
|
|
2163
2194
|
);
|
|
2164
|
-
const templateDir =
|
|
2165
|
-
const
|
|
2166
|
-
if (!
|
|
2195
|
+
const templateDir = path3.join(tempDir, templateName);
|
|
2196
|
+
const stat4 = await fs3.stat(templateDir).catch(() => null);
|
|
2197
|
+
if (!stat4?.isDirectory()) {
|
|
2167
2198
|
throw new Error(`Template "${templateName}" not found in repository`);
|
|
2168
2199
|
}
|
|
2169
2200
|
s?.message("Copying template files...");
|
|
2170
2201
|
const cwd = process.cwd();
|
|
2171
2202
|
await copyDir(templateDir, cwd);
|
|
2172
|
-
const envExamplePath =
|
|
2173
|
-
const envExampleExists = await
|
|
2203
|
+
const envExamplePath = path3.join(cwd, ".env.example");
|
|
2204
|
+
const envExampleExists = await fs3.stat(envExamplePath).catch(() => null);
|
|
2174
2205
|
if (envExampleExists) {
|
|
2175
2206
|
const anonKey = await getAnonKey();
|
|
2176
|
-
const envExample = await
|
|
2207
|
+
const envExample = await fs3.readFile(envExamplePath, "utf-8");
|
|
2177
2208
|
const envContent = envExample.replace(
|
|
2178
2209
|
/^([A-Z_]+=)(.*)$/gm,
|
|
2179
2210
|
(_, prefix, _value) => {
|
|
@@ -2183,16 +2214,16 @@ async function downloadGitHubTemplate(templateName, projectConfig, json) {
|
|
|
2183
2214
|
return `${prefix}${_value}`;
|
|
2184
2215
|
}
|
|
2185
2216
|
);
|
|
2186
|
-
await
|
|
2217
|
+
await fs3.writeFile(path3.join(cwd, ".env.local"), envContent);
|
|
2187
2218
|
}
|
|
2188
2219
|
s?.stop(`${templateName} template downloaded`);
|
|
2189
|
-
const migrationPath =
|
|
2190
|
-
const migrationExists = await
|
|
2220
|
+
const migrationPath = path3.join(cwd, "migrations", "db_int.sql");
|
|
2221
|
+
const migrationExists = await fs3.stat(migrationPath).catch(() => null);
|
|
2191
2222
|
if (migrationExists) {
|
|
2192
2223
|
const dbSpinner = !json ? clack10.spinner() : null;
|
|
2193
2224
|
dbSpinner?.start("Running database migrations...");
|
|
2194
2225
|
try {
|
|
2195
|
-
const sql = await
|
|
2226
|
+
const sql = await fs3.readFile(migrationPath, "utf-8");
|
|
2196
2227
|
await ossFetch("/api/database/advance/rawsql/unrestricted", {
|
|
2197
2228
|
method: "POST",
|
|
2198
2229
|
body: JSON.stringify({ query: sql })
|
|
@@ -2213,7 +2244,7 @@ async function downloadGitHubTemplate(templateName, projectConfig, json) {
|
|
|
2213
2244
|
clack10.log.info("You can manually clone from: https://github.com/InsForge/insforge-templates");
|
|
2214
2245
|
}
|
|
2215
2246
|
} finally {
|
|
2216
|
-
await
|
|
2247
|
+
await fs3.rm(tempDir, { recursive: true, force: true }).catch(() => {
|
|
2217
2248
|
});
|
|
2218
2249
|
}
|
|
2219
2250
|
}
|
|
@@ -2475,8 +2506,8 @@ async function listDocs(json) {
|
|
|
2475
2506
|
);
|
|
2476
2507
|
}
|
|
2477
2508
|
}
|
|
2478
|
-
async function fetchDoc(
|
|
2479
|
-
const res = await ossFetch(
|
|
2509
|
+
async function fetchDoc(path4, label, json) {
|
|
2510
|
+
const res = await ossFetch(path4);
|
|
2480
2511
|
const data = await res.json();
|
|
2481
2512
|
const doc = data.data ?? data;
|
|
2482
2513
|
if (json) {
|
|
@@ -2990,7 +3021,7 @@ function formatSize2(gb) {
|
|
|
2990
3021
|
|
|
2991
3022
|
// src/index.ts
|
|
2992
3023
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
2993
|
-
var pkg = JSON.parse(readFileSync6(
|
|
3024
|
+
var pkg = JSON.parse(readFileSync6(join7(__dirname, "../package.json"), "utf-8"));
|
|
2994
3025
|
var INSFORGE_LOGO = `
|
|
2995
3026
|
\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
2996
3027
|
\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D
|