@melcanz85/chaincss 1.5.4 → 1.5.6
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/README.md +91 -42
- package/chaincss.js +6 -4
- package/package.json +1 -1
- package/transpiler.js +31 -3
package/README.md
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
# @melcanz85/chaincss
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/js/@melcanz85%2Fchaincss)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
3
6
|
A simple JavaScript-to-CSS transpiler that converts JS objects into optimized CSS.
|
|
4
7
|
|
|
5
8
|
## 🚀 Installation
|
|
6
9
|
|
|
7
10
|
```bash
|
|
8
11
|
npm install @melcanz85/chaincss
|
|
9
|
-
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
📦 Usage (Node.js)
|
|
14
|
+
Quick Setup
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
Install development dependencies:
|
|
17
|
+
|
|
18
|
+
bash
|
|
14
19
|
|
|
15
|
-
1. **Install development dependencies:**
|
|
16
|
-
```bash
|
|
17
20
|
npm install --save-dev nodemon concurrently
|
|
18
|
-
```
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
Update your package.json scripts:
|
|
23
|
+
|
|
24
|
+
json
|
|
25
|
+
|
|
22
26
|
"scripts": {
|
|
23
27
|
"start": "concurrently \"nodemon server.js\" \"nodemon --watch chaincss/*.jcss --watch processor.js --exec 'node processor.js'\""
|
|
24
28
|
}
|
|
25
|
-
```
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
Project Structure
|
|
28
31
|
|
|
29
32
|
Create this folder structure in your project:
|
|
30
33
|
|
|
31
|
-
```
|
|
32
34
|
your-project/
|
|
33
35
|
├── chaincss/ # ChainCSS source files
|
|
34
36
|
│ ├── chaincss.jcss # Main entry file
|
|
@@ -40,29 +42,24 @@ your-project/
|
|
|
40
42
|
├── node_modules/
|
|
41
43
|
├── package.json
|
|
42
44
|
└── package-lock.json
|
|
43
|
-
```
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
Processor Setup
|
|
46
47
|
|
|
47
|
-
In
|
|
48
|
+
In chaincss/processor.js:
|
|
48
49
|
|
|
49
|
-
```javascript
|
|
50
50
|
const jss = require("@melcanz85/chaincss");
|
|
51
51
|
|
|
52
52
|
try {
|
|
53
53
|
// Process main file and output CSS
|
|
54
54
|
jss.processJSS('./chaincss/chaincss.jcss', './public/chainstyle.css');
|
|
55
55
|
} catch (err) {
|
|
56
|
-
console.error('Error processing
|
|
56
|
+
console.error('Error processing chainCSS file:', err.stack);
|
|
57
57
|
process.exit(1);
|
|
58
58
|
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## 💻 Code Examples
|
|
62
59
|
|
|
63
|
-
|
|
60
|
+
💻 Code Examples
|
|
61
|
+
Main File (chaincss/chaincss.jcss):
|
|
64
62
|
|
|
65
|
-
```javascript
|
|
66
63
|
<@
|
|
67
64
|
// Import chaining definitions
|
|
68
65
|
const style = get('./chain.jcss');
|
|
@@ -86,11 +83,9 @@ try {
|
|
|
86
83
|
);
|
|
87
84
|
@>
|
|
88
85
|
}
|
|
89
|
-
```
|
|
90
86
|
|
|
91
|
-
|
|
87
|
+
Chaining File (chaincss/chain.jcss):
|
|
92
88
|
|
|
93
|
-
```javascript
|
|
94
89
|
// Variables for consistent styling
|
|
95
90
|
const bodyBgColor = '#f0f0f0';
|
|
96
91
|
const headerBgColor = '#333';
|
|
@@ -132,32 +127,86 @@ module.exports = {
|
|
|
132
127
|
header,
|
|
133
128
|
logoImgHeight
|
|
134
129
|
};
|
|
135
|
-
```
|
|
136
130
|
|
|
137
|
-
|
|
131
|
+
📝 Notes
|
|
132
|
+
|
|
133
|
+
You can directly put css syntax on your main file.
|
|
134
|
+
|
|
135
|
+
But chainCSS syntax must be wrapped in <@ @> delimiters.
|
|
136
|
+
|
|
137
|
+
The get() function imports chaining definitions from other files
|
|
138
|
+
|
|
139
|
+
YOU can modify your style in between get() and compile() in the main file it will override the styles in the chainn file.
|
|
140
|
+
|
|
141
|
+
🎨 Editor Support
|
|
142
|
+
|
|
143
|
+
Since .jcss files are just JavaScript files with ChainCSS syntax, you can easily enable proper syntax highlighting in your editor:
|
|
144
|
+
VS Code
|
|
145
|
+
|
|
146
|
+
Add this to your project's .vscode/settings.json:
|
|
147
|
+
|
|
148
|
+
{
|
|
149
|
+
"files.associations": {
|
|
150
|
+
"*.jcss": "javascript"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
WebStorm / IntelliJ IDEA
|
|
155
|
+
|
|
156
|
+
Go to Settings/Preferences → Editor → File Types
|
|
157
|
+
|
|
158
|
+
Select JavaScript in the list
|
|
159
|
+
|
|
160
|
+
Click + and add *.jcss to the registered patterns
|
|
161
|
+
|
|
162
|
+
Vim / Neovim
|
|
163
|
+
|
|
164
|
+
Add to your .vimrc or init.vim:
|
|
165
|
+
vim
|
|
166
|
+
|
|
167
|
+
au BufRead,BufNewFile *.jcss setfiletype javascript
|
|
168
|
+
|
|
169
|
+
Sublime Text
|
|
170
|
+
|
|
171
|
+
Create or edit ~/Library/Application Support/Sublime Text/Packages/User/JCSS.sublime-settings:
|
|
172
|
+
json
|
|
173
|
+
|
|
174
|
+
{
|
|
175
|
+
"extensions": ["jcss"],
|
|
176
|
+
"syntax": "Packages/JavaScript/JavaScript.sublime-syntax"
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
Atom
|
|
180
|
+
|
|
181
|
+
Add to your config.cson:
|
|
182
|
+
coffeescript
|
|
183
|
+
|
|
184
|
+
"*":
|
|
185
|
+
core:
|
|
186
|
+
customFileTypes:
|
|
187
|
+
"source.js": [
|
|
188
|
+
"jcss"
|
|
189
|
+
]
|
|
138
190
|
|
|
139
|
-
|
|
140
|
-
|--------|---------|-------------|
|
|
141
|
-
| ✅ | Basic JS → CSS | Convert plain JS objects to CSS |
|
|
142
|
-
| 🚧 | Keyframe animations | @keyframes support |
|
|
143
|
-
| 🚧 | Vendor prefixing | Auto-add -webkit-, -moz-, etc. |
|
|
144
|
-
| 🚧 | Source maps | Debug generated CSS |
|
|
145
|
-
| 🚧 | Watch mode | Auto-recompile on file changes |
|
|
191
|
+
Other Editors
|
|
146
192
|
|
|
147
|
-
|
|
193
|
+
Most modern editors allow you to associate file extensions with language modes. Simply configure your editor to treat .jcss files as JavaScript.
|
|
148
194
|
|
|
149
|
-
## 📝 Notes
|
|
150
195
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
196
|
+
✨ Features
|
|
197
|
+
Status Feature Description
|
|
198
|
+
✅ Basic JS → CSS Convert plain JS objects to CSS
|
|
199
|
+
🚧 Keyframe animations @keyframes support
|
|
200
|
+
🚧 Vendor prefixing Auto-add -webkit-, -moz-, etc.
|
|
201
|
+
🚧 Source maps Debug generated CSS
|
|
202
|
+
🚧 Watch mode Auto-recompile on file changes
|
|
155
203
|
|
|
156
|
-
|
|
204
|
+
✅ = Working, 🚧 = Coming soon
|
|
205
|
+
👨💻 Contributing
|
|
157
206
|
|
|
158
207
|
Contributions are welcome! Feel free to open issues or submit pull requests.
|
|
159
208
|
|
|
160
|
-
## 📄 License
|
|
161
209
|
|
|
162
|
-
|
|
210
|
+
📄 License
|
|
163
211
|
|
|
212
|
+
MIT © Rommel Caneos
|
package/chaincss.js
CHANGED
|
@@ -6,14 +6,10 @@ const path = require('path');
|
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const chokidar = require('chokidar');
|
|
8
8
|
const CleanCSS = require('clean-css');
|
|
9
|
-
|
|
10
|
-
// CUSTOM MADE MODULE INSIDE JSS FOLDER
|
|
11
9
|
const transpilerModule = require('./transpiler.js');
|
|
12
10
|
|
|
13
|
-
console.log(__dirname);
|
|
14
11
|
// FUNCTION TO PROCESS CHUNKS OF SCRIPTS FROM THE INPUT FILE USING THE VM MODULE
|
|
15
12
|
const processScript = (scriptBlock) => {
|
|
16
|
-
//const output = 'cssOutput = undefined;';
|
|
17
13
|
const context = vm.createContext({
|
|
18
14
|
...transpilerModule
|
|
19
15
|
});
|
|
@@ -35,6 +31,12 @@ const minifyCss = (css) => {
|
|
|
35
31
|
|
|
36
32
|
// FUNCTION TO CONVERT JS CODES TO CSS CODE
|
|
37
33
|
const processor = (inputFile, outputFile) => {
|
|
34
|
+
const allowedExtensions = ['.jcss'];
|
|
35
|
+
const fileExt = path.extname(inputFile).toLowerCase();
|
|
36
|
+
|
|
37
|
+
if (!allowedExtensions.includes(fileExt)) {
|
|
38
|
+
throw new Error(`Invalid file extension: ${fileExt}. Only .jcss files are allowed.`);
|
|
39
|
+
}
|
|
38
40
|
const input = path.resolve(inputFile);
|
|
39
41
|
const content = fs.readFileSync(input, 'utf8');
|
|
40
42
|
const blocks = content.split(/<@([\s\S]*?)@>/gm);
|
package/package.json
CHANGED
package/transpiler.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
1
3
|
const chain = {
|
|
2
4
|
cssOutput : undefined,
|
|
3
5
|
catcher: {},
|
|
@@ -193,10 +195,13 @@ const compile = (obj) => {
|
|
|
193
195
|
for (const key in obj) {
|
|
194
196
|
if (obj.hasOwnProperty(key)) {
|
|
195
197
|
const element = obj[key];
|
|
196
|
-
let selectors = element.selectors || [];
|
|
198
|
+
let selectors = element.selectors || []; // Provide default empty array if selectors is undefined
|
|
197
199
|
let elementCSS = '';
|
|
198
|
-
|
|
200
|
+
console.log('Problematic element:', element);
|
|
201
|
+
console.log('Type of element:', typeof element);
|
|
202
|
+
console.log('Is element null?', element === null);
|
|
199
203
|
for (let prop in element) {
|
|
204
|
+
|
|
200
205
|
if (element.hasOwnProperty(prop) && prop !== 'selectors') {
|
|
201
206
|
// Convert camelCase to kebab-case
|
|
202
207
|
const kebabKey = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
@@ -212,12 +217,35 @@ const compile = (obj) => {
|
|
|
212
217
|
chain.cssOutput = cssString;
|
|
213
218
|
};
|
|
214
219
|
|
|
215
|
-
const get =
|
|
220
|
+
const get = (filename) => {
|
|
221
|
+
console.log('get() called with:', filename);
|
|
222
|
+
console.log('Current working directory:', process.cwd());
|
|
223
|
+
|
|
224
|
+
const fileExt = path.extname(filename).toLowerCase();
|
|
225
|
+
if (fileExt !== '.jcss') {
|
|
226
|
+
throw new Error(`Import error: ${filename} must have .jcss extension`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Try to resolve the path
|
|
230
|
+
const resolvedPath = path.resolve(process.cwd(), filename);
|
|
231
|
+
console.log('Resolved path:', resolvedPath);
|
|
232
|
+
|
|
233
|
+
// Check if file exists
|
|
234
|
+
const exists = fs.existsSync(resolvedPath);
|
|
235
|
+
console.log('File exists?', exists);
|
|
236
|
+
|
|
237
|
+
if (!exists) {
|
|
238
|
+
throw new Error(`File not found: ${filename} (resolved to: ${resolvedPath})`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return require(resolvedPath);
|
|
242
|
+
};
|
|
216
243
|
|
|
217
244
|
if (typeof global !== 'undefined') {
|
|
218
245
|
global.chain = chain;
|
|
219
246
|
}
|
|
220
247
|
|
|
248
|
+
|
|
221
249
|
module.exports = {
|
|
222
250
|
chain,
|
|
223
251
|
run,
|