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