@iconia/react 0.1.0-dev.f643e57 → 0.1.0-dev.fa4b45b
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/cli/index.js +14 -12
- package/dist/index.d.ts +1 -1
- package/package.json +4 -4
package/dist/cli/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as
|
|
2
|
+
import{Command as Wo}from"commander";import{Command as jo}from"commander";import X from"fs";import Fo from"path";import z from"picocolors";var Uo=`import type { IconiaConfig } from '@iconia/react';
|
|
3
3
|
|
|
4
4
|
const config: IconiaConfig = {
|
|
5
5
|
apiKey: process.env.ICONIA_API_KEY ?? '',
|
|
@@ -7,18 +7,20 @@ const config: IconiaConfig = {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export default config;
|
|
10
|
-
`,
|
|
11
|
-
Next steps:`),console.log(` 1. Set ${
|
|
12
|
-
Import icons: ${
|
|
10
|
+
`,N=new jo("init").description("Create an iconia.config.ts file in the current directory").action(()=>{let o=Fo.resolve(process.cwd(),"iconia.config.ts");if(X.existsSync(o)){console.log(z.yellow("iconia.config.ts already exists. Skipping."));return}X.writeFileSync(o,Uo),console.log(z.green("✓ Created iconia.config.ts")),console.log(`
|
|
11
|
+
Next steps:`),console.log(` 1. Set ${z.cyan("ICONIA_API_KEY")} in your environment`),console.log(` 2. Edit ${z.cyan("iconia.config.ts")} to add your collections`),console.log(` 3. Run ${z.cyan("npx iconia pull")} to fetch icons`),console.log(`
|
|
12
|
+
Import icons: ${z.cyan("import { MyIcon } from '@iconia/react/my-collection'")}`)});import{Command as Po}from"commander";import P from"picocolors";import zo from"ora";import{z as H}from"zod";import D from"path";var uo=H.object({apiKey:H.string().min(1,"apiKey is required"),collections:H.array(H.string()).default([])}),Lo="https://api.iconia.io";async function u(){let o=D.resolve(process.cwd(),"iconia.config.ts"),i=D.resolve(process.cwd(),"iconia.config.js"),r;try{let t=await import(o);r=t.default??t}catch{try{let t=await import(i);r=t.default??t}catch{throw Error("Could not find iconia.config.ts or iconia.config.js\nRun `npx @iconia/react init` to create one.")}}let n=uo.safeParse(r);if(!n.success){let t=n.error.issues.map((c)=>` - ${c.path.join(".")}: ${c.message}`).join(`
|
|
13
13
|
`);throw Error(`Invalid iconia config:
|
|
14
|
-
${
|
|
15
|
-
|
|
16
|
-
`)}function B(){
|
|
17
|
-
|
|
14
|
+
${t}`)}return{...n.data,apiUrl:Lo}}function M(o){return{Authorization:`ApiKey ${o.apiKey}`,"Content-Type":"application/json"}}async function B(o,i=3){for(let r=0;r<=i;r++){let n=await o();if(n.status!==429||r===i)return n;let t=parseInt(n.headers.get("Retry-After")??"60",10);process.stderr.write(`
|
|
15
|
+
⏳ Rate limited — waiting ${t}s before retry ${r+1}/${i}...
|
|
16
|
+
`),await new Promise((c)=>setTimeout(c,t*1000))}return o()}async function l(o){let i=await B(()=>fetch(new URL("/v1/collections",o.apiUrl).toString(),{headers:M(o)}));if(!i.ok){let n=await i.json().catch(()=>({}));throw Error(`API error ${i.status}: ${n.error??i.statusText}`)}return(await i.json()).collections}async function J(o,i){let r=new URL("/v1/collections/icons",o.apiUrl);r.searchParams.set("collections",i.join(","));let n=await B(()=>fetch(r.toString(),{headers:M(o)}));if(!n.ok){let c=await n.json().catch(()=>({}));throw Error(`API error ${n.status}: ${c.error??n.statusText}`)}return(await n.json()).icons}async function x(o,i){let r=await B(()=>fetch(new URL("/v1/icons",o.apiUrl).toString(),{method:"POST",headers:M(o),body:JSON.stringify(i)}));if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??r.statusText)}return(await r.json()).icon}import C from"fs";import V from"path";import{fileURLToPath as Ko}from"url";import _o from"picocolors";import{optimize as Co}from"svgo";function Eo(o){return Co(o,{plugins:["removeDoctype","removeXMLProcInst","removeComments","removeMetadata","removeTitle","removeDesc"]}).data.replace(/<svg([^>]*)>/i,(r,n)=>`<svg${n.replace(/\s+(width|height)=['"][^'"]*['"]/gi,"")}>`)}function g(o){let i={},r=/([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,n;while((n=r.exec(o))!==null){let t=n[1].replace(/^xlink:/,"").replace(/-([a-z])/g,(c,a)=>a.toUpperCase());i[t]=n[2]??n[3]??""}return i}function oo(o){let i=[],r=0;while(r<o.length){let n=o.indexOf("<",r);if(n===-1)break;let t=o[n+1];if(t==="/"||t==="!"||t==="?"){let I=o.indexOf(">",n);r=I===-1?o.length:I+1;continue}let c=n+1,a=!1,m="";while(c<o.length){let I=o[c];if(a){if(I===m)a=!1}else if(I==='"'||I==="'")a=!0,m=I;else if(I===">")break;c++}if(c>=o.length)break;let e=o.slice(n+1,c),f=e.trimEnd().endsWith("/"),w=f?e.slice(0,e.lastIndexOf("/")).trim():e.trim(),y=w.search(/\s/),$=y===-1?w:w.slice(0,y);if(!$){r=c+1;continue}let F=y===-1?"":w.slice(y+1),_=g(F);if(r=c+1,f)i.push([$,_]);else{let I=`<${$}`,O=`</${$}>`,R=1,j=r;while(R>0&&j<o.length){let U=o.indexOf(I,j),d=o.indexOf(O,j);if(d===-1)break;if(U!==-1&&U<d)R++,j=U+I.length;else if(R--,R===0){let so=o.slice(r,d),G=oo(so),Ro=G.length>0?[$,_,G]:[$,_];i.push(Ro),r=d+O.length}else j=d+O.length}if(R>0)i.push([$,_])}}return i}function io(o){let i=Eo(o),r=i.match(/<svg([^>]*)>/i),n=g(r?.[1]??"");delete n.xmlns,delete n.xmlnsXlink;let{viewBox:t}=n,c=t?{viewBox:t}:{},m=i.match(/<svg[^>]*>([\s\S]*)<\/svg>/i)?.[1]?.trim()??"";return{iconNode:oo(m),svgAttrs:c}}function b(o){return o.replace(/[-_\s]+(.)/g,(i,r)=>r.toUpperCase()).replace(/^(.)/,(i,r)=>r.toUpperCase())}function ro(o){if(o.length===0)return"";let i=["import { forwardRef, createElement } from 'react';","","const _r = (n) => n.map(([t, a, c], i) => createElement(t, { key: i, ...a }, ...(c ? _r(c) : [])));",""];for(let{name:r,iconNode:n,svgAttrs:t}of o){let c=b(r),a={viewBox:"0 0 24 24",...t},m=JSON.stringify(n),e=JSON.stringify(a);i.push(`export const ${c} = /*#__PURE__*/forwardRef(({ children, ...props }, ref) =>`,` createElement('svg', { ref, xmlns: 'http://www.w3.org/2000/svg', ...${e}, ...props },`,` ..._r(${m}),`," children"," )",");",`${c}.displayName = '${c}';`,"")}return i.join(`
|
|
17
|
+
`)}function no(o){let i=["import type { ForwardRefExoticComponent, SVGProps, RefAttributes } from 'react';","","type IconComponent = ForwardRefExoticComponent<SVGProps<SVGSVGElement> & RefAttributes<SVGSVGElement>>;",""];for(let r of o)i.push(`export declare const ${b(r)}: IconComponent;`);return i.push(""),i.join(`
|
|
18
|
+
`)}function T(){return V.resolve(V.dirname(Ko(import.meta.url)),"..")}function q(o,i){let r=[];for(let t of i)try{let{iconNode:c,svgAttrs:a}=io(t.svgContent);r.push({name:t.name,iconNode:c,svgAttrs:a})}catch(c){console.warn(_o.yellow(` ⚠ Skipped ${t.name}: ${c.message}`))}if(r.length===0)return 0;let n=T();return C.writeFileSync(V.join(n,`${o}.js`),ro(r),"utf-8"),C.writeFileSync(V.join(n,`${o}.d.ts`),no(r.map((t)=>t.name)),"utf-8"),r.length}function h(){let o=V.join(T(),"..","package.json");try{let i=JSON.parse(C.readFileSync(o,"utf-8")),r=i.exports??{};if(r["./*"]?.import?.startsWith("./dist/"))return;i.exports={".":r["."]??{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"},"./*":{import:"./dist/*.js",types:"./dist/*.d.ts"}},C.writeFileSync(o,JSON.stringify(i,null,2)+`
|
|
19
|
+
`,"utf-8")}catch{}}function to(o){let i=T(),r=V.join(i,`${o}.js`),n=V.join(i,`${o}.d.ts`);if(C.existsSync(r))C.unlinkSync(r);if(C.existsSync(n))C.unlinkSync(n)}import co from"fs";import Oo from"path";var Vo=".iconia-lock.json";function fo(){return Oo.resolve(process.cwd(),Vo)}function E(){try{let o=co.readFileSync(fo(),"utf-8");return JSON.parse(o)}catch{return{version:1,collections:{}}}}function K(o){co.writeFileSync(fo(),JSON.stringify(o,null,2),"utf-8")}function v(o,i,r){return{...o,collections:{...o.collections,[i]:{icons:Object.fromEntries(r.map((n)=>[n.slug,n.fingerprint]))}}}}function mo(o,i){let{[i]:r,...n}=o.collections;return{...o,collections:n}}var ao=new Po("pull").description("Fetch icons and regenerate all collection files (replaces existing)").option("-c, --collection <slug>","Pull only this collection").action(async(o)=>{let i=zo("Loading config...").start(),r;try{r=await u()}catch(f){i.fail(P.red(f.message)),process.exit(1)}let n=o.collection?[o.collection]:r.collections;if(n.length===0){i.warn(P.yellow("No collections in config. Add one with `iconia add <slug>`."));return}if(o.collection&&!r.collections.includes(o.collection))i.fail(P.red(`Collection '${o.collection}' is not in your config.`)),process.exit(1);i.text=`Fetching icons for ${n.join(", ")}...`;let t;try{t=await J(r,n)}catch(f){i.fail(P.red(`Failed to fetch icons: ${f.message}`)),process.exit(1)}if(t.length===0){i.warn(P.yellow("No icons found."));return}i.text=`Generating ${t.length} icon${t.length!==1?"s":""}...`;let c=new Map;for(let f of t){let w=c.get(f.collectionSlug)??[];w.push(f),c.set(f.collectionSlug,w)}let a=E(),m=0,e=[];for(let[f,w]of c){let y=q(f,w);if(y===0)continue;m+=y,e.push(f),a=v(a,f,w.map(($)=>({slug:$.slug,fingerprint:$.fingerprint})))}if(K(a),h(),i.succeed(P.green(`Generated ${m} icon${m!==1?"s":""} across ${e.length} collection${e.length!==1?"s":""}`)),e.length>0){let f=e[0]??"",w=b(c.get(f)?.[0]?.name??"MyIcon");console.log(`
|
|
18
20
|
Import icons:
|
|
19
|
-
${
|
|
20
|
-
${i.map((
|
|
21
|
+
${P.cyan(`import { ${w} } from '@iconia/react/${f}'`)}`)}});import{Command as Jo}from"commander";import L from"picocolors";import bo from"ora";import p from"fs";import yo from"path";function Q(){let o=yo.resolve(process.cwd(),"iconia.config.ts"),i=yo.resolve(process.cwd(),"iconia.config.js");if(p.existsSync(o))return o;if(p.existsSync(i))return i;return null}function W(o){let n=p.readFileSync(o,"utf-8").match(/collections:\s*\[([\s\S]*?)\]/)?.[1];if(!n)return null;let t=[],c=/['"]([^'"]+)['"]/g,a;while((a=c.exec(n))!==null){let m=a[1];if(m)t.push(m)}return t}function Z(o,i){let r=p.readFileSync(o,"utf-8"),n=i.length===0?"[]":`[
|
|
22
|
+
${i.map((c)=>` '${c}'`).join(`,
|
|
21
23
|
`)},
|
|
22
|
-
]`,
|
|
24
|
+
]`,t=r.replace(/collections:\s*\[[\s\S]*?\]/,`collections: ${n}`);if(t===r)return!1;return p.writeFileSync(o,t,"utf-8"),!0}var wo=new Jo("add").description("Add a collection to your project (updates config and downloads icons)").argument("<slug>","Collection slug").action(async(o)=>{let i=bo("Loading config...").start(),r;try{r=await u()}catch(m){i.fail(L.red(m.message)),process.exit(1)}if(r.collections.includes(o))i.info(L.yellow(`Collection '${o}' is already in your config. Running pull...`));else{i.text="Verifying collection...";let m;try{m=await l(r)}catch(F){i.fail(L.red(`Failed to fetch collections: ${F.message}`)),process.exit(1)}if(!m.find((F)=>F.slug===o))i.fail(L.red(`Collection '${o}' not found. Available: ${m.map((F)=>F.slug).join(", ")||"none"}`)),process.exit(1);let f=Q();if(!f)i.fail(L.red("Config file not found. Run `npx @iconia/react init` first.")),process.exit(1);let y=[...W(f)??r.collections,o];if(!Z(f,y))i.warn(L.yellow(`Could not update config automatically. Add '${o}' to collections in iconia.config.ts manually.`));else i.text=`Added '${o}' to config. Fetching icons...`}i.text=`Fetching icons for '${o}'...`;let n;try{n=await J(r,[o])}catch(m){i.fail(L.red(`Failed to fetch icons: ${m.message}`)),process.exit(1)}if(n.length===0){i.warn(L.yellow(`No icons in collection '${o}'.`));return}i.text=`Generating ${n.length} icon${n.length!==1?"s":""}...`;let t=q(o,n),c=E();c=v(c,o,n.map((m)=>({slug:m.slug,fingerprint:m.fingerprint}))),K(c),i.succeed(L.green(`Added '${o}' — ${t} icon${t!==1?"s":""} generated`));let a=b(n[0]?.name??"Icon");console.log(`
|
|
23
25
|
Import icons:
|
|
24
|
-
${
|
|
26
|
+
${L.cyan(`import { ${a} } from '@iconia/react/${o}'`)}`)});import{Command as qo}from"commander";import S from"picocolors";var $o=new qo("remove").description("Remove a collection from your project (updates config and deletes generated files)").argument("<slug>","Collection slug").action(async(o)=>{let i;try{i=await u()}catch(n){console.error(S.red(n.message)),process.exit(1)}if(!i.collections.includes(o))console.warn(S.yellow(`Collection '${o}' is not in your config.`));else{let n=Q();if(n){let c=(W(n)??i.collections).filter((m)=>m!==o);if(!Z(n,c))console.warn(S.yellow(`Could not update config automatically. Remove '${o}' from collections in iconia.config.ts manually.`))}}to(o);let r=E();r=mo(r,o),K(r),console.log(S.green(`✓ Removed collection '${o}'`))});import{Command as vo}from"commander";import s from"picocolors";import Ao from"ora";var eo=new vo("sync").description("Sync icons: add new, update changed, remove deleted — without full re-fetch").option("-c, --collection <slug>","Sync only this collection").action(async(o)=>{let i=Ao("Loading config...").start(),r;try{r=await u()}catch(y){i.fail(s.red(y.message)),process.exit(1)}let n=o.collection?[o.collection]:r.collections;if(n.length===0){i.warn(s.yellow("No collections in config. Add one with `iconia add <slug>`."));return}if(o.collection&&!r.collections.includes(o.collection))i.fail(s.red(`Collection '${o.collection}' is not in your config.`)),process.exit(1);i.text=`Fetching icons for ${n.join(", ")}...`;let t;try{t=await J(r,n)}catch(y){i.fail(s.red(`Failed to fetch icons: ${y.message}`)),process.exit(1)}let c=new Map;for(let y of t){let $=c.get(y.collectionSlug)??[];$.push(y),c.set(y.collectionSlug,$)}let a=E(),m=0,e=0,f=0,w=0;for(let y of n){let $=c.get(y)??[],F=a.collections[y]?.icons??{},_=new Map($.map((d)=>[d.slug,d])),I=new Set(Object.keys(F)),O=new Set(_.keys()),R=[...O].filter((d)=>!I.has(d)),j=[...I].filter((d)=>!O.has(d)),U=[...O].filter((d)=>I.has(d)&&F[d]!==_.get(d).fingerprint);if(R.length===0&&j.length===0&&U.length===0){console.log(s.dim(` ${y}: up to date`));continue}if(R.length>0)console.log(s.green(` ${y}: +${R.length} added`)+s.dim(` (${R.slice(0,5).join(", ")}${R.length>5?"…":""})`));if(U.length>0)console.log(s.blue(` ${y}: ~${U.length} updated`)+s.dim(` (${U.slice(0,5).join(", ")}${U.length>5?"…":""})`));if(j.length>0)console.log(s.red(` ${y}: -${j.length} removed`)+s.dim(` (${j.slice(0,5).join(", ")}${j.length>5?"…":""})`));if($.length>0)q(y,$);a=v(a,y,$.map((d)=>({slug:d.slug,fingerprint:d.fingerprint}))),m+=R.length,e+=U.length,f+=j.length,w++}if(K(a),w>0)h();if(w===0)i.succeed(s.green("Everything is up to date."));else i.succeed(s.green(`Sync complete: ${m} added, ${e} updated, ${f} removed across ${w} collection${w!==1?"s":""}`))});import{Command as Yo}from"commander";import k from"fs";import Y from"path";import A from"picocolors";import po from"ora";function Ho(o){return Y.basename(o,Y.extname(o)).toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}function ho(o){return o.split("-").map((i)=>i.charAt(0).toUpperCase()+i.slice(1)).join(" ")}function Qo(o){let i=k.statSync(o);if(i.isFile()){if(!o.endsWith(".svg"))throw Error(`File '${o}' is not an SVG.`);return[o]}if(i.isDirectory())return k.readdirSync(o).filter((r)=>r.endsWith(".svg")).map((r)=>Y.join(o,r));throw Error(`'${o}' is not a file or directory.`)}var Io=new Yo("upload").description("Upload SVG file(s) to an Iconia collection").argument("<path>","SVG file or directory of SVGs").requiredOption("-c, --collection <slug>","Target collection slug").option("--tags <tags>","Comma-separated tags to apply to all uploaded icons").action(async(o,i)=>{let r=po("Loading config...").start(),n;try{n=await u()}catch(f){r.fail(A.red(f.message)),process.exit(1)}let t;try{t=Qo(Y.resolve(process.cwd(),o))}catch(f){r.fail(A.red(f.message)),process.exit(1)}if(t.length===0){r.warn(A.yellow("No SVG files found."));return}let c=i.tags?i.tags.split(",").map((f)=>f.trim()).filter(Boolean):[];r.text=`Uploading ${t.length} file${t.length!==1?"s":""} to '${i.collection}'...`;let a=0,m=0,e=[];for(let f of t){let w=Ho(f);if(!w){e.push(`${Y.basename(f)}: could not derive a valid slug`),m++;continue}let y=k.readFileSync(f,"utf-8");try{await x(n,{collectionSlug:i.collection,name:ho(w),slug:w,svgContent:y,tags:c}),a++,r.text=`Uploading... (${a}/${t.length})`}catch($){e.push(`${Y.basename(f)}: ${$.message}`),m++}}if(m===0)r.succeed(A.green(`Uploaded ${a} icon${a!==1?"s":""} to '${i.collection}'`));else{r.warn(A.yellow(`Uploaded ${a}, failed ${m}`));for(let f of e)console.log(A.dim(` ✗ ${f}`))}});var Zo=new Wo("iconia").version("0.1.0").description("CLI for fetching and generating React icon components from Iconia").addCommand(N).addCommand(wo).addCommand($o).addCommand(ao).addCommand(eo).addCommand(Io);Zo.parse(process.argv);
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type IconNodeElement = [
|
|
|
11
11
|
export type IconNode = IconNodeElement[];
|
|
12
12
|
declare const configSchema: z.ZodObject<{
|
|
13
13
|
apiKey: z.ZodString;
|
|
14
|
-
collections: z.ZodArray<z.ZodString
|
|
14
|
+
collections: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
15
15
|
}, z.core.$strip>;
|
|
16
16
|
export type IconiaConfig = z.infer<typeof configSchema> & {
|
|
17
17
|
apiUrl?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iconia/react",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.fa4b45b",
|
|
4
4
|
"description": "Fetch and generate React icon components from your Iconia collections",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"author": "Wyesoftware",
|
|
59
59
|
"repository": {
|
|
60
60
|
"type": "git",
|
|
61
|
-
"url": "git+https://github.com/
|
|
61
|
+
"url": "git+https://github.com/iconia-io/iconia-react.git"
|
|
62
62
|
},
|
|
63
63
|
"bugs": {
|
|
64
|
-
"url": "https://github.com/
|
|
64
|
+
"url": "https://github.com/iconia-io/iconia-react/issues"
|
|
65
65
|
},
|
|
66
|
-
"homepage": "https://github.com/
|
|
66
|
+
"homepage": "https://github.com/iconia-io/iconia-react#readme"
|
|
67
67
|
}
|