@salty-css/core 0.0.1-alpha.40 → 0.0.1-alpha.42

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 K=require("commander"),H=require("fs"),i=require("fs/promises"),t=require("path"),Q=require("ejs"),X=require("../compiler/index.cjs"),Y=require("../pascal-case-iWoaJWwT.cjs"),D=require("winston"),Z=require("child_process"),ee=require("ora");var E=typeof document<"u"?document.currentScript:null;const s=D.createLogger({level:"debug",format:D.format.combine(D.format.colorize(),D.format.cli()),transports:[new D.transports.Console({})]}),j=a=>{s.error(a)},M=a=>new Promise((u,h)=>{Z.exec(a,C=>{if(C)return h(C);u()})}),F=async(...a)=>{const u=a.map(x=>x.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),h=ee(`Installing packages: ${u}`).start(),C=a.join(" ");await M(`npm install ${C}`),h.succeed(`Installed packages: ${u}`)},te=()=>H.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function I(a){try{if(!te())return;await M(`./node_modules/.bin/prettier --write "${a}"`),s.info(`Formatted ${a} with Prettier`)}catch(u){s.error(`Error formatting ${a} with Prettier:`,u)}}async function ie(){const a=new K.Command;a.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"))},h=async(o,r)=>{const{default:c}=await u[o],f=Q.render(c,r);return{fileName:o,content:f}},C=async()=>{const o=t.join(process.cwd(),".saltyrc");return await i.readFile(o,"utf-8").then(JSON.parse).catch(()=>({}))},x=async(o=t.join(process.cwd(),"package.json"))=>{const r=await i.readFile(o,"utf-8").then(JSON.parse).catch(()=>{});if(!r)throw"Could not read package.json file!";return r},W=async()=>{const o=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:E&&E.tagName.toUpperCase()==="SCRIPT"&&E.src||new URL("bin/main.cjs",document.baseURI).href);return x(o)},O=await(async()=>(await C()).defaultProject)(),v=await W(),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}`},L=o=>{const r=o==="."?"":o,c=process.cwd();return t.join(c,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(o="."){if(!await x().catch(()=>{}))return j("Salty CSS project must be initialized in a directory with a package.json file.");s.info("Initializing a new Salty-CSS project!");const{dir:c=o,cssFile:f,skipInstall:m}=this.opts();if(!c)return j("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");m||(await F(k.core,k.react),await F(`-D ${k.eslintPluginCore}`));const y=process.cwd(),n=L(c),q=await Promise.all([h("salty.config.ts"),h("saltygen/index.css")]);await i.mkdir(n,{recursive:!0});const J=q.map(async({fileName:e,content:d})=>{const p=t.join(n,e);if(await i.readFile(p,"utf-8").catch(()=>{})!==void 0){s.debug("File already exists: "+p);return}const P=e.split("/").slice(0,-1).join("/");P&&await i.mkdir(t.join(n,P),{recursive:!0}),s.info("Creating file: "+p),await i.writeFile(p,d),await I(p)});await Promise.all(J);const b=t.relative(y,n)||".",l=t.join(y,".saltyrc"),w=await i.readFile(l,"utf-8").catch(()=>{});if(w===void 0){s.info("Creating file: "+l);const d=JSON.stringify({defaultProject:b,projects:[b]},null,2);await i.writeFile(l,d)}else{s.info("Edit file: "+l);const e=JSON.parse(w),d=new Set((e==null?void 0:e.projects)||[]);d.add(b),e.projects=[...d];const p=JSON.stringify(e,null,2);await i.writeFile(l,p)}const N=t.join(y,".gitignore"),$=await i.readFile(N,"utf-8").catch(()=>{});$!==void 0&&($.includes("saltygen")||(s.info("Edit file: "+N),await i.writeFile(N,$+`
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,$+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
5
- `)));const U=["src","public","assets","styles","css","app"],B=["styles","css","app","pages"],G=["index","styles","main","global","globals"],V=[".css",".scss",".sass"],R=await(async()=>{if(f)return f;for(const e of U)for(const d of G)for(const p of V){const g=t.join(n,e,d+p);if(await i.readFile(g,"utf-8").catch(()=>{})!==void 0)return t.relative(n,g);for(const S of B){const z=t.join(n,e,S,d+p);if(await i.readFile(z,"utf-8").catch(()=>{})!==void 0)return t.relative(n,z)}}})();if(R){const e=t.join(n,R),d=await i.readFile(e,"utf-8").catch(()=>{});if(d!==void 0&&!d.includes("saltygen")){const g=t.join(e,".."),S=`@import '${t.relative(g,t.join(n,"saltygen/index.css"))}';`;s.info("Adding global import statement to CSS file: "+e),await i.writeFile(e,S+`
6
- `+d),await I(e)}}else s.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");const _=t.join(n,"vite.config.ts"),A=await i.readFile(_,"utf-8").catch(()=>{});if(A!==void 0&&!A.includes("saltyPlugin")){s.info("Edit file: "+_);const d=`import { saltyPlugin } from '@salty-css/vite';
7
- `,g=A.replace(/(plugins: \[)/,`$1
8
- saltyPlugin(__dirname),`);m||await F(`-D ${k.vite}`),s.info("Adding Salty-CSS plugin to Vite config..."),await i.writeFile(_,d+g),await I(_)}const T=["next.config.js","next.config.cjs","next.config.ts","next.config.mjs"].map(e=>t.join(n,e)).find(e=>H.existsSync(e));if(T){let e=await i.readFile(T,"utf-8").catch(()=>{});if(e!==void 0&&!e.includes("withSaltyCss")){const p=e.includes("module.exports"),g=p?`const { withSaltyCss } = require('@salty-css/next');
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;/plugins[^=]*=/.test(e)&&!a&&(e=e.replace(/plugins([^=]*)=/,(I,P)=>`plugins${P}= [withSaltyCss,`),a=!0);const S=e.includes("module.exports"),D=S?`const { withSaltyCss } = require('@salty-css/next');
9
9
  `:`import { withSaltyCss } from '@salty-css/next';
10
- `;p?e=e.replace(/module.exports = ([^;]+)/,(P,S)=>`module.exports = withSaltyCss(${S})`):e=e.replace(/export default ([^;]+)/,(P,S)=>`export default withSaltyCss(${S})`),m||await F(`-D ${k.next}`),s.info("Adding Salty-CSS plugin to Next.js config..."),await i.writeFile(T,g+e),await I(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(o=O){s.info("Building the Salty-CSS project...");const{dir:r=o}=this.opts();if(!r)return j("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const c=L(r);await X.generateCss(c)}),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(o,r=O){const{file:c=o,dir:f=r,tag:m,name:y,className:n}=this.opts();if(!c)return j("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!f)return j("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const q=L(f),J=c.split("/").slice(0,-1).join("/");J&&await i.mkdir(t.join(q,J),{recursive:!0});const b=t.join(q,c),l=t.parse(b);l.ext||(l.ext=".ts"),l.name.endsWith(".css")||(l.name=l.name+".css"),l.base=l.name+l.ext;const w=t.format(l);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 $=Y.pascalCase(y||l.base.replace(/\.css\.\w+$/,"")),{content:U}=await h("react/react-styled-file.ts",{tag:m,name:$,className:n});await i.writeFile(w,U),await I(w)}),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(){const{legacyPeerDeps:o}=this.opts(),r=t.join(process.cwd(),"package.json"),c=await x(r).catch(n=>j(n));if(!c)return;const f={...c.dependencies,...c.devDependencies},m=Object.keys(f).filter(n=>n==="salty-css"||n.startsWith("@salty-css/"));if(!m.length)return j("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+r);const y=m.map(n=>`${n}@${v.version}`);o?(s.warn("Using legacy peer dependencies to update packages."),await F(...y,"--legacy-peer-deps")):await F(...y),s.info("Salty-CSS packages updated successfully!")}),a.parseAsync(process.argv)}exports.main=ie;
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;
package/bin/main.js CHANGED
@@ -1,192 +1,194 @@
1
- import { Command as X } from "commander";
2
- import { existsSync as B } from "fs";
3
- import { mkdir as z, readFile as p, writeFile as h } from "fs/promises";
4
- import { join as o, relative as T, parse as Y, format as Z } from "path";
5
- import { render as tt } from "ejs";
6
- import { generateCss as et } from "../compiler/index.js";
7
- import { p as nt } from "../pascal-case-BQpR5PdN.js";
8
- import { createLogger as it, format as H, transports as ot } from "winston";
9
- import { exec as st } from "child_process";
10
- import at from "ora";
11
- const i = it({
1
+ import { Command as Y } from "commander";
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";
5
+ import { render as et } from "ejs";
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";
9
+ import { exec as at } from "child_process";
10
+ import rt from "ora";
11
+ const i = st({
12
12
  level: "debug",
13
- format: H.combine(H.colorize(), H.cli()),
13
+ format: W.combine(W.colorize(), W.cli()),
14
14
  transports: [new ot.Console({})]
15
- }), v = (s) => {
16
- i.error(s);
17
- }, G = (s) => new Promise((g, S) => {
18
- st(s, (P) => {
19
- if (P) return S(P);
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
20
  g();
21
21
  });
22
- }), k = async (...s) => {
23
- const g = s.map((F) => F.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), S = at(`Installing packages: ${g}`).start(), P = s.join(" ");
24
- await G(`npm install ${P}`), S.succeed(`Installed packages: ${g}`);
25
- }, rt = () => B(o(process.cwd(), "node_modules", ".bin", "prettier"));
26
- async function I(s) {
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) {
27
27
  try {
28
- if (!rt()) return;
29
- await G(`./node_modules/.bin/prettier --write "${s}"`), i.info(`Formatted ${s} with Prettier`);
28
+ if (!ct()) return;
29
+ await M(`./node_modules/.bin/prettier --write "${a}"`), i.info(`Formatted ${a} with Prettier`);
30
30
  } catch (g) {
31
- i.error(`Error formatting ${s} with Prettier:`, g);
31
+ i.error(`Error formatting ${a} with Prettier:`, g);
32
32
  }
33
33
  }
34
- async function Pt() {
35
- const s = new X();
36
- s.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
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
37
  const g = {
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, a) => {
44
- const { default: r } = await g[n], f = tt(r, a);
43
+ }, S = async (n, r) => {
44
+ const { default: c } = await g[n], f = et(c, r);
45
45
  return { fileName: n, content: f };
46
- }, P = async () => {
46
+ }, v = async () => {
47
47
  const n = o(process.cwd(), ".saltyrc");
48
48
  return await p(n, "utf-8").then(JSON.parse).catch(() => ({}));
49
49
  }, F = async (n = o(process.cwd(), "package.json")) => {
50
- const a = await p(n, "utf-8").then(JSON.parse).catch(() => {
50
+ const r = await p(n, "utf-8").then(JSON.parse).catch(() => {
51
51
  });
52
- if (!a) throw "Could not read package.json file!";
53
- return a;
54
- }, M = async () => {
52
+ if (!r) throw "Could not read package.json file!";
53
+ return r;
54
+ }, V = async () => {
55
55
  const n = new URL("../package.json", import.meta.url);
56
56
  return F(n);
57
- }, R = await (async () => (await P()).defaultProject)(), j = await M(), $ = {
57
+ }, q = await (async () => (await v()).defaultProject)(), j = await V(), $ = {
58
58
  core: `@salty-css/core@${j.version}`,
59
59
  react: `@salty-css/react@${j.version}`,
60
60
  eslintPluginCore: `@salty-css/eslint-plugin-core@${j.version}`,
61
61
  vite: `@salty-css/vite@${j.version}`,
62
62
  next: `@salty-css/next@${j.version}`
63
- }, O = (n) => {
64
- const a = n === "." ? "" : n, r = process.cwd();
65
- return o(r, a);
63
+ }, U = (n) => {
64
+ const r = n === "." ? "" : n, c = process.cwd();
65
+ return o(c, r);
66
66
  };
67
- s.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 = ".") {
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
68
  if (!await F().catch(() => {
69
- })) return v("Salty CSS project must be initialized in a directory with a package.json file.");
69
+ })) return P("Salty CSS project must be initialized in a directory with a package.json file.");
70
70
  i.info("Initializing a new Salty-CSS project!");
71
- const { dir: r = n, cssFile: f, skipInstall: m } = this.opts();
72
- if (!r) return v("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
73
- m || (await k($.core, $.react), await k(`-D ${$.eslintPluginCore}`));
74
- const y = process.cwd(), e = O(r), J = await Promise.all([S("salty.config.ts"), S("saltygen/index.css")]);
75
- await z(e, { recursive: !0 });
76
- const N = J.map(async ({ fileName: t, content: l }) => {
77
- const d = o(e, t);
78
- if (await p(d, "utf-8").catch(() => {
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(() => {
79
79
  }) !== void 0) {
80
- i.debug("File already exists: " + d);
80
+ i.debug("File already exists: " + s);
81
81
  return;
82
82
  }
83
- const x = t.split("/").slice(0, -1).join("/");
84
- x && await z(o(e, x), { recursive: !0 }), i.info("Creating file: " + d), await h(d, l), await I(d);
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);
85
85
  });
86
- await Promise.all(N);
87
- const b = T(y, e) || ".", c = o(y, ".saltyrc"), w = await p(c, "utf-8").catch(() => {
86
+ await Promise.all(E);
87
+ const b = O(m, e) || ".", l = o(m, ".saltyrc"), y = await p(l, "utf-8").catch(() => {
88
88
  });
89
- if (w === void 0) {
90
- i.info("Creating file: " + c);
91
- const l = JSON.stringify({
89
+ if (y === void 0) {
90
+ i.info("Creating file: " + l);
91
+ const d = JSON.stringify({
92
92
  defaultProject: b,
93
93
  projects: [b]
94
94
  }, null, 2);
95
- await h(c, l);
95
+ await w(l, d);
96
96
  } else {
97
- i.info("Edit file: " + c);
98
- const t = JSON.parse(w), l = new Set((t == null ? void 0 : t.projects) || []);
99
- l.add(b), t.projects = [...l];
100
- const d = JSON.stringify(t, null, 2);
101
- await h(c, d);
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);
102
102
  }
103
- const A = o(y, ".gitignore"), D = await p(A, "utf-8").catch(() => {
103
+ const L = o(m, ".gitignore"), D = await p(L, "utf-8").catch(() => {
104
104
  });
105
- D !== void 0 && (D.includes("saltygen") || (i.info("Edit file: " + A), await h(A, D + `
105
+ D !== void 0 && (D.includes("saltygen") || (i.info("Edit file: " + L), await w(L, D + `
106
106
 
107
107
  # Salty-CSS
108
108
  saltygen
109
109
  `)));
110
- const _ = ["src", "public", "assets", "styles", "css", "app"], V = ["styles", "css", "app", "pages"], K = ["index", "styles", "main", "global", "globals"], Q = [".css", ".scss", ".sass"], W = await (async () => {
110
+ const z = ["src", "public", "assets", "styles", "css", "app"], K = ["styles", "css", "app", "pages"], Q = ["index", "styles", "main", "global", "globals"], X = [".css", ".scss", ".sass"], B = await (async () => {
111
111
  if (f) return f;
112
- for (const t of _)
113
- for (const l of K)
114
- for (const d of Q) {
115
- const u = o(e, t, l + d);
116
- if (await p(u, "utf-8").catch(() => {
117
- }) !== void 0) return T(e, u);
118
- for (const C of V) {
119
- const q = o(e, t, C, l + d);
120
- if (await p(q, "utf-8").catch(() => {
121
- }) !== void 0) return T(e, q);
112
+ for (const t of z)
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);
122
122
  }
123
123
  }
124
124
  })();
125
- if (W) {
126
- const t = o(e, W), l = await p(t, "utf-8").catch(() => {
125
+ if (B) {
126
+ const t = o(e, B), d = await p(t, "utf-8").catch(() => {
127
127
  });
128
- if (l !== void 0 && !l.includes("saltygen")) {
129
- const u = o(t, ".."), C = `@import '${T(u, o(e, "saltygen/index.css"))}';`;
130
- i.info("Adding global import statement to CSS file: " + t), await h(t, C + `
131
- ` + l), await I(t);
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);
132
132
  }
133
133
  } else
134
134
  i.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
135
- const E = o(e, "vite.config.ts"), U = await p(E, "utf-8").catch(() => {
135
+ const T = o(e, "vite.config.ts"), H = await p(T, "utf-8").catch(() => {
136
136
  });
137
- if (U !== void 0 && !U.includes("saltyPlugin")) {
138
- i.info("Edit file: " + E);
139
- const l = `import { saltyPlugin } from '@salty-css/vite';
140
- `, u = U.replace(/(plugins: \[)/, `$1
137
+ if (H !== void 0 && !H.includes("saltyPlugin")) {
138
+ i.info("Edit file: " + T);
139
+ const d = `import { saltyPlugin } from '@salty-css/vite';
140
+ `, h = H.replace(/(plugins: \[)/, `$1
141
141
  saltyPlugin(__dirname),`);
142
- m || await k(`-D ${$.vite}`), i.info("Adding Salty-CSS plugin to Vite config..."), await h(E, l + u), await I(E);
142
+ u || await k(`-D ${$.vite}`), i.info("Adding Salty-CSS plugin to Vite config..."), await w(T, d + h), await A(T);
143
143
  }
144
- const L = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((t) => o(e, t)).find((t) => B(t));
145
- if (L) {
146
- let t = await p(L, "utf-8").catch(() => {
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(() => {
147
147
  });
148
148
  if (t !== void 0 && !t.includes("withSaltyCss")) {
149
- const d = t.includes("module.exports"), u = d ? `const { withSaltyCss } = require('@salty-css/next');
149
+ let s = !1;
150
+ /plugins[^=]*=/.test(t) && !s && (t = t.replace(/plugins([^=]*)=/, (J, x) => `plugins${x}= [withSaltyCss,`), s = !0);
151
+ const C = t.includes("module.exports"), I = C ? `const { withSaltyCss } = require('@salty-css/next');
150
152
  ` : `import { withSaltyCss } from '@salty-css/next';
151
153
  `;
152
- d ? t = t.replace(/module.exports = ([^;]+)/, (x, C) => `module.exports = withSaltyCss(${C})`) : t = t.replace(/export default ([^;]+)/, (x, C) => `export default withSaltyCss(${C})`), m || await k(`-D ${$.next}`), i.info("Adding Salty-CSS plugin to Next.js config..."), await h(L, u + t), await I(L);
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(_);
153
155
  }
154
156
  }
155
- }), s.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 = R) {
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) {
156
158
  i.info("Building the Salty-CSS project...");
157
- const { dir: a = n } = this.opts();
158
- if (!a) return v("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
159
- const r = O(a);
160
- await et(r);
161
- }), s.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, a = R) {
162
- const { file: r = n, dir: f = a, tag: m, name: y, className: e } = this.opts();
163
- if (!r) return v("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
164
- if (!f) return v("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
165
- const J = O(f), N = r.split("/").slice(0, -1).join("/");
166
- N && await z(o(J, N), { recursive: !0 });
167
- const b = o(J, r), c = Y(b);
168
- c.ext || (c.ext = ".ts"), c.name.endsWith(".css") || (c.name = c.name + ".css"), c.base = c.name + c.ext;
169
- const w = Z(c);
170
- if (await p(w, "utf-8").catch(() => {
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);
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
173
  }) !== void 0) {
172
- i.error("File already exists:", w);
174
+ i.error("File already exists:", y);
173
175
  return;
174
176
  }
175
- i.info("Generating a new file: " + w);
176
- const D = nt(y || c.base.replace(/\.css\.\w+$/, "")), { content: _ } = await S("react/react-styled-file.ts", { tag: m, name: D, className: e });
177
- await h(w, _), await I(w);
178
- }), s.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() {
179
- const { legacyPeerDeps: n } = this.opts(), a = o(process.cwd(), "package.json"), r = await F(a).catch((e) => v(e));
180
- if (!r) return;
181
- const f = { ...r.dependencies, ...r.devDependencies }, m = Object.keys(f).filter((e) => e === "salty-css" || e.startsWith("@salty-css/"));
182
- if (!m.length)
183
- return v(
184
- "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + a
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
185
187
  );
186
- const y = m.map((e) => `${e}@${j.version}`);
187
- n ? (i.warn("Using legacy peer dependencies to update packages."), await k(...y, "--legacy-peer-deps")) : await k(...y), i.info("Salty-CSS packages updated successfully!");
188
- }), s.parseAsync(process.argv);
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);
189
191
  }
190
192
  export {
191
- Pt as main
193
+ vt as main
192
194
  };
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("esbuild"),B=require("child_process"),P=require("../dash-case-DKzpenwY.cjs"),o=require("path"),r=require("fs"),K=require("fs/promises"),V=require("../parse-templates-W0YfTmOT.cjs");function G(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const R=G(I),N=t=>o.join(t,"./saltygen"),_=["salty","css","styles","styled"],q=(t=[])=>new RegExp(`\\.(${[..._,...t].join("|")})\\.`),O=(t,e=[])=>q(e).test(t),J=async t=>{const e=N(t),n=o.join(t,"salty.config.ts"),s=o.join(e,"salty.config.js");await R.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",external:["react"]});const a=Date.now(),{config:w}=await import(`${s}?t=${a}`);return w},M=async t=>{const e=await J(t),n=new Set,s=(d,y=[])=>d?Object.entries(d).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return s(c,[...y,p]);const C=[...y,p].join(".");n.add(`"${C}"`);const x=[...y.map(P.dashCase),P.dashCase(p)].join("-"),{result:D}=V.parseValueTokens(c);return`--${x}: ${D};`}):[],a=d=>d?Object.entries(d).flatMap(([y,p])=>{const c=s(p);return y==="base"?c.join(""):`${y} { ${c.join("")} }`}):[],w=d=>d?Object.entries(d).flatMap(([y,p])=>Object.entries(p).flatMap(([c,C])=>{const x=s(C,[y]),D=`.${y}-${c}, [data-${y}="${c}"]`,k=x.join("");return`${D} { ${k} }`})):[],j=s(e.variables),S=a(e.responsiveVariables),l=w(e.conditionalVariables),b=N(t),f=o.join(b,"css/variables.css"),i=`:root { ${j.join("")} ${S.join("")} } ${l.join("")}`;r.writeFileSync(f,i);const g=o.join(b,"types/css-tokens.d.ts"),m=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;r.writeFileSync(g,m);const u=o.join(b,"css/global.css"),h=V.parseStyles(e.global,"");r.writeFileSync(u,h);const F=o.join(b,"css/templates.css"),v=V.parseTemplates(e.templates);r.writeFileSync(F,v)},T=async(t,e)=>{const n=P.toHash(t),s=o.join(e,"js",n+".js");await R.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const a=Date.now();return await import(`${s}?t=${a}`)},E=async t=>{const e=N(t),n=o.join(e,"salty.config.js"),{config:s}=await import(n);return s},A=async t=>{try{const e=[],n=[],s=N(t),a=o.join(s,"index.css");(()=>{r.existsSync(s)&&B.execSync("rm -rf "+s),r.mkdirSync(s),r.mkdirSync(o.join(s,"css")),r.mkdirSync(o.join(s,"types"))})(),await M(t);const j=await E(t);async function S(i,g){const $=r.statSync(i);if($.isDirectory()){const m=r.readdirSync(i);await Promise.all(m.map(u=>S(o.join(i,u),o.join(g,u))))}else if($.isFile()&&O(i)){const u=await T(i,s),h=[];Object.entries(u).forEach(([y,p])=>{if(p.isKeyframes&&p.css){const k=`${p.animationName}.css`,z=`css/${k}`,H=o.join(s,z);e.push(k),r.writeFileSync(H,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:y,config:j}),C=`${c.hash}-${c.priority}.css`;n[c.priority]||(n[c.priority]=[]),n[c.priority].push(C),h.push(C);const x=`css/${C}`,D=o.join(s,x);r.writeFileSync(D,c.css)});const F=h.map(y=>`@import url('./${y}');`).join(`
2
- `),v=P.toHash(i,6),d=o.join(s,`css/${v}.css`);r.writeFileSync(d,F)}}await S(t,s);const l=e.map(i=>`@import url('./css/${i}');`).join(`
3
- `);let f=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("esbuild"),H=require("child_process"),N=require("../dash-case-DKzpenwY.cjs"),i=require("path"),l=require("fs"),K=require("fs/promises"),V=require("../parse-templates-W0YfTmOT.cjs");function G(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const e=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(s,n,e.get?e:{enumerable:!0,get:()=>t[n]})}}return s.default=t,Object.freeze(s)}const _=G(I),O=t=>i.join(t,"./saltygen"),q=["salty","css","styles","styled"],M=(t=[])=>new RegExp(`\\.(${[...q,...t].join("|")})\\.`),E=(t,s=[])=>M(s).test(t),J=async t=>{const s=O(t),n=i.join(t,"salty.config.ts"),e=i.join(s,"salty.config.js");await _.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:e,format:"esm",external:["react"]});const p=Date.now(),{config:C}=await import(`${e}?t=${p}`);return C},z=async t=>{const s=await J(t),n=new Set,e=(f,y=[])=>f?Object.entries(f).flatMap(([a,r])=>{if(!r)return;if(typeof r=="object")return e(r,[...y,a]);const F=[...y,a].join(".");n.add(`"${F}"`);const x=[...y.map(N.dashCase),N.dashCase(a)].join("-"),{result:D}=V.parseValueTokens(r);return`--${x}: ${D};`}):[],p=f=>f?Object.entries(f).flatMap(([y,a])=>{const r=e(a);return y==="base"?r.join(""):`${y} { ${r.join("")} }`}):[],C=f=>f?Object.entries(f).flatMap(([y,a])=>Object.entries(a).flatMap(([r,F])=>{const x=e(F,[y]),D=`.${y}-${r}, [data-${y}="${r}"]`,P=x.join("");return`${D} { ${P} }`})):[],b=e(s.variables),w=p(s.responsiveVariables),o=C(s.conditionalVariables),S=O(t),u=i.join(S,"css/variables.css"),c=`:root { ${b.join("")} ${w.join("")} } ${o.join("")}`;l.writeFileSync(u,c);const g=i.join(S,"types/css-tokens.d.ts"),m=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;l.writeFileSync(g,m);const d=i.join(S,"css/global.css"),h=V.parseStyles(s.global,"");l.writeFileSync(d,h);const j=i.join(S,"css/templates.css"),k=V.parseTemplates(s.templates);l.writeFileSync(j,k)},v=async(t,s)=>{const n=N.toHash(t),e=i.join(s,"js",n+".js");await _.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:e,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const p=Date.now();return await import(`${e}?t=${p}`)},R=async t=>{const s=O(t),n=i.join(s,"salty.config.js"),{config:e}=await import(n);return e},A=async t=>{try{const s=[],n=[],e=O(t),p=i.join(e,"index.css");(()=>{l.existsSync(e)&&H.execSync("rm -rf "+e),l.mkdirSync(e),l.mkdirSync(i.join(e,"css")),l.mkdirSync(i.join(e,"types"))})(),await z(t);const b=await R(t);async function w(c,g){const $=l.statSync(c);if($.isDirectory()){const m=l.readdirSync(c);await Promise.all(m.map(d=>w(i.join(c,d),i.join(g,d))))}else if($.isFile()&&E(c)){const d=await v(c,e),h=[];Object.entries(d).forEach(([y,a])=>{if(a.isKeyframes&&a.css){const P=`${a.animationName}.css`,T=`css/${P}`,B=i.join(e,T);s.push(P),l.writeFileSync(B,a.css);return}if(!a.generator)return;const r=a.generator._withBuildContext({name:y,config:b}),F=`${r.hash}-${r.priority}.css`;n[r.priority]||(n[r.priority]=[]),n[r.priority].push(F),h.push(F);const x=`css/${F}`,D=i.join(e,x);l.writeFileSync(D,r.css)});const j=h.map(y=>`@import url('./${y}');`).join(`
2
+ `),k=N.toHash(c,6),f=i.join(e,`css/${k}.css`);l.writeFileSync(f,j)}}await w(t,e);const o=s.map(c=>`@import url('./css/${c}');`).join(`
3
+ `);let u=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
4
4
 
5
5
  ${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
6
6
  `)}
7
- ${l}`;if(j.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
8
- `);f+=i}r.writeFileSync(a,f)}catch(e){console.error(e)}},L=async(t,e)=>{try{const n=[],s=o.join(t,"./saltygen"),a=o.join(s,"index.css");if(O(e)){const j=await E(t),S=await T(e,s);Object.entries(S).forEach(([g,$])=>{if(!$.generator)return;const m=$.generator._withBuildContext({name:g,config:j}),u=`${m.hash}-${m.priority}.css`,h=`css/${u}`,F=o.join(s,h);n.push(u),r.writeFileSync(F,m.css)});const l=r.readFileSync(a,"utf8").split(`
9
- `),b=n.map(g=>`@import url('../saltygen/css/${g}');`),i=[...new Set([...l,...b])].join(`
10
- `);r.writeFileSync(a,i)}}catch(n){console.error(n)}},U=async(t,e)=>{try{const n=o.join(t,"./saltygen");if(O(e)){const a=r.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==a&&await K.writeFile(e,a);const j=await E(t),S=await T(e,n);let l=a;Object.entries(S).forEach(([f,i])=>{var F;if(i.isKeyframes||!i.generator)return;const g=i.generator._withBuildContext({name:f,config:j}),$=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const m=(F=$.at(1))==null?void 0:F.trim(),u=`${f} = styled(${m}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`,h=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`,"gm");l=l.replace(h,u)});const b=P.toHash(e,6);return j.importStrategy==="component"&&(l=`import '../../saltygen/css/${b}.css';
11
- ${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error("Error in minimizeFile",n)}};exports.compileSaltyFile=T;exports.generateConfigStyles=M;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=O;exports.minimizeFile=U;exports.saltyFileExtensions=_;exports.saltyFileRegExp=q;
7
+ ${o}`;if(b.importStrategy!=="component"){const c=n.flat().map(g=>`@import url('./css/${g}');`).join(`
8
+ `);u+=c}l.writeFileSync(p,u)}catch(s){console.error(s)}},L=async(t,s)=>{try{const n=[],e=i.join(t,"./saltygen"),p=i.join(e,"index.css");if(E(s)){const b=await R(t),w=await v(s,e);Object.entries(w).forEach(([g,$])=>{if(!$.generator)return;const m=$.generator._withBuildContext({name:g,config:b}),d=`${m.hash}-${m.priority}.css`,h=`css/${d}`,j=i.join(e,h);n.push(d),l.writeFileSync(j,m.css)});const o=l.readFileSync(p,"utf8").split(`
9
+ `),S=n.map(g=>`@import url('../saltygen/css/${g}');`),c=[...new Set([...o,...S])].join(`
10
+ `);l.writeFileSync(p,c)}}catch(n){console.error(n)}},U=async(t,s)=>{try{const n=i.join(t,"./saltygen");if(E(s)){const p=l.readFileSync(s,"utf8");p.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==p&&await K.writeFile(s,p);const b=await R(t),w=await v(s,n);let o=p;Object.entries(w).forEach(([u,c])=>{var P;if(c.isKeyframes||!c.generator)return;const g=c.generator._withBuildContext({name:u,config:b}),$=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(p);if(!$)return console.error("Could not find the original declaration");const m=(P=$.at(1))==null?void 0:P.trim(),d=new RegExp(`${u}[=\\s]+styled\\(`,"g").exec(o);if(!d)return console.error("Could not find the original declaration");const{index:h}=d;let j=!1;const k=setTimeout(()=>j=!0,5e3);let f=0,y=!1,a=0;for(;!y&&!j;){const T=o[h+f];T==="("&&a++,T===")"&&a--,a===0&&T===")"&&(y=!0),f>o.length&&(j=!0),f++}if(!j)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const r=h+f,F=o.slice(h,r),x=o,D=`${u} = styled(${m}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`;o=o.replace(F,D),x===o&&console.error("Minimize file failed to change content",{name:u,tagName:m})});const S=N.toHash(s,6);return b.importStrategy==="component"&&(o=`import '../../saltygen/css/${S}.css';
11
+ ${o}`),o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=v;exports.generateConfigStyles=z;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=E;exports.minimizeFile=U;exports.saltyFileExtensions=q;exports.saltyFileRegExp=M;
package/compiler/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import * as I from "esbuild";
2
2
  import { execSync as z } from "child_process";
3
- import { t as T, d as R } from "../dash-case-DMQMcCO6.js";
4
- import { join as o } from "path";
3
+ import { t as E, d as B } from "../dash-case-DMQMcCO6.js";
4
+ import { join as i } from "path";
5
5
  import { writeFileSync as $, existsSync as H, mkdirSync as V, statSync as K, readdirSync as G, readFileSync as M } from "fs";
6
6
  import { writeFile as J } from "fs/promises";
7
7
  import { p as q, a as A, b as L } from "../parse-templates-D4p3pgQR.js";
8
- const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W = (s = []) => new RegExp(`\\.(${[...U, ...s].join("|")})\\.`), v = (s, e = []) => W(e).test(s), X = async (s) => {
9
- const e = N(s), n = o(s, "salty.config.ts"), t = o(e, "salty.config.js");
8
+ const T = (s) => i(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W = (s = []) => new RegExp(`\\.(${[...U, ...s].join("|")})\\.`), v = (s, e = []) => W(e).test(s), X = async (s) => {
9
+ const e = T(s), n = i(s, "salty.config.ts"), t = i(e, "salty.config.js");
10
10
  await I.build({
11
11
  entryPoints: [n],
12
12
  minify: !0,
@@ -16,32 +16,32 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
16
16
  format: "esm",
17
17
  external: ["react"]
18
18
  });
19
- const c = Date.now(), { config: S } = await import(`${t}?t=${c}`);
20
- return S;
19
+ const p = Date.now(), { config: x } = await import(`${t}?t=${p}`);
20
+ return x;
21
21
  }, Y = async (s) => {
22
- const e = await X(s), n = /* @__PURE__ */ new Set(), t = (u, l = []) => u ? Object.entries(u).flatMap(([p, r]) => {
22
+ const e = await X(s), n = /* @__PURE__ */ new Set(), t = (f, l = []) => f ? Object.entries(f).flatMap(([a, r]) => {
23
23
  if (!r) return;
24
- if (typeof r == "object") return t(r, [...l, p]);
25
- const x = [...l, p].join(".");
26
- n.add(`"${x}"`);
27
- const C = [...l.map(R), R(p)].join("-"), { result: D } = L(r);
24
+ if (typeof r == "object") return t(r, [...l, a]);
25
+ const S = [...l, a].join(".");
26
+ n.add(`"${S}"`);
27
+ const C = [...l.map(B), B(a)].join("-"), { result: D } = L(r);
28
28
  return `--${C}: ${D};`;
29
- }) : [], c = (u) => u ? Object.entries(u).flatMap(([l, p]) => {
30
- const r = t(p);
29
+ }) : [], p = (f) => f ? Object.entries(f).flatMap(([l, a]) => {
30
+ const r = t(a);
31
31
  return l === "base" ? r.join("") : `${l} { ${r.join("")} }`;
32
- }) : [], S = (u) => u ? Object.entries(u).flatMap(([l, p]) => Object.entries(p).flatMap(([r, x]) => {
33
- const C = t(x, [l]), D = `.${l}-${r}, [data-${l}="${r}"]`, P = C.join("");
32
+ }) : [], x = (f) => f ? Object.entries(f).flatMap(([l, a]) => Object.entries(a).flatMap(([r, S]) => {
33
+ const C = t(S, [l]), D = `.${l}-${r}, [data-${l}="${r}"]`, P = C.join("");
34
34
  return `${D} { ${P} }`;
35
- })) : [], d = t(e.variables), w = c(e.responsiveVariables), a = S(e.conditionalVariables), b = N(s), f = o(b, "css/variables.css"), i = `:root { ${d.join("")} ${w.join("")} } ${a.join("")}`;
36
- $(f, i);
37
- const y = o(b, "types/css-tokens.d.ts"), g = `type VariableTokens = ${[...n].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
38
- $(y, g);
39
- const m = o(b, "css/global.css"), F = q(e.global, "");
40
- $(m, F);
41
- const j = o(b, "css/templates.css"), k = A(e.templates);
42
- $(j, k);
43
- }, E = async (s, e) => {
44
- const n = T(s), t = o(e, "js", n + ".js");
35
+ })) : [], b = t(e.variables), j = p(e.responsiveVariables), o = x(e.conditionalVariables), w = T(s), y = i(w, "css/variables.css"), c = `:root { ${b.join("")} ${j.join("")} } ${o.join("")}`;
36
+ $(y, c);
37
+ const m = i(w, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...n].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
38
+ $(m, u);
39
+ const g = i(w, "css/global.css"), d = q(e.global, "");
40
+ $(g, d);
41
+ const h = i(w, "css/templates.css"), k = A(e.templates);
42
+ $(h, k);
43
+ }, O = async (s, e) => {
44
+ const n = E(s), t = i(e, "js", n + ".js");
45
45
  await I.build({
46
46
  entryPoints: [s],
47
47
  minify: !0,
@@ -53,113 +53,124 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
53
53
  keepNames: !0,
54
54
  external: ["react"]
55
55
  });
56
- const c = Date.now();
57
- return await import(`${t}?t=${c}`);
58
- }, O = async (s) => {
59
- const e = N(s), n = o(e, "salty.config.js"), { config: t } = await import(n);
56
+ const p = Date.now();
57
+ return await import(`${t}?t=${p}`);
58
+ }, R = async (s) => {
59
+ const e = T(s), n = i(e, "salty.config.js"), { config: t } = await import(n);
60
60
  return t;
61
61
  }, ot = async (s) => {
62
62
  try {
63
- const e = [], n = [], t = N(s), c = o(t, "index.css");
63
+ const e = [], n = [], t = T(s), p = i(t, "index.css");
64
64
  (() => {
65
- H(t) && z("rm -rf " + t), V(t), V(o(t, "css")), V(o(t, "types"));
65
+ H(t) && z("rm -rf " + t), V(t), V(i(t, "css")), V(i(t, "types"));
66
66
  })(), await Y(s);
67
- const d = await O(s);
68
- async function w(i, y) {
69
- const h = K(i);
70
- if (h.isDirectory()) {
71
- const g = G(i);
72
- await Promise.all(g.map((m) => w(o(i, m), o(y, m))));
73
- } else if (h.isFile() && v(i)) {
74
- const m = await E(i, t), F = [];
75
- Object.entries(m).forEach(([l, p]) => {
76
- if (p.isKeyframes && p.css) {
77
- const P = `${p.animationName}.css`, _ = `css/${P}`, B = o(t, _);
78
- e.push(P), $(B, p.css);
67
+ const b = await R(s);
68
+ async function j(c, m) {
69
+ const F = K(c);
70
+ if (F.isDirectory()) {
71
+ const u = G(c);
72
+ await Promise.all(u.map((g) => j(i(c, g), i(m, g))));
73
+ } else if (F.isFile() && v(c)) {
74
+ const g = await O(c, t), d = [];
75
+ Object.entries(g).forEach(([l, a]) => {
76
+ if (a.isKeyframes && a.css) {
77
+ const P = `${a.animationName}.css`, N = `css/${P}`, _ = i(t, N);
78
+ e.push(P), $(_, a.css);
79
79
  return;
80
80
  }
81
- if (!p.generator) return;
82
- const r = p.generator._withBuildContext({
81
+ if (!a.generator) return;
82
+ const r = a.generator._withBuildContext({
83
83
  name: l,
84
- config: d
85
- }), x = `${r.hash}-${r.priority}.css`;
86
- n[r.priority] || (n[r.priority] = []), n[r.priority].push(x), F.push(x);
87
- const C = `css/${x}`, D = o(t, C);
84
+ config: b
85
+ }), S = `${r.hash}-${r.priority}.css`;
86
+ n[r.priority] || (n[r.priority] = []), n[r.priority].push(S), d.push(S);
87
+ const C = `css/${S}`, D = i(t, C);
88
88
  $(D, r.css);
89
89
  });
90
- const j = F.map((l) => `@import url('./${l}');`).join(`
91
- `), k = T(i, 6), u = o(t, `css/${k}.css`);
92
- $(u, j);
90
+ const h = d.map((l) => `@import url('./${l}');`).join(`
91
+ `), k = E(c, 6), f = i(t, `css/${k}.css`);
92
+ $(f, h);
93
93
  }
94
94
  }
95
- await w(s, t);
96
- const a = e.map((i) => `@import url('./css/${i}');`).join(`
95
+ await j(s, t);
96
+ const o = e.map((c) => `@import url('./css/${c}');`).join(`
97
97
  `);
98
- let f = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
98
+ let y = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
99
99
 
100
100
  ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
101
101
  `)}
102
- ${a}`;
103
- if (d.importStrategy !== "component") {
104
- const i = n.flat().map((y) => `@import url('./css/${y}');`).join(`
102
+ ${o}`;
103
+ if (b.importStrategy !== "component") {
104
+ const c = n.flat().map((m) => `@import url('./css/${m}');`).join(`
105
105
  `);
106
- f += i;
106
+ y += c;
107
107
  }
108
- $(c, f);
108
+ $(p, y);
109
109
  } catch (e) {
110
110
  console.error(e);
111
111
  }
112
112
  }, it = async (s, e) => {
113
113
  try {
114
- const n = [], t = o(s, "./saltygen"), c = o(t, "index.css");
114
+ const n = [], t = i(s, "./saltygen"), p = i(t, "index.css");
115
115
  if (v(e)) {
116
- const d = await O(s), w = await E(e, t);
117
- Object.entries(w).forEach(([y, h]) => {
118
- if (!h.generator) return;
119
- const g = h.generator._withBuildContext({
120
- name: y,
121
- config: d
122
- }), m = `${g.hash}-${g.priority}.css`, F = `css/${m}`, j = o(t, F);
123
- n.push(m), $(j, g.css);
116
+ const b = await R(s), j = await O(e, t);
117
+ Object.entries(j).forEach(([m, F]) => {
118
+ if (!F.generator) return;
119
+ const u = F.generator._withBuildContext({
120
+ name: m,
121
+ config: b
122
+ }), g = `${u.hash}-${u.priority}.css`, d = `css/${g}`, h = i(t, d);
123
+ n.push(g), $(h, u.css);
124
124
  });
125
- const a = M(c, "utf8").split(`
126
- `), b = n.map((y) => `@import url('../saltygen/css/${y}');`), i = [.../* @__PURE__ */ new Set([...a, ...b])].join(`
125
+ const o = M(p, "utf8").split(`
126
+ `), w = n.map((m) => `@import url('../saltygen/css/${m}');`), c = [.../* @__PURE__ */ new Set([...o, ...w])].join(`
127
127
  `);
128
- $(c, i);
128
+ $(p, c);
129
129
  }
130
130
  } catch (n) {
131
131
  console.error(n);
132
132
  }
133
133
  }, rt = async (s, e) => {
134
134
  try {
135
- const n = o(s, "./saltygen");
135
+ const n = i(s, "./saltygen");
136
136
  if (v(e)) {
137
- const c = M(e, "utf8");
138
- c.replace(/^(?!export\s)const\s.*/gm, (f) => `export ${f}`) !== c && await J(e, c);
139
- const d = await O(s), w = await E(e, n);
140
- let a = c;
141
- Object.entries(w).forEach(([f, i]) => {
142
- var j;
143
- if (i.isKeyframes || !i.generator) return;
144
- const y = i.generator._withBuildContext({
145
- name: f,
146
- config: d
147
- }), h = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
148
- if (!h)
149
- return console.error("Could not find the original declaration");
150
- const g = (j = h.at(1)) == null ? void 0 : j.trim(), m = `${f} = styled(${g}, "${y.classNames}", "${y._callerName}", ${JSON.stringify(y.props)});`, F = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`, "gm");
151
- a = a.replace(F, m);
137
+ const p = M(e, "utf8");
138
+ p.replace(/^(?!export\s)const\s.*/gm, (y) => `export ${y}`) !== p && await J(e, p);
139
+ const b = await R(s), j = await O(e, n);
140
+ let o = p;
141
+ Object.entries(j).forEach(([y, c]) => {
142
+ var P;
143
+ if (c.isKeyframes || !c.generator) return;
144
+ const m = c.generator._withBuildContext({
145
+ name: y,
146
+ config: b
147
+ }), F = new RegExp(`${y}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(p);
148
+ if (!F) return console.error("Could not find the original declaration");
149
+ const u = (P = F.at(1)) == null ? void 0 : P.trim(), g = new RegExp(`${y}[=\\s]+styled\\(`, "g").exec(o);
150
+ if (!g) return console.error("Could not find the original declaration");
151
+ const { index: d } = g;
152
+ let h = !1;
153
+ const k = setTimeout(() => h = !0, 5e3);
154
+ let f = 0, l = !1, a = 0;
155
+ for (; !l && !h; ) {
156
+ const N = o[d + f];
157
+ N === "(" && a++, N === ")" && a--, a === 0 && N === ")" && (l = !0), f > o.length && (h = !0), f++;
158
+ }
159
+ if (!h) clearTimeout(k);
160
+ else throw new Error("Failed to find the end of the styled call and timed out");
161
+ const r = d + f, S = o.slice(d, r), C = o, D = `${y} = styled(${u}, "${m.classNames}", "${m._callerName}", ${JSON.stringify(m.props)});`;
162
+ o = o.replace(S, D), C === o && console.error("Minimize file failed to change content", { name: y, tagName: u });
152
163
  });
153
- const b = T(e, 6);
154
- return d.importStrategy === "component" && (a = `import '../../saltygen/css/${b}.css';
155
- ${a}`), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
164
+ const w = E(e, 6);
165
+ return b.importStrategy === "component" && (o = `import '../../saltygen/css/${w}.css';
166
+ ${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
156
167
  }
157
168
  } catch (n) {
158
- console.error("Error in minimizeFile", n);
169
+ console.error("Error in minimizeFile:", n);
159
170
  }
160
171
  };
161
172
  export {
162
- E as compileSaltyFile,
173
+ O as compileSaltyFile,
163
174
  Y as generateConfigStyles,
164
175
  ot as generateCss,
165
176
  it as generateFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.40",
3
+ "version": "0.0.1-alpha.42",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",