pinme 2.0.0-beta.6 → 2.0.0-beta.8
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 +36 -43
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1523,7 +1523,7 @@ var import_chalk22 = __toESM(require("chalk"));
|
|
|
1523
1523
|
var import_figlet5 = __toESM(require("figlet"));
|
|
1524
1524
|
|
|
1525
1525
|
// package.json
|
|
1526
|
-
var version = "2.0.0-beta.
|
|
1526
|
+
var version = "2.0.0-beta.8";
|
|
1527
1527
|
|
|
1528
1528
|
// bin/upload.ts
|
|
1529
1529
|
var import_path7 = __toESM(require("path"));
|
|
@@ -7112,7 +7112,8 @@ var import_inquirer8 = __toESM(require("inquirer"));
|
|
|
7112
7112
|
var import_child_process2 = require("child_process");
|
|
7113
7113
|
var PROJECT_DIR = process.cwd();
|
|
7114
7114
|
var API_BASE = "https://pinme.dev/api/v4";
|
|
7115
|
-
var TEMPLATE_REPO = "
|
|
7115
|
+
var TEMPLATE_REPO = "glitternetwork/pinme-worker-template";
|
|
7116
|
+
var TEMPLATE_ZIP_URL = `https://github.com/${TEMPLATE_REPO}/archive/refs/heads/main.zip`;
|
|
7116
7117
|
async function createCmd(options) {
|
|
7117
7118
|
var _a, _b, _c, _d, _e, _f;
|
|
7118
7119
|
try {
|
|
@@ -7188,19 +7189,42 @@ Directory "${projectName}" already exists.`));
|
|
|
7188
7189
|
const errorMsg = ((_d = (_c = (_b = error.response) == null ? void 0 : _b.data) == null ? void 0 : _c.data) == null ? void 0 : _d.error) || ((_f = (_e = error.response) == null ? void 0 : _e.data) == null ? void 0 : _f.msg) || error.message || "Failed to create worker";
|
|
7189
7190
|
throw new Error(errorMsg);
|
|
7190
7191
|
}
|
|
7191
|
-
console.log(import_chalk16.default.blue("\n2.
|
|
7192
|
+
console.log(import_chalk16.default.blue("\n2. Downloading template from repository..."));
|
|
7193
|
+
const zipPath = import_path11.default.join(PROJECT_DIR, "template.zip");
|
|
7194
|
+
let downloadSuccess = false;
|
|
7195
|
+
for (let attempt = 1; attempt <= 3 && !downloadSuccess; attempt++) {
|
|
7196
|
+
try {
|
|
7197
|
+
console.log(import_chalk16.default.gray(` Download attempt ${attempt}/3...`));
|
|
7198
|
+
(0, import_child_process2.execSync)(`curl -L --retry 3 --retry-delay 2 -o "${zipPath}" "${TEMPLATE_ZIP_URL}"`, {
|
|
7199
|
+
stdio: "inherit"
|
|
7200
|
+
});
|
|
7201
|
+
if (!import_fs_extra6.default.existsSync(zipPath) || import_fs_extra6.default.statSync(zipPath).size < 100) {
|
|
7202
|
+
throw new Error("Downloaded file is too small or empty");
|
|
7203
|
+
}
|
|
7204
|
+
downloadSuccess = true;
|
|
7205
|
+
} catch (downloadError) {
|
|
7206
|
+
console.log(import_chalk16.default.yellow(` Attempt ${attempt} failed: ${downloadError.message}`));
|
|
7207
|
+
if (import_fs_extra6.default.existsSync(zipPath)) {
|
|
7208
|
+
import_fs_extra6.default.removeSync(zipPath);
|
|
7209
|
+
}
|
|
7210
|
+
if (attempt === 3) {
|
|
7211
|
+
throw new Error(`Failed to download template after 3 attempts: ${downloadError.message}`);
|
|
7212
|
+
}
|
|
7213
|
+
}
|
|
7214
|
+
}
|
|
7192
7215
|
try {
|
|
7193
|
-
(0, import_child_process2.execSync)(`
|
|
7216
|
+
(0, import_child_process2.execSync)(`unzip -o "${zipPath}" -d "${PROJECT_DIR}"`, {
|
|
7194
7217
|
stdio: "inherit"
|
|
7195
7218
|
});
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
import_fs_extra6.default.removeSync(
|
|
7200
|
-
console.log(import_chalk16.default.gray(" .git directory removed"));
|
|
7219
|
+
const subDir = import_path11.default.join(PROJECT_DIR, "pinme-worker-template-main");
|
|
7220
|
+
if (import_fs_extra6.default.existsSync(subDir)) {
|
|
7221
|
+
import_fs_extra6.default.copySync(subDir, targetDir);
|
|
7222
|
+
import_fs_extra6.default.removeSync(subDir);
|
|
7201
7223
|
}
|
|
7224
|
+
import_fs_extra6.default.removeSync(zipPath);
|
|
7225
|
+
console.log(import_chalk16.default.green(` Template downloaded to: ${targetDir}`));
|
|
7202
7226
|
} catch (error) {
|
|
7203
|
-
throw new Error(`Failed to
|
|
7227
|
+
throw new Error(`Failed to extract template: ${error.message}`);
|
|
7204
7228
|
}
|
|
7205
7229
|
console.log(import_chalk16.default.blue("\n3. Updating configuration..."));
|
|
7206
7230
|
const configPath = import_path11.default.join(targetDir, "pinme.toml");
|
|
@@ -7209,29 +7233,6 @@ Directory "${projectName}" already exists.`));
|
|
|
7209
7233
|
/project_name = ".*"/,
|
|
7210
7234
|
`project_name = "${workerData.project_name}"`
|
|
7211
7235
|
);
|
|
7212
|
-
updatedConfig = updatedConfig.replace(
|
|
7213
|
-
/^VITE_WORKER_URL = ".*"$/m,
|
|
7214
|
-
`VITE_WORKER_URL = "${workerData.api_domain}"`
|
|
7215
|
-
);
|
|
7216
|
-
updatedConfig = updatedConfig.replace(
|
|
7217
|
-
/# database_id = ".*"/,
|
|
7218
|
-
`database_id = "${workerData.uuid}"`
|
|
7219
|
-
);
|
|
7220
|
-
if (workerData.api_key) {
|
|
7221
|
-
console.log(import_chalk16.default.gray(` API Key: ${workerData.api_key.slice(0, 8)}...`));
|
|
7222
|
-
updatedConfig = updatedConfig.replace(
|
|
7223
|
-
/^# api_key = ".*"$/m,
|
|
7224
|
-
`api_key = "${workerData.api_key}"`
|
|
7225
|
-
);
|
|
7226
|
-
if (!updatedConfig.includes(`api_key = "${workerData.api_key}"`)) {
|
|
7227
|
-
updatedConfig = updatedConfig.replace(
|
|
7228
|
-
/^api_key = ".*"$/m,
|
|
7229
|
-
`api_key = "${workerData.api_key}"`
|
|
7230
|
-
);
|
|
7231
|
-
}
|
|
7232
|
-
} else {
|
|
7233
|
-
console.log(import_chalk16.default.yellow(" Warning: No API Key returned from API"));
|
|
7234
|
-
}
|
|
7235
7236
|
import_fs_extra6.default.writeFileSync(configPath, updatedConfig);
|
|
7236
7237
|
console.log(import_chalk16.default.green(` Updated pinme.toml`));
|
|
7237
7238
|
console.log(import_chalk16.default.gray(` metadata: ${workerData.metadata}`));
|
|
@@ -7249,8 +7250,8 @@ Directory "${projectName}" already exists.`));
|
|
|
7249
7250
|
if (import_fs_extra6.default.existsSync(wranglerPath) && workerData.api_key) {
|
|
7250
7251
|
let wranglerContent = import_fs_extra6.default.readFileSync(wranglerPath, "utf-8");
|
|
7251
7252
|
wranglerContent = wranglerContent.replace(
|
|
7252
|
-
/^
|
|
7253
|
-
`
|
|
7253
|
+
/^name = ".*"$/m,
|
|
7254
|
+
`name = "${workerData.project_name}"`
|
|
7254
7255
|
);
|
|
7255
7256
|
import_fs_extra6.default.writeFileSync(wranglerPath, wranglerContent);
|
|
7256
7257
|
console.log(import_chalk16.default.green(` Updated backend/wrangler.toml API_KEY`));
|
|
@@ -7260,18 +7261,10 @@ Directory "${projectName}" already exists.`));
|
|
|
7260
7261
|
if (import_fs_extra6.default.existsSync(envExamplePath)) {
|
|
7261
7262
|
let envContent = import_fs_extra6.default.readFileSync(envExamplePath, "utf-8");
|
|
7262
7263
|
envContent = envContent.replace(/your-project/g, workerData.project_name);
|
|
7263
|
-
envContent = envContent.replace(
|
|
7264
|
-
/^VITE_WORKER_URL=.*$/m,
|
|
7265
|
-
`VITE_WORKER_URL=${workerData.api_domain}`
|
|
7266
|
-
);
|
|
7267
7264
|
envContent = envContent.replace(
|
|
7268
7265
|
/^VITE_API_URL=.*$/m,
|
|
7269
7266
|
`VITE_API_URL=${workerData.api_domain}`
|
|
7270
7267
|
);
|
|
7271
|
-
envContent = envContent.replace(
|
|
7272
|
-
/^VITE_API_URL=.*$/m,
|
|
7273
|
-
`VITE_API_KEY=${workerData.api_key}`
|
|
7274
|
-
);
|
|
7275
7268
|
import_fs_extra6.default.writeFileSync(envPath, envContent);
|
|
7276
7269
|
console.log(import_chalk16.default.green(` Created frontend/.env file`));
|
|
7277
7270
|
}
|