@salty-css/core 0.0.1-alpha.29 → 0.0.1-alpha.30
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/logger.d.ts +1 -0
- package/bin/main.cjs +5 -5
- package/bin/main.js +73 -71
- package/package.json +1 -1
package/bin/logger.d.ts
CHANGED
package/bin/main.cjs
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("commander"),i=require("fs/promises"),t=require("path"),R=require("ejs"),T=require("../compiler/index.cjs"),U=require("../pascal-case-iWoaJWwT.cjs"),S=require("winston"),z=require("fs"),H=require("child_process"),W=require("ora");var D=typeof document<"u"?document.currentScript:null;const r=S.createLogger({level:"debug",format:S.format.combine(S.format.colorize(),S.format.cli()),transports:[new S.transports.Console({})]}),x=n=>{r.error(n)},A=n=>new Promise((l,g)=>{H.exec(n,y=>{if(y)return g(y);l()})}),E=async(...n)=>{const l=n.map($=>$.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),g=W(`Installing packages: ${l}`).start(),y=n.join(" ");await A(`npm install ${y}`),g.succeed(`Installed packages: ${l}`)},B=()=>z.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function I(n){try{if(!B())return;await A(`./node_modules/.bin/prettier --write "${n}"`),r.info(`Formatted ${n} with Prettier`)}catch(l){r.error(`Error formatting ${n} with Prettier:`,l)}}async function G(){const n=new O.Command;n.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const l={"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"))},g=async(a,c)=>{const{default:d}=await l[a],m=R.render(d,c);return{fileName:a,content:m}},y=async()=>{const a=t.join(process.cwd(),".saltyrc");return await i.readFile(a,"utf-8").then(JSON.parse).catch(()=>({}))},$=async()=>{const a=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:D&&D.tagName.toUpperCase()==="SCRIPT"&&D.src||new URL("bin/main.cjs",document.baseURI).href);return await i.readFile(a,"utf-8").then(JSON.parse).catch(()=>({}))},N=await(async()=>(await y()).defaultProject)(),v=await $(),C={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}`};n.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(a){r.info("Initializing a new Salty-CSS project!");const{dir:c=a,cssFile:d,skipInstall:m}=this.opts();if(!c)return x("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");m||(await E(C.core,C.react),await E(`-D ${C.eslintPluginCore}`));const w=process.cwd(),f=t.join(w,c),k=await Promise.all([g("salty.config.ts"),g("saltygen/index.css")]);await i.mkdir(f,{recursive:!0});const q=k.map(async({fileName:e,content:s})=>{const p=t.join(f,e);if(await i.readFile(p,"utf-8").catch(()=>{})!==void 0){r.debug("File already exists: "+p);return}const _=e.split("/").slice(0,-1).join("/");_&&await i.mkdir(t.join(f,_),{recursive:!0}),r.info("Writing file: "+p),await i.writeFile(p,s),await I(p)});await Promise.all(q);const j=t.relative(w,f),o=t.join(w,".saltyrc"),u=await i.readFile(o,"utf-8").catch(()=>{});if(u===void 0){r.info("Creating file: "+o);const s=JSON.stringify({defaultProject:j,projects:[j]},null,2);await i.writeFile(o,s)}else{r.info("Edit file: "+o);const e=JSON.parse(u),s=new Set((e==null?void 0:e.projects)||[]);s.add(j),e.projects=[...s];const p=JSON.stringify(e,null,2);await i.writeFile(o,p)}const F=t.join(w,".gitignore"),P=await i.readFile(F,"utf-8").catch(()=>{});if(P!==void 0&&(P.includes("saltygen")||(r.info("Edit file: "+F),await i.writeFile(F,P+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
5
|
-
`))),d){const e=t.join(f,d),s=await i.readFile(e,"utf-8").catch(()=>{});if(s!==void 0&&!s.includes("saltygen")){const b=t.join(e,".."),
|
6
|
-
`+s),await
|
7
|
-
`,b=
|
8
|
-
saltyPlugin(__dirname),`);
|
5
|
+
`))),d){const e=t.join(f,d),s=await i.readFile(e,"utf-8").catch(()=>{});if(s!==void 0&&!s.includes("saltygen")){const b=t.join(e,".."),L=`@import '${t.relative(b,t.join(f,"saltygen/index.css"))}';`;r.info("Edit file: "+e),await i.writeFile(e,L+`
|
6
|
+
`+s),await I(e)}}const h=t.join(f,"vite.config.ts"),J=await i.readFile(h,"utf-8").catch(()=>{});if(J!==void 0&&!J.includes("saltyPlugin")){r.info("Edit file: "+h);const s=`import { saltyPlugin } from '@salty-css/vite';
|
7
|
+
`,b=J.replace(/(plugins: \[)/,`$1
|
8
|
+
saltyPlugin(__dirname),`);r.info("Installing @salty-css/vite"),m||await E(`-D ${C.vite}`),r.info("Adding Salty-CSS plugin to Vite config..."),await i.writeFile(h,s+b),await I(h)}}),n.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(a=N){r.info("Building the Salty-CSS project...");const{dir:c=a}=this.opts();if(!c)return x("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const d=t.join(process.cwd(),c);await T.generateCss(d)}),n.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(a,c=N){const{file:d=a,dir:m=c,tag:w,name:f,className:k}=this.opts();if(!d)return x("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!m)return x("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const q=t.join(process.cwd(),m),j=t.join(q,d),o=t.parse(j);o.ext||(o.ext=".ts"),o.name.endsWith(".css")||(o.name=o.name+".css"),o.base=o.name+o.ext;const u=t.format(o);if(await i.readFile(u,"utf-8").catch(()=>{})!==void 0){r.error("File already exists:",u);return}r.info("Generating a new file: "+u);const P=U.pascalCase(f||o.base.replace(/\.css\.\w+$/,"")),{content:h}=await g("react/react-styled-file.ts",{tag:w,name:P,className:k});await i.writeFile(u,h),await I(u)}),n.parseAsync(process.argv)}exports.main=G;
|
package/bin/main.js
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
-
import { Command as
|
2
|
-
import { mkdir as
|
3
|
-
import { join as o, relative as
|
4
|
-
import { render as
|
5
|
-
import { generateCss as
|
6
|
-
import { p as
|
7
|
-
import { createLogger as
|
8
|
-
import { existsSync as
|
9
|
-
import { exec as
|
10
|
-
import
|
11
|
-
const
|
1
|
+
import { Command as T } from "commander";
|
2
|
+
import { mkdir as _, readFile as m, writeFile as y } from "fs/promises";
|
3
|
+
import { join as o, relative as z, parse as W, format as B } from "path";
|
4
|
+
import { render as G } from "ejs";
|
5
|
+
import { generateCss as R } from "../compiler/index.js";
|
6
|
+
import { p as M } from "../pascal-case-BQpR5PdN.js";
|
7
|
+
import { createLogger as U, format as N, transports as V } from "winston";
|
8
|
+
import { existsSync as q } from "fs";
|
9
|
+
import { exec as K } from "child_process";
|
10
|
+
import Q from "ora";
|
11
|
+
const n = U({
|
12
12
|
level: "debug",
|
13
|
-
format:
|
14
|
-
transports: [new
|
15
|
-
}),
|
16
|
-
|
13
|
+
format: N.combine(N.colorize(), N.cli()),
|
14
|
+
transports: [new V.Console({})]
|
15
|
+
}), $ = (e) => {
|
16
|
+
n.error(e);
|
17
|
+
}, L = (e) => new Promise((c, g) => {
|
18
|
+
K(e, (w) => {
|
17
19
|
if (w) return g(w);
|
18
20
|
c();
|
19
21
|
});
|
20
|
-
}),
|
21
|
-
const c =
|
22
|
-
await
|
23
|
-
},
|
24
|
-
async function
|
22
|
+
}), A = async (...e) => {
|
23
|
+
const c = e.map((I) => I.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), g = Q(`Installing packages: ${c}`).start(), w = e.join(" ");
|
24
|
+
await L(`npm install ${w}`), g.succeed(`Installed packages: ${c}`);
|
25
|
+
}, X = () => q(o(process.cwd(), "node_modules", ".bin", "prettier"));
|
26
|
+
async function b(e) {
|
25
27
|
try {
|
26
|
-
if (!
|
27
|
-
await
|
28
|
+
if (!X()) return;
|
29
|
+
await L(`./node_modules/.bin/prettier --write "${e}"`), n.info(`Formatted ${e} with Prettier`);
|
28
30
|
} catch (c) {
|
29
|
-
|
31
|
+
n.error(`Error formatting ${e} with Prettier:`, c);
|
30
32
|
}
|
31
33
|
}
|
32
|
-
async function
|
33
|
-
const
|
34
|
-
|
34
|
+
async function lt() {
|
35
|
+
const e = new T();
|
36
|
+
e.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
|
35
37
|
const c = {
|
36
38
|
// Core files
|
37
39
|
"salty.config.ts": import("../salty.config-D9ANEDiH.js"),
|
@@ -39,57 +41,57 @@ async function ct() {
|
|
39
41
|
// React
|
40
42
|
"react/react-styled-file.ts": import("../react-styled-file-CGVf5n1B.js")
|
41
43
|
}, g = async (a, s) => {
|
42
|
-
const { default: l } = await c[a], u =
|
44
|
+
const { default: l } = await c[a], u = G(l, s);
|
43
45
|
return { fileName: a, content: u };
|
44
46
|
}, w = async () => {
|
45
47
|
const a = o(process.cwd(), ".saltyrc");
|
46
48
|
return await m(a, "utf-8").then(JSON.parse).catch(() => ({}));
|
47
|
-
},
|
49
|
+
}, I = async () => {
|
48
50
|
const a = new URL("../package.json", import.meta.url);
|
49
51
|
return await m(a, "utf-8").then(JSON.parse).catch(() => ({}));
|
50
|
-
},
|
52
|
+
}, O = await (async () => (await w()).defaultProject)(), C = await I(), j = {
|
51
53
|
core: `@salty-css/core@${C.version}`,
|
52
54
|
react: `@salty-css/react@${C.version}`,
|
53
55
|
eslintPluginCore: `@salty-css/eslint-plugin-core@${C.version}`,
|
54
56
|
vite: `@salty-css/vite@${C.version}`
|
55
57
|
};
|
56
|
-
|
57
|
-
|
58
|
+
e.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(a) {
|
59
|
+
n.info("Initializing a new Salty-CSS project!");
|
58
60
|
const { dir: s = a, cssFile: l, skipInstall: u } = this.opts();
|
59
|
-
if (!s)
|
60
|
-
u || (await
|
61
|
-
const h = process.cwd(), d = o(h, s),
|
62
|
-
await
|
63
|
-
const
|
61
|
+
if (!s) return $("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
|
62
|
+
u || (await A(j.core, j.react), await A(`-D ${j.eslintPluginCore}`));
|
63
|
+
const h = process.cwd(), d = o(h, s), k = await Promise.all([g("salty.config.ts"), g("saltygen/index.css")]);
|
64
|
+
await _(d, { recursive: !0 });
|
65
|
+
const J = k.map(async ({ fileName: t, content: r }) => {
|
64
66
|
const p = o(d, t);
|
65
67
|
if (await m(p, "utf-8").catch(() => {
|
66
68
|
}) !== void 0) {
|
67
|
-
|
69
|
+
n.debug("File already exists: " + p);
|
68
70
|
return;
|
69
71
|
}
|
70
|
-
const
|
71
|
-
|
72
|
+
const E = t.split("/").slice(0, -1).join("/");
|
73
|
+
E && await _(o(d, E), { recursive: !0 }), n.info("Writing file: " + p), await y(p, r), await b(p);
|
72
74
|
});
|
73
|
-
await Promise.all(
|
74
|
-
const S =
|
75
|
+
await Promise.all(J);
|
76
|
+
const S = z(h, d), i = o(h, ".saltyrc"), f = await m(i, "utf-8").catch(() => {
|
75
77
|
});
|
76
78
|
if (f === void 0) {
|
77
|
-
|
79
|
+
n.info("Creating file: " + i);
|
78
80
|
const r = JSON.stringify({
|
79
81
|
defaultProject: S,
|
80
82
|
projects: [S]
|
81
83
|
}, null, 2);
|
82
|
-
await y(
|
84
|
+
await y(i, r);
|
83
85
|
} else {
|
84
|
-
|
86
|
+
n.info("Edit file: " + i);
|
85
87
|
const t = JSON.parse(f), r = new Set((t == null ? void 0 : t.projects) || []);
|
86
88
|
r.add(S), t.projects = [...r];
|
87
89
|
const p = JSON.stringify(t, null, 2);
|
88
|
-
await y(
|
90
|
+
await y(i, p);
|
89
91
|
}
|
90
92
|
const x = o(h, ".gitignore"), v = await m(x, "utf-8").catch(() => {
|
91
93
|
});
|
92
|
-
if (v !== void 0 && (v.includes("saltygen") || (
|
94
|
+
if (v !== void 0 && (v.includes("saltygen") || (n.info("Edit file: " + x), await y(x, v + `
|
93
95
|
|
94
96
|
# Salty-CSS
|
95
97
|
saltygen
|
@@ -97,43 +99,43 @@ saltygen
|
|
97
99
|
const t = o(d, l), r = await m(t, "utf-8").catch(() => {
|
98
100
|
});
|
99
101
|
if (r !== void 0 && !r.includes("saltygen")) {
|
100
|
-
const F = o(t, ".."),
|
101
|
-
|
102
|
-
` + r), await
|
102
|
+
const F = o(t, ".."), H = `@import '${z(F, o(d, "saltygen/index.css"))}';`;
|
103
|
+
n.info("Edit file: " + t), await y(t, H + `
|
104
|
+
` + r), await b(t);
|
103
105
|
}
|
104
106
|
}
|
105
|
-
const P = o(d, "vite.config.ts"),
|
107
|
+
const P = o(d, "vite.config.ts"), D = await m(P, "utf-8").catch(() => {
|
106
108
|
});
|
107
|
-
if (
|
108
|
-
|
109
|
+
if (D !== void 0 && !D.includes("saltyPlugin")) {
|
110
|
+
n.info("Edit file: " + P);
|
109
111
|
const r = `import { saltyPlugin } from '@salty-css/vite';
|
110
|
-
`, F =
|
112
|
+
`, F = D.replace(/(plugins: \[)/, `$1
|
111
113
|
saltyPlugin(__dirname),`);
|
112
|
-
|
114
|
+
n.info("Installing @salty-css/vite"), u || await A(`-D ${j.vite}`), n.info("Adding Salty-CSS plugin to Vite config..."), await y(P, r + F), await b(P);
|
113
115
|
}
|
114
|
-
}),
|
115
|
-
|
116
|
+
}), e.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(a = O) {
|
117
|
+
n.info("Building the Salty-CSS project...");
|
116
118
|
const { dir: s = a } = this.opts();
|
117
|
-
if (!s)
|
119
|
+
if (!s) return $("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
|
118
120
|
const l = o(process.cwd(), s);
|
119
|
-
await
|
120
|
-
}),
|
121
|
-
const { file: l = a, dir: u = s, tag: h, name: d, className:
|
122
|
-
if (!l)
|
123
|
-
if (!u)
|
124
|
-
const
|
125
|
-
|
126
|
-
const f =
|
121
|
+
await R(l);
|
122
|
+
}), e.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(a, s = O) {
|
123
|
+
const { file: l = a, dir: u = s, tag: h, name: d, className: k } = this.opts();
|
124
|
+
if (!l) return $("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
|
125
|
+
if (!u) return $("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
|
126
|
+
const J = o(process.cwd(), u), S = o(J, l), i = W(S);
|
127
|
+
i.ext || (i.ext = ".ts"), i.name.endsWith(".css") || (i.name = i.name + ".css"), i.base = i.name + i.ext;
|
128
|
+
const f = B(i);
|
127
129
|
if (await m(f, "utf-8").catch(() => {
|
128
130
|
}) !== void 0) {
|
129
|
-
|
131
|
+
n.error("File already exists:", f);
|
130
132
|
return;
|
131
133
|
}
|
132
|
-
|
133
|
-
const v =
|
134
|
-
await y(f, P), await
|
135
|
-
}),
|
134
|
+
n.info("Generating a new file: " + f);
|
135
|
+
const v = M(d || i.base.replace(/\.css\.\w+$/, "")), { content: P } = await g("react/react-styled-file.ts", { tag: h, name: v, className: k });
|
136
|
+
await y(f, P), await b(f);
|
137
|
+
}), e.parseAsync(process.argv);
|
136
138
|
}
|
137
139
|
export {
|
138
|
-
|
140
|
+
lt as main
|
139
141
|
};
|