skillverse 0.1.1 → 0.1.3
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/bin.js +1845 -1671
- package/dist/bin.js.map +1 -1
- package/dist/index.js +83 -18
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/prisma/dev.db +0 -0
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import express from "express";
|
|
3
3
|
import cors from "cors";
|
|
4
4
|
import dotenv2 from "dotenv";
|
|
5
|
-
import { fileURLToPath as
|
|
6
|
-
import { dirname as
|
|
5
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
6
|
+
import { dirname as dirname3, join as join7 } from "path";
|
|
7
7
|
import { mkdir as mkdir5 } from "fs/promises";
|
|
8
|
-
import { existsSync as
|
|
8
|
+
import { existsSync as existsSync8 } from "fs";
|
|
9
9
|
|
|
10
10
|
// src/routes/skills.ts
|
|
11
11
|
import { Router } from "express";
|
|
@@ -1831,10 +1831,74 @@ function requestLogger(req, res, next) {
|
|
|
1831
1831
|
next();
|
|
1832
1832
|
}
|
|
1833
1833
|
|
|
1834
|
-
// src/
|
|
1835
|
-
|
|
1834
|
+
// src/lib/initDb.ts
|
|
1835
|
+
import { existsSync as existsSync7 } from "fs";
|
|
1836
|
+
import { join as join6, dirname as dirname2 } from "path";
|
|
1837
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1838
|
+
import { spawnSync } from "child_process";
|
|
1836
1839
|
var __filename2 = fileURLToPath2(import.meta.url);
|
|
1837
1840
|
var __dirname2 = dirname2(__filename2);
|
|
1841
|
+
function getSchemaPath() {
|
|
1842
|
+
const possiblePaths = [
|
|
1843
|
+
// Prod: dist/bin.js -> dist/../prisma/schema.prisma (i.e. ROOT/prisma/schema.prisma)
|
|
1844
|
+
join6(__dirname2, "../prisma/schema.prisma"),
|
|
1845
|
+
// Dev: src/lib/initDb.ts -> src/prisma/schema.prisma ? No, src/../prisma -> server/prisma
|
|
1846
|
+
// If __dirname is src/lib: ../../prisma/schema.prisma
|
|
1847
|
+
join6(__dirname2, "../../prisma/schema.prisma"),
|
|
1848
|
+
// Fallbacks
|
|
1849
|
+
join6(process.cwd(), "prisma/schema.prisma"),
|
|
1850
|
+
join6(process.cwd(), "server/prisma/schema.prisma")
|
|
1851
|
+
];
|
|
1852
|
+
return possiblePaths.find((p) => existsSync7(p)) || null;
|
|
1853
|
+
}
|
|
1854
|
+
async function ensureDatabaseInitialized() {
|
|
1855
|
+
try {
|
|
1856
|
+
try {
|
|
1857
|
+
await prisma.skill.count();
|
|
1858
|
+
return;
|
|
1859
|
+
} catch (error) {
|
|
1860
|
+
if (error.code === "P2021" || error.message.includes("table") || error.message.includes("does not exist")) {
|
|
1861
|
+
console.log("\u{1F4E6} Initializing database...");
|
|
1862
|
+
await initializeDatabase();
|
|
1863
|
+
} else {
|
|
1864
|
+
throw error;
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
} catch (error) {
|
|
1868
|
+
throw error;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
async function initializeDatabase() {
|
|
1872
|
+
const schemaPath = getSchemaPath();
|
|
1873
|
+
if (!schemaPath) {
|
|
1874
|
+
throw new Error("Could not find schema.prisma");
|
|
1875
|
+
}
|
|
1876
|
+
const possiblePrismaBins = [
|
|
1877
|
+
join6(__dirname2, "../node_modules/.bin/prisma"),
|
|
1878
|
+
join6(__dirname2, "../../node_modules/.bin/prisma"),
|
|
1879
|
+
join6(__dirname2, "../../../node_modules/.bin/prisma"),
|
|
1880
|
+
join6(process.cwd(), "node_modules/.bin/prisma")
|
|
1881
|
+
];
|
|
1882
|
+
const prismaBin = possiblePrismaBins.find((p) => existsSync7(p)) || "prisma";
|
|
1883
|
+
console.log(` Using schema: ${schemaPath}`);
|
|
1884
|
+
const result = spawnSync(prismaBin, ["db", "push", "--schema", schemaPath], {
|
|
1885
|
+
stdio: "inherit",
|
|
1886
|
+
env: { ...process.env }
|
|
1887
|
+
// Ensure env vars (DATABASE_URL) are passed
|
|
1888
|
+
});
|
|
1889
|
+
if (result.error) {
|
|
1890
|
+
throw result.error;
|
|
1891
|
+
}
|
|
1892
|
+
if (result.status !== 0) {
|
|
1893
|
+
throw new Error(`Database initialization failed with status ${result.status}`);
|
|
1894
|
+
}
|
|
1895
|
+
console.log("\u2705 Database initialized successfully");
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
// src/index.ts
|
|
1899
|
+
dotenv2.config();
|
|
1900
|
+
var __filename3 = fileURLToPath3(import.meta.url);
|
|
1901
|
+
var __dirname3 = dirname3(__filename3);
|
|
1838
1902
|
var app = express();
|
|
1839
1903
|
var PORT = process.env.PORT || 3001;
|
|
1840
1904
|
app.use(cors());
|
|
@@ -1842,16 +1906,16 @@ app.use(express.json());
|
|
|
1842
1906
|
app.use(express.urlencoded({ extended: true }));
|
|
1843
1907
|
app.use(requestLogger);
|
|
1844
1908
|
var possiblePublicDirs = [
|
|
1845
|
-
|
|
1909
|
+
join7(__dirname3, "../public"),
|
|
1846
1910
|
// Production: dist/index.js -> public
|
|
1847
|
-
|
|
1911
|
+
join7(__dirname3, "../../public"),
|
|
1848
1912
|
// Dev tsx might resolve here
|
|
1849
|
-
|
|
1913
|
+
join7(process.cwd(), "public"),
|
|
1850
1914
|
// Fallback: relative to cwd
|
|
1851
|
-
|
|
1915
|
+
join7(process.cwd(), "server/public")
|
|
1852
1916
|
// Fallback: from root
|
|
1853
1917
|
];
|
|
1854
|
-
var publicDir = possiblePublicDirs.find((dir) =>
|
|
1918
|
+
var publicDir = possiblePublicDirs.find((dir) => existsSync8(dir));
|
|
1855
1919
|
if (publicDir) {
|
|
1856
1920
|
app.use(express.static(publicDir));
|
|
1857
1921
|
console.log(`\u{1F4C2} Serving static files from: ${publicDir}`);
|
|
@@ -1865,19 +1929,19 @@ app.use("/api/dashboard", dashboard_default);
|
|
|
1865
1929
|
app.get("/health", (req, res) => {
|
|
1866
1930
|
res.json({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1867
1931
|
});
|
|
1868
|
-
if (publicDir &&
|
|
1932
|
+
if (publicDir && existsSync8(publicDir)) {
|
|
1869
1933
|
app.get("*", (req, res) => {
|
|
1870
|
-
res.sendFile(
|
|
1934
|
+
res.sendFile(join7(publicDir, "index.html"));
|
|
1871
1935
|
});
|
|
1872
1936
|
}
|
|
1873
1937
|
app.use(errorHandler);
|
|
1874
1938
|
async function initializeStorage() {
|
|
1875
|
-
const skillverseHome = process.env.SKILLVERSE_HOME ||
|
|
1876
|
-
const skillsDir = process.env.SKILLS_DIR ||
|
|
1877
|
-
const marketplaceDir = process.env.MARKETPLACE_DIR ||
|
|
1939
|
+
const skillverseHome = process.env.SKILLVERSE_HOME || join7(process.env.HOME || "", ".skillverse");
|
|
1940
|
+
const skillsDir = process.env.SKILLS_DIR || join7(skillverseHome, "skills");
|
|
1941
|
+
const marketplaceDir = process.env.MARKETPLACE_DIR || join7(skillverseHome, "marketplace");
|
|
1878
1942
|
const dirs = [skillverseHome, skillsDir, marketplaceDir];
|
|
1879
1943
|
for (const dir of dirs) {
|
|
1880
|
-
if (!
|
|
1944
|
+
if (!existsSync8(dir)) {
|
|
1881
1945
|
await mkdir5(dir, { recursive: true });
|
|
1882
1946
|
console.log(`Created directory: ${dir}`);
|
|
1883
1947
|
}
|
|
@@ -1886,10 +1950,11 @@ async function initializeStorage() {
|
|
|
1886
1950
|
async function startServer(port = parseInt(process.env.PORT || "3001")) {
|
|
1887
1951
|
try {
|
|
1888
1952
|
await initializeStorage();
|
|
1953
|
+
await ensureDatabaseInitialized();
|
|
1889
1954
|
return new Promise((resolve) => {
|
|
1890
1955
|
app.listen(port, () => {
|
|
1891
1956
|
console.log(`\u{1F680} SkillVerse server running on http://localhost:${port}`);
|
|
1892
|
-
console.log(`\u{1F4C1} Storage: ${process.env.SKILLVERSE_HOME ||
|
|
1957
|
+
console.log(`\u{1F4C1} Storage: ${process.env.SKILLVERSE_HOME || join7(process.env.HOME || "", ".skillverse")}`);
|
|
1893
1958
|
resolve();
|
|
1894
1959
|
});
|
|
1895
1960
|
});
|
|
@@ -1898,7 +1963,7 @@ async function startServer(port = parseInt(process.env.PORT || "3001")) {
|
|
|
1898
1963
|
process.exit(1);
|
|
1899
1964
|
}
|
|
1900
1965
|
}
|
|
1901
|
-
if (process.argv[1] ===
|
|
1966
|
+
if (process.argv[1] === fileURLToPath3(import.meta.url)) {
|
|
1902
1967
|
startServer();
|
|
1903
1968
|
}
|
|
1904
1969
|
export {
|