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