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