@salty-css/core 0.0.1-alpha.38 → 0.0.1-alpha.39

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