@salty-css/core 0.0.1-alpha.91 → 0.0.1-alpha.92

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.
Files changed (3) hide show
  1. package/bin/main.cjs +7 -6
  2. package/bin/main.js +180 -167
  3. package/package.json +1 -1
package/bin/main.cjs CHANGED
@@ -1,10 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ie=require("commander"),L=require("fs"),s=require("fs/promises"),i=require("path"),ne=require("ejs"),t=require("../index-BKoD9apd.cjs"),se=require("../pascal-case-iWoaJWwT.cjs"),oe=require("child_process"),ae=require("ora");var W=typeof document<"u"?document.currentScript:null;const Y=f=>new Promise((h,v)=>{oe.exec(f,F=>{if(F)return v(F);h()})}),I=async(...f)=>{const h=f.map(k=>k.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),v=ae(`Installing packages: ${h}`).start(),F=f.join(" ");await Y(`npm install ${F}`),v.succeed(`Installed packages: ${h}`)},re=()=>L.existsSync(i.join(process.cwd(),"node_modules",".bin","prettier"));async function j(f){try{if(!re())return;await Y(`./node_modules/.bin/prettier --write "${f}"`),t.logger.info(`Formatted ${f} with Prettier`)}catch(h){t.logger.error(`Error formatting ${f} with Prettier:`,h)}}async function ce(){const f=new ie.Command;f.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const h={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.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")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},v=async(n,r)=>{const{default:c}=await h[n],u=ne.render(c,r);return{fileName:n,content:u}},F=async()=>{const n=i.join(process.cwd(),".saltyrc.json");return await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>({}))},k=i.join(process.cwd(),"package.json"),N=async(n=k)=>{const r=await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>{});if(!r)throw"Could not read package.json file!";return r},Z=async(n,r=k)=>{typeof n=="object"&&(n=JSON.stringify(n,null,2)),await s.writeFile(r,n)},M=async()=>{const n=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:W&&W.tagName.toUpperCase()==="SCRIPT"&&W.src||new URL("bin/main.cjs",document.baseURI).href);return N(n)},B=await(async()=>(await F()).defaultProject)(),b=await M(),D={core:`@salty-css/core@${b.version}`,react:`@salty-css/react@${b.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${b.version}`,vite:`@salty-css/vite@${b.version}`,next:`@salty-css/next@${b.version}`},R=n=>{const r=n==="."?"":n,c=process.cwd();return i.join(c,r)};f.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 N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:c=n,cssFile:u,skipInstall:y}=this.opts();if(!c)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");y||await I(D.core,D.react);const p=process.cwd(),l=R(c),E=await Promise.all([v("salty.config.ts"),v("saltygen/index.css")]);await s.mkdir(l,{recursive:!0});const m=E.map(async({fileName:e,content:o})=>{const d=i.join(l,e);if(await s.readFile(d,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+d);return}const C=e.split("/").slice(0,-1).join("/");C&&await s.mkdir(i.join(l,C),{recursive:!0}),t.logger.info("Creating file: "+d),await s.writeFile(d,o),await j(d)});await Promise.all(m);const P=i.relative(p,l)||".",w=i.join(p,".saltyrc.json"),a=await s.readFile(w,"utf-8").catch(()=>{});if(a===void 0){t.logger.info("Creating file: "+w);const o=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:P,projects:[{dir:P,framework:"react"}]},null,2);await s.writeFile(w,o),await j(w)}else{const e=JSON.parse(a),o=(e==null?void 0:e.projects)||[];if(o.findIndex(g=>g.dir===P)===-1){o.push({dir:P,framework:"react"}),e.projects=[...o];const g=JSON.stringify(e,null,2);g!==a&&(t.logger.info("Edit file: "+w),await s.writeFile(w,g),await j(w))}}const S=i.join(p,".gitignore"),T=await s.readFile(S,"utf-8").catch(()=>{});T!==void 0&&(T.includes("saltygen")||(t.logger.info("Edit file: "+S),await s.writeFile(S,T+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("commander"),G=require("fs"),s=require("fs/promises"),i=require("path"),te=require("ejs"),t=require("../index-BKoD9apd.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),ne=require("child_process"),se=require("ora");var z=typeof document<"u"?document.currentScript:null;const Q=p=>new Promise((S,v)=>{ne.exec(p,k=>{if(k)return v(k);S()})}),D=async(...p)=>{const S=p.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),v=se(`Installing packages: ${S}`).start(),k=p.join(" ");await Q(`npm install ${k}`),v.succeed(`Installed packages: ${S}`)},oe=()=>G.existsSync(i.join(process.cwd(),"node_modules",".bin","prettier"));async function w(p){try{if(!oe())return;await Q(`./node_modules/.bin/prettier --write "${p}"`),t.logger.info(`Formatted ${p} with Prettier`)}catch(S){t.logger.error(`Error formatting ${p} with Prettier:`,S)}}async function ae(){const p=new ee.Command;p.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const S={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.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")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},v=async(n,c)=>{const{default:l}=await S[n],y=te.render(l,c);return{fileName:n,content:y}},k=async()=>{const n=i.join(process.cwd(),".saltyrc.json");return await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>({}))},b=i.join(process.cwd(),"package.json"),q=async(n=b)=>{const c=await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>{});if(!c)throw"Could not read package.json file!";return c},X=async(n,c=b)=>{typeof n=="object"&&(n=JSON.stringify(n,null,2)),await s.writeFile(c,n)},B=async()=>{const n=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return q(n)},V=await(async()=>(await k()).defaultProject)(),$=await B(),T={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=n=>{const c=n==="."?"":n,l=process.cwd();return i.join(l,c)};p.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 q().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=n,cssFile:y,skipInstall:m}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");m||await D(T.core,T.react);const f=process.cwd(),a=R(l),E=await Promise.all([v("salty.config.ts"),v("saltygen/index.css")]);await s.mkdir(a,{recursive:!0});const h=E.map(async({fileName:e,content:d})=>{const o=i.join(a,e);if(await s.readFile(o,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+o);return}const g=e.split("/").slice(0,-1).join("/");g&&await s.mkdir(i.join(a,g),{recursive:!0}),t.logger.info("Creating file: "+o),await s.writeFile(o,d),await w(o)});await Promise.all(h);const x=i.relative(f,a)||".",C=i.join(f,".saltyrc.json"),r=await s.readFile(C,"utf-8").catch(()=>{});if(r===void 0){t.logger.info("Creating file: "+C);const d=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:x,projects:[{dir:x,framework:"react"}]},null,2);await s.writeFile(C,d),await w(C)}else{const e=JSON.parse(r),d=(e==null?void 0:e.projects)||[];if(d.findIndex(u=>u.dir===x)===-1){d.push({dir:x,framework:"react"}),e.projects=[...d];const u=JSON.stringify(e,null,2);u!==r&&(t.logger.info("Edit file: "+C),await s.writeFile(C,u),await w(C))}}const j=i.join(f,".gitignore"),L=await s.readFile(j,"utf-8").catch(()=>{});L!==void 0&&(L.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,L+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
5
- `)));const x=["src","public","assets","styles","css","app"],H=["styles","css","app","pages"],z=["index","styles","main","global","globals"],_=[".css",".scss",".sass"],$=await(async()=>{if(u)return u;for(const e of x)for(const o of z)for(const d of _){const g=i.join(l,e,o+d);if(await s.readFile(g,"utf-8").catch(()=>{})!==void 0)return i.relative(l,g);for(const q of H){const O=i.join(l,e,q,o+d);if(await s.readFile(O,"utf-8").catch(()=>{})!==void 0)return i.relative(l,O)}}})();if($){const e=i.join(l,$),o=await s.readFile(e,"utf-8").catch(()=>{});if(o!==void 0&&!o.includes("saltygen")){const g=i.join(e,".."),q=`@import '${i.relative(g,i.join(l,"saltygen/index.css"))}';`;t.logger.info("Adding global import statement to CSS file: "+e),await s.writeFile(e,q+`
6
- `+o),await j(e)}}else t.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");const K=i.join(p,".eslintrc.json"),ee=L.existsSync(K),Q=i.join(l,".eslintrc.json"),X=L.existsSync(Q);if(ee||X){y||await I(D.eslintConfigCore);const e=X?Q:K,o=await s.readFile(e,"utf-8").catch(()=>{});if(!o)return t.logError("Could not read ESLint config file.");if(!o.includes("salty-css")){const g=JSON.parse(o);t.logger.info("Edit file: "+e),g.extends||(g.extends=[]),g.extends.push("@salty-css/core");const C=JSON.stringify(g,null,2);await s.writeFile(e,C),await j(e)}}const A=i.join(l,"vite.config.ts"),G=await s.readFile(A,"utf-8").catch(()=>{});if(G!==void 0&&!G.includes("saltyPlugin")){t.logger.info("Edit file: "+A);const o=`import { saltyPlugin } from '@salty-css/vite';
7
- `,g=G.replace(/(plugins: \[)/,`$1
8
- saltyPlugin(__dirname),`);y||await I(`-D ${D.vite}`),t.logger.info("Adding Salty-CSS plugin to Vite config..."),await s.writeFile(A,o+g),await j(A)}const U=["next.config.js","next.config.cjs","next.config.ts","next.config.mjs"].map(e=>i.join(l,e)).find(e=>L.existsSync(e));if(U){let e=await s.readFile(U,"utf-8").catch(()=>{});if(e!==void 0&&!e.includes("withSaltyCss")){let d=!1;/\splugins([^=]*)=[^[]\[/.test(e)&&!d&&(e=e.replace(/\splugins([^=]*)=[^[]\[/,(O,J)=>` plugins${J}= [withSaltyCss,`),d=!0);const C=e.includes("module.exports"),q=C?`const { withSaltyCss } = require('@salty-css/next');
5
+ `)));const F=["src","public","assets","styles","css","app"],H=["styles","css","app","pages"],M=["index","styles","main","global","globals"],_=[".css",".scss",".sass"],J=await(async()=>{if(y)return y;for(const e of F)for(const d of M)for(const o of _){const u=i.join(a,e,d+o);if(await s.readFile(u,"utf-8").catch(()=>{})!==void 0)return i.relative(a,u);for(const I of H){const O=i.join(a,e,I,d+o);if(await s.readFile(O,"utf-8").catch(()=>{})!==void 0)return i.relative(a,O)}}})();if(J){const e=i.join(a,J),d=await s.readFile(e,"utf-8").catch(()=>{});if(d!==void 0&&!d.includes("saltygen")){const u=i.join(e,".."),I=`@import '${i.relative(u,i.join(a,"saltygen/index.css"))}';`;t.logger.info("Adding global import statement to CSS file: "+e),await s.writeFile(e,I+`
6
+ `+d),await w(e)}}else t.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");const Y={projectJs:i.join(a,"eslint.config.js"),rootJs:i.join(f,"eslint.config.js"),projectMjs:i.join(a,"eslint.config.mjs"),rootMjs:i.join(f,"eslint.config.mjs"),projectJson:i.join(a,".eslintrc.json"),rootJson:i.join(f,".eslintrc.json")},P=Object.values(Y).find(e=>G.existsSync(e));if(P){m||await D(T.eslintConfigCore);const e=await s.readFile(P,"utf-8").catch(()=>{});if(!e)return t.logError("Could not read ESLint config file.");if(!e.includes("salty-css")){const o=JSON.parse(e);if(t.logger.info("Edit file: "+P),P.endsWith("js")){let g=`import saltyCss from "@salty-css/eslint-config-core/flat";
7
+ ${o}`;e.includes("typescript-eslint")?g.includes(".config(")?g=g.replace(".config(",".config(saltyCss,"):t.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."):g.includes("export default [")?g=g.replace("export default [","export default [ saltyCss,"):g.includes("eslintConfig = [")?g=g.replace("eslintConfig = [","eslintConfig = [ saltyCss,"):t.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."),await s.writeFile(P,g),await w(P)}else{o.extends||(o.extends=[]),o.extends.push("@salty-css/core");const u=JSON.stringify(o,null,2);await s.writeFile(P,u),await w(P)}}}const A=i.join(a,"vite.config.ts"),W=await s.readFile(A,"utf-8").catch(()=>{});if(W!==void 0&&!W.includes("saltyPlugin")){t.logger.info("Edit file: "+A);const d=`import { saltyPlugin } from '@salty-css/vite';
8
+ `,u=W.replace(/(plugins: \[)/,`$1
9
+ saltyPlugin(__dirname),`);m||await D(`-D ${T.vite}`),t.logger.info("Adding Salty-CSS plugin to Vite config..."),await s.writeFile(A,d+u),await w(A)}const U=["next.config.js","next.config.cjs","next.config.ts","next.config.mjs"].map(e=>i.join(a,e)).find(e=>G.existsSync(e));if(U){let e=await s.readFile(U,"utf-8").catch(()=>{});if(e!==void 0&&!e.includes("withSaltyCss")){let o=!1;/\splugins([^=]*)=[^[]\[/.test(e)&&!o&&(e=e.replace(/\splugins([^=]*)=[^[]\[/,(O,N)=>` plugins${N}= [withSaltyCss,`),o=!0);const g=e.includes("module.exports"),I=g?`const { withSaltyCss } = require('@salty-css/next');
9
10
  `:`import { withSaltyCss } from '@salty-css/next';
10
- `;C&&!d?(e=e.replace(/module.exports = ([^;]+)/,(O,J)=>`module.exports = withSaltyCss(${J})`),d=!0):d||(e=e.replace(/export default ([^;]+)/,(O,J)=>`export default withSaltyCss(${J})`)),y||await I(`-D ${D.next}`),t.logger.info("Adding Salty-CSS plugin to Next.js config..."),await s.writeFile(U,q+e),await j(U)}}const te=await N().catch(()=>t.logError("Could not read package.json file.")).then(e=>(e.scripts||(e.scripts={}),e.scripts.prepare?e.scripts.prepare.includes("salty-css")||(t.logger.info("Edit file: "+k),e.scripts.prepare=e.scripts.prepare+" && npx salty-css build"):(t.logger.info("Edit file: "+k),e.scripts.prepare="npx salty-css build"),e));await Z(te),t.logger.info("🎉 Salty CSS project initialized successfully!"),t.logger.info("Next steps:"),t.logger.info("1. Configure variables and templates in `salty.config.ts`"),t.logger.info("2. Create a new component with `npx salty-css generate [component-name]`"),t.logger.info("3. Run `npx salty-css build` to generate the CSS"),t.logger.info("4. Read about the features in the documentation: https://salty-css.dev"),t.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐")}),f.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=B){t.logger.info("Building the Salty-CSS project...");const{dir:r=n}=this.opts();if(!r)return t.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const c=R(r);await t.generateCss(c)}),f.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("-rc, --reactComponent <rc>","Generate a React component as well.").action(async function(n,r=B){const{file:c=n,dir:u=r,tag:y,name:p,className:l,reactComponent:E=!1}=this.opts();if(!c)return t.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!u)return t.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const m=R(u),P=c.split("/").slice(0,-1).join("/");P&&await s.mkdir(i.join(m,P),{recursive:!0});const w=i.join(m,c),a=i.parse(w);a.ext||(a.ext=".ts"),a.name.endsWith(".css")||(a.name=a.name+".css"),a.base=a.name+a.ext;const S=i.format(a);if(await s.readFile(S,"utf-8").catch(()=>{})!==void 0){t.logger.error("File already exists:",S);return}let x=se.pascalCase(p||a.base.replace(/\.css\.\w+$/,""));if(E){const z=x+"Component";x=x+"Wrapper";const _=a.base.replace(/\.css\.\w+$/,""),{content:V}=await v("react/react-vanilla-file.ts",{tag:y,componentName:z,styledComponentName:x,className:l,fileName:_});a.name=_.replace(/\.css$/,""),a.ext=".tsx",a.base=a.name+a.ext;const $=i.format(a);t.logger.info("Generating a new file: "+$),await s.writeFile($,V),await j($)}const{content:H}=await v("react/react-styled-file.ts",{tag:y,name:x,className:l});t.logger.info("Generating a new file: "+S),await s.writeFile(S,H),await j(S)}),f.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:c=n}=this.opts(),u=i.join(process.cwd(),"package.json"),y=await N(u).catch(m=>t.logError(m));if(!y)return;const p={...y.dependencies,...y.devDependencies},l=Object.keys(p).filter(m=>m==="salty-css"||m.startsWith("@salty-css/"));if(!l.length)return t.logError("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 E=l.map(m=>c==="@"?`${m}@${b.version}`:`${m}@${c.replace(/^@/,"")}`);r?(t.logger.warn("Using legacy peer dependencies to update packages."),await I(...E,"--legacy-peer-deps")):await I(...E),t.logger.info("Salty-CSS packages updated successfully!")}),f.option("-v, --version","Show the current version of Salty-CSS.").action(async function(){const n=await M();t.logger.info("CLI is running: "+n.version);const r=i.join(process.cwd(),"package.json"),c=await N(r).catch(p=>t.logError(p));if(!c)return;const u={...c.dependencies,...c.devDependencies},y=Object.keys(u).filter(p=>p==="salty-css"||p.startsWith("@salty-css/"));if(!y.length)return t.logError("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 p of y)t.logger.info(`${p}: ${u[p]}`)}),f.parseAsync(process.argv)}exports.main=ce;
11
+ `;g&&!o?(e=e.replace(/module.exports = ([^;]+)/,(O,N)=>`module.exports = withSaltyCss(${N})`),o=!0):o||(e=e.replace(/export default ([^;]+)/,(O,N)=>`export default withSaltyCss(${N})`)),m||await D(`-D ${T.next}`),t.logger.info("Adding Salty-CSS plugin to Next.js config..."),await s.writeFile(U,I+e),await w(U)}}const Z=await q().catch(()=>t.logError("Could not read package.json file.")).then(e=>(e.scripts||(e.scripts={}),e.scripts.prepare?e.scripts.prepare.includes("salty-css")||(t.logger.info("Edit file: "+b),e.scripts.prepare=e.scripts.prepare+" && npx salty-css build"):(t.logger.info("Edit file: "+b),e.scripts.prepare="npx salty-css build"),e));await X(Z),t.logger.info("🎉 Salty CSS project initialized successfully!"),t.logger.info("Next steps:"),t.logger.info("1. Configure variables and templates in `salty.config.ts`"),t.logger.info("2. Create a new component with `npx salty-css generate [component-name]`"),t.logger.info("3. Run `npx salty-css build` to generate the CSS"),t.logger.info("4. Read about the features in the documentation: https://salty-css.dev"),t.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐")}),p.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=V){t.logger.info("Building the Salty-CSS project...");const{dir:c=n}=this.opts();if(!c)return t.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const l=R(c);await t.generateCss(l)}),p.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("-rc, --reactComponent <rc>","Generate a React component as well.").action(async function(n,c=V){const{file:l=n,dir:y=c,tag:m,name:f,className:a,reactComponent:E=!1}=this.opts();if(!l)return t.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!y)return t.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const h=R(y),x=l.split("/").slice(0,-1).join("/");x&&await s.mkdir(i.join(h,x),{recursive:!0});const C=i.join(h,l),r=i.parse(C);r.ext||(r.ext=".ts"),r.name.endsWith(".css")||(r.name=r.name+".css"),r.base=r.name+r.ext;const j=i.format(r);if(await s.readFile(j,"utf-8").catch(()=>{})!==void 0){t.logger.error("File already exists:",j);return}let F=ie.pascalCase(f||r.base.replace(/\.css\.\w+$/,""));if(E){const M=F+"Component";F=F+"Wrapper";const _=r.base.replace(/\.css\.\w+$/,""),{content:K}=await v("react/react-vanilla-file.ts",{tag:m,componentName:M,styledComponentName:F,className:a,fileName:_});r.name=_.replace(/\.css$/,""),r.ext=".tsx",r.base=r.name+r.ext;const J=i.format(r);t.logger.info("Generating a new file: "+J),await s.writeFile(J,K),await w(J)}const{content:H}=await v("react/react-styled-file.ts",{tag:m,name:F,className:a});t.logger.info("Generating a new file: "+j),await s.writeFile(j,H),await w(j)}),p.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:c,version:l=n}=this.opts(),y=i.join(process.cwd(),"package.json"),m=await q(y).catch(h=>t.logError(h));if(!m)return;const f={...m.dependencies,...m.devDependencies},a=Object.keys(f).filter(h=>h==="salty-css"||h.startsWith("@salty-css/"));if(!a.length)return t.logError("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+y);const E=a.map(h=>l==="@"?`${h}@${$.version}`:`${h}@${l.replace(/^@/,"")}`);c?(t.logger.warn("Using legacy peer dependencies to update packages."),await D(...E,"--legacy-peer-deps")):await D(...E),t.logger.info("Salty-CSS packages updated successfully!")}),p.option("-v, --version","Show the current version of Salty-CSS.").action(async function(){const n=await B();t.logger.info("CLI is running: "+n.version);const c=i.join(process.cwd(),"package.json"),l=await q(c).catch(f=>t.logError(f));if(!l)return;const y={...l.dependencies,...l.devDependencies},m=Object.keys(y).filter(f=>f==="salty-css"||f.startsWith("@salty-css/"));if(!m.length)return t.logError("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+c);for(const f of m)t.logger.info(`${f}: ${y[f]}`)}),p.parseAsync(process.argv)}exports.main=ae;
package/bin/main.js CHANGED
@@ -1,233 +1,246 @@
1
- import { Command as ot } from "commander";
2
- import { existsSync as G } from "fs";
3
- import { mkdir as V, readFile as m, writeFile as h } from "fs/promises";
4
- import { join as a, relative as z, parse as rt, format as et } from "path";
5
- import { render as ct } from "ejs";
6
- import { l as e, a as w, g as lt } from "../index-BGaLvshf.js";
7
- import { p as dt } from "../pascal-case-BQpR5PdN.js";
8
- import { exec as ft } from "child_process";
9
- import pt from "ora";
10
- const st = (f) => new Promise((C, x) => {
11
- ft(f, (b) => {
12
- if (b) return x(b);
13
- C();
1
+ import { Command as it } from "commander";
2
+ import { existsSync as K } from "fs";
3
+ import { mkdir as V, readFile as h, writeFile as C } from "fs/promises";
4
+ import { join as n, relative as z, parse as at, format as Z } from "path";
5
+ import { render as ot } from "ejs";
6
+ import { l as e, a as S, g as rt } from "../index-BGaLvshf.js";
7
+ import { p as ct } from "../pascal-case-BQpR5PdN.js";
8
+ import { exec as lt } from "child_process";
9
+ import dt from "ora";
10
+ const tt = (p) => new Promise((j, x) => {
11
+ lt(p, ($) => {
12
+ if ($) return x($);
13
+ j();
14
14
  });
15
- }), I = async (...f) => {
16
- const C = f.map(($) => $.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), x = pt(`Installing packages: ${C}`).start(), b = f.join(" ");
17
- await st(`npm install ${b}`), x.succeed(`Installed packages: ${C}`);
18
- }, gt = () => G(a(process.cwd(), "node_modules", ".bin", "prettier"));
19
- async function P(f) {
15
+ }), A = async (...p) => {
16
+ const j = p.map((J) => J.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), x = dt(`Installing packages: ${j}`).start(), $ = p.join(" ");
17
+ await tt(`npm install ${$}`), x.succeed(`Installed packages: ${j}`);
18
+ }, ft = () => K(n(process.cwd(), "node_modules", ".bin", "prettier"));
19
+ async function w(p) {
20
20
  try {
21
- if (!gt()) return;
22
- await st(`./node_modules/.bin/prettier --write "${f}"`), e.info(`Formatted ${f} with Prettier`);
23
- } catch (C) {
24
- e.error(`Error formatting ${f} with Prettier:`, C);
21
+ if (!ft()) return;
22
+ await tt(`./node_modules/.bin/prettier --write "${p}"`), e.info(`Formatted ${p} with Prettier`);
23
+ } catch (j) {
24
+ e.error(`Error formatting ${p} with Prettier:`, j);
25
25
  }
26
26
  }
27
- async function kt() {
28
- const f = new ot();
29
- f.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
30
- const C = {
27
+ async function Pt() {
28
+ const p = new it();
29
+ p.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
30
+ const j = {
31
31
  // Core files
32
32
  "salty.config.ts": import("../salty.config-BhBY_oOk.js"),
33
33
  "saltygen/index.css": import("../index-D_732b92.js"),
34
34
  // React
35
35
  "react/react-styled-file.ts": import("../react-styled-file-CGVf5n1B.js"),
36
36
  "react/react-vanilla-file.ts": import("../react-vanilla-file-CCXbsjIb.js")
37
- }, x = async (s, o) => {
38
- const { default: r } = await C[s], g = ct(r, o);
39
- return { fileName: s, content: g };
40
- }, b = async () => {
41
- const s = a(process.cwd(), ".saltyrc.json");
42
- return await m(s, "utf-8").then(JSON.parse).catch(() => ({}));
43
- }, $ = a(process.cwd(), "package.json"), A = async (s = $) => {
44
- const o = await m(s, "utf-8").then(JSON.parse).catch(() => {
37
+ }, x = async (s, r) => {
38
+ const { default: c } = await j[s], u = ot(c, r);
39
+ return { fileName: s, content: u };
40
+ }, $ = async () => {
41
+ const s = n(process.cwd(), ".saltyrc.json");
42
+ return await h(s, "utf-8").then(JSON.parse).catch(() => ({}));
43
+ }, J = n(process.cwd(), "package.json"), T = async (s = J) => {
44
+ const r = await h(s, "utf-8").then(JSON.parse).catch(() => {
45
45
  });
46
- if (!o) throw "Could not read package.json file!";
47
- return o;
48
- }, nt = async (s, o = $) => {
49
- typeof s == "object" && (s = JSON.stringify(s, null, 2)), await h(o, s);
50
- }, K = async () => {
46
+ if (!r) throw "Could not read package.json file!";
47
+ return r;
48
+ }, et = async (s, r = J) => {
49
+ typeof s == "object" && (s = JSON.stringify(s, null, 2)), await C(r, s);
50
+ }, Q = async () => {
51
51
  const s = new URL("../package.json", import.meta.url);
52
- return A(s);
53
- }, Q = await (async () => (await b()).defaultProject)(), J = await K(), O = {
54
- core: `@salty-css/core@${J.version}`,
55
- react: `@salty-css/react@${J.version}`,
56
- eslintConfigCore: `@salty-css/eslint-config-core@${J.version}`,
57
- vite: `@salty-css/vite@${J.version}`,
58
- next: `@salty-css/next@${J.version}`
59
- }, W = (s) => {
60
- const o = s === "." ? "" : s, r = process.cwd();
61
- return a(r, o);
52
+ return T(s);
53
+ }, X = await (async () => (await $()).defaultProject)(), N = await Q(), L = {
54
+ core: `@salty-css/core@${N.version}`,
55
+ react: `@salty-css/react@${N.version}`,
56
+ eslintConfigCore: `@salty-css/eslint-config-core@${N.version}`,
57
+ vite: `@salty-css/vite@${N.version}`,
58
+ next: `@salty-css/next@${N.version}`
59
+ }, G = (s) => {
60
+ const r = s === "." ? "" : s, c = process.cwd();
61
+ return n(c, r);
62
62
  };
63
- f.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>", "Project directory to initialize the project in.").option("--css-file <css-file>", "Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install", "Skip installing dependencies.").action(async function(s = ".") {
64
- if (!await A().catch(() => {
65
- })) return w("Salty CSS project must be initialized in a directory with a package.json file.");
63
+ p.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>", "Project directory to initialize the project in.").option("--css-file <css-file>", "Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install", "Skip installing dependencies.").action(async function(s = ".") {
64
+ if (!await T().catch(() => {
65
+ })) return S("Salty CSS project must be initialized in a directory with a package.json file.");
66
66
  e.info("Initializing a new Salty-CSS project!");
67
- const { dir: r = s, cssFile: g, skipInstall: u } = this.opts();
68
- if (!r) return w("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
69
- u || await I(O.core, O.react);
70
- const p = process.cwd(), c = W(r), N = await Promise.all([x("salty.config.ts"), x("saltygen/index.css")]);
71
- await V(c, { recursive: !0 });
72
- const y = N.map(async ({ fileName: t, content: n }) => {
73
- const l = a(c, t);
74
- if (await m(l, "utf-8").catch(() => {
67
+ const { dir: c = s, cssFile: u, skipInstall: y } = this.opts();
68
+ if (!c) return S("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
69
+ y || await A(L.core, L.react);
70
+ const d = process.cwd(), a = G(c), D = await Promise.all([x("salty.config.ts"), x("saltygen/index.css")]);
71
+ await V(a, { recursive: !0 });
72
+ const m = D.map(async ({ fileName: t, content: l }) => {
73
+ const i = n(a, t);
74
+ if (await h(i, "utf-8").catch(() => {
75
75
  }) !== void 0) {
76
- e.debug("File already exists: " + l);
76
+ e.debug("File already exists: " + i);
77
77
  return;
78
78
  }
79
- const j = t.split("/").slice(0, -1).join("/");
80
- j && await V(a(c, j), { recursive: !0 }), e.info("Creating file: " + l), await h(l, n), await P(l);
79
+ const f = t.split("/").slice(0, -1).join("/");
80
+ f && await V(n(a, f), { recursive: !0 }), e.info("Creating file: " + i), await C(i, l), await w(i);
81
81
  });
82
- await Promise.all(y);
83
- const k = z(p, c) || ".", S = a(p, ".saltyrc.json"), i = await m(S, "utf-8").catch(() => {
82
+ await Promise.all(m);
83
+ const F = z(d, a) || ".", v = n(d, ".saltyrc.json"), o = await h(v, "utf-8").catch(() => {
84
84
  });
85
- if (i === void 0) {
86
- e.info("Creating file: " + S);
87
- const n = JSON.stringify({
85
+ if (o === void 0) {
86
+ e.info("Creating file: " + v);
87
+ const l = JSON.stringify({
88
88
  $schema: "./node_modules/@salty-css/core/.saltyrc.schema.json",
89
89
  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.",
90
- defaultProject: k,
90
+ defaultProject: F,
91
91
  projects: [
92
92
  {
93
- dir: k,
93
+ dir: F,
94
94
  framework: "react"
95
95
  }
96
96
  ]
97
97
  }, null, 2);
98
- await h(S, n), await P(S);
98
+ await C(v, l), await w(v);
99
99
  } else {
100
- const t = JSON.parse(i), n = (t == null ? void 0 : t.projects) || [];
101
- if (n.findIndex((d) => d.dir === k) === -1) {
102
- n.push({ dir: k, framework: "react" }), t.projects = [...n];
103
- const d = JSON.stringify(t, null, 2);
104
- d !== i && (e.info("Edit file: " + S), await h(S, d), await P(S));
100
+ const t = JSON.parse(o), l = (t == null ? void 0 : t.projects) || [];
101
+ if (l.findIndex((g) => g.dir === F) === -1) {
102
+ l.push({ dir: F, framework: "react" }), t.projects = [...l];
103
+ const g = JSON.stringify(t, null, 2);
104
+ g !== o && (e.info("Edit file: " + v), await C(v, g), await w(v));
105
105
  }
106
106
  }
107
- const v = a(p, ".gitignore"), L = await m(v, "utf-8").catch(() => {
107
+ const P = n(d, ".gitignore"), U = await h(P, "utf-8").catch(() => {
108
108
  });
109
- L !== void 0 && (L.includes("saltygen") || (e.info("Edit file: " + v), await h(v, L + `
109
+ U !== void 0 && (U.includes("saltygen") || (e.info("Edit file: " + P), await C(P, U + `
110
110
 
111
111
  # Salty-CSS
112
112
  saltygen
113
113
  `)));
114
- const F = ["src", "public", "assets", "styles", "css", "app"], M = ["styles", "css", "app", "pages"], q = ["index", "styles", "main", "global", "globals"], U = [".css", ".scss", ".sass"], D = await (async () => {
115
- if (g) return g;
116
- for (const t of F)
117
- for (const n of q)
118
- for (const l of U) {
119
- const d = a(c, t, n + l);
120
- if (await m(d, "utf-8").catch(() => {
121
- }) !== void 0) return z(c, d);
122
- for (const H of M) {
123
- const T = a(c, t, H, n + l);
124
- if (await m(T, "utf-8").catch(() => {
125
- }) !== void 0) return z(c, T);
114
+ const b = ["src", "public", "assets", "styles", "css", "app"], M = ["styles", "css", "app", "pages"], q = ["index", "styles", "main", "global", "globals"], _ = [".css", ".scss", ".sass"], I = await (async () => {
115
+ if (u) return u;
116
+ for (const t of b)
117
+ for (const l of q)
118
+ for (const i of _) {
119
+ const g = n(a, t, l + i);
120
+ if (await h(g, "utf-8").catch(() => {
121
+ }) !== void 0) return z(a, g);
122
+ for (const E of M) {
123
+ const H = n(a, t, E, l + i);
124
+ if (await h(H, "utf-8").catch(() => {
125
+ }) !== void 0) return z(a, H);
126
126
  }
127
127
  }
128
128
  })();
129
- if (D) {
130
- const t = a(c, D), n = await m(t, "utf-8").catch(() => {
129
+ if (I) {
130
+ const t = n(a, I), l = await h(t, "utf-8").catch(() => {
131
131
  });
132
- if (n !== void 0 && !n.includes("saltygen")) {
133
- const d = a(t, ".."), H = `@import '${z(d, a(c, "saltygen/index.css"))}';`;
134
- e.info("Adding global import statement to CSS file: " + t), await h(t, H + `
135
- ` + n), await P(t);
132
+ if (l !== void 0 && !l.includes("saltygen")) {
133
+ const g = n(t, ".."), E = `@import '${z(g, n(a, "saltygen/index.css"))}';`;
134
+ e.info("Adding global import statement to CSS file: " + t), await C(t, E + `
135
+ ` + l), await w(t);
136
136
  }
137
137
  } else
138
138
  e.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
139
- const Y = a(p, ".eslintrc.json"), it = G(Y), Z = a(c, ".eslintrc.json"), tt = G(Z);
140
- if (it || tt) {
141
- u || await I(O.eslintConfigCore);
142
- const t = tt ? Z : Y, n = await m(t, "utf-8").catch(() => {
139
+ const st = {
140
+ projectJs: n(a, "eslint.config.js"),
141
+ rootJs: n(d, "eslint.config.js"),
142
+ projectMjs: n(a, "eslint.config.mjs"),
143
+ rootMjs: n(d, "eslint.config.mjs"),
144
+ projectJson: n(a, ".eslintrc.json"),
145
+ rootJson: n(d, ".eslintrc.json")
146
+ }, k = Object.values(st).find((t) => K(t));
147
+ if (k) {
148
+ y || await A(L.eslintConfigCore);
149
+ const t = await h(k, "utf-8").catch(() => {
143
150
  });
144
- if (!n) return w("Could not read ESLint config file.");
145
- if (!n.includes("salty-css")) {
146
- const d = JSON.parse(n);
147
- e.info("Edit file: " + t), d.extends || (d.extends = []), d.extends.push("@salty-css/core");
148
- const j = JSON.stringify(d, null, 2);
149
- await h(t, j), await P(t);
151
+ if (!t) return S("Could not read ESLint config file.");
152
+ if (!t.includes("salty-css")) {
153
+ const i = JSON.parse(t);
154
+ if (e.info("Edit file: " + k), k.endsWith("js")) {
155
+ let f = `import saltyCss from "@salty-css/eslint-config-core/flat";
156
+ ${i}`;
157
+ t.includes("typescript-eslint") ? f.includes(".config(") ? f = f.replace(".config(", ".config(saltyCss,") : e.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.") : f.includes("export default [") ? f = f.replace("export default [", "export default [ saltyCss,") : f.includes("eslintConfig = [") ? f = f.replace("eslintConfig = [", "eslintConfig = [ saltyCss,") : e.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."), await C(k, f), await w(k);
158
+ } else {
159
+ i.extends || (i.extends = []), i.extends.push("@salty-css/core");
160
+ const g = JSON.stringify(i, null, 2);
161
+ await C(k, g), await w(k);
162
+ }
150
163
  }
151
164
  }
152
- const _ = a(c, "vite.config.ts"), B = await m(_, "utf-8").catch(() => {
165
+ const R = n(a, "vite.config.ts"), B = await h(R, "utf-8").catch(() => {
153
166
  });
154
167
  if (B !== void 0 && !B.includes("saltyPlugin")) {
155
- e.info("Edit file: " + _);
156
- const n = `import { saltyPlugin } from '@salty-css/vite';
157
- `, d = B.replace(/(plugins: \[)/, `$1
168
+ e.info("Edit file: " + R);
169
+ const l = `import { saltyPlugin } from '@salty-css/vite';
170
+ `, g = B.replace(/(plugins: \[)/, `$1
158
171
  saltyPlugin(__dirname),`);
159
- u || await I(`-D ${O.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await h(_, n + d), await P(_);
172
+ y || await A(`-D ${L.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await C(R, l + g), await w(R);
160
173
  }
161
- const R = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((t) => a(c, t)).find((t) => G(t));
162
- if (R) {
163
- let t = await m(R, "utf-8").catch(() => {
174
+ const W = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((t) => n(a, t)).find((t) => K(t));
175
+ if (W) {
176
+ let t = await h(W, "utf-8").catch(() => {
164
177
  });
165
178
  if (t !== void 0 && !t.includes("withSaltyCss")) {
166
- let l = !1;
167
- /\splugins([^=]*)=[^[]\[/.test(t) && !l && (t = t.replace(/\splugins([^=]*)=[^[]\[/, (T, E) => ` plugins${E}= [withSaltyCss,`), l = !0);
168
- const j = t.includes("module.exports"), H = j ? `const { withSaltyCss } = require('@salty-css/next');
179
+ let i = !1;
180
+ /\splugins([^=]*)=[^[]\[/.test(t) && !i && (t = t.replace(/\splugins([^=]*)=[^[]\[/, (H, O) => ` plugins${O}= [withSaltyCss,`), i = !0);
181
+ const f = t.includes("module.exports"), E = f ? `const { withSaltyCss } = require('@salty-css/next');
169
182
  ` : `import { withSaltyCss } from '@salty-css/next';
170
183
  `;
171
- j && !l ? (t = t.replace(/module.exports = ([^;]+)/, (T, E) => `module.exports = withSaltyCss(${E})`), l = !0) : l || (t = t.replace(/export default ([^;]+)/, (T, E) => `export default withSaltyCss(${E})`)), u || await I(`-D ${O.next}`), e.info("Adding Salty-CSS plugin to Next.js config..."), await h(R, H + t), await P(R);
184
+ f && !i ? (t = t.replace(/module.exports = ([^;]+)/, (H, O) => `module.exports = withSaltyCss(${O})`), i = !0) : i || (t = t.replace(/export default ([^;]+)/, (H, O) => `export default withSaltyCss(${O})`)), y || await A(`-D ${L.next}`), e.info("Adding Salty-CSS plugin to Next.js config..."), await C(W, E + t), await w(W);
172
185
  }
173
186
  }
174
- const at = await A().catch(() => w("Could not read package.json file.")).then((t) => (t.scripts || (t.scripts = {}), t.scripts.prepare ? t.scripts.prepare.includes("salty-css") || (e.info("Edit file: " + $), t.scripts.prepare = t.scripts.prepare + " && npx salty-css build") : (e.info("Edit file: " + $), t.scripts.prepare = "npx salty-css build"), t));
175
- await nt(at), e.info("🎉 Salty CSS project initialized successfully!"), e.info("Next steps:"), e.info("1. Configure variables and templates in `salty.config.ts`"), e.info("2. Create a new component with `npx salty-css generate [component-name]`"), e.info("3. Run `npx salty-css build` to generate the CSS"), e.info("4. Read about the features in the documentation: https://salty-css.dev"), e.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
176
- }), f.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").action(async function(s = Q) {
187
+ const nt = await T().catch(() => S("Could not read package.json file.")).then((t) => (t.scripts || (t.scripts = {}), t.scripts.prepare ? t.scripts.prepare.includes("salty-css") || (e.info("Edit file: " + J), t.scripts.prepare = t.scripts.prepare + " && npx salty-css build") : (e.info("Edit file: " + J), t.scripts.prepare = "npx salty-css build"), t));
188
+ await et(nt), e.info("🎉 Salty CSS project initialized successfully!"), e.info("Next steps:"), e.info("1. Configure variables and templates in `salty.config.ts`"), e.info("2. Create a new component with `npx salty-css generate [component-name]`"), e.info("3. Run `npx salty-css build` to generate the CSS"), e.info("4. Read about the features in the documentation: https://salty-css.dev"), e.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
189
+ }), p.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").action(async function(s = X) {
177
190
  e.info("Building the Salty-CSS project...");
178
- const { dir: o = s } = this.opts();
179
- if (!o) return w("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
180
- const r = W(o);
181
- await lt(r);
182
- }), f.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("-rc, --reactComponent <rc>", "Generate a React component as well.").action(async function(s, o = Q) {
183
- const { file: r = s, dir: g = o, tag: u, name: p, className: c, reactComponent: N = !1 } = this.opts();
184
- if (!r) return w("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
185
- if (!g) return w("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
186
- const y = W(g), k = r.split("/").slice(0, -1).join("/");
187
- k && await V(a(y, k), { recursive: !0 });
188
- const S = a(y, r), i = rt(S);
189
- i.ext || (i.ext = ".ts"), i.name.endsWith(".css") || (i.name = i.name + ".css"), i.base = i.name + i.ext;
190
- const v = et(i);
191
- if (await m(v, "utf-8").catch(() => {
191
+ const { dir: r = s } = this.opts();
192
+ if (!r) return S("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
193
+ const c = G(r);
194
+ await rt(c);
195
+ }), p.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("-rc, --reactComponent <rc>", "Generate a React component as well.").action(async function(s, r = X) {
196
+ const { file: c = s, dir: u = r, tag: y, name: d, className: a, reactComponent: D = !1 } = this.opts();
197
+ if (!c) return S("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
198
+ if (!u) return S("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
199
+ const m = G(u), F = c.split("/").slice(0, -1).join("/");
200
+ F && await V(n(m, F), { recursive: !0 });
201
+ const v = n(m, c), o = at(v);
202
+ o.ext || (o.ext = ".ts"), o.name.endsWith(".css") || (o.name = o.name + ".css"), o.base = o.name + o.ext;
203
+ const P = Z(o);
204
+ if (await h(P, "utf-8").catch(() => {
192
205
  }) !== void 0) {
193
- e.error("File already exists:", v);
206
+ e.error("File already exists:", P);
194
207
  return;
195
208
  }
196
- let F = dt(p || i.base.replace(/\.css\.\w+$/, ""));
197
- if (N) {
198
- const q = F + "Component";
199
- F = F + "Wrapper";
200
- const U = i.base.replace(/\.css\.\w+$/, ""), { content: X } = await x("react/react-vanilla-file.ts", { tag: u, componentName: q, styledComponentName: F, className: c, fileName: U });
201
- i.name = U.replace(/\.css$/, ""), i.ext = ".tsx", i.base = i.name + i.ext;
202
- const D = et(i);
203
- e.info("Generating a new file: " + D), await h(D, X), await P(D);
209
+ let b = ct(d || o.base.replace(/\.css\.\w+$/, ""));
210
+ if (D) {
211
+ const q = b + "Component";
212
+ b = b + "Wrapper";
213
+ const _ = o.base.replace(/\.css\.\w+$/, ""), { content: Y } = await x("react/react-vanilla-file.ts", { tag: y, componentName: q, styledComponentName: b, className: a, fileName: _ });
214
+ o.name = _.replace(/\.css$/, ""), o.ext = ".tsx", o.base = o.name + o.ext;
215
+ const I = Z(o);
216
+ e.info("Generating a new file: " + I), await C(I, Y), await w(I);
204
217
  }
205
- const { content: M } = await x("react/react-styled-file.ts", { tag: u, name: F, className: c });
206
- e.info("Generating a new file: " + v), await h(v, M), await P(v);
207
- }), f.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(s = "latest") {
208
- const { legacyPeerDeps: o, version: r = s } = this.opts(), g = a(process.cwd(), "package.json"), u = await A(g).catch((y) => w(y));
209
- if (!u) return;
210
- const p = { ...u.dependencies, ...u.devDependencies }, c = Object.keys(p).filter((y) => y === "salty-css" || y.startsWith("@salty-css/"));
211
- if (!c.length)
212
- return w(
213
- "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + g
218
+ const { content: M } = await x("react/react-styled-file.ts", { tag: y, name: b, className: a });
219
+ e.info("Generating a new file: " + P), await C(P, M), await w(P);
220
+ }), p.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(s = "latest") {
221
+ const { legacyPeerDeps: r, version: c = s } = this.opts(), u = n(process.cwd(), "package.json"), y = await T(u).catch((m) => S(m));
222
+ if (!y) return;
223
+ const d = { ...y.dependencies, ...y.devDependencies }, a = Object.keys(d).filter((m) => m === "salty-css" || m.startsWith("@salty-css/"));
224
+ if (!a.length)
225
+ return S(
226
+ "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + u
214
227
  );
215
- const N = c.map((y) => r === "@" ? `${y}@${J.version}` : `${y}@${r.replace(/^@/, "")}`);
216
- o ? (e.warn("Using legacy peer dependencies to update packages."), await I(...N, "--legacy-peer-deps")) : await I(...N), e.info("Salty-CSS packages updated successfully!");
217
- }), f.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
218
- const s = await K();
228
+ const D = a.map((m) => c === "@" ? `${m}@${N.version}` : `${m}@${c.replace(/^@/, "")}`);
229
+ r ? (e.warn("Using legacy peer dependencies to update packages."), await A(...D, "--legacy-peer-deps")) : await A(...D), e.info("Salty-CSS packages updated successfully!");
230
+ }), p.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
231
+ const s = await Q();
219
232
  e.info("CLI is running: " + s.version);
220
- const o = a(process.cwd(), "package.json"), r = await A(o).catch((p) => w(p));
221
- if (!r) return;
222
- const g = { ...r.dependencies, ...r.devDependencies }, u = Object.keys(g).filter((p) => p === "salty-css" || p.startsWith("@salty-css/"));
223
- if (!u.length)
224
- return w(
225
- "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + o
233
+ const r = n(process.cwd(), "package.json"), c = await T(r).catch((d) => S(d));
234
+ if (!c) return;
235
+ const u = { ...c.dependencies, ...c.devDependencies }, y = Object.keys(u).filter((d) => d === "salty-css" || d.startsWith("@salty-css/"));
236
+ if (!y.length)
237
+ return S(
238
+ "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + r
226
239
  );
227
- for (const p of u)
228
- e.info(`${p}: ${g[p]}`);
229
- }), f.parseAsync(process.argv);
240
+ for (const d of y)
241
+ e.info(`${d}: ${u[d]}`);
242
+ }), p.parseAsync(process.argv);
230
243
  }
231
244
  export {
232
- kt as main
245
+ Pt as main
233
246
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.91",
3
+ "version": "0.0.1-alpha.92",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",