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

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 +168 -156
  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((w,j)=>{ne.exec(p,k=>{if(k)return j(k);w()})}),N=async(...p)=>{const w=p.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),j=se(`Installing packages: ${w}`).start(),k=p.join(" ");await Q(`npm install ${k}`),j.succeed(`Installed packages: ${w}`)},oe=()=>G.existsSync(i.join(process.cwd(),"node_modules",".bin","prettier"));async function h(p){try{if(!oe())return;await Q(`./node_modules/.bin/prettier --write "${p}"`),t.logger.info(`Formatted ${p} with Prettier`)}catch(w){t.logger.error(`Error formatting ${p} with Prettier:`,w)}}async function ae(){const p=new ee.Command;p.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const w={"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"))},j=async(n,l)=>{const{default:d}=await w[n],u=te.render(d,l);return{fileName:n,content:u}},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"),D=async(n=b)=>{const l=await s.readFile(n,"utf-8").then(JSON.parse).catch(()=>{});if(!l)throw"Could not read package.json file!";return l},X=async(n,l=b)=>{typeof n=="object"&&(n=JSON.stringify(n,null,2)),await s.writeFile(l,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 D(n)},V=await(async()=>(await k()).defaultProject)(),$=await B(),q={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 l=n==="."?"":n,d=process.cwd();return i.join(d,l)};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 D().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:d=n,cssFile:u,skipInstall:y}=this.opts();if(!d)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");y||await N(q.core,q.react);const g=process.cwd(),r=R(d),E=await Promise.all([j("salty.config.ts"),j("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=E.map(async({fileName:e,content:f})=>{const a=i.join(r,e);if(await s.readFile(a,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+a);return}const P=e.split("/").slice(0,-1).join("/");P&&await s.mkdir(i.join(r,P),{recursive:!0}),t.logger.info("Creating file: "+a),await s.writeFile(a,f),await h(a)});await Promise.all(m);const x=i.relative(g,r)||".",S=i.join(g,".saltyrc.json"),c=await s.readFile(S,"utf-8").catch(()=>{});if(c===void 0){t.logger.info("Creating file: "+S);const f=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(S,f),await h(S)}else{const e=JSON.parse(c),f=(e==null?void 0:e.projects)||[];if(f.findIndex(o=>o.dir===x)===-1){f.push({dir:x,framework:"react"}),e.projects=[...f];const o=JSON.stringify(e,null,2);o!==c&&(t.logger.info("Edit file: "+S),await s.writeFile(S,o),await h(S))}}const C=i.join(g,".gitignore"),L=await s.readFile(C,"utf-8").catch(()=>{});L!==void 0&&(L.includes("saltygen")||(t.logger.info("Edit file: "+C),await s.writeFile(C,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(u)return u;for(const e of F)for(const f of M)for(const a of _){const o=i.join(r,e,f+a);if(await s.readFile(o,"utf-8").catch(()=>{})!==void 0)return i.relative(r,o);for(const T of H){const O=i.join(r,e,T,f+a);if(await s.readFile(O,"utf-8").catch(()=>{})!==void 0)return i.relative(r,O)}}})();if(J){const e=i.join(r,J),f=await s.readFile(e,"utf-8").catch(()=>{});if(f!==void 0&&!f.includes("saltygen")){const o=i.join(e,".."),T=`@import '${i.relative(o,i.join(r,"saltygen/index.css"))}';`;t.logger.info("Adding global import statement to CSS file: "+e),await s.writeFile(e,T+`
6
+ `+f),await h(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(r,"eslint.config.js"),rootJs:i.join(g,"eslint.config.js"),projectMjs:i.join(r,"eslint.config.mjs"),rootMjs:i.join(g,"eslint.config.mjs"),projectJson:i.join(r,".eslintrc.json"),rootJson:i.join(g,".eslintrc.json")},v=Object.values(Y).find(e=>G.existsSync(e));if(v){y||await N(q.eslintConfigCore);const e=await s.readFile(v,"utf-8").catch(()=>{});if(!e)return t.logError("Could not read ESLint config file.");if(!e.includes("salty-css"))if(t.logger.info("Edit file: "+v),v.endsWith("js")){let o=`import saltyCss from "@salty-css/eslint-config-core/flat";
7
+ ${e}`;e.includes("typescript-eslint")?o.includes(".config(")?o=o.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."):o.includes("export default [")?o=o.replace("export default [","export default [ saltyCss,"):o.includes("eslintConfig = [")?o=o.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(v,o),await h(v)}else{const a=JSON.parse(e);a.extends||(a.extends=[]),a.extends.push("@salty-css/core");const o=JSON.stringify(a,null,2);await s.writeFile(v,o),await h(v)}}const A=i.join(r,"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 f=`import { saltyPlugin } from '@salty-css/vite';
8
+ `,o=W.replace(/(plugins: \[)/,`$1
9
+ saltyPlugin(__dirname),`);y||await N(`-D ${q.vite}`),t.logger.info("Adding Salty-CSS plugin to Vite config..."),await s.writeFile(A,f+o),await h(A)}const U=["next.config.js","next.config.cjs","next.config.ts","next.config.mjs"].map(e=>i.join(r,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 a=!1;/\splugins([^=]*)=[^[]\[/.test(e)&&!a&&(e=e.replace(/\splugins([^=]*)=[^[]\[/,(O,I)=>` plugins${I}= [withSaltyCss,`),a=!0);const P=e.includes("module.exports"),T=P?`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
+ `;P&&!a?(e=e.replace(/module.exports = ([^;]+)/,(O,I)=>`module.exports = withSaltyCss(${I})`),a=!0):a||(e=e.replace(/export default ([^;]+)/,(O,I)=>`export default withSaltyCss(${I})`)),y||await N(`-D ${q.next}`),t.logger.info("Adding Salty-CSS plugin to Next.js config..."),await s.writeFile(U,T+e),await h(U)}}const Z=await D().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:l=n}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const d=R(l);await t.generateCss(d)}),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,l=V){const{file:d=n,dir:u=l,tag:y,name:g,className:r,reactComponent:E=!1}=this.opts();if(!d)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),x=d.split("/").slice(0,-1).join("/");x&&await s.mkdir(i.join(m,x),{recursive:!0});const S=i.join(m,d),c=i.parse(S);c.ext||(c.ext=".ts"),c.name.endsWith(".css")||(c.name=c.name+".css"),c.base=c.name+c.ext;const C=i.format(c);if(await s.readFile(C,"utf-8").catch(()=>{})!==void 0){t.logger.error("File already exists:",C);return}let F=ie.pascalCase(g||c.base.replace(/\.css\.\w+$/,""));if(E){const M=F+"Component";F=F+"Wrapper";const _=c.base.replace(/\.css\.\w+$/,""),{content:K}=await j("react/react-vanilla-file.ts",{tag:y,componentName:M,styledComponentName:F,className:r,fileName:_});c.name=_.replace(/\.css$/,""),c.ext=".tsx",c.base=c.name+c.ext;const J=i.format(c);t.logger.info("Generating a new file: "+J),await s.writeFile(J,K),await h(J)}const{content:H}=await j("react/react-styled-file.ts",{tag:y,name:F,className:r});t.logger.info("Generating a new file: "+C),await s.writeFile(C,H),await h(C)}),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:l,version:d=n}=this.opts(),u=i.join(process.cwd(),"package.json"),y=await D(u).catch(m=>t.logError(m));if(!y)return;const g={...y.dependencies,...y.devDependencies},r=Object.keys(g).filter(m=>m==="salty-css"||m.startsWith("@salty-css/"));if(!r.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=r.map(m=>d==="@"?`${m}@${$.version}`:`${m}@${d.replace(/^@/,"")}`);l?(t.logger.warn("Using legacy peer dependencies to update packages."),await N(...E,"--legacy-peer-deps")):await N(...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 l=i.join(process.cwd(),"package.json"),d=await D(l).catch(g=>t.logError(g));if(!d)return;const u={...d.dependencies,...d.devDependencies},y=Object.keys(u).filter(g=>g==="salty-css"||g.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: "+l);for(const g of y)t.logger.info(`${g}: ${u[g]}`)}),p.parseAsync(process.argv)}exports.main=ae;
package/bin/main.js CHANGED
@@ -1,233 +1,245 @@
1
- import { Command as ot } from "commander";
2
- import { existsSync as G } from "fs";
1
+ import { Command as it } from "commander";
2
+ import { existsSync as K } from "fs";
3
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();
4
+ import { join as i, 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 C, 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((w, P) => {
11
+ lt(p, ($) => {
12
+ if ($) return P($);
13
+ w();
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
+ }), O = async (...p) => {
16
+ const w = p.map((J) => J.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), P = dt(`Installing packages: ${w}`).start(), $ = p.join(" ");
17
+ await tt(`npm install ${$}`), P.succeed(`Installed packages: ${w}`);
18
+ }, ft = () => K(i(process.cwd(), "node_modules", ".bin", "prettier"));
19
+ async function S(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 (w) {
24
+ e.error(`Error formatting ${p} with Prettier:`, w);
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 w = {
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);
37
+ }, P = async (s, c) => {
38
+ const { default: l } = await w[s], g = ot(l, c);
39
39
  return { fileName: s, content: g };
40
- }, b = async () => {
41
- const s = a(process.cwd(), ".saltyrc.json");
40
+ }, $ = async () => {
41
+ const s = i(process.cwd(), ".saltyrc.json");
42
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(() => {
43
+ }, J = i(process.cwd(), "package.json"), A = async (s = J) => {
44
+ const c = await m(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 (!c) throw "Could not read package.json file!";
47
+ return c;
48
+ }, et = async (s, c = J) => {
49
+ typeof s == "object" && (s = JSON.stringify(s, null, 2)), await h(c, s);
50
+ }, Q = async () => {
51
51
  const s = new URL("../package.json", import.meta.url);
52
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);
53
+ }, X = await (async () => (await $()).defaultProject)(), N = await Q(), T = {
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 c = s === "." ? "" : s, l = process.cwd();
61
+ return i(l, c);
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 = ".") {
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
64
  if (!await A().catch(() => {
65
- })) return w("Salty CSS project must be initialized in a directory with a package.json file.");
65
+ })) return C("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: l = s, cssFile: g, skipInstall: u } = this.opts();
68
+ if (!l) return C("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
69
+ u || await O(T.core, T.react);
70
+ const f = process.cwd(), o = G(l), D = await Promise.all([P("salty.config.ts"), P("saltygen/index.css")]);
71
+ await V(o, { recursive: !0 });
72
+ const y = D.map(async ({ fileName: t, content: d }) => {
73
+ const a = i(o, t);
74
+ if (await m(a, "utf-8").catch(() => {
75
75
  }) !== void 0) {
76
- e.debug("File already exists: " + l);
76
+ e.debug("File already exists: " + a);
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 k = t.split("/").slice(0, -1).join("/");
80
+ k && await V(i(o, k), { recursive: !0 }), e.info("Creating file: " + a), await h(a, d), await S(a);
81
81
  });
82
82
  await Promise.all(y);
83
- const k = z(p, c) || ".", S = a(p, ".saltyrc.json"), i = await m(S, "utf-8").catch(() => {
83
+ const F = z(f, o) || ".", j = i(f, ".saltyrc.json"), r = await m(j, "utf-8").catch(() => {
84
84
  });
85
- if (i === void 0) {
86
- e.info("Creating file: " + S);
87
- const n = JSON.stringify({
85
+ if (r === void 0) {
86
+ e.info("Creating file: " + j);
87
+ const d = 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 h(j, d), await S(j);
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(r), d = (t == null ? void 0 : t.projects) || [];
101
+ if (d.findIndex((n) => n.dir === F) === -1) {
102
+ d.push({ dir: F, framework: "react" }), t.projects = [...d];
103
+ const n = JSON.stringify(t, null, 2);
104
+ n !== r && (e.info("Edit file: " + j), await h(j, n), await S(j));
105
105
  }
106
106
  }
107
- const v = a(p, ".gitignore"), L = await m(v, "utf-8").catch(() => {
107
+ const v = i(f, ".gitignore"), U = await m(v, "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: " + v), await h(v, 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 () => {
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
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);
116
+ for (const t of b)
117
+ for (const d of q)
118
+ for (const a of _) {
119
+ const n = i(o, t, d + a);
120
+ if (await m(n, "utf-8").catch(() => {
121
+ }) !== void 0) return z(o, n);
122
+ for (const L of M) {
123
+ const H = i(o, t, L, d + a);
124
+ if (await m(H, "utf-8").catch(() => {
125
+ }) !== void 0) return z(o, 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 = i(o, I), d = await m(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 (d !== void 0 && !d.includes("saltygen")) {
133
+ const n = i(t, ".."), L = `@import '${z(n, i(o, "saltygen/index.css"))}';`;
134
+ e.info("Adding global import statement to CSS file: " + t), await h(t, L + `
135
+ ` + d), await S(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: i(o, "eslint.config.js"),
141
+ rootJs: i(f, "eslint.config.js"),
142
+ projectMjs: i(o, "eslint.config.mjs"),
143
+ rootMjs: i(f, "eslint.config.mjs"),
144
+ projectJson: i(o, ".eslintrc.json"),
145
+ rootJson: i(f, ".eslintrc.json")
146
+ }, x = Object.values(st).find((t) => K(t));
147
+ if (x) {
148
+ u || await O(T.eslintConfigCore);
149
+ const t = await m(x, "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);
150
- }
151
+ if (!t) return C("Could not read ESLint config file.");
152
+ if (!t.includes("salty-css"))
153
+ if (e.info("Edit file: " + x), x.endsWith("js")) {
154
+ let n = `import saltyCss from "@salty-css/eslint-config-core/flat";
155
+ ${t}`;
156
+ t.includes("typescript-eslint") ? n.includes(".config(") ? n = n.replace(".config(", ".config(saltyCss,") : e.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.") : n.includes("export default [") ? n = n.replace("export default [", "export default [ saltyCss,") : n.includes("eslintConfig = [") ? n = n.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 h(x, n), await S(x);
157
+ } else {
158
+ const a = JSON.parse(t);
159
+ a.extends || (a.extends = []), a.extends.push("@salty-css/core");
160
+ const n = JSON.stringify(a, null, 2);
161
+ await h(x, n), await S(x);
162
+ }
151
163
  }
152
- const _ = a(c, "vite.config.ts"), B = await m(_, "utf-8").catch(() => {
164
+ const R = i(o, "vite.config.ts"), B = await m(R, "utf-8").catch(() => {
153
165
  });
154
166
  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
167
+ e.info("Edit file: " + R);
168
+ const d = `import { saltyPlugin } from '@salty-css/vite';
169
+ `, n = B.replace(/(plugins: \[)/, `$1
158
170
  saltyPlugin(__dirname),`);
159
- u || await I(`-D ${O.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await h(_, n + d), await P(_);
171
+ u || await O(`-D ${T.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await h(R, d + n), await S(R);
160
172
  }
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(() => {
173
+ const W = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((t) => i(o, t)).find((t) => K(t));
174
+ if (W) {
175
+ let t = await m(W, "utf-8").catch(() => {
164
176
  });
165
177
  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');
178
+ let a = !1;
179
+ /\splugins([^=]*)=[^[]\[/.test(t) && !a && (t = t.replace(/\splugins([^=]*)=[^[]\[/, (H, E) => ` plugins${E}= [withSaltyCss,`), a = !0);
180
+ const k = t.includes("module.exports"), L = k ? `const { withSaltyCss } = require('@salty-css/next');
169
181
  ` : `import { withSaltyCss } from '@salty-css/next';
170
182
  `;
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);
183
+ k && !a ? (t = t.replace(/module.exports = ([^;]+)/, (H, E) => `module.exports = withSaltyCss(${E})`), a = !0) : a || (t = t.replace(/export default ([^;]+)/, (H, E) => `export default withSaltyCss(${E})`)), u || await O(`-D ${T.next}`), e.info("Adding Salty-CSS plugin to Next.js config..."), await h(W, L + t), await S(W);
172
184
  }
173
185
  }
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) {
186
+ const nt = await A().catch(() => C("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));
187
+ 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 ⭐");
188
+ }), 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
189
  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);
190
+ const { dir: c = s } = this.opts();
191
+ if (!c) return C("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
192
+ const l = G(c);
193
+ await rt(l);
194
+ }), 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, c = X) {
195
+ const { file: l = s, dir: g = c, tag: u, name: f, className: o, reactComponent: D = !1 } = this.opts();
196
+ if (!l) return C("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
197
+ if (!g) return C("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
198
+ const y = G(g), F = l.split("/").slice(0, -1).join("/");
199
+ F && await V(i(y, F), { recursive: !0 });
200
+ const j = i(y, l), r = at(j);
201
+ r.ext || (r.ext = ".ts"), r.name.endsWith(".css") || (r.name = r.name + ".css"), r.base = r.name + r.ext;
202
+ const v = Z(r);
191
203
  if (await m(v, "utf-8").catch(() => {
192
204
  }) !== void 0) {
193
205
  e.error("File already exists:", v);
194
206
  return;
195
207
  }
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);
208
+ let b = ct(f || r.base.replace(/\.css\.\w+$/, ""));
209
+ if (D) {
210
+ const q = b + "Component";
211
+ b = b + "Wrapper";
212
+ const _ = r.base.replace(/\.css\.\w+$/, ""), { content: Y } = await P("react/react-vanilla-file.ts", { tag: u, componentName: q, styledComponentName: b, className: o, fileName: _ });
213
+ r.name = _.replace(/\.css$/, ""), r.ext = ".tsx", r.base = r.name + r.ext;
214
+ const I = Z(r);
215
+ e.info("Generating a new file: " + I), await h(I, Y), await S(I);
204
216
  }
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));
217
+ const { content: M } = await P("react/react-styled-file.ts", { tag: u, name: b, className: o });
218
+ e.info("Generating a new file: " + v), await h(v, M), await S(v);
219
+ }), 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") {
220
+ const { legacyPeerDeps: c, version: l = s } = this.opts(), g = i(process.cwd(), "package.json"), u = await A(g).catch((y) => C(y));
209
221
  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(
222
+ const f = { ...u.dependencies, ...u.devDependencies }, o = Object.keys(f).filter((y) => y === "salty-css" || y.startsWith("@salty-css/"));
223
+ if (!o.length)
224
+ return C(
213
225
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + g
214
226
  );
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();
227
+ const D = o.map((y) => l === "@" ? `${y}@${N.version}` : `${y}@${l.replace(/^@/, "")}`);
228
+ c ? (e.warn("Using legacy peer dependencies to update packages."), await O(...D, "--legacy-peer-deps")) : await O(...D), e.info("Salty-CSS packages updated successfully!");
229
+ }), p.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
230
+ const s = await Q();
219
231
  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/"));
232
+ const c = i(process.cwd(), "package.json"), l = await A(c).catch((f) => C(f));
233
+ if (!l) return;
234
+ const g = { ...l.dependencies, ...l.devDependencies }, u = Object.keys(g).filter((f) => f === "salty-css" || f.startsWith("@salty-css/"));
223
235
  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
236
+ return C(
237
+ "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + c
226
238
  );
227
- for (const p of u)
228
- e.info(`${p}: ${g[p]}`);
229
- }), f.parseAsync(process.argv);
239
+ for (const f of u)
240
+ e.info(`${f}: ${g[f]}`);
241
+ }), p.parseAsync(process.argv);
230
242
  }
231
243
  export {
232
- kt as main
244
+ Pt as main
233
245
  };
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.93",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",