@salty-css/core 0.0.1-alpha.55 → 0.0.1-alpha.57

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