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