@salty-css/core 0.0.1-alpha.27 → 0.0.1-alpha.28

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