@salty-css/core 0.0.1-alpha.12 → 0.0.1-alpha.120
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/.saltyrc.schema.json +40 -0
- package/README.md +102 -26
- package/bin/bin-util.d.ts +2 -0
- package/bin/index.cjs +2 -0
- package/bin/index.d.ts +2 -0
- package/bin/index.js +3 -0
- package/bin/logger.d.ts +2 -0
- package/bin/main.cjs +11 -0
- package/bin/main.d.ts +1 -0
- package/bin/main.js +260 -0
- package/bin/prettier.d.ts +1 -0
- package/compiler/get-files.d.ts +3 -0
- package/compiler/index.cjs +1 -11
- package/compiler/index.d.ts +4 -6
- package/compiler/index.js +16 -180
- package/config/config-types.d.ts +15 -5
- package/dash-case-BJEkFEGQ.cjs +1 -0
- package/dash-case-DBThphLm.js +19 -0
- package/generator/index.cjs +1 -1
- package/generator/index.js +34 -18
- package/generator/parse-templates.d.ts +2 -0
- package/generator/style-generator.d.ts +13 -4
- package/index-84Wroia-.cjs +1 -0
- package/index-BKt0qRhM.js +300 -0
- package/index-D_732b92.js +4 -0
- package/index-mhoDzsNb.cjs +21 -0
- package/package.json +20 -2
- package/parse-templates-BuKrl3n7.js +100 -0
- package/parse-templates-DIOn-gO_.cjs +8 -0
- package/pascal-case-BQpR5PdN.js +6 -0
- package/pascal-case-iWoaJWwT.cjs +1 -0
- package/react-styled-file-CGVf5n1B.js +11 -0
- package/react-styled-file-Dkubsz-U.cjs +8 -0
- package/react-vanilla-file-CCXbsjIb.js +18 -0
- package/react-vanilla-file-CG_WJLam.cjs +15 -0
- package/salty.config-BhBY_oOk.js +10 -0
- package/salty.config-Dk6ZcCxI.cjs +7 -0
- package/templates/salty-reset.d.ts +2 -0
- package/types/index.d.ts +48 -21
- package/util/camel-case.d.ts +1 -0
- package/util/dot-case.d.ts +1 -0
- package/util/index.cjs +1 -1
- package/util/index.d.ts +2 -0
- package/util/index.js +7 -15
- package/util/module-type.d.ts +1 -0
- package/util/pascal-case.d.ts +1 -0
- package/parse-templates-BOSK0Tb6.js +0 -90
- package/parse-templates-BY1Xai-_.cjs +0 -8
@@ -0,0 +1,40 @@
|
|
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 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."
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"required": ["dir", "framework"]
|
36
|
+
}
|
37
|
+
}
|
38
|
+
},
|
39
|
+
"required": ["defaultProject", "projects"]
|
40
|
+
}
|
package/README.md
CHANGED
@@ -1,15 +1,91 @@
|
|
1
|
-
# Salty
|
1
|
+
# Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
|
2
2
|
|
3
|
-
|
3
|
+
In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
|
4
4
|
|
5
|
-
|
5
|
+
## Features
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
- Build time compilation to achieve awesome runtime performance and minimal size
|
8
|
+
- Next.js, React Server Components, Vite and Webpack support
|
9
|
+
- Type safety with out of the box TypeScript and ESLint plugin
|
10
|
+
- Advanced CSS variables configuration to allow smooth token usage
|
11
|
+
- Style templates to create reusable styles easily
|
11
12
|
|
12
|
-
|
13
|
+
## Get started
|
14
|
+
|
15
|
+
- Initialize: `npx salty-css init [directory]`
|
16
|
+
- Create component: `npx salty-css generate [filePath]`
|
17
|
+
- Build: `npx salty-css build [directory]`
|
18
|
+
|
19
|
+
### Initialize
|
20
|
+
|
21
|
+
Fastest way to get started with any framework is [npx salty-css init [directory]](#initialize-salty-css-for-a-project) command
|
22
|
+
|
23
|
+
- Next.js → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
|
24
|
+
- React → [React guide](#react) + [React example code](#code-examples)
|
25
|
+
- Vite → [Vite guide](#vite)
|
26
|
+
- Webpack → Guide coming soon
|
27
|
+
- ESLint → Guide coming soon
|
28
|
+
|
29
|
+
### Salty CSS CLI
|
30
|
+
|
31
|
+
In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
|
32
|
+
|
33
|
+
- 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.
|
34
|
+
- 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.
|
35
|
+
- 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
|
36
|
+
|
37
|
+
### Guides
|
38
|
+
|
39
|
+
#### Next.js
|
40
|
+
|
41
|
+
In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
|
42
|
+
|
43
|
+
##### Manual configuration
|
44
|
+
|
45
|
+
1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
|
46
|
+
2. Create `salty.config.ts` to your app directory
|
47
|
+
3. Add Salty CSS plugin to next.js config
|
48
|
+
|
49
|
+
- **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);`
|
50
|
+
- **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);`
|
51
|
+
|
52
|
+
4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
|
53
|
+
5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
54
|
+
6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
55
|
+
|
56
|
+
[Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
|
57
|
+
|
58
|
+
#### Vite
|
59
|
+
|
60
|
+
In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
|
61
|
+
|
62
|
+
##### Manual configuration
|
63
|
+
|
64
|
+
1. For Vite support install `npm i @salty-css/vite @salty-css/core`
|
65
|
+
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
|
66
|
+
3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
|
67
|
+
4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
68
|
+
5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
69
|
+
|
70
|
+
#### React
|
71
|
+
|
72
|
+
In your existing React repository you can run `npx salty-css init` to automatically configure Salty CSS.
|
73
|
+
|
74
|
+
##### Manual configuration
|
75
|
+
|
76
|
+
1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
|
77
|
+
2. Create `salty.config.ts` to your app directory
|
78
|
+
3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack) or after changes run `npx salty-css build`
|
79
|
+
|
80
|
+
[Check out react example code](#code-examples)
|
81
|
+
|
82
|
+
### Create components
|
83
|
+
|
84
|
+
1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
85
|
+
|
86
|
+
## Code examples
|
87
|
+
|
88
|
+
### Basic usage example with Button
|
13
89
|
|
14
90
|
**Salty config**
|
15
91
|
|
@@ -31,23 +107,6 @@ export const config = defineConfig({
|
|
31
107
|
});
|
32
108
|
```
|
33
109
|
|
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
110
|
**Wrapper** (`components/wrapper/wrapper.css.ts`)
|
52
111
|
|
53
112
|
```tsx
|
@@ -72,7 +131,7 @@ export const Button = styled('button', {
|
|
72
131
|
padding: `0.6em 1.2em`,
|
73
132
|
border: '1px solid currentColor',
|
74
133
|
background: 'transparent',
|
75
|
-
color: 'currentColor
|
134
|
+
color: 'currentColor',
|
76
135
|
cursor: 'pointer',
|
77
136
|
transition: '200ms',
|
78
137
|
textDecoration: 'none',
|
@@ -108,4 +167,21 @@ export const Button = styled('button', {
|
|
108
167
|
});
|
109
168
|
```
|
110
169
|
|
170
|
+
**Your React component file**
|
171
|
+
|
172
|
+
```tsx
|
173
|
+
import { Wrapper } from '../components/wrapper/wrapper.css';
|
174
|
+
import { Button } from '../components/button/button.css';
|
175
|
+
|
176
|
+
export const IndexPage = () => {
|
177
|
+
return (
|
178
|
+
<Wrapper>
|
179
|
+
<Button variant="solid" onClick={() => alert('It is a button.')}>
|
180
|
+
Outlined
|
181
|
+
</Button>
|
182
|
+
</Wrapper>
|
183
|
+
);
|
184
|
+
};
|
185
|
+
```
|
186
|
+
|
111
187
|
More examples coming soon
|
package/bin/index.cjs
ADDED
package/bin/index.d.ts
ADDED
package/bin/index.js
ADDED
package/bin/logger.d.ts
ADDED
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-mhoDzsNb.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","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>;
|
package/bin/main.js
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
import { Command as oe } from "commander";
|
2
|
+
import { existsSync as K } from "fs";
|
3
|
+
import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
|
4
|
+
import { join as i, relative as z, parse as re, format as ee } from "path";
|
5
|
+
import { render as ce } from "ejs";
|
6
|
+
import { l as t, a as h, g as te } from "../index-BKt0qRhM.js";
|
7
|
+
import { p as le } from "../pascal-case-BQpR5PdN.js";
|
8
|
+
import { exec as de } from "child_process";
|
9
|
+
import fe from "ora";
|
10
|
+
const ne = (g) => new Promise((P, x) => {
|
11
|
+
de(g, (F) => {
|
12
|
+
if (F) return x(F);
|
13
|
+
P();
|
14
|
+
});
|
15
|
+
}), E = async (...g) => {
|
16
|
+
const P = g.map((J) => J.replace("-D", "").split("@").slice(0, -1).join("@").trim()).join(", "), x = fe(`Installing packages: ${P}`).start(), F = g.join(" ");
|
17
|
+
await ne(`npm install ${F}`), x.succeed(`Installed packages: ${P}`);
|
18
|
+
}, pe = () => K(i(process.cwd(), "node_modules", ".bin", "prettier"));
|
19
|
+
async function j(g) {
|
20
|
+
try {
|
21
|
+
if (!pe()) return;
|
22
|
+
await ne(`./node_modules/.bin/prettier --write "${g}"`), t.info(`Formatted ${g} with Prettier`);
|
23
|
+
} catch (P) {
|
24
|
+
t.error(`Error formatting ${g} with Prettier:`, P);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
async function xe() {
|
28
|
+
const g = new oe();
|
29
|
+
g.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
|
30
|
+
const P = {
|
31
|
+
// Core files
|
32
|
+
"salty.config.ts": import("../salty.config-BhBY_oOk.js"),
|
33
|
+
"saltygen/index.css": import("../index-D_732b92.js"),
|
34
|
+
// React
|
35
|
+
"react/react-styled-file.ts": import("../react-styled-file-CGVf5n1B.js"),
|
36
|
+
"react/react-vanilla-file.ts": import("../react-vanilla-file-CCXbsjIb.js")
|
37
|
+
}, x = async (n, a) => {
|
38
|
+
const { default: c } = await P[n], u = ce(c, a);
|
39
|
+
return { fileName: n, content: u };
|
40
|
+
}, F = async () => {
|
41
|
+
const n = i(process.cwd(), ".saltyrc.json");
|
42
|
+
return await C(n, "utf-8").then(JSON.parse).catch(() => ({}));
|
43
|
+
}, J = i(process.cwd(), "package.json"), O = async (n = J) => {
|
44
|
+
const a = await C(n, "utf-8").then(JSON.parse).catch(() => {
|
45
|
+
});
|
46
|
+
if (!a) throw "Could not read package.json file!";
|
47
|
+
return a;
|
48
|
+
}, se = async (n, a = J) => {
|
49
|
+
typeof n == "object" && (n = JSON.stringify(n, null, 2)), await w(a, n);
|
50
|
+
}, Q = async () => {
|
51
|
+
const n = new URL("../package.json", import.meta.url);
|
52
|
+
return O(n);
|
53
|
+
}, X = await (async () => (await F()).defaultProject)(), N = await Q(), A = {
|
54
|
+
core: `@salty-css/core@${N.version}`,
|
55
|
+
react: `@salty-css/react@${N.version}`,
|
56
|
+
eslintConfigCore: `@salty-css/eslint-config-core@${N.version}`,
|
57
|
+
vite: `@salty-css/vite@${N.version}`,
|
58
|
+
next: `@salty-css/next@${N.version}`
|
59
|
+
}, G = (n) => {
|
60
|
+
const a = n === "." ? "" : n, c = process.cwd();
|
61
|
+
return i(c, a);
|
62
|
+
};
|
63
|
+
g.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(n = ".") {
|
64
|
+
if (!await O().catch(() => {
|
65
|
+
})) return h("Salty CSS project must be initialized in a directory with a package.json file.");
|
66
|
+
t.info("Initializing a new Salty-CSS project!");
|
67
|
+
const { dir: c = n, cssFile: u, skipInstall: p } = this.opts();
|
68
|
+
if (!c) return h("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
|
69
|
+
p || await E(A.core, A.react);
|
70
|
+
const d = process.cwd(), o = G(c), H = await Promise.all([x("salty.config.ts"), x("saltygen/index.css")]);
|
71
|
+
await q(o, { recursive: !0 });
|
72
|
+
const y = H.map(async ({ fileName: e, content: f }) => {
|
73
|
+
const r = i(o, e);
|
74
|
+
if (await C(r, "utf-8").catch(() => {
|
75
|
+
}) !== void 0) {
|
76
|
+
t.debug("File already exists: " + r);
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
const b = e.split("/").slice(0, -1).join("/");
|
80
|
+
b && await q(i(o, b), { recursive: !0 }), t.info("Creating file: " + r), await w(r, f), await j(r);
|
81
|
+
});
|
82
|
+
await Promise.all(y);
|
83
|
+
const S = z(d, o) || ".", m = i(d, ".saltyrc.json"), l = await C(m, "utf-8").catch(() => {
|
84
|
+
});
|
85
|
+
if (l === void 0) {
|
86
|
+
t.info("Creating file: " + m);
|
87
|
+
const f = JSON.stringify({
|
88
|
+
$schema: "./node_modules/@salty-css/core/.saltyrc.schema.json",
|
89
|
+
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.",
|
90
|
+
defaultProject: S,
|
91
|
+
projects: [
|
92
|
+
{
|
93
|
+
dir: S,
|
94
|
+
framework: "react"
|
95
|
+
}
|
96
|
+
]
|
97
|
+
}, null, 2);
|
98
|
+
await w(m, f), await j(m);
|
99
|
+
} else {
|
100
|
+
const e = JSON.parse(l), f = (e == null ? void 0 : e.projects) || [];
|
101
|
+
if (f.findIndex((s) => s.dir === S) === -1) {
|
102
|
+
f.push({ dir: S, framework: "react" }), e.projects = [...f];
|
103
|
+
const s = JSON.stringify(e, null, 2);
|
104
|
+
s !== l && (t.info("Edit file: " + m), await w(m, s), await j(m));
|
105
|
+
}
|
106
|
+
}
|
107
|
+
const k = i(d, ".gitignore"), U = await C(k, "utf-8").catch(() => {
|
108
|
+
});
|
109
|
+
U !== void 0 && (U.includes("saltygen") || (t.info("Edit file: " + k), await w(k, U + `
|
110
|
+
|
111
|
+
# Salty-CSS
|
112
|
+
saltygen
|
113
|
+
`)));
|
114
|
+
const $ = ["src", "public", "assets", "styles", "css", "app"], M = ["styles", "css", "app", "pages"], B = ["index", "styles", "main", "global", "globals"], R = [".css", ".scss", ".sass"], D = await (async () => {
|
115
|
+
if (u) return u;
|
116
|
+
for (const e of $)
|
117
|
+
for (const f of B)
|
118
|
+
for (const r of R) {
|
119
|
+
const s = i(o, e, f + r);
|
120
|
+
if (await C(s, "utf-8").catch(() => {
|
121
|
+
}) !== void 0) return z(o, s);
|
122
|
+
for (const T of M) {
|
123
|
+
const L = i(o, e, T, f + r);
|
124
|
+
if (await C(L, "utf-8").catch(() => {
|
125
|
+
}) !== void 0) return z(o, L);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
})();
|
129
|
+
if (D) {
|
130
|
+
const e = i(o, D), f = await C(e, "utf-8").catch(() => {
|
131
|
+
});
|
132
|
+
if (f !== void 0 && !f.includes("saltygen")) {
|
133
|
+
const s = i(e, ".."), T = `@import '${z(s, i(o, "saltygen/index.css"))}';`;
|
134
|
+
t.info("Adding global import statement to CSS file: " + e), await w(e, T + `
|
135
|
+
` + f), await j(e);
|
136
|
+
}
|
137
|
+
} else
|
138
|
+
t.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
|
139
|
+
const ie = {
|
140
|
+
projectJs: i(o, "eslint.config.js"),
|
141
|
+
rootJs: i(d, "eslint.config.js"),
|
142
|
+
projectMjs: i(o, "eslint.config.mjs"),
|
143
|
+
rootMjs: i(d, "eslint.config.mjs"),
|
144
|
+
projectJson: i(o, ".eslintrc.json"),
|
145
|
+
rootJson: i(d, ".eslintrc.json")
|
146
|
+
}, v = Object.values(ie).find((e) => K(e));
|
147
|
+
if (v) {
|
148
|
+
p || await E(A.eslintConfigCore);
|
149
|
+
const e = await C(v, "utf-8").catch(() => {
|
150
|
+
});
|
151
|
+
if (!e) return h("Could not read ESLint config file.");
|
152
|
+
if (!e.includes("salty-css"))
|
153
|
+
if (t.info("Edit file: " + v), v.endsWith("js")) {
|
154
|
+
let s = `import saltyCss from "@salty-css/eslint-config-core/flat";
|
155
|
+
${e}`;
|
156
|
+
e.includes("typescript-eslint") ? s.includes(".config(") ? s = s.replace(".config(", ".config(saltyCss,") : t.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.") : s.includes("export default [") ? s = s.replace("export default [", "export default [ saltyCss,") : s.includes("eslintConfig = [") ? s = s.replace("eslintConfig = [", "eslintConfig = [ saltyCss,") : t.warn("Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually."), await w(v, s), await j(v);
|
157
|
+
} else {
|
158
|
+
const r = JSON.parse(e);
|
159
|
+
r.extends || (r.extends = []), r.extends.push("@salty-css/core");
|
160
|
+
const s = JSON.stringify(r, null, 2);
|
161
|
+
await w(v, s), await j(v);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
const _ = i(o, "vite.config.ts"), V = await C(_, "utf-8").catch(() => {
|
165
|
+
});
|
166
|
+
if (V !== void 0 && !V.includes("saltyPlugin")) {
|
167
|
+
t.info("Edit file: " + _);
|
168
|
+
const f = `import { saltyPlugin } from '@salty-css/vite';
|
169
|
+
`, s = V.replace(/(plugins: \[)/, `$1
|
170
|
+
saltyPlugin(__dirname),`);
|
171
|
+
p || await E(`-D ${A.vite}`), t.info("Adding Salty-CSS plugin to Vite config..."), await w(_, f + s), await j(_);
|
172
|
+
}
|
173
|
+
const W = ["next.config.js", "next.config.cjs", "next.config.ts", "next.config.mjs"].map((e) => i(o, e)).find((e) => K(e));
|
174
|
+
if (W) {
|
175
|
+
let e = await C(W, "utf-8").catch(() => {
|
176
|
+
});
|
177
|
+
if (e !== void 0 && !e.includes("withSaltyCss")) {
|
178
|
+
let r = !1;
|
179
|
+
/\splugins([^=]*)=[^[]\[/.test(e) && !r && (e = e.replace(/\splugins([^=]*)=[^[]\[/, (L, I) => ` plugins${I}= [withSaltyCss,`), r = !0);
|
180
|
+
const b = e.includes("module.exports"), T = b ? `const { withSaltyCss } = require('@salty-css/next');
|
181
|
+
` : `import { withSaltyCss } from '@salty-css/next';
|
182
|
+
`;
|
183
|
+
b && !r ? (e = e.replace(/module.exports = ([^;]+)/, (L, I) => `module.exports = withSaltyCss(${I})`), r = !0) : r || (e = e.replace(/export default ([^;]+)/, (L, I) => `export default withSaltyCss(${I})`)), p || await E(`-D ${A.next}`), t.info("Adding Salty-CSS plugin to Next.js config..."), await w(W, T + e), await j(W);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
const ae = await O().catch(() => h("Could not read package.json file.")).then((e) => (e.scripts || (e.scripts = {}), e.scripts.prepare ? e.scripts.prepare.includes("salty-css") || (t.info("Edit file: " + J), e.scripts.prepare = e.scripts.prepare + " && npx salty-css build") : (t.info("Edit file: " + J), e.scripts.prepare = "npx salty-css build"), e));
|
187
|
+
await se(ae), t.info("Running the build to generate initial CSS..."), await te(o), t.info("🎉 Salty CSS project initialized successfully!"), t.info("Next steps:"), t.info("1. Configure variables and templates in `salty.config.ts`"), t.info("2. Create a new component with `npx salty-css generate [component-name]`"), t.info("3. Run `npx salty-css build` to generate the CSS"), t.info("4. Read about the features in the documentation: https://salty-css.dev"), t.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
|
188
|
+
}), g.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(n = X) {
|
189
|
+
t.info("Building the Salty-CSS project...");
|
190
|
+
const { dir: a = n } = this.opts();
|
191
|
+
if (!a) return h("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
|
192
|
+
const c = G(a);
|
193
|
+
await te(c);
|
194
|
+
}), g.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(n, a = X) {
|
195
|
+
const { file: c = n, dir: u = a, tag: p, name: d, className: o, reactComponent: H = !1 } = this.opts();
|
196
|
+
if (!c) return h("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
|
197
|
+
if (!u) return h("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
|
198
|
+
const y = G(u), S = c.split("/").slice(0, -1).join("/");
|
199
|
+
S && await q(i(y, S), { recursive: !0 });
|
200
|
+
const m = i(y, c), l = re(m);
|
201
|
+
l.ext || (l.ext = ".ts"), l.name.endsWith(".css") || (l.name = l.name + ".css"), l.base = l.name + l.ext;
|
202
|
+
const k = ee(l);
|
203
|
+
if (await C(k, "utf-8").catch(() => {
|
204
|
+
}) !== void 0) {
|
205
|
+
t.error("File already exists:", k);
|
206
|
+
return;
|
207
|
+
}
|
208
|
+
let $ = le(d || l.base.replace(/\.css\.\w+$/, ""));
|
209
|
+
if (H) {
|
210
|
+
const B = $ + "Component";
|
211
|
+
$ = $ + "Wrapper";
|
212
|
+
const R = l.base.replace(/\.css\.\w+$/, ""), { content: Z } = await x("react/react-vanilla-file.ts", { tag: p, componentName: B, styledComponentName: $, className: o, fileName: R });
|
213
|
+
l.name = R.replace(/\.css$/, ""), l.ext = ".tsx", l.base = l.name + l.ext;
|
214
|
+
const D = ee(l);
|
215
|
+
t.info("Generating a new file: " + D), await w(D, Z), await j(D);
|
216
|
+
}
|
217
|
+
const { content: M } = await x("react/react-styled-file.ts", { tag: p, name: $, className: o });
|
218
|
+
t.info("Generating a new file: " + k), await w(k, M), await j(k);
|
219
|
+
});
|
220
|
+
const Y = async () => {
|
221
|
+
const n = i(process.cwd(), "package.json"), a = await O(n).catch((p) => h(p));
|
222
|
+
if (!a) return h("Could not read package.json file.");
|
223
|
+
const c = { ...a.dependencies, ...a.devDependencies }, u = Object.entries(c).filter(([p]) => p === "salty-css" || p.startsWith("@salty-css/"));
|
224
|
+
return u.length ? u : h(
|
225
|
+
"No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + n
|
226
|
+
);
|
227
|
+
};
|
228
|
+
g.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(n = "latest") {
|
229
|
+
const { legacyPeerDeps: a, version: c = n } = this.opts(), u = await Y();
|
230
|
+
if (!u) return h("Could not update Salty-CSS packages as any were found in package.json.");
|
231
|
+
const p = u.map(([y]) => c === "@" ? `${y}@${N.version}` : `${y}@${c.replace(/^@/, "")}`);
|
232
|
+
a ? (t.warn("Using legacy peer dependencies to update packages."), await E(...p, "--legacy-peer-deps")) : await E(...p);
|
233
|
+
const d = await Y();
|
234
|
+
if (!d) return h("Something went wrong while reading the updated packages.");
|
235
|
+
const o = d.reduce((y, [S, m]) => (y[m] || (y[m] = []), y[m].push(S), y), {});
|
236
|
+
if (Object.keys(o).length === 1) {
|
237
|
+
const S = Object.keys(o)[0].replace(/^\^/, "");
|
238
|
+
t.info(`Updated to all Salty CSS packages successfully to ${S}`);
|
239
|
+
} else
|
240
|
+
for (const [y, S] of Object.entries(o)) {
|
241
|
+
const m = y.replace(/^\^/, "");
|
242
|
+
t.info(`Updated to ${m}: ${S.join(", ")}`);
|
243
|
+
}
|
244
|
+
}), g.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
|
245
|
+
const n = await Q();
|
246
|
+
t.info("CLI is running: " + n.version);
|
247
|
+
const a = i(process.cwd(), "package.json"), c = await O(a).catch((d) => h(d));
|
248
|
+
if (!c) return;
|
249
|
+
const u = { ...c.dependencies, ...c.devDependencies }, p = Object.keys(u).filter((d) => d === "salty-css" || d.startsWith("@salty-css/"));
|
250
|
+
if (!p.length)
|
251
|
+
return h(
|
252
|
+
"No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + a
|
253
|
+
);
|
254
|
+
for (const d of p)
|
255
|
+
t.info(`${d}: ${u[d]}`);
|
256
|
+
}), g.parseAsync(process.argv);
|
257
|
+
}
|
258
|
+
export {
|
259
|
+
xe as main
|
260
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function formatWithPrettier(filePath: string): Promise<void>;
|
package/compiler/index.cjs
CHANGED
@@ -1,11 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
2
|
-
`),C=N.toHash(i,6),f=o.join(e,`css/${C}.css`);r.writeFileSync(f,F)}}await w(t,e);const l=s.map(i=>`@import url('./css/${i}');`).join(`
|
3
|
-
`);let u=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
4
|
-
|
5
|
-
${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
|
6
|
-
`)}
|
7
|
-
${l}`;if(b.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
|
8
|
-
`);u+=i}r.writeFileSync(a,u)}catch(s){console.error(s)}},X=async(t,s)=>{try{const n=[],e=o.join(t,"./saltygen"),a=o.join(e,"index.css");if(T(s)){const b=await E(t),w=await V(s,e);Object.entries(w).forEach(([g,$])=>{if(!$.generator)return;const d=$.generator._withBuildContext({name:g,config:b}),m=`${d.hash}-${d.priority}.css`,S=`css/${m}`,F=o.join(e,S);n.push(m),r.writeFileSync(F,d.css)});const l=r.readFileSync(a,"utf8").split(`
|
9
|
-
`),j=n.map(g=>`@import url('../saltygen/css/${g}');`),i=[...new Set([...l,...j])].join(`
|
10
|
-
`);r.writeFileSync(a,i)}}catch(n){console.error(n)}},Y=async(t,s)=>{try{const n=o.join(t,"./saltygen");if(T(s)){let a=r.readFileSync(s,"utf8");a.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==a&&await L.writeFile(s,a);const b=await E(t),w=await V(s,n);let l=a;Object.entries(w).forEach(([u,i])=>{var f;if(i.isKeyframes){console.log("value",i);return}if(!i.generator)return;const g=i.generator._withBuildContext({name:u,config:b}),$=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const d=(f=$.at(1))==null?void 0:f.trim(),{element:m,variantKeys:S}=g.props,F=`${u} = styled(${d}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(m)}, ${JSON.stringify(S)});`,C=new RegExp(`${u}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");l=l.replace(C,F)});const j=N.toHash(s,6);return b.importStrategy==="component"&&(l=`import '../../saltygen/css/${j}.css';
|
11
|
-
${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error(n)}};exports.compileSaltyFile=V;exports.generateCss=W;exports.generateFile=X;exports.generateVariables=H;exports.isSaltyFile=T;exports.logger=A;exports.minimizeFile=Y;exports.saltyFileExtensions=M;exports.saltyFileRegExp=z;
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-templates-DIOn-gO_.cjs");const e=require("../index-mhoDzsNb.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
|
package/compiler/index.d.ts
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
import { StyleComponentGenerator } from '../generator/style-generator';
|
2
|
-
import * as winston from 'winston';
|
3
|
-
export declare const logger: winston.Logger;
|
4
2
|
export declare const saltyFileExtensions: string[];
|
5
3
|
export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
|
6
4
|
export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
|
7
|
-
export declare const
|
8
|
-
export declare const compileSaltyFile: (sourceFilePath: string, outputDirectory: string) => Promise<{
|
5
|
+
export declare const generateConfigStyles: (dirname: string) => Promise<void>;
|
6
|
+
export declare const compileSaltyFile: (dirname: string, sourceFilePath: string, outputDirectory: string) => Promise<{
|
9
7
|
[key: string]: {
|
10
8
|
generator: StyleComponentGenerator;
|
11
9
|
isKeyframes?: boolean;
|
@@ -13,6 +11,6 @@ export declare const compileSaltyFile: (sourceFilePath: string, outputDirectory:
|
|
13
11
|
css?: string;
|
14
12
|
};
|
15
13
|
}>;
|
16
|
-
export declare const generateCss: (dirname: string) => Promise<void>;
|
14
|
+
export declare const generateCss: (dirname: string, prod?: boolean) => Promise<void>;
|
17
15
|
export declare const generateFile: (dirname: string, file: string) => Promise<void>;
|
18
|
-
export declare const minimizeFile: (dirname: string, file: string) => Promise<string | undefined>;
|
16
|
+
export declare const minimizeFile: (dirname: string, file: string, prod?: boolean) => Promise<string | undefined>;
|