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