@melcanz85/chaincss 1.5.5 → 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 +11 -12
- package/chaincss.js +6 -4
- package/package.json +1 -1
- package/transpiler.js +31 -3
package/README.md
CHANGED
|
@@ -30,7 +30,6 @@ json
|
|
|
30
30
|
Project Structure
|
|
31
31
|
|
|
32
32
|
Create this folder structure in your project:
|
|
33
|
-
text
|
|
34
33
|
|
|
35
34
|
your-project/
|
|
36
35
|
├── chaincss/ # ChainCSS source files
|
|
@@ -47,7 +46,6 @@ your-project/
|
|
|
47
46
|
Processor Setup
|
|
48
47
|
|
|
49
48
|
In chaincss/processor.js:
|
|
50
|
-
javascript
|
|
51
49
|
|
|
52
50
|
const jss = require("@melcanz85/chaincss");
|
|
53
51
|
|
|
@@ -55,13 +53,12 @@ try {
|
|
|
55
53
|
// Process main file and output CSS
|
|
56
54
|
jss.processJSS('./chaincss/chaincss.jcss', './public/chainstyle.css');
|
|
57
55
|
} catch (err) {
|
|
58
|
-
console.error('Error processing
|
|
56
|
+
console.error('Error processing chainCSS file:', err.stack);
|
|
59
57
|
process.exit(1);
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
💻 Code Examples
|
|
63
|
-
Main File (chaincss/chaincss.jcss)
|
|
64
|
-
javascript
|
|
61
|
+
Main File (chaincss/chaincss.jcss):
|
|
65
62
|
|
|
66
63
|
<@
|
|
67
64
|
// Import chaining definitions
|
|
@@ -87,8 +84,7 @@ javascript
|
|
|
87
84
|
@>
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
Chaining File (chaincss/chain.jcss)
|
|
91
|
-
javascript
|
|
87
|
+
Chaining File (chaincss/chain.jcss):
|
|
92
88
|
|
|
93
89
|
// Variables for consistent styling
|
|
94
90
|
const bodyBgColor = '#f0f0f0';
|
|
@@ -133,14 +129,14 @@ module.exports = {
|
|
|
133
129
|
};
|
|
134
130
|
|
|
135
131
|
📝 Notes
|
|
132
|
+
|
|
133
|
+
You can directly put css syntax on your main file.
|
|
136
134
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ChainCSS syntax must be wrapped in <@ @> delimiters
|
|
135
|
+
But chainCSS syntax must be wrapped in <@ @> delimiters.
|
|
140
136
|
|
|
141
137
|
The get() function imports chaining definitions from other files
|
|
142
138
|
|
|
143
|
-
|
|
139
|
+
YOU can modify your style in between get() and compile() in the main file it will override the styles in the chainn file.
|
|
144
140
|
|
|
145
141
|
🎨 Editor Support
|
|
146
142
|
|
|
@@ -148,7 +144,6 @@ Since .jcss files are just JavaScript files with ChainCSS syntax, you can easily
|
|
|
148
144
|
VS Code
|
|
149
145
|
|
|
150
146
|
Add this to your project's .vscode/settings.json:
|
|
151
|
-
json
|
|
152
147
|
|
|
153
148
|
{
|
|
154
149
|
"files.associations": {
|
|
@@ -196,6 +191,8 @@ coffeescript
|
|
|
196
191
|
Other Editors
|
|
197
192
|
|
|
198
193
|
Most modern editors allow you to associate file extensions with language modes. Simply configure your editor to treat .jcss files as JavaScript.
|
|
194
|
+
|
|
195
|
+
|
|
199
196
|
✨ Features
|
|
200
197
|
Status Feature Description
|
|
201
198
|
✅ Basic JS → CSS Convert plain JS objects to CSS
|
|
@@ -208,6 +205,8 @@ Status Feature Description
|
|
|
208
205
|
👨💻 Contributing
|
|
209
206
|
|
|
210
207
|
Contributions are welcome! Feel free to open issues or submit pull requests.
|
|
208
|
+
|
|
209
|
+
|
|
211
210
|
📄 License
|
|
212
211
|
|
|
213
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,
|