@salty-css/core 0.4.4 → 0.4.5-alpha.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0EpC,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,KAAG,IA8DtD,CAAC"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkFpC,eAAO,MAAM,mBAAmB,GAAI,SAAS,OAAO,KAAG,IAgEtD,CAAC"}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../main-O200T0y4.cjs").t().catch(e=>console.error(e));
2
+ require("../main-BoqRA5gm.cjs").t().catch(e=>console.error(e));
package/dist/bin/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as e } from "../main-1KMR8LtG.js";
2
+ import { t as e } from "../main-v3rdDsFh.js";
3
3
  //#region src/bin/index.ts
4
4
  e().catch((e) => console.error(e));
5
5
  //#endregion
package/dist/bin/main.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../main-O200T0y4.cjs");exports.main=e.t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../main-BoqRA5gm.cjs");exports.main=e.t;
package/dist/bin/main.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "../main-1KMR8LtG.js";
1
+ import { t as e } from "../main-v3rdDsFh.js";
2
2
  export { e as main };
@@ -1,5 +1,6 @@
1
1
  declare const templateLoaders: {
2
2
  readonly 'salty.config.ts': () => Promise<typeof import("*__template")>;
3
+ readonly 'styles/index.css': () => Promise<typeof import("*__template")>;
3
4
  readonly 'saltygen/index.css': () => Promise<typeof import("*__template")>;
4
5
  readonly 'react/styled-file.ts': () => Promise<typeof import("*__template")>;
5
6
  readonly 'react/vanilla-file.ts': () => Promise<typeof import("*__template")>;
@@ -8,7 +9,7 @@ declare const templateLoaders: {
8
9
  };
9
10
  export type TemplateKey = keyof typeof templateLoaders;
10
11
  export declare const readTemplate: <T extends object>(key: TemplateKey, options?: T) => Promise<{
11
- fileName: "salty.config.ts" | "saltygen/index.css" | "react/styled-file.ts" | "react/vanilla-file.ts" | "astro/styled-file.ts" | "astro/component.astro";
12
+ fileName: "salty.config.ts" | "styles/index.css" | "saltygen/index.css" | "react/styled-file.ts" | "react/vanilla-file.ts" | "astro/styled-file.ts" | "astro/component.astro";
12
13
  content: string;
13
14
  }>;
14
15
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/bin/templates.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,eAAe;;;;;;;CAOX,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,eAAe,CAAC;AAEvD,eAAO,MAAM,YAAY,GAAU,CAAC,SAAS,MAAM,EAAE,KAAK,WAAW,EAAE,UAAU,CAAC;;;EAIjF,CAAC"}
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/bin/templates.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,eAAe;;;;;;;;CAQX,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,eAAe,CAAC;AAEvD,eAAO,MAAM,YAAY,GAAU,CAAC,SAAS,MAAM,EAAE,KAAK,WAAW,EAAE,UAAU,CAAC;;;EAIjF,CAAC"}
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../salty-compiler-GObjXtub.cjs");exports.SaltyCompiler=e.t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../salty-compiler-1LbXg6lw.cjs");exports.SaltyCompiler=e.t;
@@ -1,2 +1,2 @@
1
- import { t as e } from "../salty-compiler-x-HZUW36.js";
1
+ import { t as e } from "../salty-compiler-u42y07vy.js";
2
2
  export { e as SaltyCompiler };
@@ -0,0 +1,11 @@
1
+ const e=require("./chunk-CMqjfN_6.cjs"),t=require("./salty-compiler-1LbXg6lw.cjs"),n=require("./compiler/helpers.cjs"),r=require("./util/index.cjs"),i=require("./server/index.cjs");let a=require("commander"),o=require("fs"),s=require("path"),c=require("fs/promises"),l=require("child_process"),u=require("ora");u=e.t(u,1);let d=require("ejs");d=e.t(d,1);let f=require("readline/promises");var p=(0,s.join)(process.cwd(),`package.json`),m=async(e=p)=>{let t=await(0,c.readFile)(e,`utf-8`).then(JSON.parse).catch(()=>void 0);if(!t)throw`Could not read package.json file!`;return t},h=async(e,t=p)=>{typeof e==`object`&&(e=JSON.stringify(e,null,2)),await(0,c.writeFile)(t,e)},g=async()=>m(new URL(`../package.json`,``+{}.url)),_={core:e=>`@salty-css/core@${e}`,eslintConfigCore:e=>`@salty-css/eslint-config-core@${e}`},v=e=>{e.scripts||={};let t=e.scripts.prepare;if(t){if(t.includes(`salty-css`))return{changed:!1,pkg:e};e.scripts.prepare=t+` && npx salty-css build`}else e.scripts.prepare=`npx salty-css build`;return{changed:!0,pkg:e}},y=e=>new Promise((t,n)=>{(0,l.exec)(e,e=>{if(e)return n(e);t()})}),b=async(...e)=>{let t=e.map(e=>e.replace(`-D`,``).split(`@`).slice(0,-1).join(`@`).trim()).join(`, `),n=(0,u.default)(`Installing packages: ${t}`).start();await y(`npm install ${e.join(` `)}`),n.succeed(`Installed packages: ${t}`)},x=()=>(0,o.existsSync)((0,s.join)(process.cwd(),`node_modules`,`.bin`,`prettier`));async function S(e){try{if(!x())return;await y(`./node_modules/.bin/prettier --write "${e}"`),t.r.info(`Formatted ${e} with Prettier`)}catch(n){t.r.error(`Error formatting ${e} with Prettier:`,n)}}var C=(e=process.cwd())=>(0,s.join)(e,`.saltyrc.json`),w=async(e=process.cwd())=>await(0,c.readFile)(C(e),`utf-8`).then(JSON.parse).catch(()=>({})),ee=async(e=process.cwd())=>(0,c.readFile)(C(e),`utf-8`).catch(()=>void 0),T=async(e=process.cwd())=>(await w(e)).defaultProject,E=(e,t,n,r={})=>{let i=(0,s.join)(t,n.srcDirectory),a={dir:i,framework:n.name,...r};if(e===void 0)return{content:JSON.stringify({$schema:`./node_modules/@salty-css/core/.saltyrc.schema.json`,info:`This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.`,defaultProject:i,projects:[a]},null,2),changed:!0,created:!0};let o=JSON.parse(e),c=o.projects||[];if(c.some(e=>e.dir===i))return{content:e,changed:!1,created:!1};c.push(a),o.projects=[...c];let l=JSON.stringify(o,null,2);return{content:l,changed:l!==e,created:!1}},D=async(e,n,r,i={})=>{let a=C(e),{content:o,changed:s,created:l}=E(await ee(e),n,r,i);return s?(l?t.r.info(`Creating file: `+a):t.r.info(`Edit file: `+a),await(0,c.writeFile)(a,o),await S(a),!0):!1},te=(e,t)=>(e.projects||[]).find(e=>e.dir===t)?.framework,O=(e,t=process.cwd())=>(0,s.join)(t,e===`.`?``:e),k=async e=>{let t=process.cwd(),n=O(e.dir,t),r=(0,s.relative)(t,n)||`.`,i=await m().catch(()=>void 0);if(e.requirePackageJson!==!1&&!i)throw Error(`Salty CSS project must be initialized in a directory with a package.json file.`);return{cwd:t,projectDir:n,relativeProjectPath:r,packageJson:i,rcFile:await w(t),cliVersion:(await g()).version||`0.0.0`,skipInstall:!!e.skipInstall,yes:!!e.yes}},A=(e,r)=>{e.command(`build [directory]`).alias(`b`).description(`Build the Salty-CSS project.`).option(`-d, --dir <dir>`,`Project directory to build the project in.`).option(`--watch`,`Watch for changes and rebuild the project.`).option(`--mode <mode>`,`Build mode: "production" or "development". Defaults to NODE_ENV-based detection.`).action(async function(e=r){t.r.info(`Building the Salty-CSS project...`);let{dir:a=e,watch:s,mode:c}=this.opts();if(c!==void 0&&c!==`production`&&c!==`development`)return t.n(`Invalid --mode "${c}". Expected "production" or "development".`);let l=a??await T();if(!l)return t.n(`Project directory must be provided. Add it as the first argument after build command or use the --dir option.`);let u=O(l),d=new t.t(u,{mode:c});await d.generateCss(),s&&(t.r.info(`Watching for changes in the project directory...`),(0,o.watch)(u,{recursive:!0},async(e,t)=>{if(!t)return console.warn(`File path not provided for change event`);await i.checkShouldRestart(t)?await d.generateCss(!1):n.isSaltyFile(t)&&await d.generateFile(t)}))})},ne=[`astro.config.mjs`,`astro.config.ts`,`astro.config.js`,`astro.config.cjs`],j=e=>{for(let t of ne){let n=(0,s.join)(e,t);if((0,o.existsSync)(n))return n}return null},M=e=>{let t=e.packageJson;if(!t)return!1;let n={...t.dependencies,...t.devDependencies};return Object.prototype.hasOwnProperty.call(n,`astro`)},N={name:`astro`,srcDirectory:`src`,detect:e=>!!j(e.projectDir)||M(e),runtimePackage:e=>`@salty-css/astro@${e}`,templates:{styled:`astro/styled-file.ts`,component:{styled:`astro/styled-file.ts`,wrapper:`astro/component.astro`,wrapperExt:`.astro`}}},P={name:`react`,srcDirectory:``,detect:()=>!0,runtimePackage:e=>`@salty-css/react@${e}`,templates:{styled:`react/styled-file.ts`,component:{styled:`react/styled-file.ts`,wrapper:`react/vanilla-file.ts`,wrapperExt:`.tsx`}}},F=[N,P],I={astro:N,react:P},L=async e=>{for(let t of F)if(await t.detect(e))return t;return P},R=e=>{if(e)return I[e]},z={"salty.config.ts":()=>Promise.resolve().then(()=>require("./salty.config-B0ZiRpHR.cjs")),"styles/index.css":()=>Promise.resolve().then(()=>require("./styles_index-DgmdjfFo.cjs")),"saltygen/index.css":()=>Promise.resolve().then(()=>require("./saltygen_index-BGHLaAOm.cjs")),"react/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-BCbAEzBB.cjs")),"react/vanilla-file.ts":()=>Promise.resolve().then(()=>require("./vanilla-file-Z3VsOa_U.cjs")),"astro/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-DorArlCk.cjs")),"astro/component.astro":()=>Promise.resolve().then(()=>require("./astro-component-r0qEcF1p.cjs"))},B=async(e,t)=>{let{default:n}=await z[e]();return{fileName:e,content:d.default.render(n,t)}},V=(e,n)=>{e.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.`).option(`-r, --reactComponent`,`Generate a wrapper component file alongside the styled definition.`).action(async function(e,i=n){let{file:a=e,dir:o=i,tag:l,name:u,className:d,reactComponent:f=!1}=this.opts();if(!a)return t.n(`File to generate must be provided. Add it as the first argument after generate command or use the --file option.`);if(!o)return t.n(`Project directory must be provided. Add it as the second argument after generate command or use the --dir option.`);let p;try{p=await k({dir:o,requirePackageJson:!1})}catch(e){return t.n(e instanceof Error?e.message:String(e))}let m=R(te(p.rcFile,p.relativeProjectPath))??await L(p),h=a.split(`/`).slice(0,-1).join(`/`);h&&await(0,c.mkdir)((0,s.join)(p.projectDir,h),{recursive:!0});let g=(0,s.parse)((0,s.join)(p.projectDir,a));g.ext||=`.ts`,g.name.endsWith(`.css`)||(g.name+=`.css`),g.base=g.name+g.ext;let _=(0,s.format)(g);if(await(0,c.readFile)(_,`utf-8`).catch(()=>void 0)!==void 0){t.r.error(`File already exists: `+_);return}let v=r.pascalCase(u||g.base.replace(/\.css\.\w+$/,``));if(f){if(!m.templates.component)return t.n(`--reactComponent is not supported for the ${m.name} framework.`);let e=v+`Component`;v+=`Wrapper`;let n=g.base.replace(/\.css\.\w+$/,``),{content:r}=await B(m.templates.component.wrapper,{tag:l,componentName:e,styledComponentName:v,className:d,fileName:n});g.name=n.replace(/\.css$/,``),g.ext=m.templates.component.wrapperExt,g.base=g.name+g.ext;let i=(0,s.format)(g);t.r.info(`Generating a new file: `+i),await(0,c.writeFile)(i,r),await S(i)}let{content:y}=await B(f&&m.templates.component?m.templates.component.styled:m.templates.styled,{tag:l,name:v,className:d});t.r.info(`Generating a new file: `+_),await(0,c.writeFile)(_,y),await S(_)})},H=e=>{let t=e.trim();return t.startsWith(`-D `)?`${t.slice(3).trim()} (dev)`:t},U=e=>e.map(e=>` + ${H(e)}`).join(`
2
+ `),W=async(e,t,n={})=>{if(t||e.length===0)return;let r=n.input??process.stdin,i=n.output??process.stdout;if(!(n.isTTY??process.stdin.isTTY??!1))throw Error(`Cannot prompt for install confirmation: stdin is not a TTY. Re-run with --yes to install the listed packages without prompting.`);i.write(`The following packages will be installed:\n${U(e)}\n`);let a=(0,f.createInterface)({input:r,output:i,terminal:!1});try{let e=(await a.question(`Proceed? (y/N) `)).trim().toLowerCase();if(e!==`y`&&e!==`yes`)throw Error(`Install cancelled by user.`)}finally{a.close()}},G=async(e,t={})=>{if(t.yes)return!0;let n=t.input??process.stdin,r=t.output??process.stdout;if(!(t.isTTY??process.stdin.isTTY??!1))return!1;let i=t.defaultYes?`(Y/n)`:`(y/N)`,a=(0,f.createInterface)({input:n,output:r,terminal:!1});try{let n=(await a.question(`${e} ${i} `)).trim().toLowerCase();return n===``?!!t.defaultYes:n===`y`||n===`yes`}finally{a.close()}},K=[`src`,`public`,`assets`,`styles`,`css`,`app`],q=[`styles`,`css`,`app`,`pages`],J=[`index`,`styles`,`main`,`app`,`global`,`globals`],Y=[`.css`,`.scss`,`.sass`],X=async e=>{for(let t of K)for(let n of J)for(let r of Y){let i=(0,s.join)(e,t,n+r);if(await(0,c.readFile)(i,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,i);for(let i of q){let a=(0,s.join)(e,t,i,n+r);if(await(0,c.readFile)(a,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,a)}}},Z=e=>`@salty-css/astro@${e}`,re=`import saltyIntegration from '@salty-css/astro/integration';
3
+ `,ie=e=>{if(e.includes(`@salty-css/astro`))return{content:null};let t=e,n=!1;return/integrations\s*:\s*\[/.test(t)?(t=t.replace(/integrations\s*:\s*\[/,e=>`${e}saltyIntegration(),`),n=!0):/defineConfig\s*\(\s*\{/.test(t)&&(t=t.replace(/defineConfig\s*\(\s*\{/,e=>`${e}\n integrations: [saltyIntegration()],`),n=!0),n?{content:re+t}:{content:null,warning:`Could not find a place to add saltyIntegration() in the Astro config. Please add it manually.`}},ae={name:`astro`,detect:e=>j(e.projectDir),plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let i=ie(r);if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[`-D ${Z(e.cliVersion)}`],execute:async()=>(t.r.info(`Adding Salty-CSS integration to Astro config: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},oe=[[`projectJs`,`eslint.config.js`],[`rootJs`,`eslint.config.js`],[`projectMjs`,`eslint.config.mjs`],[`rootMjs`,`eslint.config.mjs`],[`projectJson`,`.eslintrc.json`],[`rootJson`,`.eslintrc.json`]],se=(e,t)=>oe.map(([n,r])=>(0,s.join)(n.startsWith(`root`)?t:e,r)),ce=(e,t)=>{if(e.includes(`salty-css`))return{content:null};if(t){let t=`import saltyCss from "@salty-css/eslint-config-core/flat";\n${e}`;if(e.includes(`typescript-eslint`))if(t.includes(`.config(`))t=t.replace(`.config(`,`.config(saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};else if(t.includes(`export default [`))t=t.replace(`export default [`,`export default [ saltyCss,`);else if(t.includes(`eslintConfig = [`))t=t.replace(`eslintConfig = [`,`eslintConfig = [ saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};return{content:t}}let n=JSON.parse(e);return n.extends||=[],n.extends.includes(`@salty-css/core`)||n.extends.push(`@salty-css/core`),{content:JSON.stringify(n,null,2)}},le={name:`eslint`,detect:e=>se(e.projectDir,e.cwd).find(e=>(0,o.existsSync)(e))??null,plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return t.r.error(`Could not read ESLint config file.`),null;let i=ce(r,n.endsWith(`js`));if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[_.eslintConfigCore(e.cliVersion)],execute:async()=>(t.r.info(`Edit file: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},ue=[`next.config.js`,`next.config.cjs`,`next.config.ts`,`next.config.mjs`],de=e=>`@salty-css/next@${e}`,fe=e=>{if(e.includes(`withSaltyCss`))return{content:null};let t=e,n=!1;/\splugins([^=]*)=[^[]\[/.test(t)&&(t=t.replace(/\splugins([^=]*)=[^[]\[/,(e,t)=>` plugins${t}= [withSaltyCss,`),n=!0);let r=t.includes(`module.exports`),i=r?`const { withSaltyCss } = require('@salty-css/next');
4
+ `:`import { withSaltyCss } from '@salty-css/next';
5
+ `;return r&&!n?(t=t.replace(/module.exports = ([^;]+)/,(e,t)=>`module.exports = withSaltyCss(${t})`),n=!0):n||(t=t.replace(/export default ([^;]+)/,(e,t)=>`export default withSaltyCss(${t})`)),{content:i+t}},pe={name:`next`,detect:e=>ue.map(t=>(0,s.join)(e.projectDir,t)).find(e=>(0,o.existsSync)(e))??null,plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let{content:i}=fe(r);return i===null?null:{packages:[`-D ${de(e.cliVersion)}`],execute:async()=>(t.r.info(`Adding Salty-CSS plugin to Next.js config...`),await(0,c.writeFile)(n,i),await S(n),{changed:!0})}}},me=e=>`@salty-css/vite@${e}`,he=e=>e.includes(`saltyPlugin`)?{content:null}:{content:`import { saltyPlugin } from '@salty-css/vite';
6
+ `+e.replace(/(plugins: \[)/,`$1
7
+ saltyPlugin(__dirname),`)},ge=[le,{name:`vite`,detect:e=>{let t=(0,s.join)(e.projectDir,`vite.config.ts`);return(0,o.existsSync)(t)?t:null},plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let{content:i}=he(r);return i===null?null:{packages:[`-D ${me(e.cliVersion)}`],execute:async()=>(t.r.info(`Edit file: `+n),t.r.info(`Adding Salty-CSS plugin to Vite config...`),await(0,c.writeFile)(n,i),await S(n),{changed:!0})}}},pe,ae],_e=async e=>{let t=[];for(let n of ge){let r=await n.detect(e);if(!r)continue;let i=await n.plan(e,r);i&&t.push({name:n.name,configPath:r,plan:i})}return t},ve=async e=>{let t=[];for(let{name:n,configPath:r,plan:i}of e){let e=await i.execute();t.push({name:n,configPath:r,changed:e.changed})}return t},ye={vite:[`dist/**`],next:[`.next/**`,`out/**`]},be=({framework:e,integrations:t,hasSrcDir:n})=>{if(e===`astro`)return{};let r=[...new Set(t.flatMap(e=>ye[e]??[]))],i={};return n&&(i.include=[`src/**`]),r.length&&(i.exclude=r),i},Q=async(e,n,r)=>{let i=(0,s.join)(e,n);if((0,o.existsSync)(i)){t.r.debug(`File already exists: `+i);return}let a=n.split(`/`).slice(0,-1).join(`/`);a&&await(0,c.mkdir)((0,s.join)(e,a),{recursive:!0}),t.r.info(`Creating file: `+i),await(0,c.writeFile)(i,r),await S(i)},xe=async e=>{let n=(0,s.join)(e,`.gitignore`),r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);r!==void 0&&(r.includes(`saltygen`)||(t.r.info(`Edit file: `+n),await(0,c.writeFile)(n,r+`
8
+
9
+ # Salty-CSS
10
+ saltygen
11
+ `)))},Se=async(e,n)=>{let r=n??await X(e);if(!r){if(!await G("Could not find a CSS file to import the generated CSS. Do you want to create a new `styles/index.css` file and import it there? (y/N) ")){t.r.warn(`Could not find a CSS file to import the generated CSS. Please add it manually.`);return}let{fileName:n,content:r}=await B(`styles/index.css`);await Q(e,n,r);return}let i=(0,s.join)(e,r),a=await(0,c.readFile)(i,`utf-8`).catch(()=>void 0);if(a===void 0||a.includes(`saltygen`))return;let o=(0,s.relative)((0,s.join)(i,`..`),(0,s.join)(e,`saltygen/index.css`));t.r.info(`Adding global import statement to CSS file: `+i),await(0,c.writeFile)(i,`@import '${o}';\n`+a),await S(i)},Ce=async()=>{let e=await m().catch(()=>{t.n(`Could not read package.json file.`)});if(!e)return;let{pkg:n}=v(e);await h(n)},we=e=>{e.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.`).option(`-y, --yes`,`Skip the install confirmation prompt.`).action(async function(e=`.`){try{let n=this.opts(),r=n.dir??e;if(!r)return t.n(`Project directory must be provided. Add it as the first argument after init command or use the --dir option.`);let i=await k({dir:r,skipInstall:n.skipInstall,yes:n.yes});t.r.info(`Initializing a new Salty-CSS project!`);let a=await L(i);t.r.info(`Detected framework: ${a.name}`);let l=await _e(i);if(!i.skipInstall){let e=[_.core(i.cliVersion),a.runtimePackage(i.cliVersion),...l.flatMap(e=>e.plan.packages)];await W(e,i.yes),await b(...e)}let u=await Promise.all([B(`salty.config.ts`),B(`saltygen/index.css`)]),d=(0,s.join)(i.projectDir,a.srcDirectory);await(0,c.mkdir)(d,{recursive:!0}),await Promise.all(u.map(({fileName:e,content:t})=>Q(d,e,t)));let f=be({framework:a.name,integrations:l.map(e=>e.name),hasSrcDir:(0,o.existsSync)((0,s.join)(i.projectDir,`src`))});await D(i.cwd,i.relativeProjectPath,a,f),await xe(i.cwd),await Se(d,n.cssFile),await ve(l),await Ce(),t.r.info(`Running the build to generate initial CSS...`),await new t.t(d).generateCss(),t.r.info(`🎉 Salty CSS project initialized successfully!`),t.r.info(`Next steps:`),t.r.info("1. Configure variables and templates in `salty.config.ts`"),t.r.info("2. Create a new component with `npx salty-css generate [component-name]`"),t.r.info("3. Run `npx salty-css build` to generate the CSS"),t.r.info(`4. Read about the features in the documentation: https://salty-css.dev`),t.r.info(`5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐`)}catch(e){return t.n(e instanceof Error?e.message:String(e))}})},$=async()=>{let e=(0,s.join)(process.cwd(),`package.json`),n=await m(e).catch(e=>t.n(e));if(!n)return t.n(`Could not read package.json file.`);let r={...n.dependencies,...n.devDependencies},i=Object.entries(r).filter(([e])=>e===`salty-css`||e.startsWith(`@salty-css/`));return i.length?i:t.n(`No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: `+e)},Te=e=>{e.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).option(`-y, --yes`,`Skip confirmation prompts (install and rebuild).`).option(`-d, --dir <dir>`,`Project directory to rebuild after updating.`).action(async function(e=`latest`){let{legacyPeerDeps:n,version:r=e,yes:i=!1,dir:a}=this.opts(),o=await $();if(!o)return t.n(`Could not update Salty-CSS packages as any were found in package.json.`);let s=await g(),c=o.map(([e])=>r===`@`?`${e}@${s.version}`:`${e}@${r.replace(/^@/,``)}`);try{await W(c,i)}catch(e){return t.n(e instanceof Error?e.message:String(e))}n?(t.r.warn(`Using legacy peer dependencies to update packages.`),await b(...c,`--legacy-peer-deps`)):await b(...c);let l=await $();if(!l)return t.n(`Something went wrong while reading the updated packages.`);let u=l.reduce((e,[t,n])=>(e[n]||(e[n]=[]),e[n].push(t),e),{});if(Object.keys(u).length===1){let e=Object.keys(u)[0];t.r.info(`Updated to all Salty CSS packages successfully to ${e.replace(/^\^/,``)}`)}else for(let[e,n]of Object.entries(u))t.r.info(`Updated to ${e.replace(/^\^/,``)}: ${n.join(`, `)}`);let d=a??await T();if(!d){t.r.warn("Skipping rebuild: no project directory configured. Run `salty-css build [dir]` manually.");return}if(!await G(`Rebuild Salty CSS now?`,{yes:i}))return;let f=O(d);t.r.info(`Rebuilding Salty-CSS project...`),await new t.t(f).generateCss(),t.r.info(`Rebuild complete.`)})},Ee=e=>{e.option(`-v, --version`,`Show the current version of Salty-CSS.`).action(async function(){let e=await g();t.r.info(`CLI is running: `+e.version);let n=(0,s.join)(process.cwd(),`package.json`),r=await m(n).catch(e=>t.n(e));if(!r)return;let i={...r.dependencies,...r.devDependencies},a=Object.keys(i).filter(e=>e===`salty-css`||e.startsWith(`@salty-css/`));if(!a.length)return t.n(`No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: `+n);for(let e of a)t.r.info(`${e}: ${i[e]}`)})};async function De(){let e=new a.Command;e.name(`salty-css`).description(`Salty-CSS CLI tool to help with annoying configuration tasks.`);let t=await T();we(e),Te(e),Ee(e),A(e,t),V(e,t),e.parseAsync(process.argv)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return De}});
@@ -1,4 +1,4 @@
1
- import { n as e, r as t, t as n } from "./salty-compiler-x-HZUW36.js";
1
+ import { n as e, r as t, t as n } from "./salty-compiler-u42y07vy.js";
2
2
  import { isSaltyFile as r } from "./compiler/helpers.js";
3
3
  import { pascalCase as i } from "./util/index.js";
4
4
  import { checkShouldRestart as a } from "./server/index.js";
@@ -51,7 +51,7 @@ async function O(e) {
51
51
  t.error(`Error formatting ${e} with Prettier:`, n);
52
52
  }
53
53
  }
54
- var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd()) => await m(k(e), "utf-8").then(JSON.parse).catch(() => ({})), j = async (e = process.cwd()) => m(k(e), "utf-8").catch(() => void 0), M = async (e = process.cwd()) => (await A(e)).defaultProject, N = (e, t, n, r = {}) => {
54
+ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd()) => await m(k(e), "utf-8").then(JSON.parse).catch(() => ({})), j = async (e = process.cwd()) => m(k(e), "utf-8").catch(() => void 0), M = async (e = process.cwd()) => (await A(e)).defaultProject, te = (e, t, n, r = {}) => {
55
55
  let i = u(t, n.srcDirectory), a = {
56
56
  dir: i,
57
57
  framework: n.name,
@@ -80,11 +80,11 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
80
80
  changed: c !== e,
81
81
  created: !1
82
82
  };
83
- }, P = async (e, n, r, i = {}) => {
84
- let a = k(e), { content: o, changed: s, created: c } = N(await j(e), n, r, i);
83
+ }, N = async (e, n, r, i = {}) => {
84
+ let a = k(e), { content: o, changed: s, created: c } = te(await j(e), n, r, i);
85
85
  return s ? (c ? t.info("Creating file: " + a) : t.info("Edit file: " + a), await h(a, o), await O(a), !0) : !1;
86
- }, F = (e, t) => (e.projects || []).find((e) => e.dir === t)?.framework, I = (e, t = process.cwd()) => u(t, e === "." ? "" : e), L = async (e) => {
87
- let t = process.cwd(), n = I(e.dir, t), r = f(t, n) || ".", i = await x().catch(() => void 0);
86
+ }, P = (e, t) => (e.projects || []).find((e) => e.dir === t)?.framework, F = (e, t = process.cwd()) => u(t, e === "." ? "" : e), I = async (e) => {
87
+ let t = process.cwd(), n = F(e.dir, t), r = f(t, n) || ".", i = await x().catch(() => void 0);
88
88
  if (e.requirePackageJson !== !1 && !i) throw Error("Salty CSS project must be initialized in a directory with a package.json file.");
89
89
  return {
90
90
  cwd: t,
@@ -96,31 +96,31 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
96
96
  skipInstall: !!e.skipInstall,
97
97
  yes: !!e.yes
98
98
  };
99
- }, te = (i, o) => {
99
+ }, ne = (i, o) => {
100
100
  i.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").option("--watch", "Watch for changes and rebuild the project.").option("--mode <mode>", "Build mode: \"production\" or \"development\". Defaults to NODE_ENV-based detection.").action(async function(i = o) {
101
101
  t.info("Building the Salty-CSS project...");
102
102
  let { dir: s = i, watch: l, mode: u } = this.opts();
103
103
  if (u !== void 0 && u !== "production" && u !== "development") return e(`Invalid --mode "${u}". Expected "production" or "development".`);
104
104
  let d = s ?? await M();
105
105
  if (!d) return e("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
106
- let f = I(d), p = new n(f, { mode: u });
106
+ let f = F(d), p = new n(f, { mode: u });
107
107
  await p.generateCss(), l && (t.info("Watching for changes in the project directory..."), c(f, { recursive: !0 }, async (e, t) => {
108
108
  if (!t) return console.warn("File path not provided for change event");
109
109
  await a(t) ? await p.generateCss(!1) : r(t) && await p.generateFile(t);
110
110
  }));
111
111
  });
112
- }, ne = [
112
+ }, re = [
113
113
  "astro.config.mjs",
114
114
  "astro.config.ts",
115
115
  "astro.config.js",
116
116
  "astro.config.cjs"
117
- ], R = (e) => {
118
- for (let t of ne) {
117
+ ], L = (e) => {
118
+ for (let t of re) {
119
119
  let n = u(e, t);
120
120
  if (s(n)) return n;
121
121
  }
122
122
  return null;
123
- }, z = (e) => {
123
+ }, ie = (e) => {
124
124
  let t = e.packageJson;
125
125
  if (!t) return !1;
126
126
  let n = {
@@ -128,10 +128,10 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
128
128
  ...t.devDependencies
129
129
  };
130
130
  return Object.prototype.hasOwnProperty.call(n, "astro");
131
- }, B = {
131
+ }, R = {
132
132
  name: "astro",
133
133
  srcDirectory: "src",
134
- detect: (e) => !!R(e.projectDir) || z(e),
134
+ detect: (e) => !!L(e.projectDir) || ie(e),
135
135
  runtimePackage: (e) => `@salty-css/astro@${e}`,
136
136
  templates: {
137
137
  styled: "astro/styled-file.ts",
@@ -141,7 +141,7 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
141
141
  wrapperExt: ".astro"
142
142
  }
143
143
  }
144
- }, V = {
144
+ }, z = {
145
145
  name: "react",
146
146
  srcDirectory: "",
147
147
  detect: () => !0,
@@ -154,42 +154,43 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
154
154
  wrapperExt: ".tsx"
155
155
  }
156
156
  }
157
- }, H = [B, V], U = {
158
- astro: B,
159
- react: V
160
- }, W = async (e) => {
161
- for (let t of H) if (await t.detect(e)) return t;
162
- return V;
163
- }, G = (e) => {
164
- if (e) return U[e];
165
- }, K = {
157
+ }, B = [R, z], V = {
158
+ astro: R,
159
+ react: z
160
+ }, H = async (e) => {
161
+ for (let t of B) if (await t.detect(e)) return t;
162
+ return z;
163
+ }, U = (e) => {
164
+ if (e) return V[e];
165
+ }, W = {
166
166
  "salty.config.ts": () => import("./salty.config-DWF4i7K0.js"),
167
- "saltygen/index.css": () => import("./templates-DWWLjEiU.js"),
167
+ "styles/index.css": () => import("./styles_index-CYo48NLy.js"),
168
+ "saltygen/index.css": () => import("./saltygen_index-BoZSUsyA.js"),
168
169
  "react/styled-file.ts": () => import("./styled-file-C_4eLAdV.js"),
169
170
  "react/vanilla-file.ts": () => import("./vanilla-file-BEqMIe-6.js"),
170
171
  "astro/styled-file.ts": () => import("./styled-file-DQHLzmuL.js"),
171
172
  "astro/component.astro": () => import("./astro-component-Ov1RH0CO.js")
172
- }, q = async (e, t) => {
173
- let { default: n } = await K[e]();
173
+ }, G = async (e, t) => {
174
+ let { default: n } = await W[e]();
174
175
  return {
175
176
  fileName: e,
176
177
  content: v.render(n, t)
177
178
  };
178
- }, J = (n, r) => {
179
+ }, K = (n, r) => {
179
180
  n.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.").option("-r, --reactComponent", "Generate a wrapper component file alongside the styled definition.").action(async function(n, a = r) {
180
181
  let { file: o = n, dir: s = a, tag: c, name: f, className: g, reactComponent: _ = !1 } = this.opts();
181
182
  if (!o) return e("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
182
183
  if (!s) return e("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
183
184
  let v;
184
185
  try {
185
- v = await L({
186
+ v = await I({
186
187
  dir: s,
187
188
  requirePackageJson: !1
188
189
  });
189
190
  } catch (t) {
190
191
  return e(t instanceof Error ? t.message : String(t));
191
192
  }
192
- let y = G(F(v.rcFile, v.relativeProjectPath)) ?? await W(v), b = o.split("/").slice(0, -1).join("/");
193
+ let y = U(P(v.rcFile, v.relativeProjectPath)) ?? await H(v), b = o.split("/").slice(0, -1).join("/");
193
194
  b && await p(u(v.projectDir, b), { recursive: !0 });
194
195
  let x = d(u(v.projectDir, o));
195
196
  x.ext ||= ".ts", x.name.endsWith(".css") || (x.name += ".css"), x.base = x.name + x.ext;
@@ -203,7 +204,7 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
203
204
  if (!y.templates.component) return e(`--reactComponent is not supported for the ${y.name} framework.`);
204
205
  let n = C + "Component";
205
206
  C += "Wrapper";
206
- let r = x.base.replace(/\.css\.\w+$/, ""), { content: i } = await q(y.templates.component.wrapper, {
207
+ let r = x.base.replace(/\.css\.\w+$/, ""), { content: i } = await G(y.templates.component.wrapper, {
207
208
  tag: c,
208
209
  componentName: n,
209
210
  styledComponentName: C,
@@ -214,21 +215,21 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
214
215
  let a = l(x);
215
216
  t.info("Generating a new file: " + a), await h(a, i), await O(a);
216
217
  }
217
- let { content: w } = await q(_ && y.templates.component ? y.templates.component.styled : y.templates.styled, {
218
+ let { content: w } = await G(_ && y.templates.component ? y.templates.component.styled : y.templates.styled, {
218
219
  tag: c,
219
220
  name: C,
220
221
  className: g
221
222
  });
222
223
  t.info("Generating a new file: " + S), await h(S, w), await O(S);
223
224
  });
224
- }, Y = (e) => {
225
+ }, q = (e) => {
225
226
  let t = e.trim();
226
227
  return t.startsWith("-D ") ? `${t.slice(3).trim()} (dev)` : t;
227
- }, X = (e) => e.map((e) => ` + ${Y(e)}`).join("\n"), Z = async (e, t, n = {}) => {
228
+ }, J = (e) => e.map((e) => ` + ${q(e)}`).join("\n"), Y = async (e, t, n = {}) => {
228
229
  if (t || e.length === 0) return;
229
230
  let r = n.input ?? process.stdin, i = n.output ?? process.stdout;
230
231
  if (!(n.isTTY ?? process.stdin.isTTY ?? !1)) throw Error("Cannot prompt for install confirmation: stdin is not a TTY. Re-run with --yes to install the listed packages without prompting.");
231
- i.write(`The following packages will be installed:\n${X(e)}\n`);
232
+ i.write(`The following packages will be installed:\n${J(e)}\n`);
232
233
  let a = y({
233
234
  input: r,
234
235
  output: i,
@@ -240,7 +241,7 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
240
241
  } finally {
241
242
  a.close();
242
243
  }
243
- }, re = async (e, t = {}) => {
244
+ }, X = async (e, t = {}) => {
244
245
  if (t.yes) return !0;
245
246
  let n = t.input ?? process.stdin, r = t.output ?? process.stdout;
246
247
  if (!(t.isTTY ?? process.stdin.isTTY ?? !1)) return !1;
@@ -255,67 +256,67 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
255
256
  } finally {
256
257
  a.close();
257
258
  }
258
- }, ie = [
259
+ }, ae = [
259
260
  "src",
260
261
  "public",
261
262
  "assets",
262
263
  "styles",
263
264
  "css",
264
265
  "app"
265
- ], ae = [
266
+ ], oe = [
266
267
  "styles",
267
268
  "css",
268
269
  "app",
269
270
  "pages"
270
- ], oe = [
271
+ ], se = [
271
272
  "index",
272
273
  "styles",
273
274
  "main",
274
275
  "app",
275
276
  "global",
276
277
  "globals"
277
- ], se = [
278
+ ], ce = [
278
279
  ".css",
279
280
  ".scss",
280
281
  ".sass"
281
- ], ce = async (e) => {
282
- for (let t of ie) for (let n of oe) for (let r of se) {
282
+ ], le = async (e) => {
283
+ for (let t of ae) for (let n of se) for (let r of ce) {
283
284
  let i = u(e, t, n + r);
284
285
  if (await m(i, "utf-8").catch(() => void 0) !== void 0) return f(e, i);
285
- for (let i of ae) {
286
+ for (let i of oe) {
286
287
  let a = u(e, t, i, n + r);
287
288
  if (await m(a, "utf-8").catch(() => void 0) !== void 0) return f(e, a);
288
289
  }
289
290
  }
290
- }, le = (e) => `@salty-css/astro@${e}`, ue = "import saltyIntegration from '@salty-css/astro/integration';\n", de = (e) => {
291
+ }, ue = (e) => `@salty-css/astro@${e}`, de = "import saltyIntegration from '@salty-css/astro/integration';\n", fe = (e) => {
291
292
  if (e.includes("@salty-css/astro")) return { content: null };
292
293
  let t = e, n = !1;
293
- return /integrations\s*:\s*\[/.test(t) ? (t = t.replace(/integrations\s*:\s*\[/, (e) => `${e}saltyIntegration(),`), n = !0) : /defineConfig\s*\(\s*\{/.test(t) && (t = t.replace(/defineConfig\s*\(\s*\{/, (e) => `${e}\n integrations: [saltyIntegration()],`), n = !0), n ? { content: ue + t } : {
294
+ return /integrations\s*:\s*\[/.test(t) ? (t = t.replace(/integrations\s*:\s*\[/, (e) => `${e}saltyIntegration(),`), n = !0) : /defineConfig\s*\(\s*\{/.test(t) && (t = t.replace(/defineConfig\s*\(\s*\{/, (e) => `${e}\n integrations: [saltyIntegration()],`), n = !0), n ? { content: de + t } : {
294
295
  content: null,
295
296
  warning: "Could not find a place to add saltyIntegration() in the Astro config. Please add it manually."
296
297
  };
297
- }, fe = {
298
+ }, pe = {
298
299
  name: "astro",
299
- detect: (e) => R(e.projectDir),
300
+ detect: (e) => L(e.projectDir),
300
301
  plan: async (e, n) => {
301
302
  let r = await m(n, "utf-8").catch(() => void 0);
302
303
  if (r === void 0) return null;
303
- let i = de(r);
304
+ let i = fe(r);
304
305
  if (i.warning && t.warn(i.warning), i.content === null) return null;
305
306
  let a = i.content;
306
307
  return {
307
- packages: [`-D ${le(e.cliVersion)}`],
308
+ packages: [`-D ${ue(e.cliVersion)}`],
308
309
  execute: async () => (t.info("Adding Salty-CSS integration to Astro config: " + n), await h(n, a), await O(n), { changed: !0 })
309
310
  };
310
311
  }
311
- }, pe = [
312
+ }, me = [
312
313
  ["projectJs", "eslint.config.js"],
313
314
  ["rootJs", "eslint.config.js"],
314
315
  ["projectMjs", "eslint.config.mjs"],
315
316
  ["rootMjs", "eslint.config.mjs"],
316
317
  ["projectJson", ".eslintrc.json"],
317
318
  ["rootJson", ".eslintrc.json"]
318
- ], me = (e, t) => pe.map(([n, r]) => u(n.startsWith("root") ? t : e, r)), he = (e, t) => {
319
+ ], he = (e, t) => me.map(([n, r]) => u(n.startsWith("root") ? t : e, r)), ge = (e, t) => {
319
320
  if (e.includes("salty-css")) return { content: null };
320
321
  if (t) {
321
322
  let t = `import saltyCss from "@salty-css/eslint-config-core/flat";\n${e}`;
@@ -334,13 +335,13 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
334
335
  }
335
336
  let n = JSON.parse(e);
336
337
  return n.extends ||= [], n.extends.includes("@salty-css/core") || n.extends.push("@salty-css/core"), { content: JSON.stringify(n, null, 2) };
337
- }, ge = {
338
+ }, _e = {
338
339
  name: "eslint",
339
- detect: (e) => me(e.projectDir, e.cwd).find((e) => s(e)) ?? null,
340
+ detect: (e) => he(e.projectDir, e.cwd).find((e) => s(e)) ?? null,
340
341
  plan: async (e, n) => {
341
342
  let r = await m(n, "utf-8").catch(() => void 0);
342
343
  if (r === void 0) return t.error("Could not read ESLint config file."), null;
343
- let i = he(r, n.endsWith("js"));
344
+ let i = ge(r, n.endsWith("js"));
344
345
  if (i.warning && t.warn(i.warning), i.content === null) return null;
345
346
  let a = i.content;
346
347
  return {
@@ -348,31 +349,31 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
348
349
  execute: async () => (t.info("Edit file: " + n), await h(n, a), await O(n), { changed: !0 })
349
350
  };
350
351
  }
351
- }, _e = [
352
+ }, ve = [
352
353
  "next.config.js",
353
354
  "next.config.cjs",
354
355
  "next.config.ts",
355
356
  "next.config.mjs"
356
- ], ve = (e) => `@salty-css/next@${e}`, ye = (e) => {
357
+ ], ye = (e) => `@salty-css/next@${e}`, be = (e) => {
357
358
  if (e.includes("withSaltyCss")) return { content: null };
358
359
  let t = e, n = !1;
359
360
  /\splugins([^=]*)=[^[]\[/.test(t) && (t = t.replace(/\splugins([^=]*)=[^[]\[/, (e, t) => ` plugins${t}= [withSaltyCss,`), n = !0);
360
361
  let r = t.includes("module.exports"), i = r ? "const { withSaltyCss } = require('@salty-css/next');\n" : "import { withSaltyCss } from '@salty-css/next';\n";
361
362
  return r && !n ? (t = t.replace(/module.exports = ([^;]+)/, (e, t) => `module.exports = withSaltyCss(${t})`), n = !0) : n || (t = t.replace(/export default ([^;]+)/, (e, t) => `export default withSaltyCss(${t})`)), { content: i + t };
362
- }, be = {
363
+ }, xe = {
363
364
  name: "next",
364
- detect: (e) => _e.map((t) => u(e.projectDir, t)).find((e) => s(e)) ?? null,
365
+ detect: (e) => ve.map((t) => u(e.projectDir, t)).find((e) => s(e)) ?? null,
365
366
  plan: async (e, n) => {
366
367
  let r = await m(n, "utf-8").catch(() => void 0);
367
368
  if (r === void 0) return null;
368
- let { content: i } = ye(r);
369
+ let { content: i } = be(r);
369
370
  return i === null ? null : {
370
- packages: [`-D ${ve(e.cliVersion)}`],
371
+ packages: [`-D ${ye(e.cliVersion)}`],
371
372
  execute: async () => (t.info("Adding Salty-CSS plugin to Next.js config..."), await h(n, i), await O(n), { changed: !0 })
372
373
  };
373
374
  }
374
- }, xe = (e) => `@salty-css/vite@${e}`, Se = (e) => e.includes("saltyPlugin") ? { content: null } : { content: "import { saltyPlugin } from '@salty-css/vite';\n" + e.replace(/(plugins: \[)/, "$1\n saltyPlugin(__dirname),") }, Ce = [
375
- ge,
375
+ }, Se = (e) => `@salty-css/vite@${e}`, Ce = (e) => e.includes("saltyPlugin") ? { content: null } : { content: "import { saltyPlugin } from '@salty-css/vite';\n" + e.replace(/(plugins: \[)/, "$1\n saltyPlugin(__dirname),") }, we = [
376
+ _e,
376
377
  {
377
378
  name: "vite",
378
379
  detect: (e) => {
@@ -382,18 +383,18 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
382
383
  plan: async (e, n) => {
383
384
  let r = await m(n, "utf-8").catch(() => void 0);
384
385
  if (r === void 0) return null;
385
- let { content: i } = Se(r);
386
+ let { content: i } = Ce(r);
386
387
  return i === null ? null : {
387
- packages: [`-D ${xe(e.cliVersion)}`],
388
+ packages: [`-D ${Se(e.cliVersion)}`],
388
389
  execute: async () => (t.info("Edit file: " + n), t.info("Adding Salty-CSS plugin to Vite config..."), await h(n, i), await O(n), { changed: !0 })
389
390
  };
390
391
  }
391
392
  },
392
- be,
393
- fe
394
- ], we = async (e) => {
393
+ xe,
394
+ pe
395
+ ], Te = async (e) => {
395
396
  let t = [];
396
- for (let n of Ce) {
397
+ for (let n of we) {
397
398
  let r = await n.detect(e);
398
399
  if (!r) continue;
399
400
  let i = await n.plan(e, r);
@@ -404,7 +405,7 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
404
405
  });
405
406
  }
406
407
  return t;
407
- }, Te = async (e) => {
408
+ }, Ee = async (e) => {
408
409
  let t = [];
409
410
  for (let { name: n, configPath: r, plan: i } of e) {
410
411
  let e = await i.execute();
@@ -415,14 +416,14 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
415
416
  });
416
417
  }
417
418
  return t;
418
- }, Ee = {
419
+ }, De = {
419
420
  vite: ["dist/**"],
420
421
  next: [".next/**", "out/**"]
421
- }, De = ({ framework: e, integrations: t, hasSrcDir: n }) => {
422
+ }, Oe = ({ framework: e, integrations: t, hasSrcDir: n }) => {
422
423
  if (e === "astro") return {};
423
- let r = [...new Set(t.flatMap((e) => Ee[e] ?? []))], i = {};
424
+ let r = [...new Set(t.flatMap((e) => De[e] ?? []))], i = {};
424
425
  return n && (i.include = ["src/**"]), r.length && (i.exclude = r), i;
425
- }, Oe = async (e, n, r) => {
426
+ }, Z = async (e, n, r) => {
426
427
  let i = u(e, n);
427
428
  if (s(i)) {
428
429
  t.debug("File already exists: " + i);
@@ -434,9 +435,14 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
434
435
  let n = u(e, ".gitignore"), r = await m(n, "utf-8").catch(() => void 0);
435
436
  r !== void 0 && (r.includes("saltygen") || (t.info("Edit file: " + n), await h(n, r + "\n\n# Salty-CSS\nsaltygen\n")));
436
437
  }, ke = async (e, n) => {
437
- let r = n ?? await ce(e);
438
+ let r = n ?? await le(e);
438
439
  if (!r) {
439
- t.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
440
+ if (!await X("Could not find a CSS file to import the generated CSS. Do you want to create a new `styles/index.css` file and import it there? (y/N) ")) {
441
+ t.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
442
+ return;
443
+ }
444
+ let { fileName: n, content: r } = await G("styles/index.css");
445
+ await Z(e, n, r);
440
446
  return;
441
447
  }
442
448
  let i = u(e, r), a = await m(i, "utf-8").catch(() => void 0);
@@ -455,31 +461,31 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
455
461
  try {
456
462
  let i = this.opts(), a = i.dir ?? r;
457
463
  if (!a) return e("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
458
- let o = await L({
464
+ let o = await I({
459
465
  dir: a,
460
466
  skipInstall: i.skipInstall,
461
467
  yes: i.yes
462
468
  });
463
469
  t.info("Initializing a new Salty-CSS project!");
464
- let c = await W(o);
470
+ let c = await H(o);
465
471
  t.info(`Detected framework: ${c.name}`);
466
- let l = await we(o);
472
+ let l = await Te(o);
467
473
  if (!o.skipInstall) {
468
474
  let e = [
469
475
  w.core(o.cliVersion),
470
476
  c.runtimePackage(o.cliVersion),
471
477
  ...l.flatMap((e) => e.plan.packages)
472
478
  ];
473
- await Z(e, o.yes), await D(...e);
479
+ await Y(e, o.yes), await D(...e);
474
480
  }
475
- let d = await Promise.all([q("salty.config.ts"), q("saltygen/index.css")]);
476
- await p(o.projectDir, { recursive: !0 }), await Promise.all(d.map(({ fileName: e, content: t }) => Oe(o.projectDir, e, t)));
477
- let f = De({
481
+ let d = await Promise.all([G("salty.config.ts"), G("saltygen/index.css")]), f = u(o.projectDir, c.srcDirectory);
482
+ await p(f, { recursive: !0 }), await Promise.all(d.map(({ fileName: e, content: t }) => Z(f, e, t)));
483
+ let m = Oe({
478
484
  framework: c.name,
479
485
  integrations: l.map((e) => e.name),
480
486
  hasSrcDir: s(u(o.projectDir, "src"))
481
487
  });
482
- await P(o.cwd, o.relativeProjectPath, c, f), await Q(o.cwd), await ke(o.projectDir, i.cssFile), await Te(l), await Ae(), t.info("Running the build to generate initial CSS..."), await new n(o.projectDir).generateCss(), t.info("🎉 Salty CSS project initialized successfully!"), t.info("Next steps:"), t.info("1. Configure variables and templates in `salty.config.ts`"), t.info("2. Create a new component with `npx salty-css generate [component-name]`"), t.info("3. Run `npx salty-css build` to generate the CSS"), t.info("4. Read about the features in the documentation: https://salty-css.dev"), t.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
488
+ await N(o.cwd, o.relativeProjectPath, c, m), await Q(o.cwd), await ke(f, i.cssFile), await Ee(l), await Ae(), t.info("Running the build to generate initial CSS..."), await new n(f).generateCss(), t.info("🎉 Salty CSS project initialized successfully!"), t.info("Next steps:"), t.info("1. Configure variables and templates in `salty.config.ts`"), t.info("2. Create a new component with `npx salty-css generate [component-name]`"), t.info("3. Run `npx salty-css build` to generate the CSS"), t.info("4. Read about the features in the documentation: https://salty-css.dev"), t.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
483
489
  } catch (t) {
484
490
  return e(t instanceof Error ? t.message : String(t));
485
491
  }
@@ -498,7 +504,7 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
498
504
  if (!c) return e("Could not update Salty-CSS packages as any were found in package.json.");
499
505
  let l = await C(), u = c.map(([e]) => a === "@" ? `${e}@${l.version}` : `${e}@${a.replace(/^@/, "")}`);
500
506
  try {
501
- await Z(u, o);
507
+ await Y(u, o);
502
508
  } catch (t) {
503
509
  return e(t instanceof Error ? t.message : String(t));
504
510
  }
@@ -515,8 +521,8 @@ var k = (e = process.cwd()) => u(e, ".saltyrc.json"), A = async (e = process.cwd
515
521
  t.warn("Skipping rebuild: no project directory configured. Run `salty-css build [dir]` manually.");
516
522
  return;
517
523
  }
518
- if (!await re("Rebuild Salty CSS now?", { yes: o })) return;
519
- let m = I(p);
524
+ if (!await X("Rebuild Salty CSS now?", { yes: o })) return;
525
+ let m = F(p);
520
526
  t.info("Rebuilding Salty-CSS project..."), await new n(m).generateCss(), t.info("Rebuild complete.");
521
527
  });
522
528
  }, Ne = (n) => {
@@ -539,7 +545,7 @@ async function Pe() {
539
545
  let e = new o();
540
546
  e.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
541
547
  let t = await M();
542
- je(e), Me(e), Ne(e), te(e, t), J(e, t), e.parseAsync(process.argv);
548
+ je(e), Me(e), Ne(e), ne(e, t), K(e, t), e.parseAsync(process.argv);
543
549
  }
544
550
  //#endregion
545
551
  export { Pe as t };
@@ -3,7 +3,7 @@ const e=require("./chunk-CMqjfN_6.cjs"),t=require("./compiler/helpers.cjs"),n=re
3
3
  `),S=`/*!
4
4
  * Generated with Salty CSS (https://salty-css.dev)
5
5
  * Do not edit this file directly
6
- * Version 0.4.4
6
+ * Version 0.4.5-alpha.0
7
7
  */
8
8
  @layer imports, reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;\n\n${[`_imports.css`,`_variables.css`,`_reset.css`,`_global.css`,`_templates.css`,`_fonts.css`].filter(e=>{try{return(0,c.readFileSync)((0,u.join)(o,`css`,e),`utf8`).length>0}catch{return!1}}).map(e=>`@import url('./css/${e}')${e===`_imports.css`?` layer(imports)`:``};`).join(`
9
9
  `)}\n${x}`;if(y.importStrategy!==`component`){let e=a.reduce((e,t,r)=>{let i=t.reduce((e,t)=>{let r=(0,u.join)(o,`css`,t),i=(0,c.readFileSync)(r,`utf8`),a=/.*-([^-]+)-\d+.css/.exec(t)?.at(1)||n.toHash(r,6);return e.includes(a)?e:`${e}\n/*start:${a}-${t}*/\n${i}\n/*end:${a}*/\n`},``),a=`l_${r}.css`;return(0,c.writeFileSync)((0,u.join)(o,`css`,a),`@layer l${r} { ${i}\n }`),`${e}\n@import url('./css/${a}');`},``);S+=e}(0,c.writeFileSync)(s,S);let C=Date.now()-r,w=C<200?`🔥`:C<500?`🚀`:C<1e3?`🎉`:C<2e3?`🚗`:C<5e3?`🤔`:`🥴`;h.info(`Generated CSS in ${C}ms! ${w}`)}catch(e){console.error(e)}};generateConfigStyles=async e=>{let t=await this.getDestDir(),o={mediaQueries:[],globalStyles:[],variables:[],templates:[],imports:[],fonts:[]};await Promise.all([...e].map(async e=>{let{contents:n,outputFilePath:r}=await this.compileSaltyFile(e,t);Object.entries(n).forEach(([t,n])=>{n.isMedia?o.mediaQueries.push([t,n]):n.isGlobalDefine?o.globalStyles.push(n):n.isDefineVariables?o.variables.push(n):n.isDefineTemplates?o.templates.push(n._setPath(`${t};;${r}`)):n.isDefineImport?o.imports.push(n._setPath(e)):n.isDefineFont&&o.fonts.push(n)})}));let{config:l,path:d}=await this.generateConfig(),f={...l},{mediaQueries:p}=o;f.mediaQueries=Object.fromEntries(p.map(([e,t])=>[`@${e}`,t]));let m=p.map(([e])=>`'@${e}'`).join(` | `),g=new Set,_=async(e,t=[])=>{if(!e)return[];let r=Object.entries(e).map(async([e,r])=>{let a=async r=>{if(!r)return;if(r instanceof Promise)return await a(await r);if(typeof r==`function`)return await a(await r());if(typeof r==`object`)return await _(r,[...t,e]);let o=O(e),s=n.dashCase(e),c=[...t,o].join(`.`);g.add(`"${c}"`);let l=[...t.map(n.dashCase),s].join(`-`),u=i.s(r);return u?`--${l}: ${u.transformed};`:`--${l}: ${r};`};return await a(r)});return(await Promise.all(r)).flat()},v=async e=>{if(!e)return[];let t=Object.entries(e).map(async([e,t])=>{let n=await _(t);return e===`base`?n.join(``):f.mediaQueries[e]?`${f.mediaQueries[e]} { ${n.join(``)} }`:`${e} { ${n.join(``)} }`});return(await Promise.all(t)).flat()},y=async e=>{if(!e)return[];let t=Object.entries(e).map(async([e,t])=>{let n=Object.entries(t).map(async([t,n])=>{let r=await _(n,[e]);return`${`.${e}-${t}, [data-${e}="${t}"]`} { ${r.join(``)} }`});return(await Promise.all(n)).flat()});return(await Promise.all(t)).flat()},b=(e={})=>({...e,responsive:void 0,conditional:void 0}),x=e=>o.variables.map(t=>e===`static`?b(t._current):t._current[e]),S=a.mergeObjects(b(l.variables),x(`static`)),C=await _(S),T=await v(a.mergeObjects(l.variables?.responsive,x(`responsive`))),E=await y(a.mergeObjects(l.variables?.conditional,x(`conditional`)));(0,c.writeFileSync)((0,u.join)(t,`css/_variables.css`),`:root { ${C.join(``)} ${T.join(``)} } ${E.join(``)}`),f.staticVariables=S,(0,c.writeFileSync)((0,u.join)(t,`css/_global.css`),`@layer global { ${await i.t(a.mergeObjects(l.global,o.globalStyles),``)} }`);let D=(0,u.join)(t,`css/_reset.css`);(0,c.writeFileSync)(D,`@layer reset { ${await i.t(l.reset===`none`?{}:typeof l.reset==`object`?l.reset:k,``)} }`);let A=(0,u.join)(t,`css/_templates.css`),j=a.mergeObjects(l.templates,o.templates),M=await s.parseTemplates(j),N=s.getTemplateTypes(j),P=s.getTemplateVariantMaps(j);(0,c.writeFileSync)(A,`@layer templates { ${M} }`),f.templates=j;let F=(0,u.join)(t,`css/_imports.css`),I=[];for(let e of o.imports){let n=e._path;if(n)for(let r of e._current)try{let{rule:e}=w(r,n,t);I.push(e)}catch(e){let t=typeof r==`string`?r:r.url;h.error(`Failed to resolve defineImport(${JSON.stringify(t)}) from ${n}: ${e.message}`)}}(0,c.writeFileSync)(F,I.join(`
@@ -244,7 +244,7 @@ var X = {
244
244
  let A = c.map((e) => `@import url('./css/${e}');`).join("\n"), j = `/*!
245
245
  * Generated with Salty CSS (https://salty-css.dev)
246
246
  * Do not edit this file directly
247
- * Version 0.4.4
247
+ * Version 0.4.5-alpha.0
248
248
  */
249
249
  @layer imports, reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;\n\n${[
250
250
  "_imports.css",
@@ -1,4 +1,4 @@
1
- //#region src/bin/templates/index.css__template
1
+ //#region src/bin/templates/saltygen_index.css__template
2
2
  var e = "/* Empty */";
3
3
  //#endregion
4
4
  export { e as default };
@@ -0,0 +1,4 @@
1
+ //#region src/bin/templates/styles_index.css__template
2
+ var e = "@import url(../saltygen/index.css);";
3
+ //#endregion
4
+ export { e as default };
@@ -0,0 +1 @@
1
+ var e=`@import url(../saltygen/index.css);`;exports.default=e;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/margarita-form/salty-css/issues"
17
17
  },
18
- "version": "0.4.4",
18
+ "version": "0.4.5-alpha.0",
19
19
  "type": "module",
20
20
  "scripts": {
21
21
  "build": "vite build",
@@ -1,11 +0,0 @@
1
- const e=require("./chunk-CMqjfN_6.cjs"),t=require("./salty-compiler-GObjXtub.cjs"),n=require("./compiler/helpers.cjs"),r=require("./util/index.cjs"),i=require("./server/index.cjs");let a=require("commander"),o=require("fs"),s=require("path"),c=require("fs/promises"),l=require("child_process"),u=require("ora");u=e.t(u,1);let d=require("ejs");d=e.t(d,1);let f=require("readline/promises");var p=(0,s.join)(process.cwd(),`package.json`),m=async(e=p)=>{let t=await(0,c.readFile)(e,`utf-8`).then(JSON.parse).catch(()=>void 0);if(!t)throw`Could not read package.json file!`;return t},h=async(e,t=p)=>{typeof e==`object`&&(e=JSON.stringify(e,null,2)),await(0,c.writeFile)(t,e)},g=async()=>m(new URL(`../package.json`,``+{}.url)),_={core:e=>`@salty-css/core@${e}`,eslintConfigCore:e=>`@salty-css/eslint-config-core@${e}`},v=e=>{e.scripts||={};let t=e.scripts.prepare;if(t){if(t.includes(`salty-css`))return{changed:!1,pkg:e};e.scripts.prepare=t+` && npx salty-css build`}else e.scripts.prepare=`npx salty-css build`;return{changed:!0,pkg:e}},y=e=>new Promise((t,n)=>{(0,l.exec)(e,e=>{if(e)return n(e);t()})}),b=async(...e)=>{let t=e.map(e=>e.replace(`-D`,``).split(`@`).slice(0,-1).join(`@`).trim()).join(`, `),n=(0,u.default)(`Installing packages: ${t}`).start();await y(`npm install ${e.join(` `)}`),n.succeed(`Installed packages: ${t}`)},x=()=>(0,o.existsSync)((0,s.join)(process.cwd(),`node_modules`,`.bin`,`prettier`));async function S(e){try{if(!x())return;await y(`./node_modules/.bin/prettier --write "${e}"`),t.r.info(`Formatted ${e} with Prettier`)}catch(n){t.r.error(`Error formatting ${e} with Prettier:`,n)}}var C=(e=process.cwd())=>(0,s.join)(e,`.saltyrc.json`),w=async(e=process.cwd())=>await(0,c.readFile)(C(e),`utf-8`).then(JSON.parse).catch(()=>({})),T=async(e=process.cwd())=>(0,c.readFile)(C(e),`utf-8`).catch(()=>void 0),E=async(e=process.cwd())=>(await w(e)).defaultProject,D=(e,t,n,r={})=>{let i=(0,s.join)(t,n.srcDirectory),a={dir:i,framework:n.name,...r};if(e===void 0)return{content:JSON.stringify({$schema:`./node_modules/@salty-css/core/.saltyrc.schema.json`,info:`This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.`,defaultProject:i,projects:[a]},null,2),changed:!0,created:!0};let o=JSON.parse(e),c=o.projects||[];if(c.some(e=>e.dir===i))return{content:e,changed:!1,created:!1};c.push(a),o.projects=[...c];let l=JSON.stringify(o,null,2);return{content:l,changed:l!==e,created:!1}},O=async(e,n,r,i={})=>{let a=C(e),{content:o,changed:s,created:l}=D(await T(e),n,r,i);return s?(l?t.r.info(`Creating file: `+a):t.r.info(`Edit file: `+a),await(0,c.writeFile)(a,o),await S(a),!0):!1},ee=(e,t)=>(e.projects||[]).find(e=>e.dir===t)?.framework,k=(e,t=process.cwd())=>(0,s.join)(t,e===`.`?``:e),A=async e=>{let t=process.cwd(),n=k(e.dir,t),r=(0,s.relative)(t,n)||`.`,i=await m().catch(()=>void 0);if(e.requirePackageJson!==!1&&!i)throw Error(`Salty CSS project must be initialized in a directory with a package.json file.`);return{cwd:t,projectDir:n,relativeProjectPath:r,packageJson:i,rcFile:await w(t),cliVersion:(await g()).version||`0.0.0`,skipInstall:!!e.skipInstall,yes:!!e.yes}},j=(e,r)=>{e.command(`build [directory]`).alias(`b`).description(`Build the Salty-CSS project.`).option(`-d, --dir <dir>`,`Project directory to build the project in.`).option(`--watch`,`Watch for changes and rebuild the project.`).option(`--mode <mode>`,`Build mode: "production" or "development". Defaults to NODE_ENV-based detection.`).action(async function(e=r){t.r.info(`Building the Salty-CSS project...`);let{dir:a=e,watch:s,mode:c}=this.opts();if(c!==void 0&&c!==`production`&&c!==`development`)return t.n(`Invalid --mode "${c}". Expected "production" or "development".`);let l=a??await E();if(!l)return t.n(`Project directory must be provided. Add it as the first argument after build command or use the --dir option.`);let u=k(l),d=new t.t(u,{mode:c});await d.generateCss(),s&&(t.r.info(`Watching for changes in the project directory...`),(0,o.watch)(u,{recursive:!0},async(e,t)=>{if(!t)return console.warn(`File path not provided for change event`);await i.checkShouldRestart(t)?await d.generateCss(!1):n.isSaltyFile(t)&&await d.generateFile(t)}))})},M=[`astro.config.mjs`,`astro.config.ts`,`astro.config.js`,`astro.config.cjs`],N=e=>{for(let t of M){let n=(0,s.join)(e,t);if((0,o.existsSync)(n))return n}return null},te=e=>{let t=e.packageJson;if(!t)return!1;let n={...t.dependencies,...t.devDependencies};return Object.prototype.hasOwnProperty.call(n,`astro`)},P={name:`astro`,srcDirectory:`src`,detect:e=>!!N(e.projectDir)||te(e),runtimePackage:e=>`@salty-css/astro@${e}`,templates:{styled:`astro/styled-file.ts`,component:{styled:`astro/styled-file.ts`,wrapper:`astro/component.astro`,wrapperExt:`.astro`}}},F={name:`react`,srcDirectory:``,detect:()=>!0,runtimePackage:e=>`@salty-css/react@${e}`,templates:{styled:`react/styled-file.ts`,component:{styled:`react/styled-file.ts`,wrapper:`react/vanilla-file.ts`,wrapperExt:`.tsx`}}},I=[P,F],L={astro:P,react:F},R=async e=>{for(let t of I)if(await t.detect(e))return t;return F},z=e=>{if(e)return L[e]},B={"salty.config.ts":()=>Promise.resolve().then(()=>require("./salty.config-B0ZiRpHR.cjs")),"saltygen/index.css":()=>Promise.resolve().then(()=>require("./templates-BGHLaAOm.cjs")),"react/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-BCbAEzBB.cjs")),"react/vanilla-file.ts":()=>Promise.resolve().then(()=>require("./vanilla-file-Z3VsOa_U.cjs")),"astro/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-DorArlCk.cjs")),"astro/component.astro":()=>Promise.resolve().then(()=>require("./astro-component-r0qEcF1p.cjs"))},V=async(e,t)=>{let{default:n}=await B[e]();return{fileName:e,content:d.default.render(n,t)}},H=(e,n)=>{e.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.`).option(`-r, --reactComponent`,`Generate a wrapper component file alongside the styled definition.`).action(async function(e,i=n){let{file:a=e,dir:o=i,tag:l,name:u,className:d,reactComponent:f=!1}=this.opts();if(!a)return t.n(`File to generate must be provided. Add it as the first argument after generate command or use the --file option.`);if(!o)return t.n(`Project directory must be provided. Add it as the second argument after generate command or use the --dir option.`);let p;try{p=await A({dir:o,requirePackageJson:!1})}catch(e){return t.n(e instanceof Error?e.message:String(e))}let m=z(ee(p.rcFile,p.relativeProjectPath))??await R(p),h=a.split(`/`).slice(0,-1).join(`/`);h&&await(0,c.mkdir)((0,s.join)(p.projectDir,h),{recursive:!0});let g=(0,s.parse)((0,s.join)(p.projectDir,a));g.ext||=`.ts`,g.name.endsWith(`.css`)||(g.name+=`.css`),g.base=g.name+g.ext;let _=(0,s.format)(g);if(await(0,c.readFile)(_,`utf-8`).catch(()=>void 0)!==void 0){t.r.error(`File already exists: `+_);return}let v=r.pascalCase(u||g.base.replace(/\.css\.\w+$/,``));if(f){if(!m.templates.component)return t.n(`--reactComponent is not supported for the ${m.name} framework.`);let e=v+`Component`;v+=`Wrapper`;let n=g.base.replace(/\.css\.\w+$/,``),{content:r}=await V(m.templates.component.wrapper,{tag:l,componentName:e,styledComponentName:v,className:d,fileName:n});g.name=n.replace(/\.css$/,``),g.ext=m.templates.component.wrapperExt,g.base=g.name+g.ext;let i=(0,s.format)(g);t.r.info(`Generating a new file: `+i),await(0,c.writeFile)(i,r),await S(i)}let{content:y}=await V(f&&m.templates.component?m.templates.component.styled:m.templates.styled,{tag:l,name:v,className:d});t.r.info(`Generating a new file: `+_),await(0,c.writeFile)(_,y),await S(_)})},U=e=>{let t=e.trim();return t.startsWith(`-D `)?`${t.slice(3).trim()} (dev)`:t},W=e=>e.map(e=>` + ${U(e)}`).join(`
2
- `),G=async(e,t,n={})=>{if(t||e.length===0)return;let r=n.input??process.stdin,i=n.output??process.stdout;if(!(n.isTTY??process.stdin.isTTY??!1))throw Error(`Cannot prompt for install confirmation: stdin is not a TTY. Re-run with --yes to install the listed packages without prompting.`);i.write(`The following packages will be installed:\n${W(e)}\n`);let a=(0,f.createInterface)({input:r,output:i,terminal:!1});try{let e=(await a.question(`Proceed? (y/N) `)).trim().toLowerCase();if(e!==`y`&&e!==`yes`)throw Error(`Install cancelled by user.`)}finally{a.close()}},K=async(e,t={})=>{if(t.yes)return!0;let n=t.input??process.stdin,r=t.output??process.stdout;if(!(t.isTTY??process.stdin.isTTY??!1))return!1;let i=t.defaultYes?`(Y/n)`:`(y/N)`,a=(0,f.createInterface)({input:n,output:r,terminal:!1});try{let n=(await a.question(`${e} ${i} `)).trim().toLowerCase();return n===``?!!t.defaultYes:n===`y`||n===`yes`}finally{a.close()}},q=[`src`,`public`,`assets`,`styles`,`css`,`app`],J=[`styles`,`css`,`app`,`pages`],Y=[`index`,`styles`,`main`,`app`,`global`,`globals`],X=[`.css`,`.scss`,`.sass`],Z=async e=>{for(let t of q)for(let n of Y)for(let r of X){let i=(0,s.join)(e,t,n+r);if(await(0,c.readFile)(i,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,i);for(let i of J){let a=(0,s.join)(e,t,i,n+r);if(await(0,c.readFile)(a,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,a)}}},Q=e=>`@salty-css/astro@${e}`,ne=`import saltyIntegration from '@salty-css/astro/integration';
3
- `,re=e=>{if(e.includes(`@salty-css/astro`))return{content:null};let t=e,n=!1;return/integrations\s*:\s*\[/.test(t)?(t=t.replace(/integrations\s*:\s*\[/,e=>`${e}saltyIntegration(),`),n=!0):/defineConfig\s*\(\s*\{/.test(t)&&(t=t.replace(/defineConfig\s*\(\s*\{/,e=>`${e}\n integrations: [saltyIntegration()],`),n=!0),n?{content:ne+t}:{content:null,warning:`Could not find a place to add saltyIntegration() in the Astro config. Please add it manually.`}},ie={name:`astro`,detect:e=>N(e.projectDir),plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let i=re(r);if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[`-D ${Q(e.cliVersion)}`],execute:async()=>(t.r.info(`Adding Salty-CSS integration to Astro config: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},ae=[[`projectJs`,`eslint.config.js`],[`rootJs`,`eslint.config.js`],[`projectMjs`,`eslint.config.mjs`],[`rootMjs`,`eslint.config.mjs`],[`projectJson`,`.eslintrc.json`],[`rootJson`,`.eslintrc.json`]],oe=(e,t)=>ae.map(([n,r])=>(0,s.join)(n.startsWith(`root`)?t:e,r)),se=(e,t)=>{if(e.includes(`salty-css`))return{content:null};if(t){let t=`import saltyCss from "@salty-css/eslint-config-core/flat";\n${e}`;if(e.includes(`typescript-eslint`))if(t.includes(`.config(`))t=t.replace(`.config(`,`.config(saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};else if(t.includes(`export default [`))t=t.replace(`export default [`,`export default [ saltyCss,`);else if(t.includes(`eslintConfig = [`))t=t.replace(`eslintConfig = [`,`eslintConfig = [ saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};return{content:t}}let n=JSON.parse(e);return n.extends||=[],n.extends.includes(`@salty-css/core`)||n.extends.push(`@salty-css/core`),{content:JSON.stringify(n,null,2)}},ce={name:`eslint`,detect:e=>oe(e.projectDir,e.cwd).find(e=>(0,o.existsSync)(e))??null,plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return t.r.error(`Could not read ESLint config file.`),null;let i=se(r,n.endsWith(`js`));if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[_.eslintConfigCore(e.cliVersion)],execute:async()=>(t.r.info(`Edit file: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},le=[`next.config.js`,`next.config.cjs`,`next.config.ts`,`next.config.mjs`],ue=e=>`@salty-css/next@${e}`,de=e=>{if(e.includes(`withSaltyCss`))return{content:null};let t=e,n=!1;/\splugins([^=]*)=[^[]\[/.test(t)&&(t=t.replace(/\splugins([^=]*)=[^[]\[/,(e,t)=>` plugins${t}= [withSaltyCss,`),n=!0);let r=t.includes(`module.exports`),i=r?`const { withSaltyCss } = require('@salty-css/next');
4
- `:`import { withSaltyCss } from '@salty-css/next';
5
- `;return r&&!n?(t=t.replace(/module.exports = ([^;]+)/,(e,t)=>`module.exports = withSaltyCss(${t})`),n=!0):n||(t=t.replace(/export default ([^;]+)/,(e,t)=>`export default withSaltyCss(${t})`)),{content:i+t}},fe={name:`next`,detect:e=>le.map(t=>(0,s.join)(e.projectDir,t)).find(e=>(0,o.existsSync)(e))??null,plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let{content:i}=de(r);return i===null?null:{packages:[`-D ${ue(e.cliVersion)}`],execute:async()=>(t.r.info(`Adding Salty-CSS plugin to Next.js config...`),await(0,c.writeFile)(n,i),await S(n),{changed:!0})}}},pe=e=>`@salty-css/vite@${e}`,me=e=>e.includes(`saltyPlugin`)?{content:null}:{content:`import { saltyPlugin } from '@salty-css/vite';
6
- `+e.replace(/(plugins: \[)/,`$1
7
- saltyPlugin(__dirname),`)},he=[ce,{name:`vite`,detect:e=>{let t=(0,s.join)(e.projectDir,`vite.config.ts`);return(0,o.existsSync)(t)?t:null},plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let{content:i}=me(r);return i===null?null:{packages:[`-D ${pe(e.cliVersion)}`],execute:async()=>(t.r.info(`Edit file: `+n),t.r.info(`Adding Salty-CSS plugin to Vite config...`),await(0,c.writeFile)(n,i),await S(n),{changed:!0})}}},fe,ie],ge=async e=>{let t=[];for(let n of he){let r=await n.detect(e);if(!r)continue;let i=await n.plan(e,r);i&&t.push({name:n.name,configPath:r,plan:i})}return t},_e=async e=>{let t=[];for(let{name:n,configPath:r,plan:i}of e){let e=await i.execute();t.push({name:n,configPath:r,changed:e.changed})}return t},ve={vite:[`dist/**`],next:[`.next/**`,`out/**`]},ye=({framework:e,integrations:t,hasSrcDir:n})=>{if(e===`astro`)return{};let r=[...new Set(t.flatMap(e=>ve[e]??[]))],i={};return n&&(i.include=[`src/**`]),r.length&&(i.exclude=r),i},be=async(e,n,r)=>{let i=(0,s.join)(e,n);if((0,o.existsSync)(i)){t.r.debug(`File already exists: `+i);return}let a=n.split(`/`).slice(0,-1).join(`/`);a&&await(0,c.mkdir)((0,s.join)(e,a),{recursive:!0}),t.r.info(`Creating file: `+i),await(0,c.writeFile)(i,r),await S(i)},xe=async e=>{let n=(0,s.join)(e,`.gitignore`),r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);r!==void 0&&(r.includes(`saltygen`)||(t.r.info(`Edit file: `+n),await(0,c.writeFile)(n,r+`
8
-
9
- # Salty-CSS
10
- saltygen
11
- `)))},Se=async(e,n)=>{let r=n??await Z(e);if(!r){t.r.warn(`Could not find a CSS file to import the generated CSS. Please add it manually.`);return}let i=(0,s.join)(e,r),a=await(0,c.readFile)(i,`utf-8`).catch(()=>void 0);if(a===void 0||a.includes(`saltygen`))return;let o=(0,s.relative)((0,s.join)(i,`..`),(0,s.join)(e,`saltygen/index.css`));t.r.info(`Adding global import statement to CSS file: `+i),await(0,c.writeFile)(i,`@import '${o}';\n`+a),await S(i)},Ce=async()=>{let e=await m().catch(()=>{t.n(`Could not read package.json file.`)});if(!e)return;let{pkg:n}=v(e);await h(n)},we=e=>{e.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.`).option(`-y, --yes`,`Skip the install confirmation prompt.`).action(async function(e=`.`){try{let n=this.opts(),r=n.dir??e;if(!r)return t.n(`Project directory must be provided. Add it as the first argument after init command or use the --dir option.`);let i=await A({dir:r,skipInstall:n.skipInstall,yes:n.yes});t.r.info(`Initializing a new Salty-CSS project!`);let a=await R(i);t.r.info(`Detected framework: ${a.name}`);let l=await ge(i);if(!i.skipInstall){let e=[_.core(i.cliVersion),a.runtimePackage(i.cliVersion),...l.flatMap(e=>e.plan.packages)];await G(e,i.yes),await b(...e)}let u=await Promise.all([V(`salty.config.ts`),V(`saltygen/index.css`)]);await(0,c.mkdir)(i.projectDir,{recursive:!0}),await Promise.all(u.map(({fileName:e,content:t})=>be(i.projectDir,e,t)));let d=ye({framework:a.name,integrations:l.map(e=>e.name),hasSrcDir:(0,o.existsSync)((0,s.join)(i.projectDir,`src`))});await O(i.cwd,i.relativeProjectPath,a,d),await xe(i.cwd),await Se(i.projectDir,n.cssFile),await _e(l),await Ce(),t.r.info(`Running the build to generate initial CSS...`),await new t.t(i.projectDir).generateCss(),t.r.info(`🎉 Salty CSS project initialized successfully!`),t.r.info(`Next steps:`),t.r.info("1. Configure variables and templates in `salty.config.ts`"),t.r.info("2. Create a new component with `npx salty-css generate [component-name]`"),t.r.info("3. Run `npx salty-css build` to generate the CSS"),t.r.info(`4. Read about the features in the documentation: https://salty-css.dev`),t.r.info(`5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐`)}catch(e){return t.n(e instanceof Error?e.message:String(e))}})},$=async()=>{let e=(0,s.join)(process.cwd(),`package.json`),n=await m(e).catch(e=>t.n(e));if(!n)return t.n(`Could not read package.json file.`);let r={...n.dependencies,...n.devDependencies},i=Object.entries(r).filter(([e])=>e===`salty-css`||e.startsWith(`@salty-css/`));return i.length?i:t.n(`No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: `+e)},Te=e=>{e.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).option(`-y, --yes`,`Skip confirmation prompts (install and rebuild).`).option(`-d, --dir <dir>`,`Project directory to rebuild after updating.`).action(async function(e=`latest`){let{legacyPeerDeps:n,version:r=e,yes:i=!1,dir:a}=this.opts(),o=await $();if(!o)return t.n(`Could not update Salty-CSS packages as any were found in package.json.`);let s=await g(),c=o.map(([e])=>r===`@`?`${e}@${s.version}`:`${e}@${r.replace(/^@/,``)}`);try{await G(c,i)}catch(e){return t.n(e instanceof Error?e.message:String(e))}n?(t.r.warn(`Using legacy peer dependencies to update packages.`),await b(...c,`--legacy-peer-deps`)):await b(...c);let l=await $();if(!l)return t.n(`Something went wrong while reading the updated packages.`);let u=l.reduce((e,[t,n])=>(e[n]||(e[n]=[]),e[n].push(t),e),{});if(Object.keys(u).length===1){let e=Object.keys(u)[0];t.r.info(`Updated to all Salty CSS packages successfully to ${e.replace(/^\^/,``)}`)}else for(let[e,n]of Object.entries(u))t.r.info(`Updated to ${e.replace(/^\^/,``)}: ${n.join(`, `)}`);let d=a??await E();if(!d){t.r.warn("Skipping rebuild: no project directory configured. Run `salty-css build [dir]` manually.");return}if(!await K(`Rebuild Salty CSS now?`,{yes:i}))return;let f=k(d);t.r.info(`Rebuilding Salty-CSS project...`),await new t.t(f).generateCss(),t.r.info(`Rebuild complete.`)})},Ee=e=>{e.option(`-v, --version`,`Show the current version of Salty-CSS.`).action(async function(){let e=await g();t.r.info(`CLI is running: `+e.version);let n=(0,s.join)(process.cwd(),`package.json`),r=await m(n).catch(e=>t.n(e));if(!r)return;let i={...r.dependencies,...r.devDependencies},a=Object.keys(i).filter(e=>e===`salty-css`||e.startsWith(`@salty-css/`));if(!a.length)return t.n(`No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: `+n);for(let e of a)t.r.info(`${e}: ${i[e]}`)})};async function De(){let e=new a.Command;e.name(`salty-css`).description(`Salty-CSS CLI tool to help with annoying configuration tasks.`);let t=await E();we(e),Te(e),Ee(e),j(e,t),H(e,t),e.parseAsync(process.argv)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return De}});