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