From 34c9af58f0f2c58ea44b733bbb2c0b04f6e0274e Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 30 Sep 2024 16:20:23 +0800 Subject: [PATCH] feat: support preview --- .../docs/tools/script-kit/scripts/[nav]nav.js | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/site/docs/tools/script-kit/scripts/[nav]nav.js b/site/docs/tools/script-kit/scripts/[nav]nav.js index 1ae2ae52..7d00d133 100644 --- a/site/docs/tools/script-kit/scripts/[nav]nav.js +++ b/site/docs/tools/script-kit/scripts/[nav]nav.js @@ -45,6 +45,22 @@ const dify = [ // value: 'difyMergeMain' // } // }, + { + name: 'Review Dify PR', + description: 'Review pull request', + value: { + action: 'customize', + value: 'reviewDifyPr' + } + }, + { + name: 'Reviewing Dify PR done', + description: 'Finished reviewing pull request', + value: { + action: 'customize', + value: 'reviewDifyPrDone' + } + }, { name: "Dify Production(Cloud) URL", description: "线上 URL", @@ -120,6 +136,38 @@ const dev = [ value: 'showTailwindCheatSheet' } }, + { + name: 'Tailwind Docs', + value: { + value: 'https://tailwindcss.com/docs/grid-template-columns' + } + }, + { + name: 'Git Docs', + value: { + value: 'https://iamjoel.github.io/four-dimensional-space-bag/site/build/docs/tools/git' + } + }, + { + name: 'Google Translate', + // shortcut: 'cmd shift t', + value: { + value: 'https://translate.google.com/details?hl=zh-CN&sl=zh-CN&tl=en&op=translate' + } + }, + // AI + { + name: 'Claude', + value: { + value: 'https://claude.ai/new' + } + }, + { + name: 'v0', + value: { + value: 'https://v0.dev/chat' + } + }, { name: 'Show IP', value: { @@ -137,6 +185,12 @@ const dev = [ ] const info = [ + { + name: 'Gmail', + value: { + value: 'https://mail.google.com/' + } + }, { name: "Four dimensional", value: { @@ -208,6 +262,25 @@ const info = [ let { value, action } = await arg("Select open target", [...dify, ...dev, ...info]) +function getRepoInfo(branchUrl) { + // Regular expression to match GitHub repository URL pattern + const regex = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)(?:\/tree\/([^\/]+))?/; + + // Extract parts from the URL + const match = branchUrl.match(regex); + + if (!match) { + throw new Error('Invalid GitHub branch URL'); + } + + const [, owner, repo, branch = 'main'] = match; + + return { + url: `https://github.com/${owner}/${repo}.git`, + branch: branch + }; +} + const tools = { async difyMergeMain() { const options = { @@ -221,6 +294,40 @@ const tools = { await git.mergeFromTo('main', currBranch) }, + async reviewDifyPr() { + const name = await arg("Repo brach url") + + const repo = getRepoInfo(name) + + const reviewBranch = 'review/pr' + const remoteName = 'review' + const options = { + baseDir: '/Users/joel/dify/dify' + } + const git = simpleGit(options) + await git.checkout('main') + await git.pull() + await git.checkoutLocalBranch(reviewBranch) + await git.addRemote(remoteName, repo.url) + await git.pull(remoteName, repo.branch) + await notify('Done') + }, + + async reviewDifyPrDone() { + try { + const options = { + baseDir: '/Users/joel/dify/dify' + } + const git = simpleGit(options) + await git.checkout('main') + await git.deleteLocalBranch('review/pr', true) + await git.removeRemote('review') + } catch (e) { + console.error(e) + } + await notify('Done') + }, + async outputReactComponentTemplate() { const name = await arg("Component name") const code = `'use client'