@salty-css/core 0.0.1-alpha.33 → 0.0.1-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Salty CSS - Kinda sweet but yet spicy CSS-in-JS library 🧂
1
+ # Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
2
2
 
3
3
  In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
4
4
 
@@ -12,11 +12,17 @@ In the world of frontend dev is there anything saltier than CSS? Salty CSS is bu
12
12
 
13
13
  ## Get started
14
14
 
15
+ ### TL;DR
16
+
17
+ - Initialize: `npx salty-css init [directory]`
18
+ - Create component: `npx salty-css generate [filePath]`
19
+ - Build: `npx salty-css build [directory]`
20
+
15
21
  ### Quick way of using `salty-css` CLI
16
22
 
17
23
  #### Initialize Salty CSS for a project
18
24
 
19
- In your repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory.
25
+ In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. Init will also create `.saltyrc` which contains some metadata for future CLI commands.
20
26
 
21
27
  #### Create components
22
28
 
@@ -24,7 +30,7 @@ Components can be created with `npx salty-css generate [filePath]` which then cr
24
30
 
25
31
  #### Build / Compile Salty CSS
26
32
 
27
- If you want to manually build your project that can be done by running `npx salty-css build [directory]`
33
+ If you want to manually build your project that can be done by running `npx salty-css build [directory]`. Directory is not required as CLI can use default directory defined in `.saltyrc`. Note that build generates css files but Vite / Webpack plugin is still required for full support.
28
34
 
29
35
  #### Update Salty CSS packages
30
36
 
package/bin/main.cjs CHANGED
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("commander"),a=require("fs/promises"),o=require("path"),R=require("ejs"),z=require("../compiler/index.cjs"),W=require("../pascal-case-iWoaJWwT.cjs"),k=require("winston"),H=require("fs"),M=require("child_process"),B=require("ora");var E=typeof document<"u"?document.currentScript:null;const t=k.createLogger({level:"debug",format:k.format.combine(k.format.colorize(),k.format.cli()),transports:[new k.transports.Console({})]}),v=i=>{t.error(i)},O=i=>new Promise((f,h)=>{M.exec(i,w=>{if(w)return h(w);f()})}),b=async(...i)=>{const f=i.map(x=>x.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),h=B(`Installing packages: ${f}`).start(),w=i.join(" ");await O(`npm install ${w}`),h.succeed(`Installed packages: ${f}`)},G=()=>H.existsSync(o.join(process.cwd(),"node_modules",".bin","prettier"));async function q(i){try{if(!G())return;await O(`./node_modules/.bin/prettier --write "${i}"`),t.info(`Formatted ${i} with Prettier`)}catch(f){t.error(`Error formatting ${i} with Prettier:`,f)}}async function V(){const i=new L.Command;i.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const f={"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"))},h=async(e,r)=>{const{default:c}=await f[e],p=R.render(c,r);return{fileName:e,content:p}},w=async()=>{const e=o.join(process.cwd(),".saltyrc");return await a.readFile(e,"utf-8").then(JSON.parse).catch(()=>({}))},x=async e=>{const r=await a.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});if(!r)throw"Could not read package.json file!";return r},A=async()=>{const e=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:E&&E.tagName.toUpperCase()==="SCRIPT"&&E.src||new URL("bin/main.cjs",document.baseURI).href);return x(e)},J=await(async()=>(await w()).defaultProject)(),C=await A(),I={core:`@salty-css/core@${C.version}`,react:`@salty-css/react@${C.version}`,eslintPluginCore:`@salty-css/eslint-plugin-core@${C.version}`,vite:`@salty-css/vite@${C.version}`},N=e=>{const r=e==="."?"":e,c=process.cwd();return o.join(c,r)};i.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(e="."){t.info("Initializing a new Salty-CSS project!");const{dir:r=e,cssFile:c,skipInstall:p}=this.opts();if(!r)return v("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||(await b(I.core,I.react),await b(`-D ${I.eslintPluginCore}`));const g=process.cwd(),u=N(r),S=await Promise.all([h("salty.config.ts"),h("saltygen/index.css")]);await a.mkdir(u,{recursive:!0});const j=S.map(async({fileName:n,content:d})=>{const m=o.join(u,n);if(await a.readFile(m,"utf-8").catch(()=>{})!==void 0){t.debug("File already exists: "+m);return}const U=n.split("/").slice(0,-1).join("/");U&&await a.mkdir(o.join(u,U),{recursive:!0}),t.info("Writing file: "+m),await a.writeFile(m,d),await q(m)});await Promise.all(j);const l=o.relative(g,u)||".",s=o.join(g,".saltyrc"),y=await a.readFile(s,"utf-8").catch(()=>{});if(y===void 0){t.info("Creating file: "+s);const d=JSON.stringify({defaultProject:l,projects:[l]},null,2);await a.writeFile(s,d)}else{t.info("Edit file: "+s);const n=JSON.parse(y),d=new Set((n==null?void 0:n.projects)||[]);d.add(l),n.projects=[...d];const m=JSON.stringify(n,null,2);await a.writeFile(s,m)}const $=o.join(g,".gitignore"),F=await a.readFile($,"utf-8").catch(()=>{});if(F!==void 0&&(F.includes("saltygen")||(t.info("Edit file: "+$),await a.writeFile($,F+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("commander"),o=require("fs/promises"),t=require("path"),z=require("ejs"),W=require("../compiler/index.cjs"),H=require("../pascal-case-iWoaJWwT.cjs"),b=require("winston"),M=require("fs"),B=require("child_process"),G=require("ora");var O=typeof document<"u"?document.currentScript:null;const i=b.createLogger({level:"debug",format:b.format.combine(b.format.colorize(),b.format.cli()),transports:[new b.transports.Console({})]}),j=n=>{i.error(n)},A=n=>new Promise((g,h)=>{B.exec(n,S=>{if(S)return h(S);g()})}),x=async(...n)=>{const g=n.map(v=>v.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),h=G(`Installing packages: ${g}`).start(),S=n.join(" ");await A(`npm install ${S}`),h.succeed(`Installed packages: ${g}`)},V=()=>M.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function q(n){try{if(!V())return;await A(`./node_modules/.bin/prettier --write "${n}"`),i.info(`Formatted ${n} with Prettier`)}catch(g){i.error(`Error formatting ${n} with Prettier:`,g)}}async function K(){const n=new R.Command;n.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const g={"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"))},h=async(e,s)=>{const{default:c}=await g[e],p=z.render(c,s);return{fileName:e,content:p}},S=async()=>{const e=t.join(process.cwd(),".saltyrc");return await o.readFile(e,"utf-8").then(JSON.parse).catch(()=>({}))},v=async(e=t.join(process.cwd(),"package.json"))=>{const s=await o.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});if(!s)throw"Could not read package.json file!";return s},T=async()=>{const e=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:O&&O.tagName.toUpperCase()==="SCRIPT"&&O.src||new URL("bin/main.cjs",document.baseURI).href);return v(e)},J=await(async()=>(await S()).defaultProject)(),C=await T(),I={core:`@salty-css/core@${C.version}`,react:`@salty-css/react@${C.version}`,eslintPluginCore:`@salty-css/eslint-plugin-core@${C.version}`,vite:`@salty-css/vite@${C.version}`},N=e=>{const s=e==="."?"":e,c=process.cwd();return t.join(c,s)};n.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(e="."){if(!await v().catch(()=>{}))return j("Salty CSS project must be initialized in a directory with a package.json file.");i.info("Initializing a new Salty-CSS project!");const{dir:c=e,cssFile:p,skipInstall:y}=this.opts();if(!c)return j("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");y||(await x(I.core,I.react),await x(`-D ${I.eslintPluginCore}`));const w=process.cwd(),l=N(c),P=await Promise.all([h("salty.config.ts"),h("saltygen/index.css")]);await o.mkdir(l,{recursive:!0});const f=P.map(async({fileName:a,content:d})=>{const m=t.join(l,a);if(await o.readFile(m,"utf-8").catch(()=>{})!==void 0){i.debug("File already exists: "+m);return}const E=a.split("/").slice(0,-1).join("/");E&&await o.mkdir(t.join(l,E),{recursive:!0}),i.info("Writing file: "+m),await o.writeFile(m,d),await q(m)});await Promise.all(f);const r=t.relative(w,l)||".",u=t.join(w,".saltyrc"),_=await o.readFile(u,"utf-8").catch(()=>{});if(_===void 0){i.info("Creating file: "+u);const d=JSON.stringify({defaultProject:r,projects:[r]},null,2);await o.writeFile(u,d)}else{i.info("Edit file: "+u);const a=JSON.parse(_),d=new Set((a==null?void 0:a.projects)||[]);d.add(r),a.projects=[...d];const m=JSON.stringify(a,null,2);await o.writeFile(u,m)}const k=t.join(w,".gitignore"),F=await o.readFile(k,"utf-8").catch(()=>{});if(F!==void 0&&(F.includes("saltygen")||(i.info("Edit file: "+k),await o.writeFile(k,F+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
5
- `))),c){const n=o.join(u,c),d=await a.readFile(n,"utf-8").catch(()=>{});if(d!==void 0&&!d.includes("saltygen")){const D=o.join(n,".."),T=`@import '${o.relative(D,o.join(u,"saltygen/index.css"))}';`;t.info("Edit file: "+n),await a.writeFile(n,T+`
6
- `+d),await q(n)}}const P=o.join(u,"vite.config.ts"),_=await a.readFile(P,"utf-8").catch(()=>{});if(_!==void 0&&!_.includes("saltyPlugin")){t.info("Edit file: "+P);const d=`import { saltyPlugin } from '@salty-css/vite';
7
- `,D=_.replace(/(plugins: \[)/,`$1
8
- saltyPlugin(__dirname),`);t.info("Installing @salty-css/vite"),p||await b(`-D ${I.vite}`),t.info("Adding Salty-CSS plugin to Vite config..."),await a.writeFile(P,d+D),await q(P)}}),i.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>","Project directory to build the project in.").action(async function(e=J){t.info("Building the Salty-CSS project...");const{dir:r=e}=this.opts();if(!r)return v("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const c=N(r);await z.generateCss(c)}),i.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>","File to generate.").option("-d, --dir <dir>","Project directory to generate the file in.").option("-t, --tag <tag>","HTML tag of the component.","div").option("-n, --name <name>","Name of the component.").option("-c, --className <className>","CSS class of the component.").action(async function(e,r=J){const{file:c=e,dir:p=r,tag:g,name:u,className:S}=this.opts();if(!c)return v("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!p)return v("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const j=N(p),l=o.join(j,c),s=o.parse(l);s.ext||(s.ext=".ts"),s.name.endsWith(".css")||(s.name=s.name+".css"),s.base=s.name+s.ext;const y=o.format(s);if(await a.readFile(y,"utf-8").catch(()=>{})!==void 0){t.error("File already exists:",y);return}t.info("Generating a new file: "+y);const F=W.pascalCase(u||s.base.replace(/\.css\.\w+$/,"")),{content:P}=await h("react/react-styled-file.ts",{tag:g,name:F,className:S});await a.writeFile(y,P),await q(y)}),i.command("update").alias("up").description("Update Salty-CSS packages to the latest version.").option("--legacy-peer-deps <legacyPeerDeps>","Use legacy peer dependencies (not recommended).",!1).action(async function(e,r=J){const{legacyPeerDeps:c}=this.opts(),p=o.join(process.cwd(),"package.json"),g=await x(p).catch(l=>v(l));if(!g)return;const u={...g.dependencies,...g.devDependencies},S=Object.keys(u).filter(l=>l==="salty-css"||l.startsWith("@salty-css/"));if(!S.length)return v("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+p);const j=S.map(l=>`${l}@${C.version}`);c?(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!")}),i.parseAsync(process.argv)}exports.main=V;
5
+ `))),p){const a=t.join(l,p),d=await o.readFile(a,"utf-8").catch(()=>{});if(d!==void 0&&!d.includes("saltygen")){const D=t.join(a,".."),L=`@import '${t.relative(D,t.join(l,"saltygen/index.css"))}';`;i.info("Edit file: "+a),await o.writeFile(a,L+`
6
+ `+d),await q(a)}}const $=t.join(l,"vite.config.ts"),U=await o.readFile($,"utf-8").catch(()=>{});if(U!==void 0&&!U.includes("saltyPlugin")){i.info("Edit file: "+$);const d=`import { saltyPlugin } from '@salty-css/vite';
7
+ `,D=U.replace(/(plugins: \[)/,`$1
8
+ saltyPlugin(__dirname),`);i.info("Installing @salty-css/vite"),y||await x(`-D ${I.vite}`),i.info("Adding Salty-CSS plugin to Vite config..."),await o.writeFile($,d+D),await q($)}}),n.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>","Project directory to build the project in.").action(async function(e=J){i.info("Building the Salty-CSS project...");const{dir:s=e}=this.opts();if(!s)return j("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const c=N(s);await W.generateCss(c)}),n.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>","File to generate.").option("-d, --dir <dir>","Project directory to generate the file in.").option("-t, --tag <tag>","HTML tag of the component.","div").option("-n, --name <name>","Name of the component.").option("-c, --className <className>","CSS class of the component.").action(async function(e,s=J){const{file:c=e,dir:p=s,tag:y,name:w,className:l}=this.opts();if(!c)return j("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!p)return j("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const P=N(p),f=t.join(P,c),r=t.parse(f);r.ext||(r.ext=".ts"),r.name.endsWith(".css")||(r.name=r.name+".css"),r.base=r.name+r.ext;const u=t.format(r);if(await o.readFile(u,"utf-8").catch(()=>{})!==void 0){i.error("File already exists:",u);return}i.info("Generating a new file: "+u);const k=H.pascalCase(w||r.base.replace(/\.css\.\w+$/,"")),{content:F}=await h("react/react-styled-file.ts",{tag:y,name:k,className:l});await o.writeFile(u,F),await q(u)}),n.command("update").alias("up").description("Update Salty-CSS packages to the latest version.").option("--legacy-peer-deps <legacyPeerDeps>","Use legacy peer dependencies (not recommended).",!1).action(async function(e,s=J){const{legacyPeerDeps:c}=this.opts(),p=t.join(process.cwd(),"package.json"),y=await v(p).catch(f=>j(f));if(!y)return;const w={...y.dependencies,...y.devDependencies},l=Object.keys(w).filter(f=>f==="salty-css"||f.startsWith("@salty-css/"));if(!l.length)return j("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+p);const P=l.map(f=>`${f}@${C.version}`);c?(i.warn("Using legacy peer dependencies to update packages."),await x(...P,"--legacy-peer-deps")):await x(...P),i.info("Salty-CSS packages updated successfully!")}),n.parseAsync(process.argv)}exports.main=K;
package/bin/main.js CHANGED
@@ -1,159 +1,161 @@
1
- import { Command as H } from "commander";
2
- import { mkdir as U, readFile as y, writeFile as w } from "fs/promises";
3
- import { join as r, relative as z, parse as B, format as G } from "path";
4
- import { render as M } from "ejs";
5
- import { generateCss as R } from "../compiler/index.js";
6
- import { p as V } from "../pascal-case-BQpR5PdN.js";
7
- import { createLogger as q, format as _, transports as K } from "winston";
8
- import { existsSync as Q } from "fs";
9
- import { exec as X } from "child_process";
10
- import Y from "ora";
11
- const e = q({
1
+ import { Command as B } from "commander";
2
+ import { mkdir as z, readFile as y, writeFile as S } from "fs/promises";
3
+ import { join as s, relative as L, parse as G, format as M } from "path";
4
+ import { render as R } from "ejs";
5
+ import { generateCss as V } from "../compiler/index.js";
6
+ import { p as q } from "../pascal-case-BQpR5PdN.js";
7
+ import { createLogger as K, format as U, transports as Q } from "winston";
8
+ import { existsSync as X } from "fs";
9
+ import { exec as Y } from "child_process";
10
+ import Z from "ora";
11
+ const e = K({
12
12
  level: "debug",
13
- format: _.combine(_.colorize(), _.cli()),
14
- transports: [new K.Console({})]
15
- }), C = (n) => {
13
+ format: U.combine(U.colorize(), U.cli()),
14
+ transports: [new Q.Console({})]
15
+ }), P = (n) => {
16
16
  e.error(n);
17
- }, L = (n) => new Promise((f, h) => {
18
- X(n, (S) => {
19
- if (S) return h(S);
20
- f();
17
+ }, T = (n) => new Promise((g, h) => {
18
+ Y(n, (v) => {
19
+ if (v) return h(v);
20
+ g();
21
21
  });
22
22
  }), x = async (...n) => {
23
- const f = n.map((F) => F.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), h = Y(`Installing packages: ${f}`).start(), S = n.join(" ");
24
- await L(`npm install ${S}`), h.succeed(`Installed packages: ${f}`);
25
- }, Z = () => Q(r(process.cwd(), "node_modules", ".bin", "prettier"));
23
+ const g = n.map((C) => C.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), h = Z(`Installing packages: ${g}`).start(), v = n.join(" ");
24
+ await T(`npm install ${v}`), h.succeed(`Installed packages: ${g}`);
25
+ }, tt = () => X(s(process.cwd(), "node_modules", ".bin", "prettier"));
26
26
  async function J(n) {
27
27
  try {
28
- if (!Z()) return;
29
- await L(`./node_modules/.bin/prettier --write "${n}"`), e.info(`Formatted ${n} with Prettier`);
30
- } catch (f) {
31
- e.error(`Error formatting ${n} with Prettier:`, f);
28
+ if (!tt()) return;
29
+ await T(`./node_modules/.bin/prettier --write "${n}"`), e.info(`Formatted ${n} with Prettier`);
30
+ } catch (g) {
31
+ e.error(`Error formatting ${n} with Prettier:`, g);
32
32
  }
33
33
  }
34
- async function pt() {
35
- const n = new H();
34
+ async function ft() {
35
+ const n = new B();
36
36
  n.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
37
- const f = {
37
+ const g = {
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
43
  }, h = async (t, a) => {
44
- const { default: s } = await f[t], d = M(s, a);
44
+ const { default: r } = await g[t], d = R(r, a);
45
45
  return { fileName: t, content: d };
46
- }, S = async () => {
47
- const t = r(process.cwd(), ".saltyrc");
46
+ }, v = async () => {
47
+ const t = s(process.cwd(), ".saltyrc");
48
48
  return await y(t, "utf-8").then(JSON.parse).catch(() => ({}));
49
- }, F = async (t) => {
49
+ }, C = async (t = s(process.cwd(), "package.json")) => {
50
50
  const a = await y(t, "utf-8").then(JSON.parse).catch(() => {
51
51
  });
52
52
  if (!a) throw "Could not read package.json file!";
53
53
  return a;
54
- }, T = async () => {
54
+ }, W = async () => {
55
55
  const t = new URL("../package.json", import.meta.url);
56
- return F(t);
57
- }, N = await (async () => (await S()).defaultProject)(), k = await T(), b = {
56
+ return C(t);
57
+ }, N = await (async () => (await v()).defaultProject)(), k = await W(), F = {
58
58
  core: `@salty-css/core@${k.version}`,
59
59
  react: `@salty-css/react@${k.version}`,
60
60
  eslintPluginCore: `@salty-css/eslint-plugin-core@${k.version}`,
61
61
  vite: `@salty-css/vite@${k.version}`
62
62
  }, E = (t) => {
63
- const a = t === "." ? "" : t, s = process.cwd();
64
- return r(s, a);
63
+ const a = t === "." ? "" : t, r = process.cwd();
64
+ return s(r, a);
65
65
  };
66
66
  n.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(t = ".") {
67
+ if (!await C().catch(() => {
68
+ })) return P("Salty CSS project must be initialized in a directory with a package.json file.");
67
69
  e.info("Initializing a new Salty-CSS project!");
68
- const { dir: a = t, cssFile: s, skipInstall: d } = this.opts();
69
- if (!a) return C("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
70
- d || (await x(b.core, b.react), await x(`-D ${b.eslintPluginCore}`));
71
- const g = process.cwd(), p = E(a), P = await Promise.all([h("salty.config.ts"), h("saltygen/index.css")]);
72
- await U(p, { recursive: !0 });
73
- const v = P.map(async ({ fileName: i, content: l }) => {
74
- const m = r(p, i);
70
+ const { dir: r = t, cssFile: d, skipInstall: u } = this.opts();
71
+ if (!r) return P("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
72
+ u || (await x(F.core, F.react), await x(`-D ${F.eslintPluginCore}`));
73
+ const w = process.cwd(), c = E(r), j = await Promise.all([h("salty.config.ts"), h("saltygen/index.css")]);
74
+ await z(c, { recursive: !0 });
75
+ const f = j.map(async ({ fileName: i, content: l }) => {
76
+ const m = s(c, i);
75
77
  if (await y(m, "utf-8").catch(() => {
76
78
  }) !== void 0) {
77
79
  e.debug("File already exists: " + m);
78
80
  return;
79
81
  }
80
- const O = i.split("/").slice(0, -1).join("/");
81
- O && await U(r(p, O), { recursive: !0 }), e.info("Writing file: " + m), await w(m, l), await J(m);
82
+ const _ = i.split("/").slice(0, -1).join("/");
83
+ _ && await z(s(c, _), { recursive: !0 }), e.info("Writing file: " + m), await S(m, l), await J(m);
82
84
  });
83
- await Promise.all(v);
84
- const c = z(g, p) || ".", o = r(g, ".saltyrc"), u = await y(o, "utf-8").catch(() => {
85
+ await Promise.all(f);
86
+ const o = L(w, c) || ".", p = s(w, ".saltyrc"), A = await y(p, "utf-8").catch(() => {
85
87
  });
86
- if (u === void 0) {
87
- e.info("Creating file: " + o);
88
+ if (A === void 0) {
89
+ e.info("Creating file: " + p);
88
90
  const l = JSON.stringify({
89
- defaultProject: c,
90
- projects: [c]
91
+ defaultProject: o,
92
+ projects: [o]
91
93
  }, null, 2);
92
- await w(o, l);
94
+ await S(p, l);
93
95
  } else {
94
- e.info("Edit file: " + o);
95
- const i = JSON.parse(u), l = new Set((i == null ? void 0 : i.projects) || []);
96
- l.add(c), i.projects = [...l];
96
+ e.info("Edit file: " + p);
97
+ const i = JSON.parse(A), l = new Set((i == null ? void 0 : i.projects) || []);
98
+ l.add(o), i.projects = [...l];
97
99
  const m = JSON.stringify(i, null, 2);
98
- await w(o, m);
100
+ await S(p, m);
99
101
  }
100
- const D = r(g, ".gitignore"), $ = await y(D, "utf-8").catch(() => {
102
+ const $ = s(w, ".gitignore"), b = await y($, "utf-8").catch(() => {
101
103
  });
102
- if ($ !== void 0 && ($.includes("saltygen") || (e.info("Edit file: " + D), await w(D, $ + `
104
+ if (b !== void 0 && (b.includes("saltygen") || (e.info("Edit file: " + $), await S($, b + `
103
105
 
104
106
  # Salty-CSS
105
107
  saltygen
106
- `))), s) {
107
- const i = r(p, s), l = await y(i, "utf-8").catch(() => {
108
+ `))), d) {
109
+ const i = s(c, d), l = await y(i, "utf-8").catch(() => {
108
110
  });
109
111
  if (l !== void 0 && !l.includes("saltygen")) {
110
- const I = r(i, ".."), W = `@import '${z(I, r(p, "saltygen/index.css"))}';`;
111
- e.info("Edit file: " + i), await w(i, W + `
112
+ const I = s(i, ".."), H = `@import '${L(I, s(c, "saltygen/index.css"))}';`;
113
+ e.info("Edit file: " + i), await S(i, H + `
112
114
  ` + l), await J(i);
113
115
  }
114
116
  }
115
- const j = r(p, "vite.config.ts"), A = await y(j, "utf-8").catch(() => {
117
+ const D = s(c, "vite.config.ts"), O = await y(D, "utf-8").catch(() => {
116
118
  });
117
- if (A !== void 0 && !A.includes("saltyPlugin")) {
118
- e.info("Edit file: " + j);
119
+ if (O !== void 0 && !O.includes("saltyPlugin")) {
120
+ e.info("Edit file: " + D);
119
121
  const l = `import { saltyPlugin } from '@salty-css/vite';
120
- `, I = A.replace(/(plugins: \[)/, `$1
122
+ `, I = O.replace(/(plugins: \[)/, `$1
121
123
  saltyPlugin(__dirname),`);
122
- e.info("Installing @salty-css/vite"), d || await x(`-D ${b.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await w(j, l + I), await J(j);
124
+ e.info("Installing @salty-css/vite"), u || await x(`-D ${F.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await S(D, l + I), await J(D);
123
125
  }
124
126
  }), n.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(t = N) {
125
127
  e.info("Building the Salty-CSS project...");
126
128
  const { dir: a = t } = this.opts();
127
- if (!a) return C("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
128
- const s = E(a);
129
- await R(s);
129
+ if (!a) return P("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
130
+ const r = E(a);
131
+ await V(r);
130
132
  }), n.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>", "File to generate.").option("-d, --dir <dir>", "Project directory to generate the file in.").option("-t, --tag <tag>", "HTML tag of the component.", "div").option("-n, --name <name>", "Name of the component.").option("-c, --className <className>", "CSS class of the component.").action(async function(t, a = N) {
131
- const { file: s = t, dir: d = a, tag: g, name: p, className: P } = this.opts();
132
- if (!s) return C("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
133
- if (!d) return C("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
134
- const v = E(d), c = r(v, s), o = B(c);
133
+ const { file: r = t, dir: d = a, tag: u, name: w, className: c } = this.opts();
134
+ if (!r) return P("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
135
+ if (!d) return P("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
136
+ const j = E(d), f = s(j, r), o = G(f);
135
137
  o.ext || (o.ext = ".ts"), o.name.endsWith(".css") || (o.name = o.name + ".css"), o.base = o.name + o.ext;
136
- const u = G(o);
137
- if (await y(u, "utf-8").catch(() => {
138
+ const p = M(o);
139
+ if (await y(p, "utf-8").catch(() => {
138
140
  }) !== void 0) {
139
- e.error("File already exists:", u);
141
+ e.error("File already exists:", p);
140
142
  return;
141
143
  }
142
- e.info("Generating a new file: " + u);
143
- const $ = V(p || o.base.replace(/\.css\.\w+$/, "")), { content: j } = await h("react/react-styled-file.ts", { tag: g, name: $, className: P });
144
- await w(u, j), await J(u);
144
+ e.info("Generating a new file: " + p);
145
+ const $ = q(w || o.base.replace(/\.css\.\w+$/, "")), { content: b } = await h("react/react-styled-file.ts", { tag: u, name: $, className: c });
146
+ await S(p, b), await J(p);
145
147
  }), n.command("update").alias("up").description("Update Salty-CSS packages to the latest version.").option("--legacy-peer-deps <legacyPeerDeps>", "Use legacy peer dependencies (not recommended).", !1).action(async function(t, a = N) {
146
- const { legacyPeerDeps: s } = this.opts(), d = r(process.cwd(), "package.json"), g = await F(d).catch((c) => C(c));
147
- if (!g) return;
148
- const p = { ...g.dependencies, ...g.devDependencies }, P = Object.keys(p).filter((c) => c === "salty-css" || c.startsWith("@salty-css/"));
149
- if (!P.length)
150
- return C(
148
+ const { legacyPeerDeps: r } = this.opts(), d = s(process.cwd(), "package.json"), u = await C(d).catch((f) => P(f));
149
+ if (!u) return;
150
+ const w = { ...u.dependencies, ...u.devDependencies }, c = Object.keys(w).filter((f) => f === "salty-css" || f.startsWith("@salty-css/"));
151
+ if (!c.length)
152
+ return P(
151
153
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + d
152
154
  );
153
- const v = P.map((c) => `${c}@${k.version}`);
154
- s ? (e.warn("Using legacy peer dependencies to update packages."), await x(...v, "--legacy-peer-deps")) : await x(...v), e.info("Salty-CSS packages updated successfully!");
155
+ const j = c.map((f) => `${f}@${k.version}`);
156
+ r ? (e.warn("Using legacy peer dependencies to update packages."), await x(...j, "--legacy-peer-deps")) : await x(...j), e.info("Salty-CSS packages updated successfully!");
155
157
  }), n.parseAsync(process.argv);
156
158
  }
157
159
  export {
158
- pt as main
160
+ ft as main
159
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.33",
3
+ "version": "0.0.1-alpha.34",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",