pinme 2.0.0-rc.1 → 2.0.1-beta.1
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 +232 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1523,7 +1523,7 @@ var import_chalk23 = __toESM(require("chalk"));
|
|
|
1523
1523
|
var import_figlet5 = __toESM(require("figlet"));
|
|
1524
1524
|
|
|
1525
1525
|
// package.json
|
|
1526
|
-
var version = "2.0.
|
|
1526
|
+
var version = "2.0.1-beta.1";
|
|
1527
1527
|
|
|
1528
1528
|
// bin/upload.ts
|
|
1529
1529
|
var import_path7 = __toESM(require("path"));
|
|
@@ -7113,14 +7113,6 @@ var ENV_URLS = {
|
|
|
7113
7113
|
};
|
|
7114
7114
|
async function loginCmd(options = {}) {
|
|
7115
7115
|
try {
|
|
7116
|
-
const existingAuth = getAuthConfig2();
|
|
7117
|
-
if (existingAuth) {
|
|
7118
|
-
console.log(import_chalk15.default.yellow("Already logged in"));
|
|
7119
|
-
console.log(import_chalk15.default.gray(` Address: ${existingAuth.address}`));
|
|
7120
|
-
console.log(import_chalk15.default.gray(" To re-login, please run: pinme logout\n"));
|
|
7121
|
-
process.exit(0);
|
|
7122
|
-
return;
|
|
7123
|
-
}
|
|
7124
7116
|
let webBaseUrl;
|
|
7125
7117
|
const env = (options.env || "prod").toLowerCase();
|
|
7126
7118
|
if (ENV_URLS[env]) {
|
|
@@ -7308,6 +7300,7 @@ var API_BASE = "https://pinme.dev/api/v4";
|
|
|
7308
7300
|
var TEMPLATE_REPO = "glitternetwork/pinme-worker-template";
|
|
7309
7301
|
var TEMPLATE_ZIP_URL = `https://github.com/${TEMPLATE_REPO}/archive/refs/heads/main.zip`;
|
|
7310
7302
|
async function createCmd(options) {
|
|
7303
|
+
var _a, _b;
|
|
7311
7304
|
try {
|
|
7312
7305
|
const headers = getAuthHeaders();
|
|
7313
7306
|
if (!headers["authentication-tokens"] || !headers["token-address"]) {
|
|
@@ -7378,7 +7371,6 @@ Directory "${projectName}" already exists.`));
|
|
|
7378
7371
|
console.log(import_chalk17.default.gray(` API Response: ${JSON.stringify(workerData)}`));
|
|
7379
7372
|
console.log(import_chalk17.default.green(` API Domain: ${workerData.api_domain}`));
|
|
7380
7373
|
console.log(import_chalk17.default.green(` Project Name: ${workerData.project_name}`));
|
|
7381
|
-
console.log(import_chalk17.default.green(` D1 UUID: ${workerData.uuid}`));
|
|
7382
7374
|
} catch (error) {
|
|
7383
7375
|
throw createApiError("project creation", error, [
|
|
7384
7376
|
`Project name: ${normalizedProjectName}`,
|
|
@@ -7418,6 +7410,24 @@ Directory "${projectName}" already exists.`));
|
|
|
7418
7410
|
import_fs_extra6.default.removeSync(subDir);
|
|
7419
7411
|
}
|
|
7420
7412
|
import_fs_extra6.default.removeSync(zipPath);
|
|
7413
|
+
const nodeModulesPath = import_path11.default.join(targetDir, "node_modules");
|
|
7414
|
+
const packageLockPath = import_path11.default.join(targetDir, "package-lock.json");
|
|
7415
|
+
if (import_fs_extra6.default.existsSync(nodeModulesPath)) {
|
|
7416
|
+
console.log(import_chalk17.default.gray(" Removing existing node_modules..."));
|
|
7417
|
+
import_fs_extra6.default.removeSync(nodeModulesPath);
|
|
7418
|
+
}
|
|
7419
|
+
if (import_fs_extra6.default.existsSync(packageLockPath)) {
|
|
7420
|
+
console.log(import_chalk17.default.gray(" Removing existing package-lock.json..."));
|
|
7421
|
+
import_fs_extra6.default.removeSync(packageLockPath);
|
|
7422
|
+
}
|
|
7423
|
+
const frontendNodeModules = import_path11.default.join(targetDir, "frontend", "node_modules");
|
|
7424
|
+
const backendNodeModules = import_path11.default.join(targetDir, "backend", "node_modules");
|
|
7425
|
+
const frontendPackageLock = import_path11.default.join(targetDir, "frontend", "package-lock.json");
|
|
7426
|
+
const backendPackageLock = import_path11.default.join(targetDir, "backend", "package-lock.json");
|
|
7427
|
+
if (import_fs_extra6.default.existsSync(frontendNodeModules)) import_fs_extra6.default.removeSync(frontendNodeModules);
|
|
7428
|
+
if (import_fs_extra6.default.existsSync(backendNodeModules)) import_fs_extra6.default.removeSync(backendNodeModules);
|
|
7429
|
+
if (import_fs_extra6.default.existsSync(frontendPackageLock)) import_fs_extra6.default.removeSync(frontendPackageLock);
|
|
7430
|
+
if (import_fs_extra6.default.existsSync(backendPackageLock)) import_fs_extra6.default.removeSync(backendPackageLock);
|
|
7421
7431
|
console.log(import_chalk17.default.green(` Template downloaded to: ${targetDir}`));
|
|
7422
7432
|
} catch (error) {
|
|
7423
7433
|
throw createCommandError("template extraction", `unzip -o "${zipPath}" -d "${PROJECT_DIR}"`, error, [
|
|
@@ -7466,7 +7476,7 @@ Directory "${projectName}" already exists.`));
|
|
|
7466
7476
|
import_fs_extra6.default.writeFileSync(envPath, envContent);
|
|
7467
7477
|
console.log(import_chalk17.default.green(` Created frontend/.env file`));
|
|
7468
7478
|
}
|
|
7469
|
-
console.log(import_chalk17.default.blue("\n4.
|
|
7479
|
+
console.log(import_chalk17.default.blue("\n4. Installing dependencies..."));
|
|
7470
7480
|
try {
|
|
7471
7481
|
(0, import_child_process2.execSync)("npm install", {
|
|
7472
7482
|
cwd: targetDir,
|
|
@@ -7474,11 +7484,135 @@ Directory "${projectName}" already exists.`));
|
|
|
7474
7484
|
});
|
|
7475
7485
|
console.log(import_chalk17.default.green(" Project dependencies installed"));
|
|
7476
7486
|
} catch (error) {
|
|
7487
|
+
const errorMsg = error.message || "";
|
|
7488
|
+
if (errorMsg.includes("EACCES") || errorMsg.includes("EPERM") || errorMsg.includes("permission denied")) {
|
|
7489
|
+
throw createCommandError("project dependency install", "npm install", error, [
|
|
7490
|
+
"Permission error detected. Here are some solutions:",
|
|
7491
|
+
"",
|
|
7492
|
+
"Option 1: Fix npm permissions (Recommended)",
|
|
7493
|
+
" mkdir -p ~/.npm-global",
|
|
7494
|
+
" npm config set prefix ~/.npm-global",
|
|
7495
|
+
" Then add ~/.npm-global/bin to your PATH in ~/.bashrc or ~/.zshrc",
|
|
7496
|
+
"",
|
|
7497
|
+
"Option 2: Use npx to avoid global installs",
|
|
7498
|
+
" npx npm install",
|
|
7499
|
+
"",
|
|
7500
|
+
"Option 3: Check if you have write permissions",
|
|
7501
|
+
" ls -la " + targetDir,
|
|
7502
|
+
"",
|
|
7503
|
+
"For more help: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally"
|
|
7504
|
+
]);
|
|
7505
|
+
}
|
|
7506
|
+
if (errorMsg.includes("ENOTFOUND") || errorMsg.includes("ETIMEDOUT") || errorMsg.includes("network")) {
|
|
7507
|
+
throw createCommandError("project dependency install", "npm install", error, [
|
|
7508
|
+
"Network error detected. Please check:",
|
|
7509
|
+
" 1. Internet connection is available",
|
|
7510
|
+
" 2. npm registry is accessible (https://registry.npmjs.org)",
|
|
7511
|
+
" 3. Try using a mirror: npm config set registry https://registry.npmmirror.com"
|
|
7512
|
+
]);
|
|
7513
|
+
}
|
|
7477
7514
|
throw createCommandError("project dependency install", "npm install", error, [
|
|
7515
|
+
"Dependency installation failed.",
|
|
7478
7516
|
"Check network connectivity and npm registry availability.",
|
|
7479
|
-
"Inspect the generated workspace `package.json` files for dependency conflicts."
|
|
7517
|
+
"Inspect the generated workspace `package.json` files for dependency conflicts.",
|
|
7518
|
+
"",
|
|
7519
|
+
"If this is a permission issue, try:",
|
|
7520
|
+
" sudo chown -R $(whoami) ~/.npm",
|
|
7521
|
+
" sudo chown -R $(whoami) " + targetDir + "/node_modules"
|
|
7480
7522
|
]);
|
|
7481
7523
|
}
|
|
7524
|
+
console.log(import_chalk17.default.blue("\n5. Building backend worker..."));
|
|
7525
|
+
try {
|
|
7526
|
+
(0, import_child_process2.execSync)("npm run build:worker", {
|
|
7527
|
+
cwd: targetDir,
|
|
7528
|
+
stdio: "inherit"
|
|
7529
|
+
});
|
|
7530
|
+
console.log(import_chalk17.default.green(" Worker built"));
|
|
7531
|
+
} catch (error) {
|
|
7532
|
+
throw createCommandError("worker build", "npm run build:worker", error, [
|
|
7533
|
+
"Fix the build error shown above, then rerun `pinme create`."
|
|
7534
|
+
]);
|
|
7535
|
+
}
|
|
7536
|
+
const distWorkerDir = import_path11.default.join(targetDir, "dist-worker");
|
|
7537
|
+
const workerJsPath = import_path11.default.join(distWorkerDir, "worker.js");
|
|
7538
|
+
if (!import_fs_extra6.default.existsSync(distWorkerDir) || !import_fs_extra6.default.existsSync(workerJsPath)) {
|
|
7539
|
+
throw createConfigError("Built worker output not found: `dist-worker/worker.js`.", [
|
|
7540
|
+
"Make sure `npm run build:worker` completed successfully."
|
|
7541
|
+
]);
|
|
7542
|
+
}
|
|
7543
|
+
const modulePaths = [];
|
|
7544
|
+
const files = import_fs_extra6.default.readdirSync(distWorkerDir);
|
|
7545
|
+
for (const file of files) {
|
|
7546
|
+
if (file.endsWith(".js") && file !== "worker.js") {
|
|
7547
|
+
modulePaths.push(import_path11.default.join(distWorkerDir, file));
|
|
7548
|
+
}
|
|
7549
|
+
}
|
|
7550
|
+
const sqlDir = import_path11.default.join(targetDir, "db");
|
|
7551
|
+
const sqlFiles = [];
|
|
7552
|
+
if (import_fs_extra6.default.existsSync(sqlDir)) {
|
|
7553
|
+
const sqlFileNames = import_fs_extra6.default.readdirSync(sqlDir).filter((f) => f.endsWith(".sql")).sort();
|
|
7554
|
+
for (const filename of sqlFileNames) {
|
|
7555
|
+
sqlFiles.push(import_path11.default.join(sqlDir, filename));
|
|
7556
|
+
console.log(import_chalk17.default.gray(` Including SQL: ${filename}`));
|
|
7557
|
+
}
|
|
7558
|
+
}
|
|
7559
|
+
console.log(import_chalk17.default.blue("\n6. Deploying backend worker..."));
|
|
7560
|
+
const saveApiUrl = `${API_BASE}/save_worker?project_name=${encodeURIComponent(workerData.project_name)}`;
|
|
7561
|
+
console.log(import_chalk17.default.gray(` API URL: ${saveApiUrl}`));
|
|
7562
|
+
try {
|
|
7563
|
+
const FormData4 = (await import("formdata-node")).FormData;
|
|
7564
|
+
const Blob2 = (await import("formdata-node")).Blob;
|
|
7565
|
+
const formData = new FormData4();
|
|
7566
|
+
const metadataContent = typeof workerData.metadata === "string" ? workerData.metadata : JSON.stringify(workerData.metadata, null, 2);
|
|
7567
|
+
formData.append("metadata", new Blob2([metadataContent], {
|
|
7568
|
+
type: "application/json"
|
|
7569
|
+
}), "metadata.json");
|
|
7570
|
+
const workerCode = import_fs_extra6.default.readFileSync(workerJsPath, "utf-8");
|
|
7571
|
+
formData.append("worker.js", new Blob2([workerCode], {
|
|
7572
|
+
type: "application/javascript+module"
|
|
7573
|
+
}), "worker.js");
|
|
7574
|
+
for (const modulePath of modulePaths) {
|
|
7575
|
+
const filename = import_path11.default.basename(modulePath);
|
|
7576
|
+
const content = import_fs_extra6.default.readFileSync(modulePath, "utf-8");
|
|
7577
|
+
formData.append(filename, new Blob2([content], {
|
|
7578
|
+
type: "application/javascript+module"
|
|
7579
|
+
}), filename);
|
|
7580
|
+
}
|
|
7581
|
+
for (const sqlFile of sqlFiles) {
|
|
7582
|
+
const filename = import_path11.default.basename(sqlFile);
|
|
7583
|
+
const content = import_fs_extra6.default.readFileSync(sqlFile, "utf-8");
|
|
7584
|
+
formData.append("sql_file", new Blob2([content], {
|
|
7585
|
+
type: "application/sql"
|
|
7586
|
+
}), filename);
|
|
7587
|
+
}
|
|
7588
|
+
const response = await axios_default.put(saveApiUrl, formData, {
|
|
7589
|
+
headers: { ...headers },
|
|
7590
|
+
timeout: 12e4
|
|
7591
|
+
});
|
|
7592
|
+
if (response.data) {
|
|
7593
|
+
console.log(import_chalk17.default.green(" Worker deployed"));
|
|
7594
|
+
if ((_b = (_a = response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.sql_results) {
|
|
7595
|
+
for (const result of response.data.data.sql_results) {
|
|
7596
|
+
console.log(import_chalk17.default.gray(` SQL ${result.filename}: ${result.status}`));
|
|
7597
|
+
}
|
|
7598
|
+
}
|
|
7599
|
+
} else {
|
|
7600
|
+
throw createApiError("worker save", { response: { data: response.data } }, [
|
|
7601
|
+
`Project: ${workerData.project_name}`,
|
|
7602
|
+
`Endpoint: ${saveApiUrl}`
|
|
7603
|
+
], [
|
|
7604
|
+
"Verify the project exists and your account has permission to update it."
|
|
7605
|
+
]);
|
|
7606
|
+
}
|
|
7607
|
+
} catch (error) {
|
|
7608
|
+
throw createApiError("worker save", error, [
|
|
7609
|
+
`Project: ${workerData.project_name}`,
|
|
7610
|
+
`Endpoint: ${saveApiUrl}`
|
|
7611
|
+
], [
|
|
7612
|
+
"Check whether backend metadata, SQL files, or worker bundle contains invalid content."
|
|
7613
|
+
]);
|
|
7614
|
+
}
|
|
7615
|
+
console.log(import_chalk17.default.blue("\n7. Building frontend..."));
|
|
7482
7616
|
const frontendDir = import_path11.default.join(targetDir, "frontend");
|
|
7483
7617
|
if (import_fs_extra6.default.existsSync(frontendDir)) {
|
|
7484
7618
|
try {
|
|
@@ -7493,16 +7627,40 @@ Directory "${projectName}" already exists.`));
|
|
|
7493
7627
|
]);
|
|
7494
7628
|
}
|
|
7495
7629
|
console.log(import_chalk17.default.blue(" Uploading to IPFS..."));
|
|
7630
|
+
let frontendUrl = "";
|
|
7496
7631
|
try {
|
|
7497
|
-
(0, import_child_process2.execSync)("pinme upload ./dist", {
|
|
7632
|
+
const uploadOutput = (0, import_child_process2.execSync)("pinme upload ./dist", {
|
|
7498
7633
|
cwd: frontendDir,
|
|
7499
|
-
|
|
7634
|
+
encoding: "utf-8",
|
|
7500
7635
|
env: {
|
|
7501
7636
|
...process.env,
|
|
7502
7637
|
PINME_PROJECT_NAME: workerData.project_name
|
|
7503
7638
|
}
|
|
7504
7639
|
});
|
|
7505
|
-
console.log(
|
|
7640
|
+
console.log(uploadOutput);
|
|
7641
|
+
const urlMatch = uploadOutput.match(/https:\/\/[\w-]+\.pinme\.dev/);
|
|
7642
|
+
if (urlMatch) {
|
|
7643
|
+
frontendUrl = urlMatch[0];
|
|
7644
|
+
console.log(import_chalk17.default.green(` Frontend uploaded to IPFS: ${frontendUrl}`));
|
|
7645
|
+
const configPath2 = import_path11.default.join(targetDir, "pinme.toml");
|
|
7646
|
+
let config2 = import_fs_extra6.default.readFileSync(configPath2, "utf-8");
|
|
7647
|
+
if (config2.includes("frontend_url")) {
|
|
7648
|
+
config2 = config2.replace(
|
|
7649
|
+
/frontend_url\s*=\s*"[^"]*"/,
|
|
7650
|
+
`frontend_url = "${frontendUrl}"`
|
|
7651
|
+
);
|
|
7652
|
+
} else {
|
|
7653
|
+
config2 = config2.replace(
|
|
7654
|
+
/(project_name\s*=\s*"[^"]*"\n)/,
|
|
7655
|
+
`$1frontend_url = "${frontendUrl}"
|
|
7656
|
+
`
|
|
7657
|
+
);
|
|
7658
|
+
}
|
|
7659
|
+
import_fs_extra6.default.writeFileSync(configPath2, config2);
|
|
7660
|
+
console.log(import_chalk17.default.green(" Updated pinme.toml with frontend URL"));
|
|
7661
|
+
} else {
|
|
7662
|
+
console.log(import_chalk17.default.green(" Frontend uploaded to IPFS"));
|
|
7663
|
+
}
|
|
7506
7664
|
} catch (error) {
|
|
7507
7665
|
console.log(import_chalk17.default.yellow(" Warning: IPFS upload failed, you can upload manually later"));
|
|
7508
7666
|
}
|
|
@@ -7575,9 +7733,41 @@ function installDependencies() {
|
|
|
7575
7733
|
});
|
|
7576
7734
|
console.log(import_chalk18.default.green("Project dependencies installed"));
|
|
7577
7735
|
} catch (error) {
|
|
7736
|
+
const errorMsg = error.message || "";
|
|
7737
|
+
if (errorMsg.includes("EACCES") || errorMsg.includes("EPERM") || errorMsg.includes("permission denied")) {
|
|
7738
|
+
throw createCommandError("project dependency install", "npm install", error, [
|
|
7739
|
+
"Permission error detected. Here are some solutions:",
|
|
7740
|
+
"",
|
|
7741
|
+
"Option 1: Fix npm permissions (Recommended)",
|
|
7742
|
+
" mkdir -p ~/.npm-global",
|
|
7743
|
+
" npm config set prefix ~/.npm-global",
|
|
7744
|
+
" Then add ~/.npm-global/bin to your PATH in ~/.bashrc or ~/.zshrc",
|
|
7745
|
+
"",
|
|
7746
|
+
"Option 2: Use npx to avoid global installs",
|
|
7747
|
+
" npx npm install",
|
|
7748
|
+
"",
|
|
7749
|
+
"Option 3: Check if you have write permissions",
|
|
7750
|
+
" ls -la " + PROJECT_DIR2,
|
|
7751
|
+
"",
|
|
7752
|
+
"For more help: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally"
|
|
7753
|
+
]);
|
|
7754
|
+
}
|
|
7755
|
+
if (errorMsg.includes("ENOTFOUND") || errorMsg.includes("ETIMEDOUT") || errorMsg.includes("network")) {
|
|
7756
|
+
throw createCommandError("project dependency install", "npm install", error, [
|
|
7757
|
+
"Network error detected. Please check:",
|
|
7758
|
+
" 1. Internet connection is available",
|
|
7759
|
+
" 2. npm registry is accessible (https://registry.npmjs.org)",
|
|
7760
|
+
" 3. Try using a mirror: npm config set registry https://registry.npmmirror.com"
|
|
7761
|
+
]);
|
|
7762
|
+
}
|
|
7578
7763
|
throw createCommandError("project dependency install", "npm install", error, [
|
|
7764
|
+
"Dependency installation failed.",
|
|
7579
7765
|
"Check network connectivity and npm registry availability.",
|
|
7580
|
-
"If `package-lock.json` is stale or conflicted, resolve that before retrying."
|
|
7766
|
+
"If `package-lock.json` is stale or conflicted, resolve that before retrying.",
|
|
7767
|
+
"",
|
|
7768
|
+
"If this is a permission issue, try:",
|
|
7769
|
+
" sudo chown -R $(whoami) ~/.npm",
|
|
7770
|
+
" sudo chown -R $(whoami) " + PROJECT_DIR2 + "/node_modules"
|
|
7581
7771
|
]);
|
|
7582
7772
|
}
|
|
7583
7773
|
}
|
|
@@ -7694,15 +7884,38 @@ function buildFrontend() {
|
|
|
7694
7884
|
function deployFrontend(projectName) {
|
|
7695
7885
|
console.log(import_chalk18.default.blue("Deploying frontend to IPFS..."));
|
|
7696
7886
|
try {
|
|
7697
|
-
(0, import_child_process3.execSync)("pinme upload ./frontend/dist", {
|
|
7887
|
+
const uploadOutput = (0, import_child_process3.execSync)("pinme upload ./frontend/dist", {
|
|
7698
7888
|
cwd: PROJECT_DIR2,
|
|
7699
|
-
|
|
7889
|
+
encoding: "utf-8",
|
|
7700
7890
|
env: {
|
|
7701
7891
|
...process.env,
|
|
7702
7892
|
PINME_PROJECT_NAME: projectName
|
|
7703
7893
|
}
|
|
7704
7894
|
});
|
|
7705
|
-
console.log(
|
|
7895
|
+
console.log(uploadOutput);
|
|
7896
|
+
const urlMatch = uploadOutput.match(/https:\/\/[\w-]+\.pinme\.dev/);
|
|
7897
|
+
if (urlMatch) {
|
|
7898
|
+
const frontendUrl = urlMatch[0];
|
|
7899
|
+
console.log(import_chalk18.default.green(`Frontend deployed to IPFS: ${frontendUrl}`));
|
|
7900
|
+
const configPath = import_path12.default.join(PROJECT_DIR2, "pinme.toml");
|
|
7901
|
+
let config = import_fs_extra7.default.readFileSync(configPath, "utf-8");
|
|
7902
|
+
if (config.includes("frontend_url")) {
|
|
7903
|
+
config = config.replace(
|
|
7904
|
+
/frontend_url\s*=\s*"[^"]*"/,
|
|
7905
|
+
`frontend_url = "${frontendUrl}"`
|
|
7906
|
+
);
|
|
7907
|
+
} else {
|
|
7908
|
+
config = config.replace(
|
|
7909
|
+
/(project_name\s*=\s*"[^"]*"\n)/,
|
|
7910
|
+
`$1frontend_url = "${frontendUrl}"
|
|
7911
|
+
`
|
|
7912
|
+
);
|
|
7913
|
+
}
|
|
7914
|
+
import_fs_extra7.default.writeFileSync(configPath, config);
|
|
7915
|
+
console.log(import_chalk18.default.green("Updated pinme.toml with frontend URL"));
|
|
7916
|
+
} else {
|
|
7917
|
+
console.log(import_chalk18.default.green("Frontend deployed to IPFS"));
|
|
7918
|
+
}
|
|
7706
7919
|
} catch (error) {
|
|
7707
7920
|
throw createCommandError("frontend deploy", "pinme upload ./frontend/dist", error, [
|
|
7708
7921
|
"Make sure `frontend/dist` exists and `pinme upload` works in this environment."
|