@salty-css/core 0.0.1-alpha.45 → 0.0.1-alpha.47

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/bin/main.cjs CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("commander"),M=require("fs"),i=require("fs/promises"),t=require("path"),X=require("ejs"),Y=require("../compiler/index.cjs"),Z=require("../pascal-case-iWoaJWwT.cjs"),q=require("winston"),ee=require("child_process"),te=require("ora");var R=typeof document<"u"?document.currentScript:null;const o=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]}),C=r=>{o.error(r)},W=r=>new Promise((u,w)=>{ee.exec(r,j=>{if(j)return w(j);u()})}),F=async(...r)=>{const u=r.map(x=>x.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),w=te(`Installing packages: ${u}`).start(),j=r.join(" ");await W(`npm install ${j}`),w.succeed(`Installed packages: ${u}`)},ie=()=>M.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function J(r){try{if(!ie())return;await W(`./node_modules/.bin/prettier --write "${r}"`),o.info(`Formatted ${r} with Prettier`)}catch(u){o.error(`Error formatting ${r} with Prettier:`,u)}}async function ne(){const r=new Q.Command;r.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const u={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-BupieCfE.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs"))},w=async(s,c)=>{const{default:l}=await u[s],f=X.render(l,c);return{fileName:s,content:f}},j=async()=>{const s=t.join(process.cwd(),".saltyrc");return await i.readFile(s,"utf-8").then(JSON.parse).catch(()=>({}))},x=async(s=t.join(process.cwd(),"package.json"))=>{const c=await i.readFile(s,"utf-8").then(JSON.parse).catch(()=>{});if(!c)throw"Could not read package.json file!";return c},B=async()=>{const s=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("bin/main.cjs",document.baseURI).href);return x(s)},z=await(async()=>(await j()).defaultProject)(),v=await B(),k={core:`@salty-css/core@${v.version}`,react:`@salty-css/react@${v.version}`,eslintPluginCore:`@salty-css/eslint-plugin-core@${v.version}`,vite:`@salty-css/vite@${v.version}`,next:`@salty-css/next@${v.version}`},U=s=>{const c=s==="."?"":s,l=process.cwd();return t.join(l,c)};r.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(s="."){if(!await x().catch(()=>{}))return C("Salty CSS project must be initialized in a directory with a package.json file.");o.info("Initializing a new Salty-CSS project!");const{dir:l=s,cssFile:f,skipInstall:g}=this.opts();if(!l)return C("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");g||(await F(k.core,k.react),await F(`-D ${k.eslintPluginCore}`));const m=process.cwd(),n=U(l),N=await Promise.all([w("salty.config.ts"),w("saltygen/index.css")]);await i.mkdir(n,{recursive:!0});const _=N.map(async({fileName:e,content:p})=>{const a=t.join(n,e);if(await i.readFile(a,"utf-8").catch(()=>{})!==void 0){o.debug("File already exists: "+a);return}const S=e.split("/").slice(0,-1).join("/");S&&await i.mkdir(t.join(n,S),{recursive:!0}),o.info("Creating file: "+a),await i.writeFile(a,p),await J(a)});await Promise.all(_);const b=t.relative(m,n)||".",d=t.join(m,".saltyrc"),y=await i.readFile(d,"utf-8").catch(()=>{});if(y===void 0){o.info("Creating file: "+d);const p=JSON.stringify({defaultProject:b,projects:[b]},null,2);await i.writeFile(d,p)}else{o.info("Edit file: "+d);const e=JSON.parse(y),p=new Set((e==null?void 0:e.projects)||[]);p.add(b),e.projects=[...p];const a=JSON.stringify(e,null,2);await i.writeFile(d,a)}const A=t.join(m,".gitignore"),$=await i.readFile(A,"utf-8").catch(()=>{});$!==void 0&&($.includes("saltygen")||(o.info("Edit file: "+A),await i.writeFile(A,$+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("commander"),W=require("fs"),i=require("fs/promises"),t=require("path"),X=require("ejs"),Y=require("../compiler/index.cjs"),Z=require("../pascal-case-iWoaJWwT.cjs"),N=require("winston"),ee=require("child_process"),te=require("ora");var R=typeof document<"u"?document.currentScript:null;const s=N.createLogger({level:"debug",format:N.format.combine(N.format.colorize(),N.format.cli()),transports:[new N.transports.Console({})]}),h=a=>{s.error(a)},B=a=>new Promise((m,j)=>{ee.exec(a,P=>{if(P)return j(P);m()})}),b=async(...a)=>{const m=a.map(F=>F.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),j=te(`Installing packages: ${m}`).start(),P=a.join(" ");await B(`npm install ${P}`),j.succeed(`Installed packages: ${m}`)},ne=()=>W.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function _(a){try{if(!ne())return;await B(`./node_modules/.bin/prettier --write "${a}"`),s.info(`Formatted ${a} with Prettier`)}catch(m){s.error(`Error formatting ${a} with Prettier:`,m)}}async function ie(){const a=new Q.Command;a.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const m={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-BupieCfE.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs"))},j=async(n,r)=>{const{default:o}=await m[n],u=X.render(o,r);return{fileName:n,content:u}},P=async()=>{const n=t.join(process.cwd(),".saltyrc");return await i.readFile(n,"utf-8").then(JSON.parse).catch(()=>({}))},F=async(n=t.join(process.cwd(),"package.json"))=>{const r=await i.readFile(n,"utf-8").then(JSON.parse).catch(()=>{});if(!r)throw"Could not read package.json file!";return r},z=async()=>{const n=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("bin/main.cjs",document.baseURI).href);return F(n)},H=await(async()=>(await P()).defaultProject)(),k=await z(),$={core:`@salty-css/core@${k.version}`,react:`@salty-css/react@${k.version}`,eslintPluginCore:`@salty-css/eslint-plugin-core@${k.version}`,vite:`@salty-css/vite@${k.version}`,next:`@salty-css/next@${k.version}`},U=n=>{const r=n==="."?"":n,o=process.cwd();return t.join(o,r)};a.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(n="."){if(!await F().catch(()=>{}))return h("Salty CSS project must be initialized in a directory with a package.json file.");s.info("Initializing a new Salty-CSS project!");const{dir:o=n,cssFile:u,skipInstall:g}=this.opts();if(!o)return h("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");g||(await b($.core,$.react),await b(`-D ${$.eslintPluginCore}`));const f=process.cwd(),l=U(o),C=await Promise.all([j("salty.config.ts"),j("saltygen/index.css")]);await i.mkdir(l,{recursive:!0});const y=C.map(async({fileName:e,content:p})=>{const c=t.join(l,e);if(await i.readFile(c,"utf-8").catch(()=>{})!==void 0){s.debug("File already exists: "+c);return}const v=e.split("/").slice(0,-1).join("/");v&&await i.mkdir(t.join(l,v),{recursive:!0}),s.info("Creating file: "+c),await i.writeFile(c,p),await _(c)});await Promise.all(y);const D=t.relative(f,l)||".",d=t.join(f,".saltyrc"),w=await i.readFile(d,"utf-8").catch(()=>{});if(w===void 0){s.info("Creating file: "+d);const p=JSON.stringify({defaultProject:D,projects:[D]},null,2);await i.writeFile(d,p)}else{s.info("Edit file: "+d);const e=JSON.parse(w),p=new Set((e==null?void 0:e.projects)||[]);p.add(D),e.projects=[...p];const c=JSON.stringify(e,null,2);await i.writeFile(d,c)}const A=t.join(f,".gitignore"),I=await i.readFile(A,"utf-8").catch(()=>{});I!==void 0&&(I.includes("saltygen")||(s.info("Edit file: "+A),await i.writeFile(A,I+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
5
- `)));const E=["src","public","assets","styles","css","app"],G=["styles","css","app","pages"],V=["index","styles","main","global","globals"],K=[".css",".scss",".sass"],H=await(async()=>{if(f)return f;for(const e of E)for(const p of V)for(const a of K){const h=t.join(n,e,p+a);if(await i.readFile(h,"utf-8").catch(()=>{})!==void 0)return t.relative(n,h);for(const D of G){const I=t.join(n,e,D,p+a);if(await i.readFile(I,"utf-8").catch(()=>{})!==void 0)return t.relative(n,I)}}})();if(H){const e=t.join(n,H),p=await i.readFile(e,"utf-8").catch(()=>{});if(p!==void 0&&!p.includes("saltygen")){const h=t.join(e,".."),D=`@import '${t.relative(h,t.join(n,"saltygen/index.css"))}';`;o.info("Adding global import statement to CSS file: "+e),await i.writeFile(e,D+`
6
- `+p),await J(e)}}else o.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");const T=t.join(n,"vite.config.ts"),O=await i.readFile(T,"utf-8").catch(()=>{});if(O!==void 0&&!O.includes("saltyPlugin")){o.info("Edit file: "+T);const p=`import { saltyPlugin } from '@salty-css/vite';
7
- `,h=O.replace(/(plugins: \[)/,`$1
8
- saltyPlugin(__dirname),`);g||await F(`-D ${k.vite}`),o.info("Adding Salty-CSS plugin to Vite config..."),await i.writeFile(T,p+h),await J(T)}const L=["next.config.js","next.config.cjs","next.config.ts","next.config.mjs"].map(e=>t.join(n,e)).find(e=>M.existsSync(e));if(L){let e=await i.readFile(L,"utf-8").catch(()=>{});if(e!==void 0&&!e.includes("withSaltyCss")){let a=!1;/\splugins([^=]*)=[^[]\[/.test(e)&&!a&&(e=e.replace(/\splugins([^=]*)=[^[]\[/,(I,P)=>` plugins${P}= [withSaltyCss,`),a=!0);const S=e.includes("module.exports"),D=S?`const { withSaltyCss } = require('@salty-css/next');
5
+ `)));const O=["src","public","assets","styles","css","app"],G=["styles","css","app","pages"],V=["index","styles","main","global","globals"],K=[".css",".scss",".sass"],M=await(async()=>{if(u)return u;for(const e of O)for(const p of V)for(const c of K){const S=t.join(l,e,p+c);if(await i.readFile(S,"utf-8").catch(()=>{})!==void 0)return t.relative(l,S);for(const J of G){const q=t.join(l,e,J,p+c);if(await i.readFile(q,"utf-8").catch(()=>{})!==void 0)return t.relative(l,q)}}})();if(M){const e=t.join(l,M),p=await i.readFile(e,"utf-8").catch(()=>{});if(p!==void 0&&!p.includes("saltygen")){const S=t.join(e,".."),J=`@import '${t.relative(S,t.join(l,"saltygen/index.css"))}';`;s.info("Adding global import statement to CSS file: "+e),await i.writeFile(e,J+`
6
+ `+p),await _(e)}}else s.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");const L=t.join(l,"vite.config.ts"),E=await i.readFile(L,"utf-8").catch(()=>{});if(E!==void 0&&!E.includes("saltyPlugin")){s.info("Edit file: "+L);const p=`import { saltyPlugin } from '@salty-css/vite';
7
+ `,S=E.replace(/(plugins: \[)/,`$1
8
+ saltyPlugin(__dirname),`);g||await b(`-D ${$.vite}`),s.info("Adding Salty-CSS plugin to Vite config..."),await i.writeFile(L,p+S),await _(L)}const T=["next.config.js","next.config.cjs","next.config.ts","next.config.mjs"].map(e=>t.join(l,e)).find(e=>W.existsSync(e));if(T){let e=await i.readFile(T,"utf-8").catch(()=>{});if(e!==void 0&&!e.includes("withSaltyCss")){let c=!1;/\splugins([^=]*)=[^[]\[/.test(e)&&!c&&(e=e.replace(/\splugins([^=]*)=[^[]\[/,(q,x)=>` plugins${x}= [withSaltyCss,`),c=!0);const v=e.includes("module.exports"),J=v?`const { withSaltyCss } = require('@salty-css/next');
9
9
  `:`import { withSaltyCss } from '@salty-css/next';
10
- `;S&&!a?(e=e.replace(/module.exports = ([^;]+)/,(I,P)=>`module.exports = withSaltyCss(${P})`),a=!0):a||(e=e.replace(/export default ([^;]+)/,(I,P)=>`export default withSaltyCss(${P})`)),g||await F(`-D ${k.next}`),o.info("Adding Salty-CSS plugin to Next.js config..."),await i.writeFile(L,D+e),await J(L)}}}),r.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>","Project directory to build the project in.").action(async function(s=z){o.info("Building the Salty-CSS project...");const{dir:c=s}=this.opts();if(!c)return C("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const l=U(c);await Y.generateCss(l)}),r.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>","File to generate.").option("-d, --dir <dir>","Project directory to generate the file in.").option("-t, --tag <tag>","HTML tag of the component.","div").option("-n, --name <name>","Name of the component.").option("-c, --className <className>","CSS class of the component.").action(async function(s,c=z){const{file:l=s,dir:f=c,tag:g,name:m,className:n}=this.opts();if(!l)return C("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!f)return C("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const N=U(f),_=l.split("/").slice(0,-1).join("/");_&&await i.mkdir(t.join(N,_),{recursive:!0});const b=t.join(N,l),d=t.parse(b);d.ext||(d.ext=".ts"),d.name.endsWith(".css")||(d.name=d.name+".css"),d.base=d.name+d.ext;const y=t.format(d);if(await i.readFile(y,"utf-8").catch(()=>{})!==void 0){o.error("File already exists:",y);return}o.info("Generating a new file: "+y);const $=Z.pascalCase(m||d.base.replace(/\.css\.\w+$/,"")),{content:E}=await w("react/react-styled-file.ts",{tag:g,name:$,className:n});await i.writeFile(y,E),await J(y)}),r.command("update").alias("up").description("Update Salty-CSS packages to the latest version.").option("--legacy-peer-deps <legacyPeerDeps>","Use legacy peer dependencies (not recommended).",!1).action(async function(){const{legacyPeerDeps:s}=this.opts(),c=t.join(process.cwd(),"package.json"),l=await x(c).catch(n=>C(n));if(!l)return;const f={...l.dependencies,...l.devDependencies},g=Object.keys(f).filter(n=>n==="salty-css"||n.startsWith("@salty-css/"));if(!g.length)return C("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+c);const m=g.map(n=>`${n}@${v.version}`);s?(o.warn("Using legacy peer dependencies to update packages."),await F(...m,"--legacy-peer-deps")):await F(...m),o.info("Salty-CSS packages updated successfully!")}),r.parseAsync(process.argv)}exports.main=ne;
10
+ `;v&&!c?(e=e.replace(/module.exports = ([^;]+)/,(q,x)=>`module.exports = withSaltyCss(${x})`),c=!0):c||(e=e.replace(/export default ([^;]+)/,(q,x)=>`export default withSaltyCss(${x})`)),g||await b(`-D ${$.next}`),s.info("Adding Salty-CSS plugin to Next.js config..."),await i.writeFile(T,J+e),await _(T)}}}),a.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>","Project directory to build the project in.").action(async function(n=H){s.info("Building the Salty-CSS project...");const{dir:r=n}=this.opts();if(!r)return h("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const o=U(r);await Y.generateCss(o)}),a.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>","File to generate.").option("-d, --dir <dir>","Project directory to generate the file in.").option("-t, --tag <tag>","HTML tag of the component.","div").option("-n, --name <name>","Name of the component.").option("-c, --className <className>","CSS class of the component.").action(async function(n,r=H){const{file:o=n,dir:u=r,tag:g,name:f,className:l}=this.opts();if(!o)return h("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!u)return h("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const C=U(u),y=o.split("/").slice(0,-1).join("/");y&&await i.mkdir(t.join(C,y),{recursive:!0});const D=t.join(C,o),d=t.parse(D);d.ext||(d.ext=".ts"),d.name.endsWith(".css")||(d.name=d.name+".css"),d.base=d.name+d.ext;const w=t.format(d);if(await i.readFile(w,"utf-8").catch(()=>{})!==void 0){s.error("File already exists:",w);return}s.info("Generating a new file: "+w);const I=Z.pascalCase(f||d.base.replace(/\.css\.\w+$/,"")),{content:O}=await j("react/react-styled-file.ts",{tag:g,name:I,className:l});await i.writeFile(w,O),await _(w)}),a.command("update [version]").alias("up").description("Update Salty-CSS packages to the latest or specified version.").option("-v, --version <version>","Version to update to.").option("--legacy-peer-deps <legacyPeerDeps>","Use legacy peer dependencies (not recommended).",!1).action(async function(n="latest"){const{legacyPeerDeps:r,version:o=n}=this.opts(),u=t.join(process.cwd(),"package.json"),g=await F(u).catch(y=>h(y));if(!g)return;const f={...g.dependencies,...g.devDependencies},l=Object.keys(f).filter(y=>y==="salty-css"||y.startsWith("@salty-css/"));if(!l.length)return h("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+u);const C=l.map(y=>o==="@"?`${y}@${k.version}`:`${y}@${o.replace(/^@/,"")}`);r?(s.warn("Using legacy peer dependencies to update packages."),await b(...C,"--legacy-peer-deps")):await b(...C),s.info("Salty-CSS packages updated successfully!")}),a.command("version").alias("v").description("Show the current version of Salty-CSS.").action(async function(){const n=await z();s.info("CLI is running:",n.version);const r=t.join(process.cwd(),"package.json"),o=await F(r).catch(f=>h(f));if(!o)return;const u={...o.dependencies,...o.devDependencies},g=Object.keys(u).filter(f=>f==="salty-css"||f.startsWith("@salty-css/"));if(!g.length)return h("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+r);for(const f of g)s.info(f,u[f])}),a.parseAsync(process.argv)}exports.main=ie;
package/bin/main.js CHANGED
@@ -1,108 +1,108 @@
1
1
  import { Command as Y } from "commander";
2
2
  import { existsSync as G } from "fs";
3
- import { mkdir as R, readFile as p, writeFile as w } from "fs/promises";
4
- import { join as o, relative as O, parse as Z, format as tt } from "path";
3
+ import { mkdir as W, readFile as m, writeFile as C } from "fs/promises";
4
+ import { join as i, relative as _, parse as Z, format as tt } from "path";
5
5
  import { render as et } from "ejs";
6
6
  import { generateCss as nt } from "../compiler/index.js";
7
- import { p as it } from "../pascal-case-BQpR5PdN.js";
8
- import { createLogger as st, format as W, transports as ot } from "winston";
7
+ import { p as st } from "../pascal-case-BQpR5PdN.js";
8
+ import { createLogger as it, format as M, transports as ot } from "winston";
9
9
  import { exec as at } from "child_process";
10
10
  import rt from "ora";
11
- const i = st({
11
+ const n = it({
12
12
  level: "debug",
13
- format: W.combine(W.colorize(), W.cli()),
13
+ format: M.combine(M.colorize(), M.cli()),
14
14
  transports: [new ot.Console({})]
15
- }), P = (a) => {
16
- i.error(a);
17
- }, M = (a) => new Promise((g, S) => {
18
- at(a, (v) => {
19
- if (v) return S(v);
20
- g();
15
+ }), h = (o) => {
16
+ n.error(o);
17
+ }, V = (o) => new Promise((y, v) => {
18
+ at(o, (k) => {
19
+ if (k) return v(k);
20
+ y();
21
21
  });
22
- }), k = async (...a) => {
23
- const g = a.map((F) => F.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), S = rt(`Installing packages: ${g}`).start(), v = a.join(" ");
24
- await M(`npm install ${v}`), S.succeed(`Installed packages: ${g}`);
25
- }, ct = () => G(o(process.cwd(), "node_modules", ".bin", "prettier"));
26
- async function A(a) {
22
+ }), b = async (...o) => {
23
+ const y = o.map((x) => x.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), v = rt(`Installing packages: ${y}`).start(), k = o.join(" ");
24
+ await V(`npm install ${k}`), v.succeed(`Installed packages: ${y}`);
25
+ }, ct = () => G(i(process.cwd(), "node_modules", ".bin", "prettier"));
26
+ async function E(o) {
27
27
  try {
28
28
  if (!ct()) return;
29
- await M(`./node_modules/.bin/prettier --write "${a}"`), i.info(`Formatted ${a} with Prettier`);
30
- } catch (g) {
31
- i.error(`Error formatting ${a} with Prettier:`, g);
29
+ await V(`./node_modules/.bin/prettier --write "${o}"`), n.info(`Formatted ${o} with Prettier`);
30
+ } catch (y) {
31
+ n.error(`Error formatting ${o} with Prettier:`, y);
32
32
  }
33
33
  }
34
- async function vt() {
35
- const a = new Y();
36
- a.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
37
- const g = {
34
+ async function Pt() {
35
+ const o = new Y();
36
+ o.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
37
+ const y = {
38
38
  // Core files
39
39
  "salty.config.ts": import("../salty.config-D9ANEDiH.js"),
40
40
  "saltygen/index.css": import("../index-D_732b92.js"),
41
41
  // React
42
42
  "react/react-styled-file.ts": import("../react-styled-file-CGVf5n1B.js")
43
- }, S = async (n, r) => {
44
- const { default: c } = await g[n], f = et(c, r);
45
- return { fileName: n, content: f };
46
- }, v = async () => {
47
- const n = o(process.cwd(), ".saltyrc");
48
- return await p(n, "utf-8").then(JSON.parse).catch(() => ({}));
49
- }, F = async (n = o(process.cwd(), "package.json")) => {
50
- const r = await p(n, "utf-8").then(JSON.parse).catch(() => {
43
+ }, v = async (e, a) => {
44
+ const { default: s } = await y[e], f = et(s, a);
45
+ return { fileName: e, content: f };
46
+ }, k = async () => {
47
+ const e = i(process.cwd(), ".saltyrc");
48
+ return await m(e, "utf-8").then(JSON.parse).catch(() => ({}));
49
+ }, x = async (e = i(process.cwd(), "package.json")) => {
50
+ const a = await m(e, "utf-8").then(JSON.parse).catch(() => {
51
51
  });
52
- if (!r) throw "Could not read package.json file!";
53
- return r;
54
- }, V = async () => {
55
- const n = new URL("../package.json", import.meta.url);
56
- return F(n);
57
- }, q = await (async () => (await v()).defaultProject)(), j = await V(), $ = {
58
- core: `@salty-css/core@${j.version}`,
59
- react: `@salty-css/react@${j.version}`,
60
- eslintPluginCore: `@salty-css/eslint-plugin-core@${j.version}`,
61
- vite: `@salty-css/vite@${j.version}`,
62
- next: `@salty-css/next@${j.version}`
63
- }, U = (n) => {
64
- const r = n === "." ? "" : n, c = process.cwd();
65
- return o(c, r);
52
+ if (!a) throw "Could not read package.json file!";
53
+ return a;
54
+ }, R = async () => {
55
+ const e = new URL("../package.json", import.meta.url);
56
+ return x(e);
57
+ }, q = await (async () => (await k()).defaultProject)(), F = await R(), D = {
58
+ core: `@salty-css/core@${F.version}`,
59
+ react: `@salty-css/react@${F.version}`,
60
+ eslintPluginCore: `@salty-css/eslint-plugin-core@${F.version}`,
61
+ vite: `@salty-css/vite@${F.version}`,
62
+ next: `@salty-css/next@${F.version}`
63
+ }, U = (e) => {
64
+ const a = e === "." ? "" : e, s = process.cwd();
65
+ return i(s, a);
66
66
  };
67
- a.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>", "Project directory to initialize the project in.").option("--css-file <css-file>", "Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install", "Skip installing dependencies.").action(async function(n = ".") {
68
- if (!await F().catch(() => {
69
- })) return P("Salty CSS project must be initialized in a directory with a package.json file.");
70
- i.info("Initializing a new Salty-CSS project!");
71
- const { dir: c = n, cssFile: f, skipInstall: u } = this.opts();
72
- if (!c) return P("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
73
- u || (await k($.core, $.react), await k(`-D ${$.eslintPluginCore}`));
74
- const m = process.cwd(), e = U(c), N = await Promise.all([S("salty.config.ts"), S("saltygen/index.css")]);
75
- await R(e, { recursive: !0 });
76
- const E = N.map(async ({ fileName: t, content: d }) => {
77
- const s = o(e, t);
78
- if (await p(s, "utf-8").catch(() => {
67
+ o.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>", "Project directory to initialize the project in.").option("--css-file <css-file>", "Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install", "Skip installing dependencies.").action(async function(e = ".") {
68
+ if (!await x().catch(() => {
69
+ })) return h("Salty CSS project must be initialized in a directory with a package.json file.");
70
+ n.info("Initializing a new Salty-CSS project!");
71
+ const { dir: s = e, cssFile: f, skipInstall: g } = this.opts();
72
+ if (!s) return h("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
73
+ g || (await b(D.core, D.react), await b(`-D ${D.eslintPluginCore}`));
74
+ const p = process.cwd(), c = U(s), P = await Promise.all([v("salty.config.ts"), v("saltygen/index.css")]);
75
+ await W(c, { recursive: !0 });
76
+ const u = P.map(async ({ fileName: t, content: d }) => {
77
+ const r = i(c, t);
78
+ if (await m(r, "utf-8").catch(() => {
79
79
  }) !== void 0) {
80
- i.debug("File already exists: " + s);
80
+ n.debug("File already exists: " + r);
81
81
  return;
82
82
  }
83
- const C = t.split("/").slice(0, -1).join("/");
84
- C && await R(o(e, C), { recursive: !0 }), i.info("Creating file: " + s), await w(s, d), await A(s);
83
+ const j = t.split("/").slice(0, -1).join("/");
84
+ j && await W(i(c, j), { recursive: !0 }), n.info("Creating file: " + r), await C(r, d), await E(r);
85
85
  });
86
- await Promise.all(E);
87
- const b = O(m, e) || ".", l = o(m, ".saltyrc"), y = await p(l, "utf-8").catch(() => {
86
+ await Promise.all(u);
87
+ const I = _(p, c) || ".", l = i(p, ".saltyrc"), w = await m(l, "utf-8").catch(() => {
88
88
  });
89
- if (y === void 0) {
90
- i.info("Creating file: " + l);
89
+ if (w === void 0) {
90
+ n.info("Creating file: " + l);
91
91
  const d = JSON.stringify({
92
- defaultProject: b,
93
- projects: [b]
92
+ defaultProject: I,
93
+ projects: [I]
94
94
  }, null, 2);
95
- await w(l, d);
95
+ await C(l, d);
96
96
  } else {
97
- i.info("Edit file: " + l);
98
- const t = JSON.parse(y), d = new Set((t == null ? void 0 : t.projects) || []);
99
- d.add(b), t.projects = [...d];
100
- const s = JSON.stringify(t, null, 2);
101
- await w(l, s);
97
+ n.info("Edit file: " + l);
98
+ const t = JSON.parse(w), d = new Set((t == null ? void 0 : t.projects) || []);
99
+ d.add(I), t.projects = [...d];
100
+ const r = JSON.stringify(t, null, 2);
101
+ await C(l, r);
102
102
  }
103
- const L = o(m, ".gitignore"), D = await p(L, "utf-8").catch(() => {
103
+ const L = i(p, ".gitignore"), J = await m(L, "utf-8").catch(() => {
104
104
  });
105
- D !== void 0 && (D.includes("saltygen") || (i.info("Edit file: " + L), await w(L, D + `
105
+ J !== void 0 && (J.includes("saltygen") || (n.info("Edit file: " + L), await C(L, J + `
106
106
 
107
107
  # Salty-CSS
108
108
  saltygen
@@ -111,84 +111,96 @@ saltygen
111
111
  if (f) return f;
112
112
  for (const t of z)
113
113
  for (const d of Q)
114
- for (const s of X) {
115
- const h = o(e, t, d + s);
116
- if (await p(h, "utf-8").catch(() => {
117
- }) !== void 0) return O(e, h);
118
- for (const I of K) {
119
- const J = o(e, t, I, d + s);
120
- if (await p(J, "utf-8").catch(() => {
121
- }) !== void 0) return O(e, J);
114
+ for (const r of X) {
115
+ const S = i(c, t, d + r);
116
+ if (await m(S, "utf-8").catch(() => {
117
+ }) !== void 0) return _(c, S);
118
+ for (const N of K) {
119
+ const A = i(c, t, N, d + r);
120
+ if (await m(A, "utf-8").catch(() => {
121
+ }) !== void 0) return _(c, A);
122
122
  }
123
123
  }
124
124
  })();
125
125
  if (B) {
126
- const t = o(e, B), d = await p(t, "utf-8").catch(() => {
126
+ const t = i(c, B), d = await m(t, "utf-8").catch(() => {
127
127
  });
128
128
  if (d !== void 0 && !d.includes("saltygen")) {
129
- const h = o(t, ".."), I = `@import '${O(h, o(e, "saltygen/index.css"))}';`;
130
- i.info("Adding global import statement to CSS file: " + t), await w(t, I + `
131
- ` + d), await A(t);
129
+ const S = i(t, ".."), N = `@import '${_(S, i(c, "saltygen/index.css"))}';`;
130
+ n.info("Adding global import statement to CSS file: " + t), await C(t, N + `
131
+ ` + d), await E(t);
132
132
  }
133
133
  } else
134
- i.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
135
- const T = o(e, "vite.config.ts"), H = await p(T, "utf-8").catch(() => {
134
+ n.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
135
+ const O = i(c, "vite.config.ts"), H = await m(O, "utf-8").catch(() => {
136
136
  });
137
137
  if (H !== void 0 && !H.includes("saltyPlugin")) {
138
- i.info("Edit file: " + T);
138
+ n.info("Edit file: " + O);
139
139
  const d = `import { saltyPlugin } from '@salty-css/vite';
140
- `, h = H.replace(/(plugins: \[)/, `$1
140
+ `, S = H.replace(/(plugins: \[)/, `$1
141
141
  saltyPlugin(__dirname),`);
142
- u || await k(`-D ${$.vite}`), i.info("Adding Salty-CSS plugin to Vite config..."), await w(T, d + h), await A(T);
142
+ g || await b(`-D ${D.vite}`), n.info("Adding Salty-CSS plugin to Vite config..."), await C(O, d + S), await E(O);
143
143
  }
144
- const _ = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((t) => o(e, t)).find((t) => G(t));
145
- if (_) {
146
- let t = await p(_, "utf-8").catch(() => {
144
+ const T = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((t) => i(c, t)).find((t) => G(t));
145
+ if (T) {
146
+ let t = await m(T, "utf-8").catch(() => {
147
147
  });
148
148
  if (t !== void 0 && !t.includes("withSaltyCss")) {
149
- let s = !1;
150
- /\splugins([^=]*)=[^[]\[/.test(t) && !s && (t = t.replace(/\splugins([^=]*)=[^[]\[/, (J, x) => ` plugins${x}= [withSaltyCss,`), s = !0);
151
- const C = t.includes("module.exports"), I = C ? `const { withSaltyCss } = require('@salty-css/next');
149
+ let r = !1;
150
+ /\splugins([^=]*)=[^[]\[/.test(t) && !r && (t = t.replace(/\splugins([^=]*)=[^[]\[/, (A, $) => ` plugins${$}= [withSaltyCss,`), r = !0);
151
+ const j = t.includes("module.exports"), N = j ? `const { withSaltyCss } = require('@salty-css/next');
152
152
  ` : `import { withSaltyCss } from '@salty-css/next';
153
153
  `;
154
- C && !s ? (t = t.replace(/module.exports = ([^;]+)/, (J, x) => `module.exports = withSaltyCss(${x})`), s = !0) : s || (t = t.replace(/export default ([^;]+)/, (J, x) => `export default withSaltyCss(${x})`)), u || await k(`-D ${$.next}`), i.info("Adding Salty-CSS plugin to Next.js config..."), await w(_, I + t), await A(_);
154
+ j && !r ? (t = t.replace(/module.exports = ([^;]+)/, (A, $) => `module.exports = withSaltyCss(${$})`), r = !0) : r || (t = t.replace(/export default ([^;]+)/, (A, $) => `export default withSaltyCss(${$})`)), g || await b(`-D ${D.next}`), n.info("Adding Salty-CSS plugin to Next.js config..."), await C(T, N + t), await E(T);
155
155
  }
156
156
  }
157
- }), a.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").action(async function(n = q) {
158
- i.info("Building the Salty-CSS project...");
159
- const { dir: r = n } = this.opts();
160
- if (!r) return P("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
161
- const c = U(r);
162
- await nt(c);
163
- }), a.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>", "File to generate.").option("-d, --dir <dir>", "Project directory to generate the file in.").option("-t, --tag <tag>", "HTML tag of the component.", "div").option("-n, --name <name>", "Name of the component.").option("-c, --className <className>", "CSS class of the component.").action(async function(n, r = q) {
164
- const { file: c = n, dir: f = r, tag: u, name: m, className: e } = this.opts();
165
- if (!c) return P("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
166
- if (!f) return P("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
167
- const N = U(f), E = c.split("/").slice(0, -1).join("/");
168
- E && await R(o(N, E), { recursive: !0 });
169
- const b = o(N, c), l = Z(b);
157
+ }), o.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").action(async function(e = q) {
158
+ n.info("Building the Salty-CSS project...");
159
+ const { dir: a = e } = this.opts();
160
+ if (!a) return h("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
161
+ const s = U(a);
162
+ await nt(s);
163
+ }), o.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>", "File to generate.").option("-d, --dir <dir>", "Project directory to generate the file in.").option("-t, --tag <tag>", "HTML tag of the component.", "div").option("-n, --name <name>", "Name of the component.").option("-c, --className <className>", "CSS class of the component.").action(async function(e, a = q) {
164
+ const { file: s = e, dir: f = a, tag: g, name: p, className: c } = this.opts();
165
+ if (!s) return h("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
166
+ if (!f) return h("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
167
+ const P = U(f), u = s.split("/").slice(0, -1).join("/");
168
+ u && await W(i(P, u), { recursive: !0 });
169
+ const I = i(P, s), l = Z(I);
170
170
  l.ext || (l.ext = ".ts"), l.name.endsWith(".css") || (l.name = l.name + ".css"), l.base = l.name + l.ext;
171
- const y = tt(l);
172
- if (await p(y, "utf-8").catch(() => {
171
+ const w = tt(l);
172
+ if (await m(w, "utf-8").catch(() => {
173
173
  }) !== void 0) {
174
- i.error("File already exists:", y);
174
+ n.error("File already exists:", w);
175
175
  return;
176
176
  }
177
- i.info("Generating a new file: " + y);
178
- const D = it(m || l.base.replace(/\.css\.\w+$/, "")), { content: z } = await S("react/react-styled-file.ts", { tag: u, name: D, className: e });
179
- await w(y, z), await A(y);
180
- }), a.command("update").alias("up").description("Update Salty-CSS packages to the latest version.").option("--legacy-peer-deps <legacyPeerDeps>", "Use legacy peer dependencies (not recommended).", !1).action(async function() {
181
- const { legacyPeerDeps: n } = this.opts(), r = o(process.cwd(), "package.json"), c = await F(r).catch((e) => P(e));
182
- if (!c) return;
183
- const f = { ...c.dependencies, ...c.devDependencies }, u = Object.keys(f).filter((e) => e === "salty-css" || e.startsWith("@salty-css/"));
184
- if (!u.length)
185
- return P(
186
- "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + r
177
+ n.info("Generating a new file: " + w);
178
+ const J = st(p || l.base.replace(/\.css\.\w+$/, "")), { content: z } = await v("react/react-styled-file.ts", { tag: g, name: J, className: c });
179
+ await C(w, z), await E(w);
180
+ }), o.command("update [version]").alias("up").description("Update Salty-CSS packages to the latest or specified version.").option("-v, --version <version>", "Version to update to.").option("--legacy-peer-deps <legacyPeerDeps>", "Use legacy peer dependencies (not recommended).", !1).action(async function(e = "latest") {
181
+ const { legacyPeerDeps: a, version: s = e } = this.opts(), f = i(process.cwd(), "package.json"), g = await x(f).catch((u) => h(u));
182
+ if (!g) return;
183
+ const p = { ...g.dependencies, ...g.devDependencies }, c = Object.keys(p).filter((u) => u === "salty-css" || u.startsWith("@salty-css/"));
184
+ if (!c.length)
185
+ return h(
186
+ "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + f
187
187
  );
188
- const m = u.map((e) => `${e}@${j.version}`);
189
- n ? (i.warn("Using legacy peer dependencies to update packages."), await k(...m, "--legacy-peer-deps")) : await k(...m), i.info("Salty-CSS packages updated successfully!");
190
- }), a.parseAsync(process.argv);
188
+ const P = c.map((u) => s === "@" ? `${u}@${F.version}` : `${u}@${s.replace(/^@/, "")}`);
189
+ a ? (n.warn("Using legacy peer dependencies to update packages."), await b(...P, "--legacy-peer-deps")) : await b(...P), n.info("Salty-CSS packages updated successfully!");
190
+ }), o.command("version").alias("v").description("Show the current version of Salty-CSS.").action(async function() {
191
+ const e = await R();
192
+ n.info("CLI is running:", e.version);
193
+ const a = i(process.cwd(), "package.json"), s = await x(a).catch((p) => h(p));
194
+ if (!s) return;
195
+ const f = { ...s.dependencies, ...s.devDependencies }, g = Object.keys(f).filter((p) => p === "salty-css" || p.startsWith("@salty-css/"));
196
+ if (!g.length)
197
+ return h(
198
+ "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + a
199
+ );
200
+ for (const p of g)
201
+ n.info(p, f[p]);
202
+ }), o.parseAsync(process.argv);
191
203
  }
192
204
  export {
193
- vt as main
205
+ Pt as main
194
206
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.45",
3
+ "version": "0.0.1-alpha.47",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AllHTMLAttributes, ReactDOM, ReactNode } from 'react';
2
2
  import { StyleComponentGenerator } from '../generator';
3
- import { OrString } from './util-types';
3
+ import { OrAny, OrString } from './util-types';
4
4
  export type CreateElementProps = {
5
5
  extend?: Tag<any>;
6
6
  children?: ReactNode;
@@ -13,7 +13,7 @@ export type CreateElementProps = {
13
13
  };
14
14
  export type StyledComponentProps = Record<string, unknown> & CreateElementProps;
15
15
  type FnComponent<PROPS extends StyledComponentProps> = {
16
- (props: PROPS): ReactNode;
16
+ (props: OrAny | PROPS): ReactNode;
17
17
  generator?: StyleComponentGenerator;
18
18
  };
19
19
  export type Tag<PROPS extends StyledComponentProps> = OrString | keyof ReactDOM | FnComponent<PROPS>;
@@ -38,7 +38,8 @@ type Variants = {
38
38
  };
39
39
  compoundVariants?: CompoundVariant[];
40
40
  };
41
- type VariantPropValue<T> = T extends 'true' ? 'true' | true : T;
41
+ type BooleanVariantValue = 'true' | 'false' | boolean;
42
+ type VariantPropValue<T> = T extends 'true' ? BooleanVariantValue : T extends 'false' ? BooleanVariantValue : T;
42
43
  export type VariantProps<STYLES extends StyledParams> = STYLES['variants'] extends undefined ? object : {
43
44
  [K in keyof STYLES['variants']]?: VariantPropValue<keyof STYLES['variants'][K]> | '';
44
45
  };