pinme 2.0.2-beta.0 → 2.0.2-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.
Files changed (2) hide show
  1. package/dist/index.js +56 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1775,7 +1775,7 @@ var import_chalk24 = __toESM(require("chalk"));
1775
1775
  var import_figlet5 = __toESM(require("figlet"));
1776
1776
 
1777
1777
  // package.json
1778
- var version = "2.0.2-beta.0";
1778
+ var version = "2.0.2-beta.1";
1779
1779
 
1780
1780
  // bin/upload.ts
1781
1781
  var import_path7 = __toESM(require("path"));
@@ -8499,8 +8499,43 @@ Error: ${cliError.message}`));
8499
8499
  // bin/create.ts
8500
8500
  var PROJECT_DIR = process.cwd();
8501
8501
  var API_BASE = "https://pinme.benny1996.win/api/v4";
8502
+ var TEMPLATE_BRANCH = "feat/auth";
8502
8503
  var TEMPLATE_REPO = "glitternetwork/pinme-worker-template";
8503
- var TEMPLATE_ZIP_URL = `https://github.com/${TEMPLATE_REPO}/archive/refs/heads/main.zip`;
8504
+ var TEMPLATE_REPO_NAME = TEMPLATE_REPO.split("/").pop() || "pinme-worker-template";
8505
+ function getTemplateZipUrl(branch) {
8506
+ return `https://github.com/${TEMPLATE_REPO}/archive/refs/heads/${encodeURIComponent(branch)}.zip`;
8507
+ }
8508
+ function buildAuthConfigExport(authConfig) {
8509
+ return `export const auth_config = ${JSON.stringify(authConfig, null, 2)};
8510
+ `;
8511
+ }
8512
+ function injectAuthConfigIntoFile(fileContent, authConfig) {
8513
+ const authConfigExport = buildAuthConfigExport(authConfig).trimEnd();
8514
+ const authConfigPattern = /export\s+const\s+auth_config\s*=\s*\{[\s\S]*?\};?/m;
8515
+ if (authConfigPattern.test(fileContent)) {
8516
+ return fileContent.replace(authConfigPattern, authConfigExport);
8517
+ }
8518
+ const trimmed = fileContent.trimEnd();
8519
+ if (!trimmed) {
8520
+ return `${authConfigExport}
8521
+ `;
8522
+ }
8523
+ return `${trimmed}
8524
+
8525
+ ${authConfigExport}
8526
+ `;
8527
+ }
8528
+ function resolveExtractedTemplateDir(extractDir) {
8529
+ const entries = import_fs_extra7.default.readdirSync(extractDir, { withFileTypes: true });
8530
+ const templateDir = entries.find((entry) => entry.isDirectory() && entry.name.startsWith(`${TEMPLATE_REPO_NAME}-`));
8531
+ if (!templateDir) {
8532
+ throw createConfigError("Downloaded template archive structure is invalid.", [
8533
+ `Expected a directory starting with \`${TEMPLATE_REPO_NAME}-\` inside the extracted archive.`,
8534
+ `Template branch: ${TEMPLATE_BRANCH}`
8535
+ ]);
8536
+ }
8537
+ return import_path12.default.join(extractDir, templateDir.name);
8538
+ }
8504
8539
  async function createCmd(options) {
8505
8540
  var _a, _b;
8506
8541
  try {
@@ -8581,11 +8616,14 @@ Directory "${projectName}" already exists.`));
8581
8616
  }
8582
8617
  console.log(import_chalk18.default.blue("\n2. Downloading template from repository..."));
8583
8618
  const zipPath = import_path12.default.join(PROJECT_DIR, "template.zip");
8619
+ const extractDir = import_path12.default.join(PROJECT_DIR, `.pinme-template-${Date.now()}`);
8620
+ const templateZipUrl = getTemplateZipUrl(TEMPLATE_BRANCH);
8584
8621
  let downloadSuccess = false;
8622
+ console.log(import_chalk18.default.gray(` Template branch: ${TEMPLATE_BRANCH}`));
8585
8623
  for (let attempt = 1; attempt <= 3 && !downloadSuccess; attempt++) {
8586
8624
  try {
8587
8625
  console.log(import_chalk18.default.gray(` Download attempt ${attempt}/3...`));
8588
- (0, import_child_process3.execSync)(`curl -L --retry 3 --retry-delay 2 -o "${zipPath}" "${TEMPLATE_ZIP_URL}"`, {
8626
+ (0, import_child_process3.execSync)(`curl -L --retry 3 --retry-delay 2 -o "${zipPath}" "${templateZipUrl}"`, {
8589
8627
  stdio: "inherit"
8590
8628
  });
8591
8629
  if (!import_fs_extra7.default.existsSync(zipPath) || import_fs_extra7.default.statSync(zipPath).size < 100) {
@@ -8603,15 +8641,14 @@ Directory "${projectName}" already exists.`));
8603
8641
  }
8604
8642
  }
8605
8643
  try {
8606
- (0, import_child_process3.execSync)(`unzip -o "${zipPath}" -d "${PROJECT_DIR}"`, {
8644
+ import_fs_extra7.default.ensureDirSync(extractDir);
8645
+ (0, import_child_process3.execSync)(`unzip -o "${zipPath}" -d "${extractDir}"`, {
8607
8646
  stdio: "inherit"
8608
8647
  });
8609
- const subDir = import_path12.default.join(PROJECT_DIR, "pinme-worker-template-main");
8610
- if (import_fs_extra7.default.existsSync(subDir)) {
8611
- import_fs_extra7.default.copySync(subDir, targetDir);
8612
- import_fs_extra7.default.removeSync(subDir);
8613
- }
8648
+ const subDir = resolveExtractedTemplateDir(extractDir);
8649
+ import_fs_extra7.default.copySync(subDir, targetDir);
8614
8650
  import_fs_extra7.default.removeSync(zipPath);
8651
+ import_fs_extra7.default.removeSync(extractDir);
8615
8652
  const nodeModulesPath = import_path12.default.join(targetDir, "node_modules");
8616
8653
  const packageLockPath = import_path12.default.join(targetDir, "package-lock.json");
8617
8654
  if (import_fs_extra7.default.existsSync(nodeModulesPath)) {
@@ -8665,6 +8702,16 @@ Directory "${projectName}" already exists.`));
8665
8702
  import_fs_extra7.default.writeFileSync(wranglerPath, wranglerContent);
8666
8703
  console.log(import_chalk18.default.green(` Updated backend/wrangler.toml API_KEY`));
8667
8704
  }
8705
+ const frontendConfigPath = import_path12.default.join(targetDir, "frontend", "src", "utils", "config.ts");
8706
+ if (workerData.auth_config) {
8707
+ const frontendConfigContent = import_fs_extra7.default.existsSync(frontendConfigPath) ? import_fs_extra7.default.readFileSync(frontendConfigPath, "utf-8") : "";
8708
+ import_fs_extra7.default.ensureDirSync(import_path12.default.dirname(frontendConfigPath));
8709
+ import_fs_extra7.default.writeFileSync(
8710
+ frontendConfigPath,
8711
+ injectAuthConfigIntoFile(frontendConfigContent, workerData.auth_config)
8712
+ );
8713
+ console.log(import_chalk18.default.green(` Updated frontend/src/utils/config.ts auth_config`));
8714
+ }
8668
8715
  const envExamplePath = import_path12.default.join(targetDir, "frontend", ".env.example");
8669
8716
  const envPath = import_path12.default.join(targetDir, "frontend", ".env");
8670
8717
  if (import_fs_extra7.default.existsSync(envExamplePath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "2.0.2-beta.0",
3
+ "version": "2.0.2-beta.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },