@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 CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- "use strict";const D=require("commander"),n=require("fs/promises"),t=require("path"),L=require("ejs"),O=require("../compiler/index.cjs"),R=require("../pascal-case-iWoaJWwT.cjs"),h=require("winston"),T=require("fs"),U=require("child_process");var $=typeof document<"u"?document.currentScript:null;const o=h.createLogger({level:"debug",format:h.format.combine(h.format.colorize(),h.format.cli()),transports:[new h.transports.Console({})]}),_=a=>new Promise((f,m)=>{U.exec(a,S=>{if(S)return m(S);f()})}),k=async(...a)=>{const f=a.join(" ");await _(`npm install ${f}`)},z=()=>T.existsSync(t.join(process.cwd(),"node_modules",".bin","prettier"));async function F(a){try{if(!z())return;await _(`./node_modules/.bin/prettier --write "${a}"`),o.info(`Formatted ${a} with Prettier`)}catch(f){o.error(`Error formatting ${a} with Prettier:`,f)}}async function A(){const a=new D.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"))},m=async(s,l)=>{const{default:p}=await f[s],c=L.render(p,l);return{fileName:s,content:c}},S=async()=>{const s=t.join(process.cwd(),".saltyrc");return await n.readFile(s,"utf-8").then(JSON.parse).catch(()=>({}))},E=async()=>{const s=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:$&&$.tagName.toUpperCase()==="SCRIPT"&&$.src||new URL("bin/index.cjs",document.baseURI).href);return console.log({packageJsonPath:s}),await n.readFile(s,"utf-8").then(JSON.parse).catch(()=>({}))},J=await(async()=>(await S()).defaultProject)(),j=await E(),P={core:`@salty-css/core@${j.version}`,react:`@salty-css/react@${j.version}`,eslintPluginCore:`@salty-css/eslint-plugin-core@${j.version}`,vite:`@salty-css/vite@${j.version}`};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 k(P.core,P.react),await k(`-D ${P.eslintPluginCore}`),o.info("Initializing a new Salty-CSS project...");const{dir:s,cssFile:l}=this.opts(),p=process.cwd(),c=t.join(p,s),x=await Promise.all([m("salty.config.ts"),m("saltygen/index.css")]);await n.mkdir(c,{recursive:!0});const I=x.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 F(d)});await Promise.all(I);const y=t.relative(p,c),i=t.join(p,".saltyrc"),u=await n.readFile(i,"utf-8").catch(()=>{});if(u===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(u),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 v=t.join(p,".gitignore"),w=await n.readFile(v,"utf-8").catch(()=>{});if(w!==void 0&&(w.includes("saltygen")||(o.info("Edit file: "+v),await n.writeFile(v,w+`
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,".."),N=`@import '${t.relative(C,t.join(c,"saltygen/index.css"))}';`;o.info("Edit file: "+e),await n.writeFile(e,N+`
7
- `+r),await F(e)}}const g=t.join(c,"vite.config.ts"),b=await n.readFile(g,"utf-8").catch(()=>{});if(b!==void 0&&!b.includes("saltyPlugin")){o.info("Edit file: "+g);const r=`import { saltyPlugin } from '@salty-css/vite';
8
- `,C=b.replace(/(plugins: \[)/,`$1
9
- saltyPlugin(__dirname),`);o.info("Installing @salty-css/vite"),await k(P.vite),o.info("Adding Salty-CSS plugin to Vite config..."),await n.writeFile(g,r+C),await F(g)}}),a.command("build").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>","Project directory to build the project in.",J).action(async function(){o.info("Building the Salty-CSS project...");const{dir:s}=this.opts(),l=t.join(process.cwd(),s);await O.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.",J).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:p,name:c,className:x}=this.opts(),I=t.join(process.cwd(),l),y=t.join(I,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 u=t.format(i);if(await n.readFile(u,"utf-8").catch(()=>{})!==void 0){o.error("File already exists:",u);return}o.info("Generating a new file: "+u);const w=R.pascalCase(c||i.base.replace(/\.css\.\w+$/,"")),{content:g}=await m("react/react-styled-file.ts",{tag:p,name:w,className:x});await n.writeFile(u,g),await F(u)}),a.parseAsync(process.argv)}A().catch(a=>console.error(a));
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 D, readFile as g, writeFile as m } from "fs/promises";
4
- import { join as a, relative as N, parse as A, format as H } from "path";
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 k, transports as R } from "winston";
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
- const n = G({
11
+ import U from "ora";
12
+ const i = G({
12
13
  level: "debug",
13
- format: k.combine(k.colorize(), k.cli()),
14
+ format: J.combine(J.colorize(), J.cli()),
14
15
  transports: [new R.Console({})]
15
- }), O = (i) => new Promise((d, u) => {
16
- M(i, (S) => {
17
- if (S) return u(S);
18
- d();
16
+ }), _ = (e) => new Promise((l, m) => {
17
+ M(e, (u) => {
18
+ if (u) return m(u);
19
+ l();
19
20
  });
20
- }), J = async (...i) => {
21
- const d = i.join(" ");
22
- await O(`npm install ${d}`);
23
- }, U = () => q(a(process.cwd(), "node_modules", ".bin", "prettier"));
24
- async function x(i) {
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 (!U()) return;
27
- await O(`./node_modules/.bin/prettier --write "${i}"`), n.info(`Formatted ${i} with Prettier`);
28
- } catch (d) {
29
- n.error(`Error formatting ${i} with Prettier:`, d);
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 V() {
33
- const i = new L();
34
- i.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
35
- const d = {
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
- }, u = async (o, c) => {
42
- const { default: f } = await d[o], r = T(f, c);
43
- return { fileName: o, content: r };
44
- }, S = async () => {
45
- const o = a(process.cwd(), ".saltyrc");
46
- return await g(o, "utf-8").then(JSON.parse).catch(() => ({}));
47
- }, _ = async () => {
48
- const o = new URL("../package.json", import.meta.url);
49
- return console.log({ packageJsonPath: o }), await g(o, "utf-8").then(JSON.parse).catch(() => ({}));
50
- }, E = await (async () => (await S()).defaultProject)(), P = await _(), v = {
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
- 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() {
57
- n.info("Installing salty-css packages core, eslint-plugin and react"), await J(v.core, v.react), await J(`-D ${v.eslintPluginCore}`), n.info("Initializing a new Salty-CSS project...");
58
- const { dir: o, cssFile: c } = this.opts(), f = process.cwd(), r = a(f, o), F = await Promise.all([u("salty.config.ts"), u("saltygen/index.css")]);
59
- await D(r, { recursive: !0 });
60
- const I = F.map(async ({ fileName: t, content: s }) => {
61
- const l = a(r, t);
62
- if (await g(l, "utf-8").catch(() => {
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
- n.debug("File already exists: " + l);
65
+ i.debug("File already exists: " + d);
65
66
  return;
66
67
  }
67
- const b = t.split("/").slice(0, -1).join("/");
68
- b && await D(a(r, b), { recursive: !0 }), n.info("Writing file: " + l), await m(l, s), await x(l);
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 w = N(f, r), e = a(f, ".saltyrc"), p = await g(e, "utf-8").catch(() => {
72
+ const h = O(p, r), n = o(p, ".saltyrc"), f = await g(n, "utf-8").catch(() => {
72
73
  });
73
- if (p === void 0) {
74
- n.info("Creating file: " + e);
74
+ if (f === void 0) {
75
+ i.info("Creating file: " + n);
75
76
  const s = JSON.stringify({
76
- defaultProject: w,
77
- projects: [w]
77
+ defaultProject: h,
78
+ projects: [h]
78
79
  }, null, 2);
79
- await m(e, s);
80
+ await y(n, s);
80
81
  } else {
81
- n.info("Edit file: " + e);
82
- const t = JSON.parse(p), s = new Set((t == null ? void 0 : t.projects) || []);
83
- s.add(w), t.projects = [...s];
84
- const l = JSON.stringify(t, null, 2);
85
- await m(e, l);
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 = a(f, ".gitignore"), h = await g(C, "utf-8").catch(() => {
88
+ const C = o(p, ".gitignore"), S = await g(C, "utf-8").catch(() => {
88
89
  });
89
- if (h !== void 0 && (h.includes("saltygen") || (n.info("Edit file: " + C), await m(C, h + `
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 = a(r, c), s = await g(t, "utf-8").catch(() => {
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 = a(t, ".."), z = `@import '${N(j, a(r, "saltygen/index.css"))}';`;
98
- n.info("Edit file: " + t), await m(t, z + `
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 y = a(r, "vite.config.ts"), $ = await g(y, "utf-8").catch(() => {
103
+ const w = o(r, "vite.config.ts"), b = await g(w, "utf-8").catch(() => {
103
104
  });
104
- if ($ !== void 0 && !$.includes("saltyPlugin")) {
105
- n.info("Edit file: " + y);
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 = $.replace(/(plugins: \[)/, `$1
108
+ `, j = b.replace(/(plugins: \[)/, `$1
108
109
  saltyPlugin(__dirname),`);
109
- n.info("Installing @salty-css/vite"), await J(v.vite), n.info("Adding Salty-CSS plugin to Vite config..."), await m(y, s + j), await x(y);
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
- }), i.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() {
112
- n.info("Building the Salty-CSS project...");
113
- const { dir: o } = this.opts(), c = a(process.cwd(), o);
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
- }), i.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(o) {
116
- const { dir: c, tag: f, name: r, className: F } = this.opts(), I = a(process.cwd(), c), w = a(I, o), e = A(w);
117
- e.ext || (e.ext = ".ts"), e.name.endsWith(".css") || (e.name = e.name + ".css"), e.base = e.name + e.ext;
118
- const p = H(e);
119
- if (await g(p, "utf-8").catch(() => {
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
- n.error("File already exists:", p);
122
+ i.error("File already exists:", f);
122
123
  return;
123
124
  }
124
- n.info("Generating a new file: " + p);
125
- const h = B(r || e.base.replace(/\.css\.\w+$/, "")), { content: y } = await u("react/react-styled-file.ts", { tag: f, name: h, className: F });
126
- await m(p, y), await x(p);
127
- }), i.parseAsync(process.argv);
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
- V().catch((i) => console.error(i));
130
+ K().catch((e) => console.error(e));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.20",
3
+ "version": "0.0.1-alpha.22",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",