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