@salty-css/core 0.0.1-alpha.5 → 0.0.1-alpha.50

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/README.md CHANGED
@@ -1,15 +1,62 @@
1
- # Salty Css
1
+ # Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
2
2
 
3
- ## Basic usage example with Button
3
+ In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
4
4
 
5
- ### Initial requirements
5
+ ## Features
6
6
 
7
- 1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
- 2. Create `salty-config.ts` to the root of your project
9
- 3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
- 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
7
+ - Build time compilation to achieve awesome runtime performance and minimal size
8
+ - Next.js, React Server Components, Vite and Webpack support
9
+ - Type safety with out of the box TypeScript and ESLint plugin
10
+ - Advanced CSS variables configuration to allow smooth token usage
11
+ - Style templates to create reusable styles easily
11
12
 
12
- ### Code examples
13
+ ## Get started
14
+
15
+ ### TL;DR
16
+
17
+ - Initialize: `npx salty-css init [directory]`
18
+ - Create component: `npx salty-css generate [filePath]`
19
+ - Build: `npx salty-css build [directory]`
20
+
21
+ ### Quick way of using `salty-css` CLI
22
+
23
+ #### Initialize Salty CSS for a project
24
+
25
+ In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. Init will also create `.saltyrc` which contains some metadata for future CLI commands.
26
+
27
+ #### Create components
28
+
29
+ Components can be created with `npx salty-css generate [filePath]` which then creates a new Salty CSS component file to the specified path. Additional options like `--dir, --tag, --name and --className` are also supported. Read more about them with `npx salty-css generate --help`
30
+
31
+ #### Build / Compile Salty CSS
32
+
33
+ If you want to manually build your project that can be done by running `npx salty-css build [directory]`. Directory is not required as CLI can use default directory defined in `.saltyrc`. Note that build generates css files but Vite / Webpack plugin is still required for full support.
34
+
35
+ #### Update Salty CSS packages
36
+
37
+ To ease the pain of package updates all Salty CSS packages can be updated with `npx salty-css update`
38
+
39
+ ### Manual work
40
+
41
+ #### React
42
+
43
+ 1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
44
+ 2. Create `salty.config.ts` to your app directory
45
+
46
+ #### Vite
47
+
48
+ 1. First check the instructions for React
49
+ 2. For Vite support install `npm i -D @salty-css/vite`
50
+ 3. In `vite.config.ts` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
51
+ 4. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
52
+
53
+ ### Create components
54
+
55
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
56
+
57
+ ## Code examples
58
+
59
+ ### Basic usage example with Button
13
60
 
14
61
  **Salty config**
15
62
 
@@ -54,8 +101,10 @@ export const IndexPage = () => {
54
101
  import { styled } from '@salty-css/react/styled';
55
102
 
56
103
  export const Wrapper = styled('div', {
57
- display: 'block',
58
- padding: '2vw',
104
+ base: {
105
+ display: 'block',
106
+ padding: '2vw',
107
+ },
59
108
  });
60
109
  ```
61
110
 
@@ -65,22 +114,24 @@ export const Wrapper = styled('div', {
65
114
  import { styled } from '@salty-css/react/styled';
66
115
 
67
116
  export const Button = styled('button', {
68
- display: 'block',
69
- padding: `0.6em 1.2em`,
70
- border: '1px solid currentColor',
71
- background: 'transparent',
72
- color: 'currentColor/40',
73
- cursor: 'pointer',
74
- transition: '200ms',
75
- textDecoration: 'none',
76
- '&:hover': {
77
- background: 'black',
78
- borderColor: 'black',
79
- color: 'white',
80
- },
81
- '&:disabled': {
82
- opacity: 0.25,
83
- pointerEvents: 'none',
117
+ base: {
118
+ display: 'block',
119
+ padding: `0.6em 1.2em`,
120
+ border: '1px solid currentColor',
121
+ background: 'transparent',
122
+ color: 'currentColor/40',
123
+ cursor: 'pointer',
124
+ transition: '200ms',
125
+ textDecoration: 'none',
126
+ '&:hover': {
127
+ background: 'black',
128
+ borderColor: 'black',
129
+ color: 'white',
130
+ },
131
+ '&:disabled': {
132
+ opacity: 0.25,
133
+ pointerEvents: 'none',
134
+ },
84
135
  },
85
136
  variants: {
86
137
  variant: {
@@ -0,0 +1,2 @@
1
+ export declare const execAsync: (command: string) => Promise<void>;
2
+ export declare const npmInstall: (...packages: string[]) => Promise<void>;
package/bin/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";const e=require("./main.cjs");e.main().catch(n=>console.error(n));
package/bin/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { main as r } from "./main.js";
3
+ r().catch((o) => console.error(o));
@@ -0,0 +1,2 @@
1
+ export declare const logger: import('winston').Logger;
2
+ export declare const logError: (message: string) => void;
package/bin/main.cjs ADDED
@@ -0,0 +1,10 @@
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
+
3
+ # Salty-CSS
4
+ saltygen
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
+ `:`import { withSaltyCss } from '@salty-css/next';
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.option("-v, --version","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.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function main(): Promise<void>;
package/bin/main.js ADDED
@@ -0,0 +1,206 @@
1
+ import { Command as Y } from "commander";
2
+ import { existsSync as G } from "fs";
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
+ import { render as et } from "ejs";
6
+ import { generateCss as nt } from "../compiler/index.js";
7
+ import { p as st } from "../pascal-case-BQpR5PdN.js";
8
+ import { createLogger as it, format as M, transports as ot } from "winston";
9
+ import { exec as at } from "child_process";
10
+ import rt from "ora";
11
+ const n = it({
12
+ level: "debug",
13
+ format: M.combine(M.colorize(), M.cli()),
14
+ transports: [new ot.Console({})]
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
+ });
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
+ try {
28
+ if (!ct()) return;
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
+ }
33
+ }
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
+ // Core files
39
+ "salty.config.ts": import("../salty.config-D9ANEDiH.js"),
40
+ "saltygen/index.css": import("../index-D_732b92.js"),
41
+ // React
42
+ "react/react-styled-file.ts": import("../react-styled-file-CGVf5n1B.js")
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
+ });
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
+ };
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
+ }) !== void 0) {
80
+ n.debug("File already exists: " + r);
81
+ return;
82
+ }
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
+ });
86
+ await Promise.all(u);
87
+ const I = _(p, c) || ".", l = i(p, ".saltyrc"), w = await m(l, "utf-8").catch(() => {
88
+ });
89
+ if (w === void 0) {
90
+ n.info("Creating file: " + l);
91
+ const d = JSON.stringify({
92
+ defaultProject: I,
93
+ projects: [I]
94
+ }, null, 2);
95
+ await C(l, d);
96
+ } else {
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
+ }
103
+ const L = i(p, ".gitignore"), J = await m(L, "utf-8").catch(() => {
104
+ });
105
+ J !== void 0 && (J.includes("saltygen") || (n.info("Edit file: " + L), await C(L, J + `
106
+
107
+ # Salty-CSS
108
+ saltygen
109
+ `)));
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
+ if (f) return f;
112
+ for (const t of z)
113
+ for (const d of Q)
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
+ }
123
+ }
124
+ })();
125
+ if (B) {
126
+ const t = i(c, B), d = await m(t, "utf-8").catch(() => {
127
+ });
128
+ if (d !== void 0 && !d.includes("saltygen")) {
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
+ }
133
+ } else
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
+ });
137
+ if (H !== void 0 && !H.includes("saltyPlugin")) {
138
+ n.info("Edit file: " + O);
139
+ const d = `import { saltyPlugin } from '@salty-css/vite';
140
+ `, S = H.replace(/(plugins: \[)/, `$1
141
+ saltyPlugin(__dirname),`);
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
+ }
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
+ });
148
+ if (t !== void 0 && !t.includes("withSaltyCss")) {
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
+ ` : `import { withSaltyCss } from '@salty-css/next';
153
+ `;
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
+ }
156
+ }
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
+ l.ext || (l.ext = ".ts"), l.name.endsWith(".css") || (l.name = l.name + ".css"), l.base = l.name + l.ext;
171
+ const w = tt(l);
172
+ if (await m(w, "utf-8").catch(() => {
173
+ }) !== void 0) {
174
+ n.error("File already exists:", w);
175
+ return;
176
+ }
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
+ );
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.option("-v, --version", "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);
203
+ }
204
+ export {
205
+ Pt as main
206
+ };
@@ -0,0 +1 @@
1
+ export declare function formatWithPrettier(filePath: string): Promise<void>;
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("esbuild"),B=require("winston"),K=require("child_process"),N=require("../util/index.cjs"),o=require("path"),r=require("fs"),J=require("fs/promises"),_=require("../parse-templates-BY1Xai-_.cjs");function E(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const M=E(I),k=E(B),G=k.createLogger({level:"info",format:k.format.combine(k.format.colorize(),k.format.cli()),transports:[new k.transports.Console({})]}),v=e=>o.join(e,"./saltygen"),L=["salty","css","styles","styled"],T=e=>new RegExp(`\\.(${L.join("|")})\\.`).test(e),A=async e=>{const s=v(e),n=o.join(e,"salty-config.ts"),t=o.join(s,"salty-config.js");await M.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:t,format:"esm",external:["react"]});const a=Date.now(),{config:h}=await import(`${t}?t=${a}`);return h},R=async e=>{const s=await A(e),n=new Set,t=(f,p=[])=>f?Object.entries(f).flatMap(([y,c])=>{if(!c)return;if(typeof c=="object")return t(c,[...p,y]);const C=[...p,y].join(".");n.add(`"${C}"`);const D=[...p.map(N.dashCase),N.dashCase(y)].join("-"),{result:P}=_.parseValueTokens(c);return`--${D}: ${P};`}):[],a=f=>f?Object.entries(f).flatMap(([p,y])=>{const c=t(y);return p==="base"?c.join(""):`${p} { ${c.join("")} }`}):[],h=f=>f?Object.entries(f).flatMap(([p,y])=>Object.entries(y).flatMap(([c,C])=>{const D=t(C,[p]),P=`.${p}-${c}, [data-${p}="${c}"]`,O=D.join("");return`${P} { ${O} }`})):[],b=t(s.variables),w=a(s.responsiveVariables),l=h(s.conditionalVariables),j=v(e),u=o.join(j,"css/variables.css"),i=`:root { ${b.join("")} ${w.join("")} } ${l.join("")}`;r.writeFileSync(u,i);const g=o.join(j,"types/css-tokens.d.ts"),d=`type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;r.writeFileSync(g,d);const m=o.join(j,"css/global.css"),S=_.parseStyles(s.global,"");r.writeFileSync(m,S);const F=o.join(j,"css/templates.css"),x=_.parseTemplates(s.templates);r.writeFileSync(F,x)},V=async(e,s)=>{const n=N.toHash(e),t=o.join(s,"js",n+".js");await M.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:t,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const a=Date.now();return await import(`${t}?t=${a}`)},q=async e=>{const s=v(e),n=o.join(s,"salty-config.js"),{config:t}=await import(n);return t},U=async e=>{try{const s=[],n=[],t=v(e),a=o.join(t,"index.css");(()=>{r.existsSync(t)&&K.execSync("rm -rf "+t),r.mkdirSync(t),r.mkdirSync(o.join(t,"css")),r.mkdirSync(o.join(t,"types"))})(),await R(e);const b=await q(e);async function w(i,g){const $=r.statSync(i);if($.isDirectory()){const d=r.readdirSync(i);await Promise.all(d.map(m=>w(o.join(i,m),o.join(g,m))))}else if($.isFile()&&T(i)){const m=await V(i,t),S=[];Object.entries(m).forEach(([p,y])=>{if(y.isKeyframes&&y.css){const O=`${y.animationName}.css`,z=`css/${O}`,H=o.join(t,z);s.push(O),r.writeFileSync(H,y.css);return}if(!y.generator)return;const c=y.generator._withBuildContext({name:p,config:b}),C=`${c.hash}-${c.priority}.css`;n[c.priority]||(n[c.priority]=[]),n[c.priority].push(C),S.push(C);const D=`css/${C}`,P=o.join(t,D);r.writeFileSync(P,c.css)});const F=S.map(p=>`@import url('./${p}');`).join(`
2
- `),x=N.toHash(i,6),f=o.join(t,`css/${x}.css`);r.writeFileSync(f,F)}}await w(e,t);const l=s.map(i=>`@import url('./css/${i}');`).join(`
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
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(b.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
8
- `);u+=i}r.writeFileSync(a,u)}catch(s){console.error(s)}},W=async(e,s)=>{try{const n=[],t=o.join(e,"./saltygen"),a=o.join(t,"index.css");if(T(s)){const b=await q(e),w=await V(s,t);Object.entries(w).forEach(([g,$])=>{if(!$.generator)return;const d=$.generator._withBuildContext({name:g,config:b}),m=`${d.hash}-${d.priority}.css`,S=`css/${m}`,F=o.join(t,S);n.push(m),r.writeFileSync(F,d.css)});const l=r.readFileSync(a,"utf8").split(`
9
- `),j=n.map(g=>`@import url('../saltygen/css/${g}');`),i=[...new Set([...l,...j])].join(`
10
- `);r.writeFileSync(a,i)}}catch(n){console.error(n)}},X=async(e,s)=>{try{const n=o.join(e,"./saltygen");if(T(s)){let a=r.readFileSync(s,"utf8");a.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==a&&await J.writeFile(s,a);const b=await q(e),w=await V(s,n);let l=a;Object.entries(w).forEach(([u,i])=>{var f;if(i.isKeyframes){console.log("value",i);return}if(!i.generator)return;const g=i.generator._withBuildContext({name:u,config:b}),$=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const d=(f=$.at(1))==null?void 0:f.trim(),{element:m,variantKeys:S}=g.props,F=`${u} = styled(${d}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(m)}, ${JSON.stringify(S)});`,x=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");l=l.replace(x,F)});const j=N.toHash(s,6);return b.importStrategy==="component"&&(l=`import '../../saltygen/css/${j}.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(n)}};exports.compileSaltyFile=V;exports.generateCss=U;exports.generateFile=W;exports.generateVariables=R;exports.isSaltyFile=T;exports.logger=G;exports.minimizeFile=X;
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(`\\s${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(`\\s${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;
@@ -1,8 +1,8 @@
1
1
  import { StyleComponentGenerator } from '../generator/style-generator';
2
- import * as winston from 'winston';
3
- export declare const logger: winston.Logger;
4
- export declare const isSaltyFile: (file: string) => boolean;
5
- export declare const generateVariables: (dirname: string) => Promise<void>;
2
+ export declare const saltyFileExtensions: string[];
3
+ export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
4
+ export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
5
+ export declare const generateConfigStyles: (dirname: string) => Promise<void>;
6
6
  export declare const compileSaltyFile: (sourceFilePath: string, outputDirectory: string) => Promise<{
7
7
  [key: string]: {
8
8
  generator: StyleComponentGenerator;