create-tauri-ui 1.0.2 → 1.0.4
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/assets/release.yml.tmpl +3 -4
- package/dist/index.mjs +18 -23
- package/package.json +1 -1
package/assets/release.yml.tmpl
CHANGED
|
@@ -41,7 +41,7 @@ jobs:
|
|
|
41
41
|
sudo apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev patchelf
|
|
42
42
|
|
|
43
43
|
- name: Install frontend dependencies
|
|
44
|
-
run: bun install
|
|
44
|
+
run: bun install
|
|
45
45
|
|
|
46
46
|
- name: Build and publish
|
|
47
47
|
id: tauri
|
|
@@ -57,9 +57,8 @@ jobs:
|
|
|
57
57
|
generateReleaseNotes: true
|
|
58
58
|
retryAttempts: 2
|
|
59
59
|
args: ${{ matrix.args }}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
uploadUpdaterSignatures: false
|
|
60
|
+
assetNamePattern: "[name]-[version]-[platform]-[arch][ext]"
|
|
61
|
+
includeUpdaterJson: false
|
|
63
62
|
|
|
64
63
|
- name: Release summary
|
|
65
64
|
if: steps.tauri.outputs.releaseHtmlUrl != ''
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import s from"node:fs";import a from"node:path";import S from"node:process";import{text as _,confirm as P,select as we,multiselect as ve,isCancel as xe,cancel as W,log as h,intro as ye,spinner as be,outro as ke,note as K}from"@clack/prompts";import A from"picocolors";import z from"node:os";import{execFile as
|
|
2
|
-
`)
|
|
1
|
+
import s from"node:fs";import a from"node:path";import S from"node:process";import{text as _,confirm as P,select as we,multiselect as ve,isCancel as xe,cancel as W,log as h,intro as ye,spinner as be,outro as ke,note as K}from"@clack/prompts";import A from"picocolors";import z from"node:os";import{execFile as $e}from"node:child_process";import{fileURLToPath as I}from"node:url";const D=new Set;let Y=!1,X=!1;class L extends Error{constructor(t,r,n,i){super(t),this.stdout=r,this.stderr=n,this.code=i}}class w extends Error{constructor(t,r,n){super(r),this.tool=t,this.stderr=n}}class u extends Error{constructor(t,r){super(r),this.file=t}}function Ee(e){return e?.trim().replace(/\/+$/g,"")}function q(e,t){s.statSync(e).isDirectory()?Z(e,t):(s.mkdirSync(a.dirname(t),{recursive:!0}),s.copyFileSync(e,t))}function R(e){return/^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(e)}function J(e){return e.trim().toLowerCase().replace(/\s+/g,"-").replace(/^[._]/,"").replace(/[^a-z\d\-~]+/g,"-")}function Z(e,t){s.mkdirSync(t,{recursive:!0});for(const r of s.readdirSync(e)){const n=a.resolve(e,r),i=a.resolve(t,r);q(n,i)}}function je(e){const t=s.readdirSync(e);return t.length===0||t.length===1&&t[0]===".git"}function l(e,t){const r=s.readFileSync(e,"utf-8").replace(/\r\n/g,`
|
|
2
|
+
`);s.writeFileSync(e,t(r),"utf-8")}function m(e,t){const r=JSON.parse(s.readFileSync(e,"utf-8")),n=t(r);s.writeFileSync(e,JSON.stringify(n,null,2)+`
|
|
3
|
+
`)}async function C(e,t,r){return await new Promise((n,i)=>{$e(e,t,{cwd:r?.cwd,env:{...process.env,...r?.env},maxBuffer:1024*1024*10},(o,c,N)=>{if(o){i(new L(`Command failed: ${e} ${t.join(" ")}`,c,N,typeof o.code=="number"?o.code:null));return}n(c.trim())})})}function Q(e){return s.mkdtempSync(a.join(z.tmpdir(),e))}function O(e){D.add(e)}function f(e){D.delete(e)}function g(e){s.existsSync(e)&&s.rmSync(e,{recursive:!0,force:!0})}function Se(){const e=[...D].sort((t,r)=>r.length-t.length);for(const t of e)try{g(t)}catch{}finally{D.delete(t)}}function _e(){if(Y)return;Y=!0;const e=(t,r)=>{X&&process.exit(r),X=!0,Se(),process.exit(r)};process.once("SIGINT",()=>e("SIGINT",130)),process.once("SIGTERM",()=>e("SIGTERM",143))}function Pe(e){return e.replace(/^@[^/]+\//,"").replace(/[^a-zA-Z0-9]+/g,"_").replace(/^_+|_+$/g,"")}const De={name:"astro",async apply(e,t){l(a.join(e,"astro.config.mjs"),r=>{if(r.includes("server: {"))return r;const n=r.lastIndexOf(`
|
|
3
4
|
})`);if(n===-1)throw new u("astro.config.mjs","Could not find the Astro config closing brace.");return`${r.slice(0,n)}
|
|
4
5
|
server: {
|
|
5
6
|
port: 1420,
|
|
@@ -97,9 +98,7 @@ import { DashboardShell } from "@/components/dashboard-shell"
|
|
|
97
98
|
])
|
|
98
99
|
.build(),
|
|
99
100
|
)
|
|
100
|
-
`;function Xe(){const e=a.dirname(I(import.meta.url)),t=[a.resolve(e,"../assets/debug-panel"),a.resolve(e,"../../assets/debug-panel")];return t.find(r=>s.existsSync(r))??t[0]}const qe=Xe();function Je(e){return e==="react-router"?"~/":"@/"}function ae(e,t){switch(t.template){case"next":return a.join(e,"components");case"vite":case"start":case"astro":return a.join(e,"src/components");case"react-router":return a.join(e,"app/components")}}function Ze(e,t){switch(t.template){case"next":return a.join(e,"lib");case"vite":case"start":case"astro":return a.join(e,"src/lib");case"react-router":return a.join(e,"app/lib")}}function Qe(e,t){return a.join(ae(e,t),"ui")}function x(e){switch(e.template){case"next":return"@/components/debug-panel";case"vite":return"./components/debug-panel.tsx";case"start":return"../components/debug-panel";case"react-router":return"./components/debug-panel";case"astro":return"@/components/debug-panel"}}async function et(e,t){for(const r of["button","badge","sheet","tabs","toggle-group"]){const n=a.join(Qe(e,t),`${r}.tsx`);s.existsSync(n)||await te(e,r)}}function F(e){return s.readFileSync(a.join(qe,e),"utf-8")}function tt(e,t){const r=a.join(ae(e,t),"debug-panel.tsx"),n=Ze(e,t);s.mkdirSync(a.dirname(r),{recursive:!0}),s.mkdirSync(n,{recursive:!0}),s.writeFileSync(r,F("debug-panel.tsx.tmpl").split("__ALIAS_PREFIX__").join(Je(t.template)),"utf-8"),s.writeFileSync(a.join(n,"debug-events.ts"),F("debug-events.ts.tmpl"),"utf-8"),s.writeFileSync(a.join(n,"tauri.ts"),F("tauri.ts.tmpl"),"utf-8")}function rt(e){m(a.join(e,"package.json"),t=>(t.dependencies=t.dependencies||{},t.dependencies["@tauri-apps/plugin-log"]||(t.dependencies["@tauri-apps/plugin-log"]="^2"),t))}function oe(e,t){if(e.includes(t))return e;if(!
|
|
101
|
-
`))throw new Error(`Could not find [dependencies] while inserting ${t}.`);return e.replace(`[dependencies]
|
|
102
|
-
`,`[dependencies]
|
|
101
|
+
`;function Xe(){const e=a.dirname(I(import.meta.url)),t=[a.resolve(e,"../assets/debug-panel"),a.resolve(e,"../../assets/debug-panel")];return t.find(r=>s.existsSync(r))??t[0]}const qe=Xe();function Je(e){return e==="react-router"?"~/":"@/"}function ae(e,t){switch(t.template){case"next":return a.join(e,"components");case"vite":case"start":case"astro":return a.join(e,"src/components");case"react-router":return a.join(e,"app/components")}}function Ze(e,t){switch(t.template){case"next":return a.join(e,"lib");case"vite":case"start":case"astro":return a.join(e,"src/lib");case"react-router":return a.join(e,"app/lib")}}function Qe(e,t){return a.join(ae(e,t),"ui")}function x(e){switch(e.template){case"next":return"@/components/debug-panel";case"vite":return"./components/debug-panel.tsx";case"start":return"../components/debug-panel";case"react-router":return"./components/debug-panel";case"astro":return"@/components/debug-panel"}}async function et(e,t){for(const r of["button","badge","sheet","tabs","toggle-group"]){const n=a.join(Qe(e,t),`${r}.tsx`);s.existsSync(n)||await te(e,r)}}function F(e){return s.readFileSync(a.join(qe,e),"utf-8")}function tt(e,t){const r=a.join(ae(e,t),"debug-panel.tsx"),n=Ze(e,t);s.mkdirSync(a.dirname(r),{recursive:!0}),s.mkdirSync(n,{recursive:!0}),s.writeFileSync(r,F("debug-panel.tsx.tmpl").split("__ALIAS_PREFIX__").join(Je(t.template)),"utf-8"),s.writeFileSync(a.join(n,"debug-events.ts"),F("debug-events.ts.tmpl"),"utf-8"),s.writeFileSync(a.join(n,"tauri.ts"),F("tauri.ts.tmpl"),"utf-8")}function rt(e){m(a.join(e,"package.json"),t=>(t.dependencies=t.dependencies||{},t.dependencies["@tauri-apps/plugin-log"]||(t.dependencies["@tauri-apps/plugin-log"]="^2"),t))}function oe(e,t){if(e.includes(t))return e;const r=/\[dependencies\]\r?\n/;if(!r.test(e))throw new Error(`Could not find [dependencies] while inserting ${t}.`);return e.replace(r,`[dependencies]
|
|
103
102
|
${t}
|
|
104
103
|
`)}function nt(e){const t=a.join(e,"src-tauri/Cargo.toml"),r=a.join(e,"src-tauri/src/lib.rs");l(t,n=>{let i=n;return i=oe(i,'tauri-plugin-log = "2"'),i=oe(i,'log = "0.4"'),i}),m(a.join(e,"src-tauri/capabilities/default.json"),n=>(n.permissions=Array.isArray(n.permissions)?n.permissions:[],n.permissions.includes("log:default")||n.permissions.push("log:default"),n)),l(r,n=>{let i=n;if(i.includes(T)||(i.includes(`use tauri_plugin_opener::OpenerExt;
|
|
105
104
|
`)?i=i.replace(`use tauri_plugin_opener::OpenerExt;
|
|
@@ -121,13 +120,11 @@ ${re}`)),!i.includes(ne.trim())&&i.includes(` let _ = webview.ope
|
|
|
121
120
|
`)),!i.includes(ie.trim())&&i.includes(` let _ = webview.window().show();
|
|
122
121
|
`)&&(i=i.replace(` let _ = webview.window().show();
|
|
123
122
|
`,`${ie} let _ = webview.window().show();
|
|
124
|
-
`)),i})}function it(e,t){const r=a.join(e,"src/main.tsx"),n=x(t);l(r,i=>{let o=i;if(o.includes(`import { DebugPanel } from "${n}"`)||(o=o.replace(
|
|
125
|
-
`,`import { ExternalLinkGuard } from "./components/external-link-guard.tsx"
|
|
123
|
+
`)),i})}function it(e,t){const r=a.join(e,"src/main.tsx"),n=x(t);l(r,i=>{let o=i;if(o.includes(`import { DebugPanel } from "${n}"`)||(o=o.replace(/import { ExternalLinkGuard } from "\.\/components\/external-link-guard\.tsx"\r?\n/,`import { ExternalLinkGuard } from "./components/external-link-guard.tsx"
|
|
126
124
|
import { DebugPanel } from "${n}"
|
|
127
|
-
`)),o.includes("<DebugPanel />"))return o;const c=o.replace(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
<main><App /></main>`);if(c===o)throw new u(r,"Could not mount DebugPanel in the Vite entrypoint.");return c})}function at(e,t){const r=a.join(e,"app/layout.tsx"),n=x(t);l(r,i=>{let o=i;if(o.includes(`import { DebugPanel } from "${n}"`)||(o.includes(`import { ExternalLinkGuard } from "@/components/external-link-guard"
|
|
125
|
+
`)),o.includes("<DebugPanel />"))return o;const c=o.replace(/<ExternalLinkGuard \/>\r?\n(\s*)<main><App \/><\/main>/,`<ExternalLinkGuard />
|
|
126
|
+
$1{import.meta.env.DEV ? <DebugPanel /> : null}
|
|
127
|
+
$1<main><App /></main>`);if(c===o)throw new u(r,"Could not mount DebugPanel in the Vite entrypoint.");return c})}function at(e,t){const r=a.join(e,"app/layout.tsx"),n=x(t);l(r,i=>{let o=i;if(o.includes(`import { DebugPanel } from "${n}"`)||(o.includes(`import { ExternalLinkGuard } from "@/components/external-link-guard"
|
|
131
128
|
`)?o=o.replace(`import { ExternalLinkGuard } from "@/components/external-link-guard"
|
|
132
129
|
`,`import { ExternalLinkGuard } from "@/components/external-link-guard"
|
|
133
130
|
import { DebugPanel } from "${n}"
|
|
@@ -282,13 +279,11 @@ ${U}
|
|
|
282
279
|
${n}`),!n.includes("fn external_navigation_plugin<R: tauri::Runtime>()")){if(!n.includes("#[cfg_attr(mobile, tauri::mobile_entry_point)]"))throw new u(t,"Could not find the Tauri entry point while inserting the external navigation plugin.");n=n.replace("#[cfg_attr(mobile, tauri::mobile_entry_point)]",`${ut}#[cfg_attr(mobile, tauri::mobile_entry_point)]`)}if(!n.includes(".plugin(external_navigation_plugin())")){if(!n.includes(".plugin(tauri_plugin_opener::init())"))throw new u(t,"Could not find the opener plugin while inserting the external navigation guard.");n=n.replace(` .plugin(tauri_plugin_opener::init())
|
|
283
280
|
`,` .plugin(tauri_plugin_opener::init())
|
|
284
281
|
.plugin(external_navigation_plugin())
|
|
285
|
-
`)}return n})}function mt(e){const t=a.join(e,"src/components/external-link-guard.tsx"),r=a.join(e,"src/main.tsx");y(t),l(r,n=>{let i=n;if(i.includes('import { ExternalLinkGuard } from "./components/external-link-guard.tsx"')||(i=i.replace(
|
|
286
|
-
`,`import { ThemeProvider } from "@/components/theme-provider.tsx"
|
|
282
|
+
`)}return n})}function mt(e){const t=a.join(e,"src/components/external-link-guard.tsx"),r=a.join(e,"src/main.tsx");y(t),l(r,n=>{let i=n;if(i.includes('import { ExternalLinkGuard } from "./components/external-link-guard.tsx"')||(i=i.replace(/import { ThemeProvider } from "@\/components\/theme-provider\.tsx"\r?\n/,`import { ThemeProvider } from "@/components/theme-provider.tsx"
|
|
287
283
|
import { ExternalLinkGuard } from "./components/external-link-guard.tsx"
|
|
288
|
-
`)),i.includes("<ExternalLinkGuard />"))return i;const o=i.replace(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
<main><App /></main>`);if(o===i)throw new u(r,"Could not mount ExternalLinkGuard in the Vite entrypoint.");return o})}function ft(e){const t=a.join(e,"components/external-link-guard.tsx"),r=a.join(e,"app/layout.tsx");y(t),l(r,n=>{let i=n;if(i.includes('import { ExternalLinkGuard } from "@/components/external-link-guard"')||(i.includes(`import { TooltipProvider } from "@/components/ui/tooltip"
|
|
284
|
+
`)),i.includes("<ExternalLinkGuard />"))return i;const o=i.replace(/<ThemeProvider>\r?\n(\s*)<main><App \/><\/main>/,`<ThemeProvider>
|
|
285
|
+
$1<ExternalLinkGuard />
|
|
286
|
+
$1<main><App /></main>`);if(o===i)throw new u(r,"Could not mount ExternalLinkGuard in the Vite entrypoint.");return o})}function ft(e){const t=a.join(e,"components/external-link-guard.tsx"),r=a.join(e,"app/layout.tsx");y(t),l(r,n=>{let i=n;if(i.includes('import { ExternalLinkGuard } from "@/components/external-link-guard"')||(i.includes(`import { TooltipProvider } from "@/components/ui/tooltip"
|
|
292
287
|
`)?i=i.replace(`import { TooltipProvider } from "@/components/ui/tooltip"
|
|
293
288
|
`,`import { TooltipProvider } from "@/components/ui/tooltip"
|
|
294
289
|
import { ExternalLinkGuard } from "@/components/external-link-guard"
|
|
@@ -320,7 +315,7 @@ import { ExternalLinkGuard } from "@/components/external-link-guard"
|
|
|
320
315
|
`)?n=n.replace(`use tauri::Manager;
|
|
321
316
|
`,`${V}
|
|
322
317
|
`):n=`${V}
|
|
323
|
-
${n}`),n.includes(".on_page_load("))return n;const i=n.replace(" .run(tauri::generate_context!())",`${xt} .run(tauri::generate_context!())`);if(i===n)throw new u(t,"Could not insert the startup flash-prevention page-load hook.");return i})}function bt(){const e=a.dirname(I(import.meta.url)),t=[a.resolve(e,"../assets"),a.resolve(e,"../../assets")];return t.find(r=>s.existsSync(r))??t[0]}const kt=bt();async function
|
|
318
|
+
${n}`),n.includes(".on_page_load("))return n;const i=n.replace(" .run(tauri::generate_context!())",`${xt} .run(tauri::generate_context!())`);if(i===n)throw new u(t,"Could not insert the startup flash-prevention page-load hook.");return i})}function bt(){const e=a.dirname(I(import.meta.url)),t=[a.resolve(e,"../assets"),a.resolve(e,"../../assets")];return t.find(r=>s.existsSync(r))??t[0]}const kt=bt();async function $t(e){q(a.join(kt,"app-icon.png"),a.join(e,"app-icon.png"))}function Et(e){return`"use client"
|
|
324
319
|
|
|
325
320
|
import { useState } from "react"
|
|
326
321
|
import { Button } from "${e}components/ui/button"
|
|
@@ -402,7 +397,7 @@ function Home() {
|
|
|
402
397
|
</div>
|
|
403
398
|
)
|
|
404
399
|
}
|
|
405
|
-
`}function se(e,t){switch(e){case"next":return a.join(t,"app/page.tsx");case"vite":return a.join(t,"src/App.tsx");case"start":return a.join(t,"src/routes/index.tsx");case"react-router":return a.join(t,"app/routes/home.tsx");case"astro":return a.join(t,"src/pages/index.astro")}}function _t(e,t){switch(e){case"next":return a.join(t,"components/greet.tsx");case"vite":case"start":case"astro":return a.join(t,"src/components/greet.tsx");case"react-router":return a.join(t,"app/components/greet.tsx")}}async function Pt(e,t){t.includeStarterUI||await te(e,"input");const r=t.template==="react-router"?"~/":"@/";if(s.writeFileSync(_t(t.template,e)
|
|
400
|
+
`}function se(e,t){switch(e){case"next":return a.join(t,"app/page.tsx");case"vite":return a.join(t,"src/App.tsx");case"start":return a.join(t,"src/routes/index.tsx");case"react-router":return a.join(t,"app/routes/home.tsx");case"astro":return a.join(t,"src/pages/index.astro")}}function _t(e,t){switch(e){case"next":return a.join(t,"components/greet.tsx");case"vite":case"start":case"astro":return a.join(t,"src/components/greet.tsx");case"react-router":return a.join(t,"app/components/greet.tsx")}}async function Pt(e,t){t.includeStarterUI||await te(e,"input");const r=t.template==="react-router"?"~/":"@/";if(s.writeFileSync(_t(t.template,e),Et(r)),t.includeStarterUI)return;if(t.template==="astro"){s.writeFileSync(se(t.template,e),`---
|
|
406
401
|
import Layout from "@/layouts/main.astro"
|
|
407
402
|
import { Greet } from "@/components/greet"
|
|
408
403
|
---
|
|
@@ -441,7 +436,7 @@ main {
|
|
|
441
436
|
height: 100%;
|
|
442
437
|
}
|
|
443
438
|
`;function k(e,t){l(e,r=>r.includes("overscroll-behavior: none;")?r:`${r.trimEnd()}
|
|
444
|
-
${t}`)}function
|
|
439
|
+
${t}`)}function $(e,t,r){l(e,n=>{if(n.includes("<main>"))return n;const i=n.replace(t,r);if(i===n)throw new u(e,"Could not insert the scroll container <main> wrapper.");return i})}async function Lt(e,t){switch(t.template){case"next":k(a.join(e,"app/globals.css"),b),$(a.join(e,"app/layout.tsx"),/\{children\}/,"<main>{children}</main>");return;case"vite":k(a.join(e,"src/index.css"),`${b}${Dt}`),$(a.join(e,"src/main.tsx"),/<App \/>/,"<main><App /></main>");return;case"start":k(a.join(e,"src/styles.css"),b),$(a.join(e,"src/routes/__root.tsx"),/\{children\}/,"<main>{children}</main>");return;case"react-router":k(a.join(e,"app/app.css"),b),$(a.join(e,"app/root.tsx"),/return <Outlet \/>/,"return <main><Outlet /></main>");return;case"astro":k(a.join(e,"src/styles/global.css"),b),$(a.join(e,"src/layouts/main.astro"),/<slot \/>/,"<main><slot /></main>");return;default:throw new u(e,`No scroll container battery implementation exists for template "${t.template}".`)}}const E=`
|
|
445
440
|
@layer base {
|
|
446
441
|
body {
|
|
447
442
|
@apply select-none;
|
|
@@ -462,10 +457,10 @@ ${t}`)}function E(e,t,r){l(e,n=>{if(n.includes("<main>"))return n;const i=n.repl
|
|
|
462
457
|
}
|
|
463
458
|
}
|
|
464
459
|
`;function j(e,t){l(e,r=>r.includes(".ui-selectable")?r:`${r.trimEnd()}
|
|
465
|
-
${t}`)}async function Ct(e,t){switch(t.template){case"next":j(a.join(e,"app/globals.css")
|
|
460
|
+
${t}`)}async function Ct(e,t){switch(t.template){case"next":j(a.join(e,"app/globals.css"),E);return;case"vite":j(a.join(e,"src/index.css"),E);return;case"start":j(a.join(e,"src/styles.css"),E);return;case"react-router":j(a.join(e,"app/app.css"),E);return;case"astro":j(a.join(e,"src/styles/global.css"),E);return;default:throw new u(e,`No selection behavior battery implementation exists for template "${t.template}".`)}}function Tt(){const e=a.dirname(I(import.meta.url)),t=[a.resolve(e,"../assets"),a.resolve(e,"../../assets")];return t.find(r=>s.existsSync(r))??t[0]}const Gt=Tt();function Nt(e){const t=[];for(const r of e){if(r==="macos-latest"){t.push({name:"macOS Apple Silicon",platform:"macos-latest",args:"--target aarch64-apple-darwin"},{name:"macOS Intel",platform:"macos-latest",args:"--target x86_64-apple-darwin"});continue}if(r==="ubuntu-latest"){t.push({name:"Linux",platform:"ubuntu-22.04",args:""});continue}t.push({name:"Windows",platform:r,args:""})}return t.map(r=>` - name: "${r.name}"
|
|
466
461
|
platform: "${r.platform}"
|
|
467
462
|
args: "${r.args}"`).join(`
|
|
468
|
-
`)}async function At(e,t){const r=s.readFileSync(a.join(Gt,"release.yml.tmpl"),"utf-8").replace("{{PLATFORMS}}",Nt(t.targetOS)),n=a.join(e,".github/workflows");s.mkdirSync(n,{recursive:!0}),s.writeFileSync(a.join(n,"release.yml"),r)}const It=1400,Rt=918;async function Ot(e,t,r){Z(a.join(t,"src-tauri"),a.join(e,"src-tauri")),m(a.join(e,"package.json"),o=>(o.name=r.packageName,o.dependencies=o.dependencies||{},o.dependencies["@tauri-apps/api"]="^2",o.dependencies["@tauri-apps/plugin-opener"]="^2",o.devDependencies=o.devDependencies||{},o.devDependencies["@tauri-apps/cli"]="^2",o.scripts=o.scripts||{},o.scripts.tauri="tauri",o));const n=Pe(r.packageName),i=`${n}_lib`;l(a.join(e,"src-tauri/Cargo.toml"),o=>o.replace(/^name = "tauri-app"$/m,`name = "${n}"`).replace(/^name = "tauri_app_lib"$/m,`name = "${i}"`)),l(a.join(e,"src-tauri/src/main.rs"),o=>o.replace("tauri_app_lib::run()",`${i}::run()`))}async function Ft(e,t,r){m(a.join(e,"src-tauri/tauri.conf.json"),n=>{n.productName=t.projectName,n.identifier=t.identifier,n.build={...n.build,...r},n.app=n.app||{},n.app.windows=Array.isArray(n.app.windows)?n.app.windows:[{}];const i=n.app.windows[0]||{};return n.app.windows[0]={...i,title:t.projectName,center:!0,width:It,height:Rt},n})}const B=["vite","next","start","react-router","astro"],M=["windows-latest","macos-latest","ubuntu-latest"],ce="tauri-ui",le="b0",Ut={vite:"Vite",next:"Next.js",start:"TanStack Start","react-router":"React Router",astro:"Astro"};function p(e,t="Operation cancelled"){if(xe(e))throw new Error(t);return e}function Vt(e){if(B.includes(e))return e;throw new Error(`Unsupported template "${e}". Expected one of: ${B.join(", ")}`)}function ue(e){try{return`com.${J(z.userInfo().username)||"example"}.${e}`}catch{return`com.example.${e}`}}function G(e){return{placeholder:e,defaultValue:e}}async function Bt(e,t=process.cwd()){let r
|
|
463
|
+
`)}async function At(e,t){const r=s.readFileSync(a.join(Gt,"release.yml.tmpl"),"utf-8").replace("{{PLATFORMS}}",Nt(t.targetOS)),n=a.join(e,".github/workflows");s.mkdirSync(n,{recursive:!0}),s.writeFileSync(a.join(n,"release.yml"),r)}const It=1400,Rt=918;async function Ot(e,t,r){Z(a.join(t,"src-tauri"),a.join(e,"src-tauri")),m(a.join(e,"package.json"),o=>(o.name=r.packageName,o.dependencies=o.dependencies||{},o.dependencies["@tauri-apps/api"]="^2",o.dependencies["@tauri-apps/plugin-opener"]="^2",o.devDependencies=o.devDependencies||{},o.devDependencies["@tauri-apps/cli"]="^2",o.scripts=o.scripts||{},o.scripts.tauri="tauri",o));const n=Pe(r.packageName),i=`${n}_lib`;l(a.join(e,"src-tauri/Cargo.toml"),o=>o.replace(/^name = "tauri-app"$/m,`name = "${n}"`).replace(/^name = "tauri_app_lib"$/m,`name = "${i}"`)),l(a.join(e,"src-tauri/src/main.rs"),o=>o.replace("tauri_app_lib::run()",`${i}::run()`))}async function Ft(e,t,r){m(a.join(e,"src-tauri/tauri.conf.json"),n=>{n.productName=t.projectName,n.identifier=t.identifier,n.build={...n.build,...r},n.app=n.app||{},n.app.windows=Array.isArray(n.app.windows)?n.app.windows:[{}];const i=n.app.windows[0]||{};return n.app.windows[0]={...i,title:t.projectName,center:!0,width:It,height:Rt},n})}const B=["vite","next","start","react-router","astro"],M=["windows-latest","macos-latest","ubuntu-latest"],ce="tauri-ui",le="b0",Ut={vite:"Vite",next:"Next.js",start:"TanStack Start","react-router":"React Router",astro:"Astro"};function p(e,t="Operation cancelled"){if(xe(e))throw new Error(t);return e}function Vt(e){if(B.includes(e))return e;throw new Error(`Unsupported template "${e}". Expected one of: ${B.join(", ")}`)}function ue(e){try{return`com.${J(z.userInfo().username)||"example"}.${e}`}catch{return`com.example.${e}`}}function G(e){return{placeholder:e,defaultValue:e}}async function Bt(e,t=process.cwd()){let r=Ee(e.targetDir);if(r||(r=p(await _({message:"Project name",...G(ce)}))),r||(r=ce),r===".")throw new Error("Scaffolding into the current directory is not supported yet.");const n=a.resolve(t,r),i=a.basename(n),o=R(i)?i:J(i);if(s.existsSync(n)&&!je(n))if(e.force)s.rmSync(n,{recursive:!0,force:!0});else{if(e.yes)throw new Error(`Target directory "${r}" is not empty. Re-run with --force to overwrite it.`);if(!p(await P({message:`Target directory "${r}" is not empty. Remove it and continue?`,initialValue:!1})))throw new Error("Operation cancelled");s.rmSync(n,{recursive:!0,force:!0})}let c=o;R(i)||(e.yes?c=o:c=p(await _({message:"Package name",...G(o),validate(d){if(!d||!R(d))return"Enter a valid package.json name"}})));const N=e.template?Vt(e.template):e.yes?"vite":p(await we({message:"Frontend template",initialValue:"vite",options:B.map(d=>({value:d,label:Ut[d]}))})),de=e.identifier?e.identifier:e.yes?ue(c):p(await _({message:"App identifier",...G(ue(c))})),me=e.preset?e.preset:e.yes?le:p(await _({message:"shadcn preset",...G(le)})),fe=e.includeStarterUI??(e.yes?!0:p(await P({message:"Include starter UI?",initialValue:!0}))),ge=e.includeInvokeExample??(e.yes?!0:p(await P({message:"Include Rust invoke example?",initialValue:!0}))),H=e.includeWorkflow??(e.yes?!0:p(await P({message:"Include GitHub release workflow?",initialValue:!0}))),he=H?e.yes?[...M]:p(await ve({message:"Target operating systems",initialValues:[...M],required:!0,options:M.map(d=>({value:d,label:d}))})):[];return{projectName:i,packageName:c,template:N,identifier:de,preset:me,includeStarterUI:fe,includeInvokeExample:ge,includeWorkflow:H,targetOS:he,targetDir:n}}function Mt(){console.log(`Usage: create-tauri-ui [target-dir] [options]
|
|
469
464
|
|
|
470
465
|
Options:
|
|
471
466
|
-t, --template <name> vite | next | start | react-router | astro
|
|
@@ -480,4 +475,4 @@ Options:
|
|
|
480
475
|
-f, --force overwrite an existing target directory
|
|
481
476
|
-y, --yes accept defaults
|
|
482
477
|
-h, --help display help`)}function Ht(e){const t={},r=[],n=(i,o)=>{const c=e[i+1];if(!c||c.startsWith("-"))throw new Error(`Missing value for ${o}`);return c};for(let i=0;i<e.length;i+=1){const o=e[i];switch(o){case"-h":case"--help":t.help=!0;break;case"-t":case"--template":t.template=n(i,o),i+=1;break;case"--identifier":t.identifier=n(i,o),i+=1;break;case"--preset":t.preset=n(i,o),i+=1;break;case"--starter":t.includeStarterUI=!0;break;case"--no-starter":t.includeStarterUI=!1;break;case"--invoke-example":case"--example":t.includeInvokeExample=!0;break;case"--no-invoke-example":case"--no-example":t.includeInvokeExample=!1;break;case"--workflow":t.includeWorkflow=!0;break;case"--no-workflow":t.includeWorkflow=!1;break;case"-f":case"--force":t.force=!0;break;case"-y":case"--yes":t.yes=!0;break;default:if(o.startsWith("-"))throw new Error(`Unknown flag: ${o}`);r.push(o)}}if(r.length>1)throw new Error("Only one target directory may be provided.");return r[0]&&(t.targetDir=r[0]),t}function Wt(e){const t=a.relative(S.cwd(),e)||".";return t.includes(" ")?`"${t}"`:t}function Kt(e){s.rmSync(a.join(e,"node_modules"),{recursive:!0,force:!0})}function zt(e,t){const r=[`cd ${Wt(e)}`,"bun install","bun run tauri dev","bunx tauri icon app-icon.png"];K(r.join(`
|
|
483
|
-
`),"Next steps"),t&&K("Configure the GitHub release workflow secrets before publishing builds.","Release workflow")}async function Yt(){try{await C("bun",["--version"])}catch{throw new Error("bun is required. Install it from https://bun.sh.")}}function pe(e){return e instanceof w?{message:e.message,detail:e.stderr.trim()}:e instanceof Error?{message:e.message,detail:""}:{message:"An unknown error occurred.",detail:""}}async function Xt(){const e=Ht(S.argv.slice(2));if(e.help){Mt();return}ye(A.bold("create-tauri-ui")),await Yt();const t=await Bt(e);_e(),O(t.targetDir);const r=be();let n;try{r.start("Creating the shadcn frontend scaffold"),await We(t),r.message("Creating the Tauri native scaffold");const i=await Ke(t);n=i.tempDir,r.message("Merging the native layer into the frontend project"),await Ot(t.targetDir,i.projectDir,t);const o=Oe(t.template);r.message(`Patching the ${t.template} project for Tauri`);try{await o.apply(t.targetDir,t)}catch(c){if(c instanceof u)h.warn(`${c.message} (${c.file})`);else throw c}if(await Ft(t.targetDir,t,o.tauriConfig()),r.message("Applying the startup flash-prevention battery"),await yt(t.targetDir),r.message("Applying the desktop scroll container battery"),await Lt(t.targetDir,t),r.message("Applying the external link guard battery"),await vt(t.targetDir,t),r.message("Applying the development debug panel battery"),await lt(t.targetDir,t),r.message("Applying the desktop selection-behavior battery"),await Ct(t.targetDir,t),t.includeStarterUI){r.message("Installing the starter dashboard");try{await ze(t.targetDir,t)}catch(c){if(c instanceof w)h.warn(c.message),c.stderr.trim()&&h.message(c.stderr.trim());else throw c}}t.includeInvokeExample&&(r.message("Adding the Rust invoke example"),await Pt(t.targetDir,t)),t.includeWorkflow&&(r.message("Writing the GitHub release workflow"),await At(t.targetDir,t)),r.message("Copying the app icon source"),await
|
|
478
|
+
`),"Next steps"),t&&K("Configure the GitHub release workflow secrets before publishing builds.","Release workflow")}async function Yt(){try{await C("bun",["--version"])}catch{throw new Error("bun is required. Install it from https://bun.sh.")}}function pe(e){return e instanceof w?{message:e.message,detail:e.stderr.trim()}:e instanceof Error?{message:e.message,detail:""}:{message:"An unknown error occurred.",detail:""}}async function Xt(){const e=Ht(S.argv.slice(2));if(e.help){Mt();return}ye(A.bold("create-tauri-ui")),await Yt();const t=await Bt(e);_e(),O(t.targetDir);const r=be();let n;try{r.start("Creating the shadcn frontend scaffold"),await We(t),r.message("Creating the Tauri native scaffold");const i=await Ke(t);n=i.tempDir,r.message("Merging the native layer into the frontend project"),await Ot(t.targetDir,i.projectDir,t);const o=Oe(t.template);r.message(`Patching the ${t.template} project for Tauri`);try{await o.apply(t.targetDir,t)}catch(c){if(c instanceof u)h.warn(`${c.message} (${c.file})`);else throw c}if(await Ft(t.targetDir,t,o.tauriConfig()),r.message("Applying the startup flash-prevention battery"),await yt(t.targetDir),r.message("Applying the desktop scroll container battery"),await Lt(t.targetDir,t),r.message("Applying the external link guard battery"),await vt(t.targetDir,t),r.message("Applying the development debug panel battery"),await lt(t.targetDir,t),r.message("Applying the desktop selection-behavior battery"),await Ct(t.targetDir,t),t.includeStarterUI){r.message("Installing the starter dashboard");try{await ze(t.targetDir,t)}catch(c){if(c instanceof w)h.warn(c.message),c.stderr.trim()&&h.message(c.stderr.trim());else throw c}}t.includeInvokeExample&&(r.message("Adding the Rust invoke example"),await Pt(t.targetDir,t)),t.includeWorkflow&&(r.message("Writing the GitHub release workflow"),await At(t.targetDir,t)),r.message("Copying the app icon source"),await $t(t.targetDir),Kt(t.targetDir),f(t.targetDir),r.stop("Project ready"),zt(t.targetDir,t.includeWorkflow),ke(`Scaffolded ${A.cyan(t.projectName)} in ${A.dim(t.targetDir)}`)}catch(i){const o=pe(i);r.error("Scaffolding failed"),W(o.message),o.detail&&h.message(o.detail),S.exitCode=1}finally{if(n){f(n);try{g(n)}catch{}}}}Xt().catch(e=>{const t=pe(e);W(t.message),t.detail&&h.message(t.detail),S.exit(1)});
|