@tailorkit/cli 0.1.0-beta.2 → 0.1.0-beta.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/dist/index.js +11 -12
- package/package.json +3 -12
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ data: `)}
|
|
|
55
55
|
// Do not make changes to this file directly, as it will be overwritten.
|
|
56
56
|
// Exclude this file from linting and formatting to avoid checking generated code.
|
|
57
57
|
|
|
58
|
-
import { createRemoteComponent } from "
|
|
58
|
+
import { createRemoteComponent } from "tailorkit/app";
|
|
59
59
|
`,Ii=`Record<string, never>`,Li=new Set([`Box`,`Flex`,`Grid`,`Inline`]),Z=e=>JSON.stringify(e),Ri=e=>/^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(e)?e:Z(e),zi=e=>typeof e==`string`?Z(e):typeof e==`number`||typeof e==`boolean`||e===null?JSON.stringify(e):`unknown`,Q=(e,t=0)=>{if(e===void 0)return`unknown`;if(Bi(e))return`never`;if(e.const!==void 0)return zi(e.const);if(e.enum!==void 0&&e.enum.length>0)return e.enum.map(zi).join(` | `);if(e.anyOf!==void 0&&e.anyOf.length>0){let n=e.anyOf.filter(e=>!Bi(e)).map(e=>Q(e,t)).filter(e=>e!==`never`);return n.length===0?`never`:[...new Set(n)].join(` | `)}let n=Array.isArray(e.type)?e.type[0]:e.type;return n===`string`?`string`:n===`number`||n===`integer`?`number`:n===`boolean`?`boolean`:n===`array`?`${Q(e.items,t)}[]`:n===`object`?Hi(e,t):`unknown`},Bi=e=>e.not!==void 0&&Object.keys(e.not).length===0,Vi=e=>{let t=e.properties??{},n=Object.values(t);return(Array.isArray(e.type)?e.type.includes(`object`):e.type===`object`)&&n.length>0&&n.every(Bi)},Hi=(e,t)=>{let n=e.properties??{},r=Object.entries(n);if(Vi(e))return`never`;if(r.length===0)return Ii;let i=new Set(e.required),a=` `.repeat(t),o=` `.repeat(t+2),s=[`{`];for(let[e,n]of r){let r=i.has(e)?``:`?`;s.push(`${o}${Ri(e)}${r}: ${Q(n,t+2)};`)}return s.push(`${a}}`),s.join(`
|
|
60
60
|
`)},Ui=e=>{let t=e.replaceAll(/[^A-Za-z0-9_$]/gu,`_`);return/^[A-Za-z_$]/u.test(t)?t:`_${t}`},Wi=e=>`${Ui(e)}Props`,Gi=e=>{let t=Ui(e);return`${t.charAt(0).toUpperCase()}${t.slice(1)}`},Ki=e=>{if(e.fields?.properties!==void 0)return e.fields.properties;let t={};for(let n of e.fieldKeys??[])t[n]={};return t},qi=(e,t)=>{if(e?.anyOf===void 0||e.anyOf.length!==2)return;let[n,r]=e.anyOf.filter(e=>!Bi(e));if(n===void 0||r===void 0)return;let i,a;if(n.type===`object`?(i=r,a=n):r.type===`object`&&(i=n,a=r),i===void 0||a===void 0)return;let o=Q(i,t);if(o===`never`)return`never`;let s=Object.values(a.properties??{});if(s.length!==0&&!s.map(e=>Q(e,t)).some(e=>e!==o&&e!==`never`))return`Responsive<${o}>`},Ji=(e,t)=>qi(e,t)??Q(e,t),Yi=e=>{let t={},n=new Map,r=new Set;for(let[i,a]of Object.entries(e))if(Li.has(i))for(let[e,i]of Object.entries(Ki(a))){let a=Gi(e),o=Ji(i,0),s=n.get(a);if(s===void 0){n.set(a,o),t[e]=a;continue}s!==o&&r.add(a)}return Object.fromEntries(Object.entries(t).filter(([,e])=>!r.has(e)))},Xi=(e,t)=>{let n=[`export type Breakpoint = "base" | "sm" | "md" | "lg" | "xl" | "2xl";`,`export type Responsive<TValue> = TValue | Partial<Record<Breakpoint, TValue>>;`],r=new Set;for(let[i,a]of Object.entries(e))if(Li.has(i))for(let[e,i]of Object.entries(Ki(a))){let a=t[e];a===void 0||r.has(a)||(r.add(a),n.push(`export type ${a} = ${Ji(i,0)};`))}return n.join(`
|
|
61
61
|
`)},Zi=e=>{let t=[`export interface ScreenPropsByPath {`];for(let[n,r]of Object.entries(e)){let e=Q(r.context,4).split(`
|
|
@@ -65,7 +65,7 @@ import { createRemoteComponent } from "@tailorkit/app";
|
|
|
65
65
|
`);i.push(`${r}${Ri(n)}: ${e[0]}`),i.push(...e.slice(1,-1)),i.push(`${e.at(-1)};`)}return i.push(`${n}}`),i.join(`
|
|
66
66
|
`)},ta=(e,t=[])=>{let n=[`{`];for(let[r,i]of Object.entries(e)){let e=[...t,r];if($i(i))n.push(` ${Ri(r)}: async (input: unknown) => {`),n.push(` const response = await fetch(${Z(`/api/tailorkit/actions/${e.join(`.`)}`)}, {`),n.push(` body: JSON.stringify(input),`),n.push(` headers: { "content-type": "application/json" },`),n.push(` method: "POST",`),n.push(` });`),n.push(` if (!response.ok) throw new Error(await response.text());`),n.push(` return response.json();`),n.push(` },`);else{let t=ta(i,e).split(`
|
|
67
67
|
`);n.push(` ${Ri(r)}: ${t[0]}`),n.push(...t.slice(1).map(e=>` ${e}`)),n.push(`,`)}}return n.push(`}`),n.join(`
|
|
68
|
-
`)},na=e=>{let t=ea(e.actions??{}),n=e.components??{},r=Yi(n),i=[Fi,Zi(e.screens??{}),`declare module "
|
|
68
|
+
`)},na=e=>{let t=ea(e.actions??{}),n=e.components??{},r=Yi(n),i=[Fi,Zi(e.screens??{}),`declare module "tailorkit/app" {
|
|
69
69
|
interface TailorKitScreens extends ScreenPropsByPath {}
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -93,14 +93,13 @@ export const actions = ${ta(e.actions??{})} as TailorKitActions;`,Xi(n,r)];for(l
|
|
|
93
93
|
"fix": "{{ fixScript }}"{% endif %}
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"
|
|
96
|
+
"tailorkit": "{{ tailorkitVersion }}",
|
|
97
97
|
"preact": "{{ preactVersion }}"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
|
-
"
|
|
100
|
+
"typescript": "{{ typescriptVersion }}"{% if linting %},
|
|
101
101
|
"oxlint": "{{ oxlintVersion }}"{% endif %}{% if formatting %},
|
|
102
|
-
"oxfmt": "{{ oxfmtVersion }}"{% endif %}
|
|
103
|
-
"typescript": "{{ typescriptVersion }}"
|
|
102
|
+
"oxfmt": "{{ oxfmtVersion }}"{% endif %}
|
|
104
103
|
},
|
|
105
104
|
"type": "module"
|
|
106
105
|
}
|
|
@@ -121,7 +120,7 @@ export const actions = ${ta(e.actions??{})} as TailorKitActions;`,Xi(n,r)];for(l
|
|
|
121
120
|
},
|
|
122
121
|
"include": ["src", "tailorkit.config.ts"]
|
|
123
122
|
}
|
|
124
|
-
`,ca=`import type { TailorKitConfig } from "
|
|
123
|
+
`,ca=`import type { TailorKitConfig } from "tailorkit/app/config";
|
|
125
124
|
|
|
126
125
|
const config = {
|
|
127
126
|
host: "{{ hostUrl }}",
|
|
@@ -174,7 +173,7 @@ export default defineConfig({
|
|
|
174
173
|
export default defineConfig({
|
|
175
174
|
ignorePatterns: ["src/tailorkit.gen.ts"],
|
|
176
175
|
});
|
|
177
|
-
`,fa=`import { defineClient } from "
|
|
176
|
+
`,fa=`import { defineClient } from "tailorkit/app";
|
|
178
177
|
import defaultScreen from "./screens/default";
|
|
179
178
|
|
|
180
179
|
const client = defineClient({
|
|
@@ -184,7 +183,7 @@ const client = defineClient({
|
|
|
184
183
|
});
|
|
185
184
|
|
|
186
185
|
export default client;
|
|
187
|
-
`,pa=`import { createScreen } from "
|
|
186
|
+
`,pa=`import { createScreen } from "tailorkit/app";
|
|
188
187
|
|
|
189
188
|
const screen = createScreen("/", {
|
|
190
189
|
component: ScreenComponent,
|
|
@@ -205,7 +204,7 @@ export default screen;
|
|
|
205
204
|
// Do not make changes to this file directly, as it will be overwritten.
|
|
206
205
|
// Exclude this file from linting and formatting to avoid checking generated code.
|
|
207
206
|
|
|
208
|
-
import { createRemoteComponent } from "
|
|
207
|
+
import { createRemoteComponent } from "tailorkit/app";
|
|
209
208
|
|
|
210
209
|
|
|
211
210
|
export interface ScreenPropsByPath {
|
|
@@ -218,7 +217,7 @@ export interface ScreenPropsByPath {
|
|
|
218
217
|
};
|
|
219
218
|
}
|
|
220
219
|
|
|
221
|
-
declare module "
|
|
220
|
+
declare module "tailorkit/app" {
|
|
222
221
|
interface TailorKitScreens extends ScreenPropsByPath {}
|
|
223
222
|
}
|
|
224
223
|
|
|
@@ -241,4 +240,4 @@ export interface CardProps {
|
|
|
241
240
|
export const Card = createRemoteComponent<CardProps, readonly ["header", "content", "footer"]>("Card", {
|
|
242
241
|
slots: ["header", "content", "footer"] as const,
|
|
243
242
|
});
|
|
244
|
-
`,ha=new oe({strictVariables:!0}),ga=(e,t)=>ha.parseAndRender(e,t),_a=e=>g(e,{recursive:!0}).then(()=>{}),va=async(e,t,n)=>{if(!n&&ne(e))throw Error(`${e} already exists. Use --force to overwrite it.`);await b(e,t,`utf-8`)},ya=async e=>{let{targetDirectory:t,force:n,formatting:r,hostUrl:i,linting:a,packageName:o,packageVersions:s,useWorkspaceDependencies:c}=e,l=c?`workspace:*`:s.tailorkitApp,u=c?`workspace:*`:s.tailorkitCLI,d=[],f=[];a&&(d.push(`pnpm run lint`),f.push(`pnpm run lint:fix`)),r&&(d.push(`pnpm run format`),f.push(`pnpm run format:fix`));let p={checkScript:d.join(` && `),fixScript:f.join(` && `),formatting:r,hostUrl:i,linting:a,oxfmtVersion:s.oxfmt,oxlintVersion:s.oxlint,packageName:o,preactVersion:s.preact,tailorkitAppVersion:l,tailorkitCLIVersion:u,typescriptVersion:s.typescript};await _a(C.join(t,`src`,`screens`));let m=[{template:oa,dest:`package.json`},{template:sa,dest:`tsconfig.json`},{template:ca,dest:`tailorkit.config.ts`},{template:la,dest:`.gitignore`},{template:ua,dest:`oxlint.config.ts`,condition:a},{template:da,dest:`oxfmt.config.ts`,condition:r},{template:fa,dest:C.join(`src`,`client.ts`)},{template:pa,dest:C.join(`src`,`screens`,`default.tsx`)},{template:ma,dest:C.join(`src`,`tailorkit.gen.ts`)}];await Promise.all(m.filter(e=>e.condition!==!1).map(async({template:e,dest:r})=>{let i=await ga(e,p);await va(C.join(t,r),i,n)}))},ba=`https://registry.npmjs.org`,xa=5e3,Sa={oxfmt:{fallback:`^0.46.0`,matcher:`^0`,packageName:`oxfmt`},oxlint:{fallback:`^1.61.0`,matcher:`^1`,packageName:`oxlint`},preact:{fallback:`^10.29.1`,matcher:`^10`,packageName:`preact`},tailorkitCLI:{fallback:`latest`,matcher:`^0`,packageName:`@tailorkit/cli`},tailorkitApp:{fallback:`latest`,matcher:`^0`,packageName:`@tailorkit/app`},typescript:{fallback:`^6.0.3`,matcher:`^6`,packageName:`typescript`}},Ca=e=>{let t=/^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$/u.exec(e);if(!t?.groups)return;let{major:n,minor:r,patch:i}=t.groups;if(!(!n||!r||!i))return{major:Number.parseInt(n,10),minor:Number.parseInt(r,10),patch:Number.parseInt(i,10),raw:e}},wa=(e,t)=>e.major===t.major?e.minor===t.minor?e.patch-t.patch:e.minor-t.minor:e.major-t.major,Ta=(e,t)=>{let n=/^\^(?<major>\d+)(?:\.(?<minor>\d+))?/u.exec(t);if(!n?.groups?.major)return!1;let r=Number.parseInt(n.groups.major,10),i=Number.parseInt(n.groups.minor??`0`,10);return e.major===r&&e.minor>=i},Ea=async({fallback:e,matcher:t,packageName:n})=>{try{let r=await fetch(`${ba}/${encodeURIComponent(n)}`,{signal:AbortSignal.timeout(xa)});if(!r.ok)return e;let i=await r.json(),a=Object.keys(i.versions??{}).map(Ca).filter(e=>e!==void 0).filter(e=>Ta(e,t)).toSorted(wa).at(-1);return a?`^${a.raw}`:e}catch{return e}},Da=async()=>{let[e,t,n,r,i,a]=await Promise.all([Ea(Sa.oxfmt),Ea(Sa.oxlint),Ea(Sa.preact),Ea(Sa.tailorkitCLI),Ea(Sa.tailorkitApp),Ea(Sa.typescript)]);return{oxfmt:e,oxlint:t,preact:n,tailorkitCLI:r,tailorkitApp:i,typescript:a}},Oa=[`pnpm`,`yarn`,`npm`,`bun`],ka=e=>Oa.includes(e),Aa=e=>e.trim().toLowerCase().replaceAll(/[^a-z0-9._/-]+/gu,`-`).replaceAll(/^-+|-+$/gu,``),ja=e=>(s(e)&&(i(`Init cancelled.`),process.exit(0)),e),Ma=(e,t)=>C.resolve(t,e??`.`),Na=async(e,t)=>{let n=Aa(C.basename(t))||`tailorkit-app`;return Aa(e===void 0?ja(await f({defaultValue:n,message:`Package name`,placeholder:n,validate:e=>Aa(e??``).length===0?`Enter a package name.`:void 0})):e)},Pa=async e=>{if(e!==void 0){if(ka(e))return e;throw Error(`--package-manager must be one of: ${Oa.join(`, `)}.`)}return ja(await u({initialValue:`pnpm`,message:`Package manager`,options:Oa.map(e=>({label:e,value:e}))}))},Fa=async e=>e===void 0?ja(await a({initialValue:!0,message:`Add linting with oxlint?`})):e,Ia=async e=>e===void 0?ja(await a({initialValue:!0,message:`Add formatting with oxfmt?`})):e,La=e=>{try{ti(e??``);return}catch{return`Enter a valid host URL.`}},Ra=async e=>{if(e!==void 0){let t=La(e);if(t!==void 0)throw Error(t);return ti(e)}let t=`https://example.com/api/tailorkit`;return ti(ja(await f({defaultValue:t,message:`Host URL`,placeholder:t,validate:La})))},za=async e=>e===void 0?ja(await a({initialValue:!0,message:`Install dependencies?`})):e,Ba=async(e,t)=>t||!ne(e)?t:ja(await a({initialValue:!1,message:`${m.cyan(e)} already exists. Overwrite matching files?`})),Va=(e,t,n)=>new Promise((r,i)=>{let a=ae(e,t,{cwd:n,stdio:`inherit`});a.on(`close`,r),a.on(`error`,i)}),Ha=async(e,t)=>{let n=d();n.start(`Installing dependencies with ${t}`);let r=await Va(t,[`install`],e);if(r!==0)throw n.stop(`Install failed.`),Error(`${t} install exited with code ${r}.`);n.stop(`Installed dependencies.`)},Ua=async(e,t)=>{let n=d();n.start(`Formatting project`);let r=await Va(t,[`run`,`format:fix`],e);if(r!==0)throw n.stop(`Formatting failed.`),Error(`${t} run format:fix exited with code ${r}.`);n.stop(`Formatted project.`)},Wa=async e=>{let t=Ma(e.directory,e.cwd),n=await Na(e.name,t),r=C.join(t,n),i=await Ba(r,e.force??!1),a=await Pa(e.packageManager),o=await Ra(e.host),s=await Fa(e.linting),c=await Ia(e.formatting),l=await za(e.install),u=d();u.start(`Resolving package versions`);let f=await Da();return u.stop(`Resolved package versions.`),await g(r,{recursive:!0}),await ya({force:i,formatting:c,hostUrl:o,linting:s,packageName:n,packageVersions:f,targetDirectory:r}),l&&(await Ha(r,a),c&&await Ua(r,a)),r},Ga={".css":`text/css; charset=utf-8`,".html":`text/html; charset=utf-8`,".js":`text/javascript; charset=utf-8`,".json":`application/json; charset=utf-8`,".map":`application/json; charset=utf-8`},Ka=e=>Ga[C.extname(e)]??`application/octet-stream`,qa=e=>{if(e===void 0)return;let t=Number.parseInt(String(e),10);if(!Number.isInteger(t)||t<=0)throw Error(`--port must be a positive integer.`);return t},Ja=e=>({configPath:e.config,cwd:String(e.cwd??`.`),entry:e.entry,host:e.host,mode:e.mode,outDir:e.outDir,port:qa(e.port)}),Ya=(e,t)=>T(async(n,r)=>{try{let i=new URL(n.url??`/`,`http://localhost`);if(i.pathname===`/apps`){r.writeHead(200,{"access-control-allow-origin":`*`,"content-type":`application/json; charset=utf-8`}),r.end(JSON.stringify(t));return}let a=decodeURIComponent(i.pathname),o=a===`/`?`client.js`:a.slice(1),s=C.resolve(e,o),c=C.relative(e,s);if(c.startsWith(`..`)||C.isAbsolute(c)){r.writeHead(403),r.end(`Forbidden`);return}if(!(await y(s).catch(()=>null))?.isFile()){r.writeHead(404),r.end(`Not found`);return}r.writeHead(200,{"access-control-allow-origin":`*`,"content-type":Ka(s)}),r.end(await _(s))}catch(e){r.writeHead(500),r.end(e instanceof Error?e.message:String(e))}}),Xa=async e=>{let t=C.join(e,`package.json`),n=JSON.parse(await _(t,`utf-8`)),r=typeof n.name==`string`?n.name:C.basename(e);return[{clientPath:`/client.js`,description:typeof n.description==`string`?n.description:void 0,id:r,name:typeof n.name==`string`?n.name:void 0}]},Za=async e=>{let t=await Me(e.configPath,e.cwd),n=C.resolve(t.root,e.outDir??t.config.build?.outDir??`.tailorkit`),r=e.host??`127.0.0.1`,i=e.port??4175,{buildApp:a}=await import(`./assets/builder-wgJqHM_A.js`),o=await a({configPath:e.configPath,cwd:e.cwd,entry:e.entry,mode:e.mode,outDir:e.outDir,watch:!0}),s=()=>{o&&typeof o==`object`&&`close`in o&&o.close()},l=Ya(n,await Xa(t.root));await new Promise((e,t)=>{l.once(`error`,t),l.listen(i,r,e)}),l.removeAllListeners(`error`),process.once(`SIGINT`,()=>{s(),l.close(),process.exit(0)}),process.once(`SIGTERM`,()=>{s(),l.close(),process.exit(0)}),c.info(m.green(`Experimental preview running at http://${r}:${i}`)),c.info(m.dim(`Serving built worker assets from ${n}`))},Qa=e=>{let t=S();return t===`darwin`?{args:[e],command:`open`}:t===`win32`?{args:[`/c`,`start`,``,e],command:`cmd`}:{args:[e],command:`xdg-open`}},$a=e=>new Promise(t=>{let{args:n,command:r}=Qa(e),i=ae(r,n,{detached:!0,stdio:`ignore`,windowsHide:!0});i.once(`error`,()=>{t(!1)}),i.once(`spawn`,()=>{i.unref(),t(!0)})}),$=p(`tailorkit`),eo=e=>{if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return`${n.toFixed(n>=10?1:2)} ${t[r]}`};$.option(`--cwd <path>`,`Working directory`,{default:`.`}),$.command(`login`,`Authenticate the TailorKit CLI with a host app`).option(`--config <path>`,`Path to tailorkit config`).option(`--open`,`Open the approval URL in the default browser`,{default:!0}).option(`--timeout <seconds>`,`Seconds to wait for approval`,{default:1800}).action(async e=>{o(m.bold(`TailorKit`));let t=d(),n=!1;try{let r=Number.parseInt(String(e.timeout??`1800`),10);if(!Number.isInteger(r)||r<=0)throw Error(`--timeout must be a positive integer.`);await _i({configPath:e.config,cwd:String(e.cwd??`.`),timeout:r*1e3},({expiresAt:r,hostUrl:i,userCode:a})=>{let o=fi(i,a);e.open!==!1&&$a(o),c.info(`Enter this code in the host app: ${m.bold(a)}`),c.info(`Approval URL: ${m.cyan(o)}`),c.info(`Code expires at ${r.toLocaleString()}.`),c.info(`Waiting for approval...`),t.start(`Checking approval status`),n=!0}),n&&t.stop(`Approved.`),l(`Authenticated successfully.`)}catch(e){n&&t.stop(`Approval failed.`),c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`logout`,`Remove stored TailorKit CLI credentials for a host app`).option(`--config <path>`,`Path to tailorkit config`).action(async e=>{o(m.bold(`TailorKit`));try{let t=await yi({configPath:e.config,cwd:String(e.cwd??`.`)});l(t.removed?`Logged out of ${m.cyan(t.hostUrl)}.`:`No stored credentials found for ${m.cyan(t.hostUrl)}.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`whoami`,`Show the current TailorKit CLI authentication scope`).option(`--config <path>`,`Path to tailorkit config`).action(async e=>{o(m.bold(`TailorKit`));try{let t=await vi({configPath:e.config,cwd:String(e.cwd??`.`)});c.info(`Host: ${m.cyan(t.hostUrl)}`),c.info(`Scope: ${m.cyan(t.scopeId)}`),l(`Authenticated.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`deploy`,`Build and deploy the TailorKit app`).option(`--config <path>`,`Path to tailorkit config`).option(`--entry <path>`,`Client entry file`).option(`--out-dir <path>`,`Build output directory`).option(`--mode <mode>`,`Vite mode`).action(async e=>{o(m.bold(`TailorKit`));let t=d();try{t.start(`Building and deploying app`);let n=await Pi({configPath:e.config,cwd:String(e.cwd??`.`),entry:e.entry,mode:e.mode,onMissingAppId:async({appName:e,configPath:n,hostUrl:r,reason:i})=>{t.stop(`App not linked.`),c.info(i===`missing`?`No appId found in ${m.cyan(n)}.`:`The appId in ${m.cyan(n)} does not exist.`),c.info(`Host: ${m.cyan(r)}`);let o=await a({initialValue:!0,message:i===`missing`?`Create a TailorKit app named ${e}?`:`Create a new TailorKit app named ${e} and update the config?`});return!s(o)&&(o&&t.start(`Creating app and deploying`),o)},onTypecheckFailed:async({command:e,output:n})=>{t.stop(`Type check failed.`),c.error(`Type check failed while running ${m.cyan(e)}.`),n&&c.error(n);let r=await a({initialValue:!1,message:`Type check failed, but the app built successfully. Upload anyway?`});return!s(r)&&(r&&t.start(`Uploading app`),r)},outDir:e.outDir});t.stop(`Deployed app.`),n.createdApp&&c.info(`Created app and updated tailorkit.config.ts with ${m.cyan(n.appId)}.`),c.info(`Host: ${m.cyan(n.hostUrl)}`),c.info(`App: ${m.cyan(n.appId)}`),c.info(`Deployment: ${m.cyan(n.deploymentId)}`),c.info(`Uploaded files:`);for(let e of n.uploadedFiles)c.info(` ${m.cyan(e.path)} ${m.dim(`${eo(e.size)} raw, ${eo(e.gzipSize)} gzip`)}`);n.status&&c.info(`Status: ${m.cyan(n.status)}`),l(`Deployment published.`)}catch(e){t.stop(`Deployment failed.`),c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`build`,`Build the TailorKit app`).option(`--config <path>`,`Path to tailorkit config`).option(`--entry <path>`,`Client entry file`).option(`--out-dir <path>`,`Build output directory`).option(`--mode <mode>`,`Vite mode`).action(async e=>{o(m.bold(`TailorKit`));try{let{buildApp:t}=await import(`./assets/builder-wgJqHM_A.js`);await t({configPath:e.config,cwd:String(e.cwd??`.`),entry:e.entry,mode:e.mode,outDir:e.outDir}),l(`Built app.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`experimental-preview`,`Build and preview the TailorKit worker`).option(`--config <path>`,`Path to tailorkit config`).option(`--entry <path>`,`Client entry file`).option(`--out-dir <path>`,`Build output directory`).option(`--host <host>`,`Preview host`).option(`--port <port>`,`Preview port`).option(`--mode <mode>`,`Vite mode`).action(async e=>{o(m.bold(`TailorKit`));try{await Za(Ja(e))}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`generate`,`Generate TailorKit app bindings`).option(`--config <path>`,`Path to tailorkit config`).option(`--out <path>`,`Generated TypeScript output file`).action(async e=>{o(m.bold(`TailorKit`));try{let t=await aa({configPath:e.config,cwd:String(e.cwd??`.`),outFile:e.out});l(`Generated ${m.cyan(t)}.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`init [directory]`,`Create a new TailorKit app`).option(`--name <name>`,`Package name`).option(`--host <url>`,`TailorKit host URL`).option(`--package-manager <pm>`,`Package manager: bun, yarn, pnpm, or npm`).option(`--lint`,`Add oxlint (use --no-lint to skip)`).option(`--format`,`Add oxfmt (use --no-format to skip)`).option(`--install`,`Install dependencies after scaffolding (use --no-install to skip)`).option(`--force`,`Overwrite existing files`).action(async(e,t)=>{o(m.bold(`TailorKit`));try{let n=await Wa({cwd:String(t.cwd??`.`),directory:e,force:t.force,formatting:t.format,host:t.host,install:t.install,linting:t.lint,name:t.name,packageManager:t.packageManager});l(`Created app at ${m.cyan(n)}.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.help(),$.version(`0.1.0-beta.2`),$.parse();export{Me as t};
|
|
243
|
+
`,ha=new oe({strictVariables:!0}),ga=(e,t)=>ha.parseAndRender(e,t),_a=e=>g(e,{recursive:!0}).then(()=>{}),va=async(e,t,n)=>{if(!n&&ne(e))throw Error(`${e} already exists. Use --force to overwrite it.`);await b(e,t,`utf-8`)},ya=async e=>{let{targetDirectory:t,force:n,formatting:r,hostUrl:i,linting:a,packageName:o,packageVersions:s,useWorkspaceDependencies:c}=e,l=c?`workspace:*`:s.tailorkit,u=[],d=[];a&&(u.push(`pnpm run lint`),d.push(`pnpm run lint:fix`)),r&&(u.push(`pnpm run format`),d.push(`pnpm run format:fix`));let f={checkScript:u.join(` && `),fixScript:d.join(` && `),formatting:r,hostUrl:i,linting:a,oxfmtVersion:s.oxfmt,oxlintVersion:s.oxlint,packageName:o,preactVersion:s.preact,tailorkitVersion:l,typescriptVersion:s.typescript};await _a(C.join(t,`src`,`screens`));let p=[{template:oa,dest:`package.json`},{template:sa,dest:`tsconfig.json`},{template:ca,dest:`tailorkit.config.ts`},{template:la,dest:`.gitignore`},{template:ua,dest:`oxlint.config.ts`,condition:a},{template:da,dest:`oxfmt.config.ts`,condition:r},{template:fa,dest:C.join(`src`,`client.ts`)},{template:pa,dest:C.join(`src`,`screens`,`default.tsx`)},{template:ma,dest:C.join(`src`,`tailorkit.gen.ts`)}];await Promise.all(p.filter(e=>e.condition!==!1).map(async({template:e,dest:r})=>{let i=await ga(e,f);await va(C.join(t,r),i,n)}))},ba=`https://registry.npmjs.org`,xa=5e3,Sa={oxfmt:{fallback:`^0.46.0`,matcher:`^0`,packageName:`oxfmt`},oxlint:{fallback:`^1.61.0`,matcher:`^1`,packageName:`oxlint`},preact:{fallback:`^10.29.1`,matcher:`^10`,packageName:`preact`},tailorkit:{fallback:`latest`,matcher:`^0`,packageName:`tailorkit`},typescript:{fallback:`^6.0.3`,matcher:`^6`,packageName:`typescript`}},Ca=e=>{let t=/^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$/u.exec(e);if(!t?.groups)return;let{major:n,minor:r,patch:i}=t.groups;if(!(!n||!r||!i))return{major:Number.parseInt(n,10),minor:Number.parseInt(r,10),patch:Number.parseInt(i,10),raw:e}},wa=(e,t)=>e.major===t.major?e.minor===t.minor?e.patch-t.patch:e.minor-t.minor:e.major-t.major,Ta=(e,t)=>{let n=/^\^(?<major>\d+)(?:\.(?<minor>\d+))?/u.exec(t);if(!n?.groups?.major)return!1;let r=Number.parseInt(n.groups.major,10),i=Number.parseInt(n.groups.minor??`0`,10);return e.major===r&&e.minor>=i},Ea=async({fallback:e,matcher:t,packageName:n})=>{try{let r=await fetch(`${ba}/${encodeURIComponent(n)}`,{signal:AbortSignal.timeout(xa)});if(!r.ok)return e;let i=await r.json(),a=Object.keys(i.versions??{}).map(Ca).filter(e=>e!==void 0).filter(e=>Ta(e,t)).toSorted(wa).at(-1);return a?`^${a.raw}`:e}catch{return e}},Da=async()=>{let[e,t,n,r,i]=await Promise.all([Ea(Sa.oxfmt),Ea(Sa.oxlint),Ea(Sa.preact),Ea(Sa.tailorkit),Ea(Sa.typescript)]);return{oxfmt:e,oxlint:t,preact:n,tailorkit:r,typescript:i}},Oa=[`pnpm`,`yarn`,`npm`,`bun`],ka=e=>Oa.includes(e),Aa=e=>e.trim().toLowerCase().replaceAll(/[^a-z0-9._/-]+/gu,`-`).replaceAll(/^-+|-+$/gu,``),ja=e=>(s(e)&&(i(`Init cancelled.`),process.exit(0)),e),Ma=(e,t)=>C.resolve(t,e??`.`),Na=async(e,t)=>{let n=Aa(C.basename(t))||`tailorkit-app`;return Aa(e===void 0?ja(await f({defaultValue:n,message:`Package name`,placeholder:n,validate:e=>Aa(e??``).length===0?`Enter a package name.`:void 0})):e)},Pa=async e=>{if(e!==void 0){if(ka(e))return e;throw Error(`--package-manager must be one of: ${Oa.join(`, `)}.`)}return ja(await u({initialValue:`pnpm`,message:`Package manager`,options:Oa.map(e=>({label:e,value:e}))}))},Fa=async e=>e===void 0?ja(await a({initialValue:!0,message:`Add linting with oxlint?`})):e,Ia=async e=>e===void 0?ja(await a({initialValue:!0,message:`Add formatting with oxfmt?`})):e,La=e=>{try{ti(e??``);return}catch{return`Enter a valid host URL.`}},Ra=async e=>{if(e!==void 0){let t=La(e);if(t!==void 0)throw Error(t);return ti(e)}let t=`https://example.com/api/tailorkit`;return ti(ja(await f({defaultValue:t,message:`Host URL`,placeholder:t,validate:La})))},za=async e=>e===void 0?ja(await a({initialValue:!0,message:`Install dependencies?`})):e,Ba=async(e,t)=>t||!ne(e)?t:ja(await a({initialValue:!1,message:`${m.cyan(e)} already exists. Overwrite matching files?`})),Va=(e,t,n)=>new Promise((r,i)=>{let a=ae(e,t,{cwd:n,stdio:`inherit`});a.on(`close`,r),a.on(`error`,i)}),Ha=async(e,t)=>{let n=d();n.start(`Installing dependencies with ${t}`);let r=await Va(t,[`install`],e);if(r!==0)throw n.stop(`Install failed.`),Error(`${t} install exited with code ${r}.`);n.stop(`Installed dependencies.`)},Ua=async(e,t)=>{let n=d();n.start(`Formatting project`);let r=await Va(t,[`run`,`format:fix`],e);if(r!==0)throw n.stop(`Formatting failed.`),Error(`${t} run format:fix exited with code ${r}.`);n.stop(`Formatted project.`)},Wa=async e=>{let t=Ma(e.directory,e.cwd),n=await Na(e.name,t),r=C.join(t,n),i=await Ba(r,e.force??!1),a=await Pa(e.packageManager),o=await Ra(e.host),s=await Fa(e.linting),c=await Ia(e.formatting),l=await za(e.install),u=d();u.start(`Resolving package versions`);let f=await Da();return u.stop(`Resolved package versions.`),await g(r,{recursive:!0}),await ya({force:i,formatting:c,hostUrl:o,linting:s,packageName:n,packageVersions:f,targetDirectory:r}),l&&(await Ha(r,a),c&&await Ua(r,a)),r},Ga={".css":`text/css; charset=utf-8`,".html":`text/html; charset=utf-8`,".js":`text/javascript; charset=utf-8`,".json":`application/json; charset=utf-8`,".map":`application/json; charset=utf-8`},Ka=e=>Ga[C.extname(e)]??`application/octet-stream`,qa=e=>{if(e===void 0)return;let t=Number.parseInt(String(e),10);if(!Number.isInteger(t)||t<=0)throw Error(`--port must be a positive integer.`);return t},Ja=e=>({configPath:e.config,cwd:String(e.cwd??`.`),entry:e.entry,host:e.host,mode:e.mode,outDir:e.outDir,port:qa(e.port)}),Ya=(e,t)=>T(async(n,r)=>{try{let i=new URL(n.url??`/`,`http://localhost`);if(i.pathname===`/apps`){r.writeHead(200,{"access-control-allow-origin":`*`,"content-type":`application/json; charset=utf-8`}),r.end(JSON.stringify(t));return}let a=decodeURIComponent(i.pathname),o=a===`/`?`client.js`:a.slice(1),s=C.resolve(e,o),c=C.relative(e,s);if(c.startsWith(`..`)||C.isAbsolute(c)){r.writeHead(403),r.end(`Forbidden`);return}if(!(await y(s).catch(()=>null))?.isFile()){r.writeHead(404),r.end(`Not found`);return}r.writeHead(200,{"access-control-allow-origin":`*`,"content-type":Ka(s)}),r.end(await _(s))}catch(e){r.writeHead(500),r.end(e instanceof Error?e.message:String(e))}}),Xa=async e=>{let t=C.join(e,`package.json`),n=JSON.parse(await _(t,`utf-8`)),r=typeof n.name==`string`?n.name:C.basename(e);return[{clientPath:`/client.js`,description:typeof n.description==`string`?n.description:void 0,id:r,name:typeof n.name==`string`?n.name:void 0}]},Za=async e=>{let t=await Me(e.configPath,e.cwd),n=C.resolve(t.root,e.outDir??t.config.build?.outDir??`.tailorkit`),r=e.host??`127.0.0.1`,i=e.port??4175,{buildApp:a}=await import(`./assets/builder-wgJqHM_A.js`),o=await a({configPath:e.configPath,cwd:e.cwd,entry:e.entry,mode:e.mode,outDir:e.outDir,watch:!0}),s=()=>{o&&typeof o==`object`&&`close`in o&&o.close()},l=Ya(n,await Xa(t.root));await new Promise((e,t)=>{l.once(`error`,t),l.listen(i,r,e)}),l.removeAllListeners(`error`),process.once(`SIGINT`,()=>{s(),l.close(),process.exit(0)}),process.once(`SIGTERM`,()=>{s(),l.close(),process.exit(0)}),c.info(m.green(`Experimental preview running at http://${r}:${i}`)),c.info(m.dim(`Serving built worker assets from ${n}`))},Qa=e=>{let t=S();return t===`darwin`?{args:[e],command:`open`}:t===`win32`?{args:[`/c`,`start`,``,e],command:`cmd`}:{args:[e],command:`xdg-open`}},$a=e=>new Promise(t=>{let{args:n,command:r}=Qa(e),i=ae(r,n,{detached:!0,stdio:`ignore`,windowsHide:!0});i.once(`error`,()=>{t(!1)}),i.once(`spawn`,()=>{i.unref(),t(!0)})}),$=p(`tailorkit`),eo=e=>{if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return`${n.toFixed(n>=10?1:2)} ${t[r]}`};$.option(`--cwd <path>`,`Working directory`,{default:`.`}),$.command(`login`,`Authenticate the TailorKit CLI with a host app`).option(`--config <path>`,`Path to tailorkit config`).option(`--open`,`Open the approval URL in the default browser`,{default:!0}).option(`--timeout <seconds>`,`Seconds to wait for approval`,{default:1800}).action(async e=>{o(m.bold(`TailorKit`));let t=d(),n=!1;try{let r=Number.parseInt(String(e.timeout??`1800`),10);if(!Number.isInteger(r)||r<=0)throw Error(`--timeout must be a positive integer.`);await _i({configPath:e.config,cwd:String(e.cwd??`.`),timeout:r*1e3},({expiresAt:r,hostUrl:i,userCode:a})=>{let o=fi(i,a);e.open!==!1&&$a(o),c.info(`Enter this code in the host app: ${m.bold(a)}`),c.info(`Approval URL: ${m.cyan(o)}`),c.info(`Code expires at ${r.toLocaleString()}.`),c.info(`Waiting for approval...`),t.start(`Checking approval status`),n=!0}),n&&t.stop(`Approved.`),l(`Authenticated successfully.`)}catch(e){n&&t.stop(`Approval failed.`),c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`logout`,`Remove stored TailorKit CLI credentials for a host app`).option(`--config <path>`,`Path to tailorkit config`).action(async e=>{o(m.bold(`TailorKit`));try{let t=await yi({configPath:e.config,cwd:String(e.cwd??`.`)});l(t.removed?`Logged out of ${m.cyan(t.hostUrl)}.`:`No stored credentials found for ${m.cyan(t.hostUrl)}.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`whoami`,`Show the current TailorKit CLI authentication scope`).option(`--config <path>`,`Path to tailorkit config`).action(async e=>{o(m.bold(`TailorKit`));try{let t=await vi({configPath:e.config,cwd:String(e.cwd??`.`)});c.info(`Host: ${m.cyan(t.hostUrl)}`),c.info(`Scope: ${m.cyan(t.scopeId)}`),l(`Authenticated.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`deploy`,`Build and deploy the TailorKit app`).option(`--config <path>`,`Path to tailorkit config`).option(`--entry <path>`,`Client entry file`).option(`--out-dir <path>`,`Build output directory`).option(`--mode <mode>`,`Vite mode`).action(async e=>{o(m.bold(`TailorKit`));let t=d();try{t.start(`Building and deploying app`);let n=await Pi({configPath:e.config,cwd:String(e.cwd??`.`),entry:e.entry,mode:e.mode,onMissingAppId:async({appName:e,configPath:n,hostUrl:r,reason:i})=>{t.stop(`App not linked.`),c.info(i===`missing`?`No appId found in ${m.cyan(n)}.`:`The appId in ${m.cyan(n)} does not exist.`),c.info(`Host: ${m.cyan(r)}`);let o=await a({initialValue:!0,message:i===`missing`?`Create a TailorKit app named ${e}?`:`Create a new TailorKit app named ${e} and update the config?`});return!s(o)&&(o&&t.start(`Creating app and deploying`),o)},onTypecheckFailed:async({command:e,output:n})=>{t.stop(`Type check failed.`),c.error(`Type check failed while running ${m.cyan(e)}.`),n&&c.error(n);let r=await a({initialValue:!1,message:`Type check failed, but the app built successfully. Upload anyway?`});return!s(r)&&(r&&t.start(`Uploading app`),r)},outDir:e.outDir});t.stop(`Deployed app.`),n.createdApp&&c.info(`Created app and updated tailorkit.config.ts with ${m.cyan(n.appId)}.`),c.info(`Host: ${m.cyan(n.hostUrl)}`),c.info(`App: ${m.cyan(n.appId)}`),c.info(`Deployment: ${m.cyan(n.deploymentId)}`),c.info(`Uploaded files:`);for(let e of n.uploadedFiles)c.info(` ${m.cyan(e.path)} ${m.dim(`${eo(e.size)} raw, ${eo(e.gzipSize)} gzip`)}`);n.status&&c.info(`Status: ${m.cyan(n.status)}`),l(`Deployment published.`)}catch(e){t.stop(`Deployment failed.`),c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`build`,`Build the TailorKit app`).option(`--config <path>`,`Path to tailorkit config`).option(`--entry <path>`,`Client entry file`).option(`--out-dir <path>`,`Build output directory`).option(`--mode <mode>`,`Vite mode`).action(async e=>{o(m.bold(`TailorKit`));try{let{buildApp:t}=await import(`./assets/builder-wgJqHM_A.js`);await t({configPath:e.config,cwd:String(e.cwd??`.`),entry:e.entry,mode:e.mode,outDir:e.outDir}),l(`Built app.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`experimental-preview`,`Build and preview the TailorKit worker`).option(`--config <path>`,`Path to tailorkit config`).option(`--entry <path>`,`Client entry file`).option(`--out-dir <path>`,`Build output directory`).option(`--host <host>`,`Preview host`).option(`--port <port>`,`Preview port`).option(`--mode <mode>`,`Vite mode`).action(async e=>{o(m.bold(`TailorKit`));try{await Za(Ja(e))}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`generate`,`Generate TailorKit app bindings`).option(`--config <path>`,`Path to tailorkit config`).option(`--out <path>`,`Generated TypeScript output file`).action(async e=>{o(m.bold(`TailorKit`));try{let t=await aa({configPath:e.config,cwd:String(e.cwd??`.`),outFile:e.out});l(`Generated ${m.cyan(t)}.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.command(`init [directory]`,`Create a new TailorKit app`).option(`--name <name>`,`Package name`).option(`--host <url>`,`TailorKit host URL`).option(`--package-manager <pm>`,`Package manager: bun, yarn, pnpm, or npm`).option(`--lint`,`Add oxlint (use --no-lint to skip)`).option(`--format`,`Add oxfmt (use --no-format to skip)`).option(`--install`,`Install dependencies after scaffolding (use --no-install to skip)`).option(`--force`,`Overwrite existing files`).action(async(e,t)=>{o(m.bold(`TailorKit`));try{let n=await Wa({cwd:String(t.cwd??`.`),directory:e,force:t.force,formatting:t.format,host:t.host,install:t.install,linting:t.lint,name:t.name,packageManager:t.packageManager});l(`Created app at ${m.cyan(n)}.`)}catch(e){c.error(e instanceof Error?e.message:String(e)),process.exit(1)}}),$.help(),$.version(`0.1.0-beta.4`),$.parse();export{Me as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailorkit/cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,15 +15,6 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"type": "module",
|
|
18
|
-
"imports": {
|
|
19
|
-
"#*": [
|
|
20
|
-
"./src/*",
|
|
21
|
-
"./src/*.ts",
|
|
22
|
-
"./src/*.tsx",
|
|
23
|
-
"./src/*/index.ts",
|
|
24
|
-
"./src/*/index.tsx"
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
18
|
"exports": {
|
|
28
19
|
".": "./dist/index.js"
|
|
29
20
|
},
|
|
@@ -32,8 +23,8 @@
|
|
|
32
23
|
},
|
|
33
24
|
"dependencies": {
|
|
34
25
|
"@clack/prompts": "^1.7.0",
|
|
35
|
-
"@tailorkit/app": "0.1.0-beta.
|
|
36
|
-
"@tailorkit/core": "0.1.0-beta.
|
|
26
|
+
"@tailorkit/app": "0.1.0-beta.4",
|
|
27
|
+
"@tailorkit/core": "0.1.0-beta.4",
|
|
37
28
|
"cac": "^7.0.0",
|
|
38
29
|
"liquidjs": "^10.29.0",
|
|
39
30
|
"picocolors": "^1.1.1",
|