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