@salty-css/core 0.0.1-alpha.15 → 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 CHANGED
@@ -1 +1,2 @@
1
1
  export declare const execAsync: (command: string) => Promise<void>;
2
+ export declare const npmInstall: (packageName: string) => Promise<void>;
package/bin/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- "use strict";const _=require("commander"),n=require("fs/promises"),t=require("path"),$=require("ejs"),D=require("../compiler/index.cjs"),N=require("../pascal-case-iWoaJWwT.cjs"),h=require("winston"),O=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({})]}),I=a=>new Promise((g,m)=>{z.exec(a,j=>{if(j)return m(j);g()})}),J=()=>O.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function v(a){try{if(!J())return;await I(`./node_modules/.bin/prettier --write "${a}"`),o.info(`Formatted ${a} with Prettier`)}catch(g){o.error(`Error formatting ${a} with Prettier:`,g)}}async function k(){const a=new _.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"))},m=async(s,l)=>{const{default:f}=await g[s],c=$.render(f,l);return{fileName:s,content:c}},j=async()=>{const s=t.join(process.cwd(),".saltyrc");return await n.readFile(s,"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("Initializing a new Salty-CSS project...");const{dir:s,cssFile:l}=this.opts(),f=process.cwd(),c=t.join(f,s),C=await Promise.all([m("salty.config.ts"),m("saltygen/index.css")]);await n.mkdir(c,{recursive:!0});const F=C.map(async({fileName:e,content:r})=>{const d=t.join(c,e);if(await n.readFile(d,"utf-8").catch(()=>{})!==void 0){o.debug("File already exists: "+d);return}const q=e.split("/").slice(0,-1).join("/");q&&await n.mkdir(t.join(c,q),{recursive:!0}),o.info("Writing file: "+d),await n.writeFile(d,r),await v(d)});await Promise.all(F);const y=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 r=JSON.stringify({defaultProject:y,projects:[y]},null,2);await n.writeFile(i,r)}else{o.info("Edit file: "+i);const e=JSON.parse(p),r=new Set((e==null?void 0:e.projects)||[]);r.add(y),e.projects=[...r];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+`
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),r=await n.readFile(e,"utf-8").catch(()=>{});if(r!==void 0&&!r.includes("saltygen")){const P=t.join(e,".."),E=`@import '${t.relative(P,t.join(c,"saltygen/index.css"))}';`;o.info("Edit file: "+e),await n.writeFile(e,E+`
7
- `+r),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 r=`import { saltyPlugin } from '@salty-css/vite';
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..."),await I("npm install @salty-css/vite"),o.info("Adding Salty-CSS plugin to Vite config..."),await n.writeFile(u,r+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:s}=this.opts(),l=t.join(process.cwd(),s);await D.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(s){const{dir:l,tag:f,name:c,className:C}=this.opts(),F=t.join(process.cwd(),l),y=t.join(F,s),i=t.parse(y);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=N.pascalCase(c||i.base.replace(/\.css\.\w+$/,"")),{content:u}=await m("react/react-styled-file.ts",{tag:f,name:w,className:C});await n.writeFile(p,u),await v(p)}),a.parseAsync(process.argv)}k().catch(a=>console.error(a));
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 _ } from "commander";
3
- import { mkdir as $, readFile as p, writeFile as m } from "fs/promises";
4
- import { join as n, relative as D, parse as z, format as J } from "path";
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 I, transports as k } from "winston";
9
- import { existsSync as B } from "fs";
10
- import { exec as G } from "child_process";
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: I.combine(I.colorize(), I.cli()),
14
- transports: [new k.Console({})]
15
- }), N = (o) => new Promise((g, u) => {
16
- G(o, (S) => {
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
- }), T = () => B(n(process.cwd(), "node_modules", ".bin", "prettier"));
21
- async function v(o) {
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 (!T()) return;
24
- await N(`./node_modules/.bin/prettier --write "${o}"`), i.info(`Formatted ${o} with Prettier`);
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 ${o} with Prettier:`, g);
28
+ i.error(`Error formatting ${n} with Prettier:`, g);
27
29
  }
28
30
  }
29
- async function q() {
30
- const o = new _();
31
- o.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
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 = n(process.cwd(), ".saltyrc");
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
- o.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() {
46
- i.info("Initializing a new Salty-CSS project...");
47
- const { dir: s, cssFile: c } = this.opts(), d = process.cwd(), r = n(d, s), j = await Promise.all([u("salty.config.ts"), u("saltygen/index.css")]);
48
- await $(r, { recursive: !0 });
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 = n(r, t);
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 b = t.split("/").slice(0, -1).join("/");
57
- b && await $(n(r, b), { recursive: !0 }), i.info("Writing file: " + l), await m(l, a), await v(l);
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 = D(d, r), e = n(d, ".saltyrc"), f = await p(e, "utf-8").catch(() => {
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 = n(d, ".gitignore"), h = await p(P, "utf-8").catch(() => {
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 = n(r, c), a = await p(t, "utf-8").catch(() => {
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 = n(t, ".."), O = `@import '${D(C, n(r, "saltygen/index.css"))}';`;
87
- i.info("Edit file: " + t), await m(t, O + `
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 = n(r, "vite.config.ts"), F = await p(y, "utf-8").catch(() => {
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..."), await N("npm install @salty-css/vite"), i.info("Adding Salty-CSS plugin to Vite config..."), await m(y, a + C), await v(y);
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
- }), o.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() {
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 = n(process.cwd(), s);
104
+ const { dir: s } = this.opts(), c = o(process.cwd(), s);
103
105
  await H(c);
104
- }), o.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) {
105
- const { dir: c, tag: d, name: r, className: j } = this.opts(), x = n(process.cwd(), c), w = n(x, s), e = z(w);
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 = J(e);
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
- }), o.parseAsync(process.argv);
118
+ }), n.parseAsync(process.argv);
117
119
  }
118
- q().catch((o) => console.error(o));
120
+ M().catch((n) => console.error(n));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.15",
3
+ "version": "0.0.1-alpha.17",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -56,7 +56,9 @@
56
56
  }
57
57
  },
58
58
  "bin": {
59
+ "salty": "./bin/index.js",
59
60
  "salty-css": "./bin/index.js",
60
- "salty-css-cjs": "./bin/index.cjs"
61
+ "salty-css-cjs": "./bin/index.cjs",
62
+ "@salty-css/core": "./bin/index.js"
61
63
  }
62
64
  }