@salty-css/core 0.0.1-alpha.35 → 0.0.1-alpha.37
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 +4 -4
- package/bin/main.js +70 -68
- package/compiler/index.cjs +3 -3
- package/compiler/index.js +19 -23
- package/package.json +1 -1
package/bin/main.cjs
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("commander"),i=require("fs/promises"),t=require("path"),z=require("ejs"),W=require("../compiler/index.cjs"),H=require("../pascal-case-iWoaJWwT.cjs"),x=require("winston"),M=require("fs"),B=require("child_process"),G=require("ora");var O=typeof document<"u"?document.currentScript:null;const n=x.createLogger({level:"debug",format:x.format.combine(x.format.colorize(),x.format.cli()),transports:[new x.transports.Console({})]}),S=a=>{n.error(a)},A=a=>new Promise((
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("commander"),i=require("fs/promises"),t=require("path"),z=require("ejs"),W=require("../compiler/index.cjs"),H=require("../pascal-case-iWoaJWwT.cjs"),x=require("winston"),M=require("fs"),B=require("child_process"),G=require("ora");var O=typeof document<"u"?document.currentScript:null;const n=x.createLogger({level:"debug",format:x.format.combine(x.format.colorize(),x.format.cli()),transports:[new x.transports.Console({})]}),S=a=>{n.error(a)},A=a=>new Promise((f,h)=>{B.exec(a,P=>{if(P)return h(P);f()})}),I=async(...a)=>{const f=a.map(C=>C.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),h=G(`Installing packages: ${f}`).start(),P=a.join(" ");await A(`npm install ${P}`),h.succeed(`Installed packages: ${f}`)},V=()=>M.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function J(a){try{if(!V())return;await A(`./node_modules/.bin/prettier --write "${a}"`),n.info(`Formatted ${a} with Prettier`)}catch(f){n.error(`Error formatting ${a} with Prettier:`,f)}}async function K(){const a=new R.Command;a.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const f={"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"))},h=async(e,r)=>{const{default:c}=await f[e],p=z.render(c,r);return{fileName:e,content:p}},P=async()=>{const e=t.join(process.cwd(),".saltyrc");return await i.readFile(e,"utf-8").then(JSON.parse).catch(()=>({}))},C=async(e=t.join(process.cwd(),"package.json"))=>{const r=await i.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});if(!r)throw"Could not read package.json file!";return r},T=async()=>{const e=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:O&&O.tagName.toUpperCase()==="SCRIPT"&&O.src||new URL("bin/main.cjs",document.baseURI).href);return C(e)},N=await(async()=>(await P()).defaultProject)(),k=await T(),$={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}`},_=e=>{const r=e==="."?"":e,c=process.cwd();return t.join(c,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(e="."){if(!await C().catch(()=>{}))return S("Salty CSS project must be initialized in a directory with a package.json file.");n.info("Initializing a new Salty-CSS project!");const{dir:c=e,cssFile:p,skipInstall:m}=this.opts();if(!c)return S("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");m||(await I($.core,$.react),await I(`-D ${$.eslintPluginCore}`));const w=process.cwd(),l=_(c),j=await Promise.all([h("salty.config.ts"),h("saltygen/index.css")]);await i.mkdir(l,{recursive:!0});const u=j.map(async({fileName:o,content:d})=>{const g=t.join(l,o);if(await i.readFile(g,"utf-8").catch(()=>{})!==void 0){n.debug("File already exists: "+g);return}const E=o.split("/").slice(0,-1).join("/");E&&await i.mkdir(t.join(l,E),{recursive:!0}),n.info("Writing file: "+g),await i.writeFile(g,d),await J(g)});await Promise.all(u);const F=t.relative(w,l)||".",s=t.join(w,".saltyrc"),y=await i.readFile(s,"utf-8").catch(()=>{});if(y===void 0){n.info("Creating file: "+s);const d=JSON.stringify({defaultProject:F,projects:[F]},null,2);await i.writeFile(s,d)}else{n.info("Edit file: "+s);const o=JSON.parse(y),d=new Set((o==null?void 0:o.projects)||[]);d.add(F),o.projects=[...d];const g=JSON.stringify(o,null,2);await i.writeFile(s,g)}const D=t.join(w,".gitignore"),b=await i.readFile(D,"utf-8").catch(()=>{});if(b!==void 0&&(b.includes("saltygen")||(n.info("Edit file: "+D),await i.writeFile(D,b+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
5
|
-
`))),
|
6
|
-
`+
|
5
|
+
`))),p){const o=t.join(l,p),d=await i.readFile(o,"utf-8").catch(()=>{});if(d!==void 0&&!d.includes("saltygen")){const q=t.join(o,".."),L=`@import '${t.relative(q,t.join(l,"saltygen/index.css"))}';`;n.info("Edit file: "+o),await i.writeFile(o,L+`
|
6
|
+
`+d),await J(o)}}const v=t.join(l,"vite.config.ts"),U=await i.readFile(v,"utf-8").catch(()=>{});if(U!==void 0&&!U.includes("saltyPlugin")){n.info("Edit file: "+v);const d=`import { saltyPlugin } from '@salty-css/vite';
|
7
7
|
`,q=U.replace(/(plugins: \[)/,`$1
|
8
|
-
saltyPlugin(__dirname),`);n.info("Installing @salty-css/vite"),
|
8
|
+
saltyPlugin(__dirname),`);n.info("Installing @salty-css/vite"),m||await I(`-D ${$.vite}`),n.info("Adding Salty-CSS plugin to Vite config..."),await i.writeFile(v,d+q),await J(v)}}),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(e=N){n.info("Building the Salty-CSS project...");const{dir:r=e}=this.opts();if(!r)return S("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const c=_(r);await W.generateCss(c)}),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(e,r=N){const{file:c=e,dir:p=r,tag:m,name:w,className:l}=this.opts();if(!c)return S("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!p)return S("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const j=_(p),u=c.split("/").slice(0,-1).join("/");u&&await i.mkdir(t.join(j,u),{recursive:!0});const F=t.join(j,c),s=t.parse(F);s.ext||(s.ext=".ts"),s.name.endsWith(".css")||(s.name=s.name+".css"),s.base=s.name+s.ext;const y=t.format(s);if(await i.readFile(y,"utf-8").catch(()=>{})!==void 0){n.error("File already exists:",y);return}n.info("Generating a new file: "+y);const b=H.pascalCase(w||s.base.replace(/\.css\.\w+$/,"")),{content:v}=await h("react/react-styled-file.ts",{tag:m,name:b,className:l});await i.writeFile(y,v),await J(y)}),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(e,r=N){const{legacyPeerDeps:c}=this.opts(),p=t.join(process.cwd(),"package.json"),m=await C(p).catch(u=>S(u));if(!m)return;const w={...m.dependencies,...m.devDependencies},l=Object.keys(w).filter(u=>u==="salty-css"||u.startsWith("@salty-css/"));if(!l.length)return S("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+p);const j=l.map(u=>`${u}@${k.version}`);c?(n.warn("Using legacy peer dependencies to update packages."),await I(...j,"--legacy-peer-deps")):await I(...j),n.info("Salty-CSS packages updated successfully!")}),a.parseAsync(process.argv)}exports.main=K;
|
package/bin/main.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Command as B } from "commander";
|
2
2
|
import { mkdir as U, readFile as y, writeFile as P } from "fs/promises";
|
3
|
-
import { join as
|
3
|
+
import { join as o, relative as L, parse as G, format as M } from "path";
|
4
4
|
import { render as R } from "ejs";
|
5
5
|
import { generateCss as V } from "../compiler/index.js";
|
6
6
|
import { p as q } from "../pascal-case-BQpR5PdN.js";
|
@@ -14,43 +14,43 @@ const e = K({
|
|
14
14
|
transports: [new Q.Console({})]
|
15
15
|
}), v = (i) => {
|
16
16
|
e.error(i);
|
17
|
-
}, T = (i) => new Promise((
|
17
|
+
}, T = (i) => new Promise((f, h) => {
|
18
18
|
Y(i, (j) => {
|
19
19
|
if (j) return h(j);
|
20
|
-
|
20
|
+
f();
|
21
21
|
});
|
22
22
|
}), x = async (...i) => {
|
23
|
-
const
|
24
|
-
await T(`npm install ${j}`), h.succeed(`Installed packages: ${
|
25
|
-
}, tt = () => X(
|
23
|
+
const f = i.map((k) => k.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), h = Z(`Installing packages: ${f}`).start(), j = i.join(" ");
|
24
|
+
await T(`npm install ${j}`), h.succeed(`Installed packages: ${f}`);
|
25
|
+
}, tt = () => X(o(process.cwd(), "node_modules", ".bin", "prettier"));
|
26
26
|
async function N(i) {
|
27
27
|
try {
|
28
28
|
if (!tt()) return;
|
29
29
|
await T(`./node_modules/.bin/prettier --write "${i}"`), e.info(`Formatted ${i} with Prettier`);
|
30
|
-
} catch (
|
31
|
-
e.error(`Error formatting ${i} with Prettier:`,
|
30
|
+
} catch (f) {
|
31
|
+
e.error(`Error formatting ${i} with Prettier:`, f);
|
32
32
|
}
|
33
33
|
}
|
34
34
|
async function ft() {
|
35
35
|
const i = new B();
|
36
36
|
i.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
|
37
|
-
const
|
37
|
+
const f = {
|
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
|
-
}, h = async (t,
|
44
|
-
const { default: r } = await
|
45
|
-
return { fileName: t, content:
|
43
|
+
}, h = async (t, s) => {
|
44
|
+
const { default: r } = await f[t], d = R(r, s);
|
45
|
+
return { fileName: t, content: d };
|
46
46
|
}, j = async () => {
|
47
|
-
const t =
|
47
|
+
const t = o(process.cwd(), ".saltyrc");
|
48
48
|
return await y(t, "utf-8").then(JSON.parse).catch(() => ({}));
|
49
|
-
}, k = async (t =
|
50
|
-
const
|
49
|
+
}, k = async (t = o(process.cwd(), "package.json")) => {
|
50
|
+
const s = await y(t, "utf-8").then(JSON.parse).catch(() => {
|
51
51
|
});
|
52
|
-
if (!
|
53
|
-
return
|
52
|
+
if (!s) throw "Could not read package.json file!";
|
53
|
+
return s;
|
54
54
|
}, W = async () => {
|
55
55
|
const t = new URL("../package.json", import.meta.url);
|
56
56
|
return k(t);
|
@@ -60,99 +60,101 @@ async function ft() {
|
|
60
60
|
eslintPluginCore: `@salty-css/eslint-plugin-core@${F.version}`,
|
61
61
|
vite: `@salty-css/vite@${F.version}`
|
62
62
|
}, A = (t) => {
|
63
|
-
const
|
64
|
-
return
|
63
|
+
const s = t === "." ? "" : t, r = process.cwd();
|
64
|
+
return o(r, s);
|
65
65
|
};
|
66
66
|
i.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(t = ".") {
|
67
67
|
if (!await k().catch(() => {
|
68
68
|
})) return v("Salty CSS project must be initialized in a directory with a package.json file.");
|
69
69
|
e.info("Initializing a new Salty-CSS project!");
|
70
|
-
const { dir: r = t, cssFile:
|
70
|
+
const { dir: r = t, cssFile: d, skipInstall: m } = this.opts();
|
71
71
|
if (!r) return v("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
|
72
|
-
|
72
|
+
m || (await x(D.core, D.react), await x(`-D ${D.eslintPluginCore}`));
|
73
73
|
const w = process.cwd(), c = A(r), S = await Promise.all([h("salty.config.ts"), h("saltygen/index.css")]);
|
74
74
|
await U(c, { recursive: !0 });
|
75
|
-
const
|
76
|
-
const
|
77
|
-
if (await y(
|
75
|
+
const p = S.map(async ({ fileName: n, content: l }) => {
|
76
|
+
const g = o(c, n);
|
77
|
+
if (await y(g, "utf-8").catch(() => {
|
78
78
|
}) !== void 0) {
|
79
|
-
e.debug("File already exists: " +
|
79
|
+
e.debug("File already exists: " + g);
|
80
80
|
return;
|
81
81
|
}
|
82
82
|
const _ = n.split("/").slice(0, -1).join("/");
|
83
|
-
_ && await U(
|
83
|
+
_ && await U(o(c, _), { recursive: !0 }), e.info("Writing file: " + g), await P(g, l), await N(g);
|
84
84
|
});
|
85
|
-
await Promise.all(
|
86
|
-
const
|
85
|
+
await Promise.all(p);
|
86
|
+
const $ = L(w, c) || ".", a = o(w, ".saltyrc"), u = await y(a, "utf-8").catch(() => {
|
87
87
|
});
|
88
|
-
if (
|
89
|
-
e.info("Creating file: " +
|
90
|
-
const
|
91
|
-
defaultProject:
|
92
|
-
projects: [
|
88
|
+
if (u === void 0) {
|
89
|
+
e.info("Creating file: " + a);
|
90
|
+
const l = JSON.stringify({
|
91
|
+
defaultProject: $,
|
92
|
+
projects: [$]
|
93
93
|
}, null, 2);
|
94
|
-
await P(
|
94
|
+
await P(a, l);
|
95
95
|
} else {
|
96
|
-
e.info("Edit file: " +
|
97
|
-
const n = JSON.parse(
|
98
|
-
|
99
|
-
const
|
100
|
-
await P(
|
96
|
+
e.info("Edit file: " + a);
|
97
|
+
const n = JSON.parse(u), l = new Set((n == null ? void 0 : n.projects) || []);
|
98
|
+
l.add($), n.projects = [...l];
|
99
|
+
const g = JSON.stringify(n, null, 2);
|
100
|
+
await P(a, g);
|
101
101
|
}
|
102
|
-
const I =
|
102
|
+
const I = o(w, ".gitignore"), b = await y(I, "utf-8").catch(() => {
|
103
103
|
});
|
104
104
|
if (b !== void 0 && (b.includes("saltygen") || (e.info("Edit file: " + I), await P(I, b + `
|
105
105
|
|
106
106
|
# Salty-CSS
|
107
107
|
saltygen
|
108
|
-
`))),
|
109
|
-
const n =
|
108
|
+
`))), d) {
|
109
|
+
const n = o(c, d), l = await y(n, "utf-8").catch(() => {
|
110
110
|
});
|
111
|
-
if (
|
112
|
-
const J =
|
111
|
+
if (l !== void 0 && !l.includes("saltygen")) {
|
112
|
+
const J = o(n, ".."), H = `@import '${L(J, o(c, "saltygen/index.css"))}';`;
|
113
113
|
e.info("Edit file: " + n), await P(n, H + `
|
114
|
-
` +
|
114
|
+
` + l), await N(n);
|
115
115
|
}
|
116
116
|
}
|
117
|
-
const C =
|
117
|
+
const C = o(c, "vite.config.ts"), O = await y(C, "utf-8").catch(() => {
|
118
118
|
});
|
119
119
|
if (O !== void 0 && !O.includes("saltyPlugin")) {
|
120
120
|
e.info("Edit file: " + C);
|
121
|
-
const
|
121
|
+
const l = `import { saltyPlugin } from '@salty-css/vite';
|
122
122
|
`, J = O.replace(/(plugins: \[)/, `$1
|
123
123
|
saltyPlugin(__dirname),`);
|
124
|
-
e.info("Installing @salty-css/vite"),
|
124
|
+
e.info("Installing @salty-css/vite"), m || await x(`-D ${D.vite}`), e.info("Adding Salty-CSS plugin to Vite config..."), await P(C, l + J), await N(C);
|
125
125
|
}
|
126
126
|
}), i.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(t = E) {
|
127
127
|
e.info("Building the Salty-CSS project...");
|
128
|
-
const { dir:
|
129
|
-
if (!
|
130
|
-
const r = A(
|
128
|
+
const { dir: s = t } = this.opts();
|
129
|
+
if (!s) return v("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
|
130
|
+
const r = A(s);
|
131
131
|
await V(r);
|
132
|
-
}), i.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(t,
|
133
|
-
const { file: r = t, dir:
|
132
|
+
}), i.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(t, s = E) {
|
133
|
+
const { file: r = t, dir: d = s, tag: m, name: w, className: c } = this.opts();
|
134
134
|
if (!r) return v("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
|
135
|
-
if (!
|
136
|
-
const S = A(
|
137
|
-
|
138
|
-
const
|
139
|
-
|
135
|
+
if (!d) return v("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
|
136
|
+
const S = A(d), p = r.split("/").slice(0, -1).join("/");
|
137
|
+
p && await U(o(S, p), { recursive: !0 });
|
138
|
+
const $ = o(S, r), a = G($);
|
139
|
+
a.ext || (a.ext = ".ts"), a.name.endsWith(".css") || (a.name = a.name + ".css"), a.base = a.name + a.ext;
|
140
|
+
const u = M(a);
|
141
|
+
if (await y(u, "utf-8").catch(() => {
|
140
142
|
}) !== void 0) {
|
141
|
-
e.error("File already exists:",
|
143
|
+
e.error("File already exists:", u);
|
142
144
|
return;
|
143
145
|
}
|
144
|
-
e.info("Generating a new file: " +
|
145
|
-
const b = q(w ||
|
146
|
-
await P(
|
147
|
-
}), i.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(t,
|
148
|
-
const { legacyPeerDeps: r } = this.opts(),
|
149
|
-
if (!
|
150
|
-
const w = { ...
|
146
|
+
e.info("Generating a new file: " + u);
|
147
|
+
const b = q(w || a.base.replace(/\.css\.\w+$/, "")), { content: C } = await h("react/react-styled-file.ts", { tag: m, name: b, className: c });
|
148
|
+
await P(u, C), await N(u);
|
149
|
+
}), i.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(t, s = E) {
|
150
|
+
const { legacyPeerDeps: r } = this.opts(), d = o(process.cwd(), "package.json"), m = await k(d).catch((p) => v(p));
|
151
|
+
if (!m) return;
|
152
|
+
const w = { ...m.dependencies, ...m.devDependencies }, c = Object.keys(w).filter((p) => p === "salty-css" || p.startsWith("@salty-css/"));
|
151
153
|
if (!c.length)
|
152
154
|
return v(
|
153
|
-
"No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " +
|
155
|
+
"No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + d
|
154
156
|
);
|
155
|
-
const S = c.map((
|
157
|
+
const S = c.map((p) => `${p}@${F.version}`);
|
156
158
|
r ? (e.warn("Using legacy peer dependencies to update packages."), await x(...S, "--legacy-peer-deps")) : await x(...S), e.info("Salty-CSS packages updated successfully!");
|
157
159
|
}), i.parseAsync(process.argv);
|
158
160
|
}
|
package/compiler/index.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("esbuild"),B=require("child_process"),P=require("../dash-case-DKzpenwY.cjs"),o=require("path"),r=require("fs"),K=require("fs/promises"),V=require("../parse-templates-W0YfTmOT.cjs");function G(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const R=G(I),N=t=>o.join(t,"./saltygen"),_=["salty","css","styles","styled"],q=(t=[])=>new RegExp(`\\.(${[..._,...t].join("|")})\\.`),O=(t,e=[])=>q(e).test(t),J=async t=>{const e=N(t),n=o.join(t,"salty.config.ts"),s=o.join(e,"salty.config.js");await R.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",external:["react"]});const a=Date.now(),{config:w}=await import(`${s}?t=${a}`);return w},M=async t=>{const e=await J(t),n=new Set,s=(d,y=[])=>d?Object.entries(d).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return s(c,[...y,p]);const C=[...y,p].join(".");n.add(`"${C}"`);const x=[...y.map(P.dashCase),P.dashCase(p)].join("-"),{result:D}=V.parseValueTokens(c);return`--${x}: ${D};`}):[],a=d=>d?Object.entries(d).flatMap(([y,p])=>{const c=s(p);return y==="base"?c.join(""):`${y} { ${c.join("")} }`}):[],w=d=>d?Object.entries(d).flatMap(([y,p])=>Object.entries(p).flatMap(([c,C])=>{const x=s(C,[y]),D=`.${y}-${c}, [data-${y}="${c}"]`,k=x.join("");return`${D} { ${k} }`})):[],j=s(e.variables),S=a(e.responsiveVariables),l=w(e.conditionalVariables),b=N(t),f=o.join(b,"css/variables.css"),i=`:root { ${j.join("")} ${S.join("")} } ${l.join("")}`;r.writeFileSync(f,i);const g=o.join(b,"types/css-tokens.d.ts"),m=`type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;r.writeFileSync(g,m);const u=o.join(b,"css/global.css"),h=V.parseStyles(e.global,"");r.writeFileSync(u,h);const F=o.join(b,"css/templates.css"),v=V.parseTemplates(e.templates);r.writeFileSync(F,v)},T=async(t,e)=>{const n=P.toHash(t),s=o.join(e,"js",n+".js");await R.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const a=Date.now();return await import(`${s}?t=${a}`)},E=async t=>{const e=N(t),n=o.join(e,"salty.config.js"),{config:s}=await import(n);return s},A=async t=>{try{const e=[],n=[],s=N(t),a=o.join(s,"index.css");(()=>{r.existsSync(s)&&B.execSync("rm -rf "+s),r.mkdirSync(s),r.mkdirSync(o.join(s,"css")),r.mkdirSync(o.join(s,"types"))})(),await M(t);const j=await E(t);async function S(i,g){const $=r.statSync(i);if($.isDirectory()){const m=r.readdirSync(i);await Promise.all(m.map(u=>S(o.join(i,u),o.join(g,u))))}else if($.isFile()&&O(i)){const u=await T(i,s),h=[];Object.entries(u).forEach(([y,p])=>{if(p.isKeyframes&&p.css){const k=`${p.animationName}.css`,z=`css/${k}`,H=o.join(s,z);e.push(k),r.writeFileSync(H,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:y,config:j}),C=`${c.hash}-${c.priority}.css`;n[c.priority]||(n[c.priority]=[]),n[c.priority].push(C),h.push(C);const x=`css/${C}`,D=o.join(s,x);r.writeFileSync(D,c.css)});const F=h.map(y=>`@import url('./${y}');`).join(`
|
2
2
|
`),v=P.toHash(i,6),d=o.join(s,`css/${v}.css`);r.writeFileSync(d,F)}}await S(t,s);const l=e.map(i=>`@import url('./css/${i}');`).join(`
|
3
3
|
`);let f=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
4
4
|
|
@@ -7,5 +7,5 @@ ${["@import url('./css/variables.css');","@import url('./css/global.css');","@im
|
|
7
7
|
${l}`;if(j.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
|
8
8
|
`);f+=i}r.writeFileSync(a,f)}catch(e){console.error(e)}},L=async(t,e)=>{try{const n=[],s=o.join(t,"./saltygen"),a=o.join(s,"index.css");if(O(e)){const j=await E(t),S=await T(e,s);Object.entries(S).forEach(([g,$])=>{if(!$.generator)return;const m=$.generator._withBuildContext({name:g,config:j}),u=`${m.hash}-${m.priority}.css`,h=`css/${u}`,F=o.join(s,h);n.push(u),r.writeFileSync(F,m.css)});const l=r.readFileSync(a,"utf8").split(`
|
9
9
|
`),b=n.map(g=>`@import url('../saltygen/css/${g}');`),i=[...new Set([...l,...b])].join(`
|
10
|
-
`);r.writeFileSync(a,i)}}catch(n){console.error(n)}},U=async(t,e)=>{try{const n=o.join(t,"./saltygen");if(O(e)){const a=r.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==a&&await K.writeFile(e,a);const j=await E(t),S=await T(e,n);let l=a;Object.entries(S).forEach(([f,i])=>{var F;if(i.isKeyframes
|
11
|
-
${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error(n)}};exports.compileSaltyFile=T;exports.generateConfigStyles=M;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=O;exports.minimizeFile=U;exports.saltyFileExtensions=_;exports.saltyFileRegExp=q;
|
10
|
+
`);r.writeFileSync(a,i)}}catch(n){console.error(n)}},U=async(t,e)=>{try{const n=o.join(t,"./saltygen");if(O(e)){const a=r.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==a&&await K.writeFile(e,a);const j=await E(t),S=await T(e,n);let l=a;Object.entries(S).forEach(([f,i])=>{var F;if(i.isKeyframes||!i.generator)return;const g=i.generator._withBuildContext({name:f,config:j}),$=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const m=(F=$.at(1))==null?void 0:F.trim(),u=`${f} = styled(${m}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`,h=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`,"gm");l=l.replace(h,u)});const b=P.toHash(e,6);return j.importStrategy==="component"&&(l=`import '../../saltygen/css/${b}.css';
|
11
|
+
${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error("Error in minimizeFile",n)}};exports.compileSaltyFile=T;exports.generateConfigStyles=M;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=O;exports.minimizeFile=U;exports.saltyFileExtensions=_;exports.saltyFileRegExp=q;
|
package/compiler/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import * as I from "esbuild";
|
2
|
-
import { execSync as
|
2
|
+
import { execSync as z } from "child_process";
|
3
3
|
import { t as T, d as R } from "../dash-case-DMQMcCO6.js";
|
4
4
|
import { join as o } from "path";
|
5
|
-
import { writeFileSync as $, existsSync as
|
5
|
+
import { writeFileSync as $, existsSync as H, mkdirSync as V, statSync as K, readdirSync as G, readFileSync as M } from "fs";
|
6
6
|
import { writeFile as J } from "fs/promises";
|
7
7
|
import { p as q, a as A, b as L } from "../parse-templates-D4p3pgQR.js";
|
8
8
|
const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W = (s = []) => new RegExp(`\\.(${[...U, ...s].join("|")})\\.`), v = (s, e = []) => W(e).test(s), X = async (s) => {
|
@@ -34,10 +34,10 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
|
|
34
34
|
return `${D} { ${P} }`;
|
35
35
|
})) : [], d = t(e.variables), w = c(e.responsiveVariables), a = S(e.conditionalVariables), b = N(s), f = o(b, "css/variables.css"), i = `:root { ${d.join("")} ${w.join("")} } ${a.join("")}`;
|
36
36
|
$(f, i);
|
37
|
-
const y = o(b, "types/css-tokens.d.ts"),
|
38
|
-
$(y,
|
39
|
-
const
|
40
|
-
$(
|
37
|
+
const y = o(b, "types/css-tokens.d.ts"), g = `type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
38
|
+
$(y, g);
|
39
|
+
const m = o(b, "css/global.css"), F = q(e.global, "");
|
40
|
+
$(m, F);
|
41
41
|
const j = o(b, "css/templates.css"), k = A(e.templates);
|
42
42
|
$(j, k);
|
43
43
|
}, E = async (s, e) => {
|
@@ -62,17 +62,17 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
|
|
62
62
|
try {
|
63
63
|
const e = [], n = [], t = N(s), c = o(t, "index.css");
|
64
64
|
(() => {
|
65
|
-
|
65
|
+
H(t) && z("rm -rf " + t), V(t), V(o(t, "css")), V(o(t, "types"));
|
66
66
|
})(), await Y(s);
|
67
67
|
const d = await O(s);
|
68
68
|
async function w(i, y) {
|
69
|
-
const h =
|
69
|
+
const h = K(i);
|
70
70
|
if (h.isDirectory()) {
|
71
|
-
const
|
72
|
-
await Promise.all(
|
71
|
+
const g = G(i);
|
72
|
+
await Promise.all(g.map((m) => w(o(i, m), o(y, m))));
|
73
73
|
} else if (h.isFile() && v(i)) {
|
74
|
-
const
|
75
|
-
Object.entries(
|
74
|
+
const m = await E(i, t), F = [];
|
75
|
+
Object.entries(m).forEach(([l, p]) => {
|
76
76
|
if (p.isKeyframes && p.css) {
|
77
77
|
const P = `${p.animationName}.css`, _ = `css/${P}`, B = o(t, _);
|
78
78
|
e.push(P), $(B, p.css);
|
@@ -116,11 +116,11 @@ ${a}`;
|
|
116
116
|
const d = await O(s), w = await E(e, t);
|
117
117
|
Object.entries(w).forEach(([y, h]) => {
|
118
118
|
if (!h.generator) return;
|
119
|
-
const
|
119
|
+
const g = h.generator._withBuildContext({
|
120
120
|
name: y,
|
121
121
|
config: d
|
122
|
-
}),
|
123
|
-
n.push(
|
122
|
+
}), m = `${g.hash}-${g.priority}.css`, F = `css/${m}`, j = o(t, F);
|
123
|
+
n.push(m), $(j, g.css);
|
124
124
|
});
|
125
125
|
const a = M(c, "utf8").split(`
|
126
126
|
`), b = n.map((y) => `@import url('../saltygen/css/${y}');`), i = [.../* @__PURE__ */ new Set([...a, ...b])].join(`
|
@@ -140,26 +140,22 @@ ${a}`;
|
|
140
140
|
let a = c;
|
141
141
|
Object.entries(w).forEach(([f, i]) => {
|
142
142
|
var j;
|
143
|
-
if (i.isKeyframes)
|
144
|
-
console.log("value", i);
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
if (!i.generator) return;
|
143
|
+
if (i.isKeyframes || !i.generator) return;
|
148
144
|
const y = i.generator._withBuildContext({
|
149
145
|
name: f,
|
150
146
|
config: d
|
151
147
|
}), h = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
|
152
148
|
if (!h)
|
153
149
|
return console.error("Could not find the original declaration");
|
154
|
-
const
|
155
|
-
a = a.replace(F,
|
150
|
+
const g = (j = h.at(1)) == null ? void 0 : j.trim(), m = `${f} = styled(${g}, "${y.classNames}", "${y._callerName}", ${JSON.stringify(y.props)});`, F = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`, "gm");
|
151
|
+
a = a.replace(F, m);
|
156
152
|
});
|
157
153
|
const b = T(e, 6);
|
158
154
|
return d.importStrategy === "component" && (a = `import '../../saltygen/css/${b}.css';
|
159
155
|
${a}`), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
|
160
156
|
}
|
161
157
|
} catch (n) {
|
162
|
-
console.error(n);
|
158
|
+
console.error("Error in minimizeFile", n);
|
163
159
|
}
|
164
160
|
};
|
165
161
|
export {
|