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