Skip to content

Commit

Permalink
Merge branch 'main' of github.com:uni-helper/create-uni
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Jan 9, 2025
2 parents f872c5d + 7ba4b89 commit 6d9c9de
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 77 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-uni",
"type": "module",
"version": "2.0.0-beta.6",
"version": "2.0.0",
"packageManager": "[email protected]",
"description": "轻松创建你的 uni-app 项目",
"author": "FliPPeDround <[email protected]>",
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/command/actions/gui.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process'
import moduleData from '@/question/module/module.data'
import pluginData from '@/question/plugin/plugin.data'
import { templateList } from '@/question/template/template.data'
Expand Down Expand Up @@ -25,7 +26,9 @@ export function actionGuiCLI() {
})

const [command, ..._args] = fullCustomCommand.split(' ')
const { error, stdout } = sync(command, [..._args, '--input', input], {

process.env.CREATE_UNI_GUI_INPUT = input
const { error, stdout } = sync(command, [..._args], {
stdio: 'pipe',
})

Expand All @@ -35,7 +38,6 @@ export function actionGuiCLI() {
let data: any
if (stdout.length > 0) {
const data_string = stdout.toString()
console.log(data_string)
try {
const _data = JSON.parse(data_string)
if (_data.useTemplate) {
Expand All @@ -48,10 +50,13 @@ export function actionGuiCLI() {
data = _data
}
}
catch (e) {
throw new Error(`Error parsing JSON: ${e}`)
catch {
process.exit(0)
}
}

if (!data?.projectName) {
process.exit(0)
}
return data
}
2 changes: 1 addition & 1 deletion packages/gui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@create-uni/gui",
"version": "0.0.3",
"version": "0.0.4",
"license": "MIT",
"main": "./bin/index.cjs",
"bin": {
Expand Down
24 changes: 14 additions & 10 deletions packages/gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use wry::{dpi::LogicalSize, http::Request, WebViewBuilder};

use rfd::FileDialog;
use std::env;
use std::io::{self, Read};
use std::path::PathBuf;
use webbrowser::{open_browser, Browser::Default};

Expand All @@ -27,14 +26,14 @@ enum UserEvent {
#[napi]
pub fn create_webview() -> Result<()> {
let current_dir: PathBuf = env::current_dir().expect("Unable to get current working directory");
let mut input = String::new();

let args: Vec<String> = env::args().collect();
if let Some(input_value) = args.iter().position(|x| x == "--input").and_then(|i| args.get(i + 1)) {
input = input_value.to_string();
} else {
println!("No input provided.");
}
let input = match env::var("CREATE_UNI_GUI_INPUT") {
Ok(val) => {
val
},
Err(_) => {
String::from("default_value")
}
};

let current_dir_str = current_dir.to_str().unwrap_or("");
let escaped_current_dir_str = current_dir_str.replace("\\", "\\\\");
Expand Down Expand Up @@ -74,6 +73,9 @@ pub fn create_webview() -> Result<()> {
let url = req.next().unwrap();
open_browser(Default, url).unwrap();
}
"close" => {
let _ = proxy.send_event(UserEvent::CloseWindow);
}
"install" => {
let message = req.next().unwrap();
println!("{}", message);
Expand Down Expand Up @@ -108,7 +110,9 @@ pub fn create_webview() -> Result<()> {
event: WindowEvent::CloseRequested,
..
}
| Event::UserEvent(UserEvent::CloseWindow) => *control_flow = ControlFlow::Exit,
| Event::UserEvent(UserEvent::CloseWindow) => {
*control_flow = ControlFlow::Exit
},

Event::UserEvent(e) => match e {
UserEvent::FilePath => {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@radix-ui/react-checkbox": "^1.1.3",
"@radix-ui/react-context-menu": "^2.2.4",
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-dropdown-menu": "^2.1.4",
"@radix-ui/react-label": "^2.1.1",
Expand Down
198 changes: 198 additions & 0 deletions packages/ui/src/components/ui/context-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import { cn } from '@/lib/utils'
import * as ContextMenuPrimitive from '@radix-ui/react-context-menu'
import { Check, ChevronRight, Circle } from 'lucide-react'

import * as React from 'react'

const ContextMenu = ContextMenuPrimitive.Root

const ContextMenuTrigger = ContextMenuPrimitive.Trigger

const ContextMenuGroup = ContextMenuPrimitive.Group

const ContextMenuPortal = ContextMenuPrimitive.Portal

const ContextMenuSub = ContextMenuPrimitive.Sub

const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup

const ContextMenuSubTrigger = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.SubTrigger>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {
inset?: boolean
}
>(({ className, inset, children, ...props }, ref) => (
<ContextMenuPrimitive.SubTrigger
ref={ref}
className={cn(
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground',
inset && 'pl-8',
className,
)}
{...props}
>
{children}
<ChevronRight className="ml-auto h-4 w-4" />
</ContextMenuPrimitive.SubTrigger>
))
ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName

const ContextMenuSubContent = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.SubContent>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>
>(({ className, ...props }, ref) => (
<ContextMenuPrimitive.SubContent
ref={ref}
className={cn(
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
className,
)}
{...props}
/>
))
ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName

const ContextMenuContent = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>
>(({ className, ...props }, ref) => (
<ContextMenuPrimitive.Portal>
<ContextMenuPrimitive.Content
ref={ref}
className={cn(
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
className,
)}
{...props}
/>
</ContextMenuPrimitive.Portal>
))
ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName

const ContextMenuItem = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item> & {
inset?: boolean
}
>(({ className, inset, ...props }, ref) => (
<ContextMenuPrimitive.Item
ref={ref}
className={cn(
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
inset && 'pl-8',
className,
)}
{...props}
/>
))
ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName

const ContextMenuCheckboxItem = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.CheckboxItem>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.CheckboxItem>
>(({ className, children, checked, ...props }, ref) => (
<ContextMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
className,
)}
checked={checked}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
</ContextMenuPrimitive.ItemIndicator>
</span>
{children}
</ContextMenuPrimitive.CheckboxItem>
))
ContextMenuCheckboxItem.displayName
= ContextMenuPrimitive.CheckboxItem.displayName

const ContextMenuRadioItem = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.RadioItem>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.RadioItem>
>(({ className, children, ...props }, ref) => (
<ContextMenuPrimitive.RadioItem
ref={ref}
className={cn(
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
className,
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<ContextMenuPrimitive.ItemIndicator>
<Circle className="h-4 w-4 fill-current" />
</ContextMenuPrimitive.ItemIndicator>
</span>
{children}
</ContextMenuPrimitive.RadioItem>
))
ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName

const ContextMenuLabel = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label> & {
inset?: boolean
}
>(({ className, inset, ...props }, ref) => (
<ContextMenuPrimitive.Label
ref={ref}
className={cn(
'px-2 py-1.5 text-sm font-semibold text-foreground',
inset && 'pl-8',
className,
)}
{...props}
/>
))
ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName

const ContextMenuSeparator = React.forwardRef<
React.ElementRef<typeof ContextMenuPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator>
>(({ className, ...props }, ref) => (
<ContextMenuPrimitive.Separator
ref={ref}
className={cn('-mx-1 my-1 h-px bg-border', className)}
{...props}
/>
))
ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName

function ContextMenuShortcut({
className,
...props
}: React.HTMLAttributes<HTMLSpanElement>) {
return (
<span
className={cn(
'ml-auto text-xs tracking-widest text-muted-foreground',
className,
)}
{...props}
/>
)
}
ContextMenuShortcut.displayName = 'ContextMenuShortcut'

export {
ContextMenu,
ContextMenuCheckboxItem,
ContextMenuContent,
ContextMenuGroup,
ContextMenuItem,
ContextMenuLabel,
ContextMenuPortal,
ContextMenuRadioGroup,
ContextMenuRadioItem,
ContextMenuSeparator,
ContextMenuShortcut,
ContextMenuSub,
ContextMenuSubContent,
ContextMenuSubTrigger,
ContextMenuTrigger,
}
50 changes: 41 additions & 9 deletions packages/ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuTrigger,
} from '@/components/ui/context-menu'
import CLIInterface from '@/page/index'
import { render } from 'preact'
import { Footer } from './components/footer'
import { Header } from './components/header'
import { USER_EVENT } from './constants/USER_EVENT'
import './style.css'

// document.addEventListener('contextmenu', (event) => {
// event.preventDefault()
// })

export function App() {
return (
<div class="bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 h-[100vh] overflow-y-auto transition-colors duration-200 flex flex-col">
<Header />
<CLIInterface />
<Footer />
</div>
<ContextMenu>
<ContextMenuTrigger>
<div class="bg-white dark:bg-zinc-900 text-zinc-900 dark:text-zinc-100 h-[100vh] overflow-y-auto transition-colors duration-200 flex flex-col">
<Header />
<CLIInterface />
<Footer />
</div>
</ContextMenuTrigger>
<ContextMenuContent className="w-40">
<ContextMenuItem
onClick={() => window.ipc.postMessage(`${USER_EVENT.OPEN}|https://github.com/uni-helper/create-uni`)}
>
Github
</ContextMenuItem>
<ContextMenuItem
onClick={() => window.ipc.postMessage(`${USER_EVENT.OPEN}|https://afdian.com/a/flippedround`)}
>
Sponsor
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onClick={() => window.location.reload()}
>
Reload
</ContextMenuItem>
<ContextMenuItem
onClick={() => window.ipc.postMessage(USER_EVENT.CLOSE)}
>
Exit
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>

)
}

Expand Down
Loading

0 comments on commit 6d9c9de

Please sign in to comment.