@salty-css/core 0.0.1-alpha.22 → 0.0.1-alpha.220

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.
Files changed (94) hide show
  1. package/.saltyrc.schema.json +48 -0
  2. package/README.md +143 -26
  3. package/bin/index.cjs +1 -8
  4. package/bin/index.js +2 -129
  5. package/bin/logger.d.ts +1 -0
  6. package/bin/main.cjs +11 -0
  7. package/bin/main.d.ts +1 -0
  8. package/bin/main.js +260 -0
  9. package/compiler/get-files.d.ts +3 -0
  10. package/compiler/index.cjs +1 -11
  11. package/compiler/index.d.ts +19 -11
  12. package/compiler/index.js +18 -172
  13. package/config/define-config.d.ts +1 -1
  14. package/config/index.cjs +1 -1
  15. package/config/index.d.ts +2 -1
  16. package/config/index.js +12 -2
  17. package/css/index.cjs +1 -1
  18. package/css/index.d.ts +4 -1
  19. package/css/index.js +10 -2
  20. package/css/keyframes.cjs +1 -0
  21. package/css/keyframes.d.ts +22 -0
  22. package/css/keyframes.js +34 -0
  23. package/css/media.cjs +1 -0
  24. package/css/media.d.ts +87 -0
  25. package/css/media.js +88 -0
  26. package/css/merge.cjs +1 -0
  27. package/css/merge.d.ts +7 -0
  28. package/css/merge.js +5 -0
  29. package/css/token.cjs +1 -0
  30. package/css/token.d.ts +1 -0
  31. package/css/token.js +4 -0
  32. package/{dash-case-DKzpenwY.cjs → dash-case-BJEkFEGQ.cjs} +1 -1
  33. package/{dash-case-DMQMcCO6.js → dash-case-DBThphLm.js} +2 -2
  34. package/define-templates-4A2yHcMF.js +52 -0
  35. package/define-templates-Cunsb_Tr.cjs +1 -0
  36. package/factories/define-global-styles.d.ts +7 -0
  37. package/factories/define-media-query.d.ts +8 -0
  38. package/factories/define-templates.d.ts +27 -0
  39. package/factories/define-variables.d.ts +12 -0
  40. package/factories/index.d.ts +4 -0
  41. package/generators/class-name-generator.d.ts +6 -0
  42. package/generators/index.cjs +1 -0
  43. package/generators/index.d.ts +2 -0
  44. package/generators/index.js +86 -0
  45. package/generators/styled-generator.d.ts +19 -0
  46. package/generators/styles-generator.d.ts +22 -0
  47. package/helpers/color.d.ts +18 -0
  48. package/helpers/index.cjs +1 -0
  49. package/helpers/index.d.ts +2 -0
  50. package/helpers/index.js +1156 -0
  51. package/helpers/viewport-clamp.d.ts +8 -0
  52. package/index-CNuRN2e-.cjs +38 -0
  53. package/index-ClF7lS_W.js +502 -0
  54. package/package.json +34 -2
  55. package/parse-styles-3N79AOBO.cjs +5 -0
  56. package/parse-styles-Bo7fQ_SV.js +134 -0
  57. package/parsers/index.cjs +1 -0
  58. package/parsers/index.d.ts +5 -0
  59. package/parsers/index.js +30 -0
  60. package/parsers/parse-modifiers.d.ts +3 -0
  61. package/parsers/parse-styles.d.ts +13 -0
  62. package/parsers/parse-templates.d.ts +4 -0
  63. package/parsers/parse-tokens.d.ts +3 -0
  64. package/parsers/parser-types.d.ts +8 -0
  65. package/parsers/property-name-check.d.ts +1 -0
  66. package/parsers/unit-check.d.ts +7 -0
  67. package/react-vanilla-file-CCXbsjIb.js +18 -0
  68. package/react-vanilla-file-CG_WJLam.cjs +15 -0
  69. package/{salty.config-D9ANEDiH.js → salty.config-BhBY_oOk.js} +1 -0
  70. package/{salty.config-BupieCfE.cjs → salty.config-Dk6ZcCxI.cjs} +3 -2
  71. package/server/index.cjs +1 -0
  72. package/server/index.d.ts +1 -0
  73. package/server/index.js +12 -0
  74. package/server/should-restart.d.ts +1 -0
  75. package/templates/salty-reset.d.ts +2 -0
  76. package/types/cli-types.d.ts +10 -0
  77. package/types/config-types.d.ts +84 -0
  78. package/types/index.d.ts +52 -22
  79. package/util/dot-case.d.ts +1 -0
  80. package/util/index.cjs +1 -1
  81. package/util/index.js +1 -1
  82. package/util/module-type.d.ts +1 -0
  83. package/config/config-types.d.ts +0 -59
  84. package/generator/index.cjs +0 -1
  85. package/generator/index.d.ts +0 -1
  86. package/generator/index.js +0 -61
  87. package/generator/parse-modifiers.d.ts +0 -3
  88. package/generator/parse-styles.d.ts +0 -2
  89. package/generator/parse-templates.d.ts +0 -2
  90. package/generator/parse-tokens.d.ts +0 -2
  91. package/generator/parser-types.d.ts +0 -4
  92. package/generator/style-generator.d.ts +0 -28
  93. package/parse-templates-D4p3pgQR.js +0 -92
  94. package/parse-templates-W0YfTmOT.cjs +0 -8
@@ -0,0 +1,48 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Salty CSS CLI Run Configuration",
4
+ "description": "File .saltyrc.json is used to define projects and their configurations in json format for salty css cli.",
5
+ "type": "object",
6
+ "properties": {
7
+ "info": {
8
+ "type": "string",
9
+ "description": "Info about what the file is about."
10
+ },
11
+ "defaultProject": {
12
+ "type": "string",
13
+ "description": "The default project to be used."
14
+ },
15
+ "projects": {
16
+ "type": "array",
17
+ "description": "List of projects.",
18
+ "items": {
19
+ "type": "object",
20
+ "properties": {
21
+ "dir": {
22
+ "type": "string",
23
+ "description": "The root directory of the project. This is also used as the project name."
24
+ },
25
+ "framework": {
26
+ "type": "string",
27
+ "description": "The framework used by the project.",
28
+ "enum": ["react", "other"]
29
+ },
30
+ "components": {
31
+ "type": "string",
32
+ "description": "The directory for the components, relative to the project root."
33
+ },
34
+ "configDir": {
35
+ "type": "string",
36
+ "description": "Dir3ectorywhere the project configuration file is located, relative to the project root."
37
+ },
38
+ "saltygenDir": {
39
+ "type": "string",
40
+ "description": "Directory where the salty css files will be generated to, relative to the project root."
41
+ }
42
+ },
43
+ "required": ["dir", "framework"]
44
+ }
45
+ }
46
+ },
47
+ "required": ["defaultProject", "projects"]
48
+ }
package/README.md CHANGED
@@ -1,15 +1,132 @@
1
- # Salty Css
1
+ ![Salty CSS Banner](https://salty-css.dev/assets/banners/dvd.svg)
2
2
 
3
- ## Basic usage example with Button
3
+ # Salty CSS - CSS-in-JS library that is kinda sweet
4
4
 
5
- ### Initial requirements
5
+ Is there anything saltier than CSS in frontend web development? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
6
6
 
7
- 1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
- 2. Create `salty.config.ts` to the root of your project
9
- 3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
- 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
7
+ ## Features
11
8
 
12
- ### Code examples
9
+ - Build time compilation to achieve awesome runtime performance and minimal size
10
+ - Next.js, React Server Components, Vite and Webpack support
11
+ - Type safety with out of the box TypeScript and ESLint plugin
12
+ - Advanced CSS variables configuration to allow smooth token usage
13
+ - Style templates to create reusable styles easily
14
+
15
+ ## Get started
16
+
17
+ Fastest way to get started with any framework is `npx salty-css init [directory]` command
18
+
19
+ - Next.js → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
20
+ - React + Vite → [React + Vite guide](#react--vite) + [React example code](#code-examples)
21
+ - React + Webpack → Guide coming soon
22
+
23
+ ## Useful commands
24
+
25
+ - Create component: `npx salty-css generate [filePath]`
26
+ - Build: `npx salty-css build [directory]`
27
+ - Update Salty CSS packages: `npx salty-css up`
28
+
29
+ ## Salty CSS styled function
30
+
31
+ ```ts
32
+ // components/wrapper.css.ts
33
+ import { styled } from '@salty-css/react/styled';
34
+
35
+ // Define a component with styled function. First argument is the component name or existing component to extend and second argument is the object containing the styles and other options
36
+ export const Component = styled('div', {
37
+ className: 'wrapper', // Define custom class name that will be included for this component
38
+ element: 'section', // Define the html element that will be rendered for this component, overrides the first 'div' argument
39
+ base: {
40
+ // 👉 Add your CSS-in-JS base styles here! 👈
41
+ },
42
+ variants: {
43
+ // Define conditional styles that will be applied to the component based on the variant prop values
44
+ },
45
+ compoundVariants: [
46
+ // Define conditional styles that will be applied to the component based on the combination of variant prop values
47
+ ],
48
+ defaultVariants: {
49
+ // Set default variant prop values
50
+ },
51
+ defaultProps: {
52
+ // Add additional default props for the component (eg, id and other html element attributes)
53
+ },
54
+ passProps: true, // Pass variant props to the rendered element / parent component (default: false)
55
+ });
56
+ ```
57
+
58
+ ## Salty CSS CLI
59
+
60
+ In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
61
+
62
+ - Initialize project → `npx salty-css init [directory]` - Installs required packages, detects framework in use and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory.
63
+ - Generate component → `npx salty-css update [version]` - Update @salty-css packages in your repository. Default version is "latest". Additional options like `--dir`, `--tag`, `--name` and `--className` are also supported.
64
+ - Build files → `npx salty-css build [directory]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
65
+
66
+ ## Usage
67
+
68
+ ### Next.js
69
+
70
+ ![salty-next](https://github.com/user-attachments/assets/2cf6a93f-cdd5-4f5f-ab2e-3bc8bcfb83e8)
71
+
72
+ Salty CSS provides Next.js App & Pages router support with full React Server Components support.
73
+
74
+ ### Add Salty CSS to Next.js
75
+
76
+ 1. In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
77
+ 2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
78
+ 3. Import your component for example to `page.tsx` and see it working!
79
+
80
+ And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
81
+
82
+ #### Manual configuration
83
+
84
+ 1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
85
+ 2. Create `salty.config.ts` to your app directory
86
+ 3. Add Salty CSS plugin to next.js config
87
+
88
+ - **Next.js 15:** In `next.config.ts` add import for salty plugin `import { withSaltyCss } from '@salty-css/next';` and then add `withSaltyCss` to wrap your nextConfig export like so `export default withSaltyCss(nextConfig);`
89
+ - **Next.js 14 and older:** In `next.config.js` add import for salty plugin `const { withSaltyCss } = require('@salty-css/next');` and then add `withSaltyCss` to wrap your nextConfig export like so `module.exports = withSaltyCss(nextConfig);`
90
+
91
+ 4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
92
+ 5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
93
+ 6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
94
+
95
+ [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
96
+
97
+ ---
98
+
99
+ ### React + Vite
100
+
101
+ ![salty-vite-react](https://github.com/user-attachments/assets/12ec5b6a-0dcc-48fa-afc1-d337fc8f800c)
102
+
103
+ ### Add Salty CSS to your React + Vite app
104
+
105
+ 1. In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
106
+ 2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
107
+ 3. Import your component for example to `main.tsx` and see it working!
108
+
109
+ And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
110
+
111
+ #### Manual configuration
112
+
113
+ 1. For Vite support install `npm i @salty-css/vite @salty-css/core`
114
+ 2. In `vite.config` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
115
+ 3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
116
+ 4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
117
+ 5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
118
+
119
+ [Check out react example code](#code-examples)
120
+
121
+ ---
122
+
123
+ ### Create components
124
+
125
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
126
+
127
+ ## Code examples
128
+
129
+ ### Basic usage example with Button
13
130
 
14
131
  **Salty config**
15
132
 
@@ -31,23 +148,6 @@ export const config = defineConfig({
31
148
  });
32
149
  ```
33
150
 
34
- **Your React component file**
35
-
36
- ```tsx
37
- import { Wrapper } from '../components/wrapper/wrapper.css';
38
- import { Button } from '../components/button/button.css';
39
-
40
- export const IndexPage = () => {
41
- return (
42
- <Wrapper>
43
- <Button variant="solid" onClick={() => alert('It is a button.')}>
44
- Outlined
45
- </Button>
46
- </Wrapper>
47
- );
48
- };
49
- ```
50
-
51
151
  **Wrapper** (`components/wrapper/wrapper.css.ts`)
52
152
 
53
153
  ```tsx
@@ -72,7 +172,7 @@ export const Button = styled('button', {
72
172
  padding: `0.6em 1.2em`,
73
173
  border: '1px solid currentColor',
74
174
  background: 'transparent',
75
- color: 'currentColor/40',
175
+ color: 'currentColor',
76
176
  cursor: 'pointer',
77
177
  transition: '200ms',
78
178
  textDecoration: 'none',
@@ -108,4 +208,21 @@ export const Button = styled('button', {
108
208
  });
109
209
  ```
110
210
 
211
+ **Your React component file**
212
+
213
+ ```tsx
214
+ import { Wrapper } from '../components/wrapper/wrapper.css';
215
+ import { Button } from '../components/button/button.css';
216
+
217
+ export const IndexPage = () => {
218
+ return (
219
+ <Wrapper>
220
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
221
+ Outlined
222
+ </Button>
223
+ </Wrapper>
224
+ );
225
+ };
226
+ ```
227
+
111
228
  More examples coming soon
package/bin/index.cjs CHANGED
@@ -1,9 +1,2 @@
1
1
  #!/usr/bin/env node
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
-
4
- # Salty-CSS
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,".."),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));
2
+ "use strict";const e=require("./main.cjs");e.main().catch(n=>console.error(n));
package/bin/index.js CHANGED
@@ -1,130 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { Command as L } from "commander";
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
- import { render as T } from "ejs";
6
- import { generateCss as W } from "../compiler/index.js";
7
- import { p as B } from "../pascal-case-BQpR5PdN.js";
8
- import { createLogger as G, format as J, transports as R } from "winston";
9
- import { existsSync as q } from "fs";
10
- import { exec as M } from "child_process";
11
- import U from "ora";
12
- const i = G({
13
- level: "debug",
14
- format: J.combine(J.colorize(), J.cli()),
15
- transports: [new R.Console({})]
16
- }), _ = (e) => new Promise((l, m) => {
17
- M(e, (u) => {
18
- if (u) return m(u);
19
- l();
20
- });
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) {
26
- try {
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);
31
- }
32
- }
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 = {
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, 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 = {
52
- core: `@salty-css/core@${P.version}`,
53
- react: `@salty-css/react@${P.version}`,
54
- eslintPluginCore: `@salty-css/eslint-plugin-core@${P.version}`,
55
- vite: `@salty-css/vite@${P.version}`
56
- };
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(() => {
64
- }) !== void 0) {
65
- i.debug("File already exists: " + d);
66
- return;
67
- }
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);
70
- });
71
- await Promise.all(I);
72
- const h = O(p, r), n = o(p, ".saltyrc"), f = await g(n, "utf-8").catch(() => {
73
- });
74
- if (f === void 0) {
75
- i.info("Creating file: " + n);
76
- const s = JSON.stringify({
77
- defaultProject: h,
78
- projects: [h]
79
- }, null, 2);
80
- await y(n, s);
81
- } else {
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);
87
- }
88
- const C = o(p, ".gitignore"), S = await g(C, "utf-8").catch(() => {
89
- });
90
- if (S !== void 0 && (S.includes("saltygen") || (i.info("Edit file: " + C), await y(C, S + `
91
-
92
- # Salty-CSS
93
- saltygen
94
- `))), c) {
95
- const t = o(r, c), s = await g(t, "utf-8").catch(() => {
96
- });
97
- if (s !== void 0 && !s.includes("saltygen")) {
98
- const j = o(t, ".."), z = `@import '${O(j, o(r, "saltygen/index.css"))}';`;
99
- i.info("Edit file: " + t), await y(t, z + `
100
- ` + s), await x(t);
101
- }
102
- }
103
- const w = o(r, "vite.config.ts"), b = await g(w, "utf-8").catch(() => {
104
- });
105
- if (b !== void 0 && !b.includes("saltyPlugin")) {
106
- i.info("Edit file: " + w);
107
- const s = `import { saltyPlugin } from '@salty-css/vite';
108
- `, j = b.replace(/(plugins: \[)/, `$1
109
- saltyPlugin(__dirname),`);
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);
111
- }
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);
115
- await W(c);
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(() => {
121
- }) !== void 0) {
122
- i.error("File already exists:", f);
123
- return;
124
- }
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);
129
- }
130
- K().catch((e) => console.error(e));
2
+ import { main as r } from "./main.js";
3
+ r().catch((o) => console.error(o));
package/bin/logger.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare const logger: import('winston').Logger;
2
+ export declare const logError: (message: string) => void;
package/bin/main.cjs ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-CNuRN2e-.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.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")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.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(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
2
+
3
+ # Salty-CSS
4
+ saltygen
5
+ `)));const x=["src","public","assets","styles","css","app"],H=["styles","css","app","pages"],M=["index","styles","main","app","global","globals"],L=[".css",".scss",".sass"],E=await(async()=>{if(u)return u;for(const e of x)for(const g of M)for(const c of L){const o=n.join(r,e,g+c);if(await s.readFile(o,"utf-8").catch(()=>{})!==void 0)return n.relative(r,o);for(const O of H){const q=n.join(r,e,O,g+c);if(await s.readFile(q,"utf-8").catch(()=>{})!==void 0)return n.relative(r,q)}}})();if(E){const e=n.join(r,E),g=await s.readFile(e,"utf-8").catch(()=>{});if(g!==void 0&&!g.includes("saltygen")){const o=n.join(e,".."),O=`@import '${n.relative(o,n.join(r,"saltygen/index.css"))}';`;t.logger.info("Adding global import statement to CSS file: "+e),await s.writeFile(e,O+`
6
+ `+g),await S(e)}}else t.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");const Z={projectJs:n.join(r,"eslint.config.js"),rootJs:n.join(f,"eslint.config.js"),projectMjs:n.join(r,"eslint.config.mjs"),rootMjs:n.join(f,"eslint.config.mjs"),projectJson:n.join(r,".eslintrc.json"),rootJson:n.join(f,".eslintrc.json")},v=Object.values(Z).find(e=>G.existsSync(e));if(v){p||await I(D.eslintConfigCore);const e=await s.readFile(v,"utf-8").catch(()=>{});if(!e)return t.logError("Could not read ESLint config file.");if(!e.includes("salty-css"))if(t.logger.info("Edit file: "+v),v.endsWith("js")){let o=`import saltyCss from "@salty-css/eslint-config-core/flat";
7
+ ${e}`;e.includes("typescript-eslint")?o.includes(".config(")?o=o.replace(".config(",".config(saltyCss,"):t.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."):o.includes("export default [")?o=o.replace("export default [","export default [ saltyCss,"):o.includes("eslintConfig = [")?o=o.replace("eslintConfig = [","eslintConfig = [ saltyCss,"):t.logger.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."),await s.writeFile(v,o),await S(v)}else{const c=JSON.parse(e);c.extends||(c.extends=[]),c.extends.push("@salty-css/core");const o=JSON.stringify(c,null,2);await s.writeFile(v,o),await S(v)}}const _=n.join(r,"vite.config.ts"),W=await s.readFile(_,"utf-8").catch(()=>{});if(W!==void 0&&!W.includes("saltyPlugin")){t.logger.info("Edit file: "+_);const g=`import { saltyPlugin } from '@salty-css/vite';
8
+ `,o=W.replace(/(plugins: \[)/,`$1
9
+ saltyPlugin(__dirname),`);p||await I(`-D ${D.vite}`),t.logger.info("Adding Salty-CSS plugin to Vite config..."),await s.writeFile(_,g+o),await S(_)}const A=["next.config.js","next.config.cjs","next.config.ts","next.config.mjs"].map(e=>n.join(r,e)).find(e=>G.existsSync(e));if(A){let e=await s.readFile(A,"utf-8").catch(()=>{});if(e!==void 0&&!e.includes("withSaltyCss")){let c=!1;/\splugins([^=]*)=[^[]\[/.test(e)&&!c&&(e=e.replace(/\splugins([^=]*)=[^[]\[/,(q,J)=>` plugins${J}= [withSaltyCss,`),c=!0);const k=e.includes("module.exports"),O=k?`const { withSaltyCss } = require('@salty-css/next');
10
+ `:`import { withSaltyCss } from '@salty-css/next';
11
+ `;k&&!c?(e=e.replace(/module.exports = ([^;]+)/,(q,J)=>`module.exports = withSaltyCss(${J})`),c=!0):c||(e=e.replace(/export default ([^;]+)/,(q,J)=>`export default withSaltyCss(${J})`)),p||await I(`-D ${D.next}`),t.logger.info("Adding Salty-CSS plugin to Next.js config..."),await s.writeFile(A,O+e),await S(A)}}const ee=await N().catch(()=>t.logError("Could not read package.json file.")).then(e=>(e.scripts||(e.scripts={}),e.scripts.prepare?e.scripts.prepare.includes("salty-css")||(t.logger.info("Edit file: "+b),e.scripts.prepare=e.scripts.prepare+" && npx salty-css build"):(t.logger.info("Edit file: "+b),e.scripts.prepare="npx salty-css build"),e));await Y(ee),t.logger.info("Running the build to generate initial CSS..."),await t.generateCss(r),t.logger.info("🎉 Salty CSS project initialized successfully!"),t.logger.info("Next steps:"),t.logger.info("1. Configure variables and templates in `salty.config.ts`"),t.logger.info("2. Create a new component with `npx salty-css generate [component-name]`"),t.logger.info("3. Run `npx salty-css build` to generate the CSS"),t.logger.info("4. Read about the features in the documentation: https://salty-css.dev"),t.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐")}),y.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(i=V){t.logger.info("Building the Salty-CSS project...");const{dir:a=i}=this.opts();if(!a)return t.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");const l=R(a);await t.generateCss(l)}),y.command("generate [file] [directory]").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.").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.").option("-r, --reactComponent","Generate a React component as well.").action(async function(i,a=V){const{file:l=i,dir:u=a,tag:p,name:f,className:r,reactComponent:T=!1}=this.opts();if(!l)return t.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");if(!u)return t.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");const m=R(u),w=l.split("/").slice(0,-1).join("/");w&&await s.mkdir(n.join(m,w),{recursive:!0});const h=n.join(m,l),d=n.parse(h);d.ext||(d.ext=".ts"),d.name.endsWith(".css")||(d.name=d.name+".css"),d.base=d.name+d.ext;const j=n.format(d);if(await s.readFile(j,"utf-8").catch(()=>{})!==void 0){t.logger.error("File already exists:",j);return}let x=ie.pascalCase(f||d.base.replace(/\.css\.\w+$/,""));if(T){const M=x+"Component";x=x+"Wrapper";const L=d.base.replace(/\.css\.\w+$/,""),{content:Q}=await P("react/react-vanilla-file.ts",{tag:p,componentName:M,styledComponentName:x,className:r,fileName:L});d.name=L.replace(/\.css$/,""),d.ext=".tsx",d.base=d.name+d.ext;const E=n.format(d);t.logger.info("Generating a new file: "+E),await s.writeFile(E,Q),await S(E)}const{content:H}=await P("react/react-styled-file.ts",{tag:p,name:x,className:r});t.logger.info("Generating a new file: "+j),await s.writeFile(j,H),await S(j)});const K=async()=>{const i=n.join(process.cwd(),"package.json"),a=await N(i).catch(p=>t.logError(p));if(!a)return t.logError("Could not read package.json file.");const l={...a.dependencies,...a.devDependencies},u=Object.entries(l).filter(([p])=>p==="salty-css"||p.startsWith("@salty-css/"));return u.length?u:t.logError("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+i)};y.command("update [version]").alias("up").description("Update Salty-CSS packages to the latest or specified version.").option("-v, --version <version>","Version to update to.").option("--legacy-peer-deps <legacyPeerDeps>","Use legacy peer dependencies (not recommended).",!1).action(async function(i="latest"){const{legacyPeerDeps:a,version:l=i}=this.opts(),u=await K();if(!u)return t.logError("Could not update Salty-CSS packages as any were found in package.json.");const p=u.map(([m])=>l==="@"?`${m}@${$.version}`:`${m}@${l.replace(/^@/,"")}`);a?(t.logger.warn("Using legacy peer dependencies to update packages."),await I(...p,"--legacy-peer-deps")):await I(...p);const f=await K();if(!f)return t.logError("Something went wrong while reading the updated packages.");const r=f.reduce((m,[w,h])=>(m[h]||(m[h]=[]),m[h].push(w),m),{});if(Object.keys(r).length===1){const w=Object.keys(r)[0].replace(/^\^/,"");t.logger.info(`Updated to all Salty CSS packages successfully to ${w}`)}else for(const[m,w]of Object.entries(r)){const h=m.replace(/^\^/,"");t.logger.info(`Updated to ${h}: ${w.join(", ")}`)}}),y.option("-v, --version","Show the current version of Salty-CSS.").action(async function(){const i=await B();t.logger.info("CLI is running: "+i.version);const a=n.join(process.cwd(),"package.json"),l=await N(a).catch(f=>t.logError(f));if(!l)return;const u={...l.dependencies,...l.devDependencies},p=Object.keys(u).filter(f=>f==="salty-css"||f.startsWith("@salty-css/"));if(!p.length)return t.logError("No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: "+a);for(const f of p)t.logger.info(`${f}: ${u[f]}`)}),y.parseAsync(process.argv)}exports.main=re;
package/bin/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function main(): Promise<void>;