UNPKG

@stencil/react-output-target

Version:

React output target for @stencil/core components.

19 lines (17 loc) 4.75 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("node:fs/promises"),s=require("node:path");async function j(t){try{return await d.access(t),!0}catch{return!1}}async function x(t,c,f,u){await d.mkdir(s.join(t,"src"),{recursive:!0});const m={name:c,version:"0.0.1",type:"module",main:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},scripts:{build:"tsc",dev:"tsc --watch"},peerDependencies:{react:"^18 || ^19","react-dom":"^18 || ^19"},dependencies:{[f]:u},devDependencies:{typescript:">=4 <7"}},y={compilerOptions:{target:"ES2022",module:"esnext",moduleResolution:"bundler",declaration:!0,rootDir:"src",outDir:"dist",strict:!0,skipLibCheck:!0},include:["src/**/*.ts","src/**/*.tsx"]};await Promise.all([d.writeFile(s.join(t,".gitignore"),`dist/ node_modules/ `,"utf8"),d.writeFile(s.join(t,"package.json"),JSON.stringify(m,null,2)+` `,"utf8"),d.writeFile(s.join(t,"tsconfig.json"),JSON.stringify(y,null,2)+` `,"utf8"),d.writeFile(s.join(t,"src","index.ts"),`// Re-exports React wrappers generated by @stencil/react-output-target. // src/components.ts is populated by \`stencil build\` — do not edit manually. export * from './components.js'; `,"utf8")])}const D={init:{id:"@stencil/react-output-target",displayName:"React",description:"Type-safe React wrappers for your Stencil components",async run({config:t,workspaceRoot:c,prompts:f,nypm:u,openStencilConfig:m}){const{intro:y,outro:T,text:w,confirm:h,spinner:v,isCancel:p,cancel:l,log:o}=f;y("React output target");const r=await m();if(r.outputTargetsContains("reactOutputTarget(")){const e=await h({message:"reactOutputTarget is already in stencil.config.ts — reconfigure?",initialValue:!1});if(p(e)||!e){l("Skipping React setup.");return}}let n,i=`${t.fsNamespace}-react`;if(c){const e=await w({message:"Wrapper package name?",placeholder:i,defaultValue:i});if(p(e)){l("Setup cancelled.");return}i=e,n=s.join(s.dirname(t.rootDir),"react")}else{const e=`../${t.fsNamespace}-react`,a=await w({message:"Wrapper package directory? (relative to stencil.config.ts)",placeholder:e,defaultValue:e});if(p(a)){l("Setup cancelled.");return}n=s.join(t.rootDir,a)}const k=s.relative(t.rootDir,s.join(n,"src")).replace(/\\/g,"/"),g=await h({message:"Enable server-side rendering (SSR)?",initialValue:!1});if(p(g)){l("Setup cancelled.");return}if(g&&!c){const e=await w({message:"React wrapper npm package name? (used as clientModule in the SSR config)",placeholder:i,defaultValue:i});if(p(e)){l("Setup cancelled.");return}i=e}const C=!await j(n);if(C){const e=v();e.start(`Scaffolding wrapper package at ${s.relative(c??t.rootDir,n)}`);try{const a=c?await u.detectPackageManager(c):void 0,O=(a==null?void 0:a.name)==="pnpm"||(a==null?void 0:a.name)==="bun"||(a==null?void 0:a.name)==="yarn"&&a.majorVersion!=="1"?"workspace:*":`file:${s.relative(n,t.rootDir).replace(/\\/g,"/")}`;await x(n,i,t.fsNamespace,O),e.stop("Wrapper package scaffolded")}catch(a){e.stop("Scaffolding failed — continuing"),o.warn(`Could not scaffold wrapper package: ${a}`)}}const S=g?`reactOutputTarget({ outDir: '${k}', hydrateModule: '${t.fsNamespace}/dist/ssr', clientModule: '${i}', })`:`reactOutputTarget({ outDir: '${k}' })`;try{r.addImport("@stencil/react-output-target",["reactOutputTarget"]),r.outputTargetsContains("type: 'standalone'")||r.outputTargetsContains('type: "standalone"')||r.outputTargetsContains("type: 'dist-custom-elements'")||r.outputTargetsContains('type: "dist-custom-elements"')||r.addOutputTarget("{ type: 'standalone' }"),g&&(r.outputTargetsContains("type: 'ssr'")||r.outputTargetsContains('type: "ssr"')||r.outputTargetsContains("type: 'dist-hydrate-script'")||r.outputTargetsContains('type: "dist-hydrate-script"')||r.addOutputTarget("{ type: 'ssr' }")),r.replaceOutputTarget("reactOutputTarget(",S)||r.addOutputTarget(S),await r.save(),o.success("stencil.config.ts updated")}catch(e){o.warn(`Could not automatically update stencil.config.ts (${e}). Add manually: import { reactOutputTarget } from '@stencil/react-output-target'; // in outputTargets: ${S}`+(g?` { type: 'ssr' }`:""))}o.info("Installing @stencil/react-output-target..."),await u.addDependency(["@stencil/react-output-target"],{cwd:t.rootDir,dev:!0}),o.success("Installed @stencil/react-output-target"),C&&await j(n)&&(o.info("Installing React peer dependencies in wrapper package..."),await u.addDependency(["@stencil/react-output-target"],{cwd:n,dev:!0}),await u.addDependency(["react","react-dom","@types/react","@types/react-dom","typescript"],{cwd:n,dev:!0}),o.success("React peer dependencies installed")),T("React output target configured")}}};exports.wizard=D; //# sourceMappingURL=wizard.cjs.map