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