reacticx 0.1.6 → 0.1.7
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 +14 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as U}from"commander";import
|
|
3
|
-
\u274C Invalid ${
|
|
4
|
-
Example config:`)),console.log(v.dim(JSON.stringify({outDir:"src/shared/ui"},null,2))),process.exit(1)),t}async function
|
|
5
|
-
\u274C No component.config.json found`)),console.log(
|
|
6
|
-
Create one in your project root:`)),console.log(
|
|
7
|
-
Or use --dir flag:`)),console.log(
|
|
8
|
-
Available components:`));let
|
|
9
|
-
Files created:`)),x.forEach(
|
|
10
|
-
\u{1F4E6} Reacticx UI Components (v${
|
|
11
|
-
`)),console.log(
|
|
12
|
-
`));let
|
|
2
|
+
import{Command as U}from"commander";import d from"fs-extra";import p from"path";import s from"chalk";import L from"ora";var P="https://reacticx-ui-components.pages.dev";async function h(){let o=await fetch(`${P}/registry.json`);if(!o.ok)throw new Error("Failed to fetch registry");return o.json()}async function $(o,t){let n=o.replace(/^src\/components\//,""),f=`${P}/${n}/${t}`,a=await fetch(f);if(!a.ok)throw new Error(`Failed to fetch ${t}`);return a.text()}import y from"fs-extra";import O from"path";import v from"chalk";var D="component.config.json";async function F(){let o=O.join(process.cwd(),D);if(!await y.pathExists(o))return null;let t=await y.readJson(o);return t.outDir||(console.log(v.red(`
|
|
3
|
+
\u274C Invalid ${D}: missing "outDir" field`)),console.log(v.dim(`
|
|
4
|
+
Example config:`)),console.log(v.dim(JSON.stringify({outDir:"src/shared/ui"},null,2))),process.exit(1)),t}async function R(o){let t=O.join(process.cwd(),o);await y.pathExists(t)||await y.ensureDir(t)}async function b(o="src/shared/ui"){let t=O.join(process.cwd(),D),n={outDir:o};await y.writeJson(t,n,{spaces:2})}async function E(o,t){let n=await F();!n&&!t.dir&&(console.log(s.red(`
|
|
5
|
+
\u274C No component.config.json found`)),console.log(s.dim(`
|
|
6
|
+
Create one in your project root:`)),console.log(s.cyan(JSON.stringify({outDir:"src/shared/ui"},null,2))),console.log(s.dim(`
|
|
7
|
+
Or use --dir flag:`)),console.log(s.cyan(` npx reacticx add ${o} --dir src/components`)),process.exit(1));let f=t.dir||n.outDir,a=L(`Fetching ${o}...`).start();try{let l=await h(),c=l.components[o];if(!c){a.fail(s.red(`Component "${o}" not found`)),console.log(s.yellow(`
|
|
8
|
+
Available components:`));let e=Object.keys(l.components).sort().filter(r=>r.toLowerCase().includes(o.toLowerCase()));e.length>0?(console.log(s.dim("Did you mean:")),e.slice(0,5).forEach(r=>console.log(` - ${r}`))):console.log(s.dim('Run "npx reacticx list" to see all components')),process.exit(1)}a.text=`Adding ${o}...`,await R(f);let m=t.dir?p.join(process.cwd(),f):p.join(process.cwd(),f,c.category,o);if(!t.overwrite){let i=[];for(let e of c.files){let r=p.join(m,e);await d.pathExists(r)&&i.push(e)}if(c.folders)for(let e of c.folders)for(let r of e.files){let C=p.join(m,e.name,r);await d.pathExists(C)&&i.push(`${e.name}/${r}`)}i.length>0&&(a.warn(s.yellow(`${o} already exists. Use --overwrite to replace.`)),process.exit(1))}await d.ensureDir(m);let x=[];for(let i of c.files){let e=await $(c.path,i),r=p.join(m,i);await d.writeFile(r,e,"utf-8"),x.push(r)}if(c.folders&&c.folders.length>0)for(let i of c.folders){let e=p.join(m,i.name);await d.ensureDir(e);for(let r of i.files){let C=await $(c.path,`${i.name}/${r}`),j=p.join(m,i.name,r);await d.ensureDir(p.dirname(j)),await d.writeFile(j,C,"utf-8"),x.push(j)}}a.succeed(s.green(`Added ${o}!`)),console.log(s.dim(`
|
|
9
|
+
Files created:`)),x.forEach(i=>{let e=p.relative(process.cwd(),i);console.log(s.dim(` ${e}`))}),console.log()}catch(l){a.fail(s.red(`Failed to add ${o}`)),console.error(l),process.exit(1)}}import g from"chalk";import T from"ora";async function k(o){let t=T("Fetching components...").start();try{let n=await h();t.stop(),console.log(g.bold(`
|
|
10
|
+
\u{1F4E6} Reacticx UI Components (v${n.version})
|
|
11
|
+
`)),console.log(g.dim(`Total: ${n.totalComponents} components
|
|
12
|
+
`));let f={};for(let[a,l]of Object.entries(n.components))o.category&&l.category!==o.category||(f[l.category]||(f[l.category]=[]),f[l.category].push(a));for(let[a,l]of Object.entries(f).sort())console.log(g.cyan.bold(`${a}/`)),l.sort().forEach(c=>{console.log(g.white(` ${c}`))}),console.log();console.log(g.dim("Run `npx reacticx add <component>` to add a component\n"))}catch(n){t.fail(g.red("Failed to fetch components")),console.error(n),process.exit(1)}}import u from"chalk";import A from"prompts";import J from"fs-extra";import S from"path";async function I(){console.log(u.bold(`
|
|
13
13
|
\u{1F680} Initialize Reacticx
|
|
14
|
-
`));let o=S.join(process.cwd(),"component.config.json");if(await J.pathExists(o)){let{overwrite:
|
|
15
|
-
\u2705 Created component.config.json`)),console.log(
|
|
16
|
-
You can now run:`)),console.log(
|
|
14
|
+
`));let o=S.join(process.cwd(),"component.config.json");if(await J.pathExists(o)){let{overwrite:n}=await A({type:"confirm",name:"overwrite",message:"component.config.json already exists. Overwrite?",initial:!1});n||(console.log(u.yellow("Cancelled")),process.exit(0))}let t=await A([{type:"text",name:"outDir",message:"Where do you want to install components?",initial:"src/shared/ui"}]);t.outDir||(console.log(u.yellow("Cancelled")),process.exit(0)),await b(t.outDir),console.log(u.green(`
|
|
15
|
+
\u2705 Created component.config.json`)),console.log(u.dim(`
|
|
16
|
+
You can now run:`)),console.log(u.cyan(" npx reacticx add button")),console.log()}var w=new U;w.name("reacticx").description("Add beautiful React Native components to your project").version("0.1.0");w.command("init").description("Initialize reacticx in your project").action(I);w.command("list").description("List all available components").option("-c, --category <category>","Filter by category").action(k);w.command("add").description("Add a component to your project").argument("<component>","Component name to add").option("-o, --overwrite","Overwrite existing files",!1).option("-d, --dir <directory>","Target directory").action(E);w.parse();
|