xatriumcss 1.0.13 ā 1.0.15
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/package.json +1 -1
- package/src/cli.js +57 -34
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -12,10 +12,10 @@ function parseArgs(argv) {
|
|
|
12
12
|
'--output': null,
|
|
13
13
|
'--watch': false
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
for (let i = 0; i < argv.length; i++) {
|
|
17
17
|
const arg = argv[i];
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
if (arg === '--watch' || arg === '-w') {
|
|
20
20
|
args['--watch'] = true;
|
|
21
21
|
} else if (arg === '--input' || arg === '-i') {
|
|
@@ -24,7 +24,7 @@ function parseArgs(argv) {
|
|
|
24
24
|
args['--output'] = argv[++i];
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
return args;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -44,12 +44,12 @@ config.output = path.resolve(projectRoot, config.output);
|
|
|
44
44
|
|
|
45
45
|
function build() {
|
|
46
46
|
const startTime = process.hrtime.bigint();
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
console.log('š Checking for @import "xatriumcss"...');
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
// Check if input CSS has the import
|
|
51
51
|
const hasImport = hasXatriumImport(config.input);
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
if (!hasImport) {
|
|
54
54
|
console.log('ā ļø No @import "xatriumcss" found - writing empty CSS');
|
|
55
55
|
const outputDir = path.dirname(config.output);
|
|
@@ -57,24 +57,24 @@ function build() {
|
|
|
57
57
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
58
58
|
}
|
|
59
59
|
fs.writeFileSync(config.output, '', 'utf-8');
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
const endTime = process.hrtime.bigint();
|
|
62
62
|
const duration = endTime - startTime;
|
|
63
63
|
console.log(`ā
Done in ${formatTime(duration)}`);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
runParser(config);
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
const endTime = process.hrtime.bigint();
|
|
70
70
|
const duration = endTime - startTime;
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
console.log(`ā
Done in ${formatTime(duration)}`);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function formatTime(nanoseconds) {
|
|
76
76
|
const ms = Number(nanoseconds) / 1_000_000;
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
if (ms < 1000) return `${Math.round(ms)}ms`;
|
|
79
79
|
return `${(ms / 1000).toFixed(2)}s`;
|
|
80
80
|
}
|
|
@@ -89,96 +89,119 @@ function formatTime(nanoseconds) {
|
|
|
89
89
|
process.exit(1);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
// Watch mode
|
|
92
93
|
// Watch mode
|
|
93
94
|
if (args['--watch']) {
|
|
94
95
|
console.log('\nš Watch mode enabled\n');
|
|
95
96
|
console.log('\nš Watching for changes...\n');
|
|
96
|
-
|
|
97
|
+
|
|
97
98
|
const changedFiles = new Set();
|
|
98
99
|
let rebuildTimer = null;
|
|
99
|
-
|
|
100
|
+
let isBuilding = false; // ā ADD THIS FLAG
|
|
101
|
+
|
|
100
102
|
function scheduleRebuild() {
|
|
101
|
-
if (rebuildTimer) return;
|
|
102
|
-
|
|
103
|
+
if (rebuildTimer || isBuilding) return; // ā Check if building
|
|
104
|
+
|
|
103
105
|
rebuildTimer = setTimeout(() => {
|
|
104
106
|
const files = Array.from(changedFiles);
|
|
105
107
|
changedFiles.clear();
|
|
106
108
|
rebuildTimer = null;
|
|
107
|
-
|
|
109
|
+
|
|
110
|
+
isBuilding = true; // ā Set flag
|
|
108
111
|
try {
|
|
109
112
|
build();
|
|
110
113
|
} catch (error) {
|
|
111
114
|
console.error('ā Build error:', error.message);
|
|
115
|
+
} finally {
|
|
116
|
+
isBuilding = false; // ā Clear flag
|
|
112
117
|
}
|
|
113
|
-
},
|
|
118
|
+
}, 100); // ā Increase to 100ms
|
|
114
119
|
}
|
|
115
|
-
|
|
120
|
+
|
|
116
121
|
// Get directories to watch
|
|
117
122
|
const watchDirs = new Set();
|
|
118
123
|
const contentPatterns = Array.isArray(config.content) ? config.content : [config.content];
|
|
119
|
-
|
|
124
|
+
|
|
125
|
+
// Normalize output path for comparison
|
|
126
|
+
const normalizedOutput = path.normalize(config.output).toLowerCase();
|
|
127
|
+
|
|
120
128
|
for (const pattern of contentPatterns) {
|
|
121
129
|
const baseDir = pattern.split('**')[0].replace(/\*/g, '');
|
|
122
130
|
const resolvedDir = path.resolve(projectRoot, baseDir || '.');
|
|
123
|
-
|
|
131
|
+
|
|
124
132
|
if (fs.existsSync(resolvedDir)) {
|
|
125
133
|
watchDirs.add(resolvedDir);
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
|
-
|
|
136
|
+
|
|
129
137
|
// IMPORTANT: Watch the input CSS directory
|
|
130
138
|
const inputDir = path.dirname(config.input);
|
|
131
139
|
if (fs.existsSync(inputDir)) {
|
|
132
140
|
watchDirs.add(inputDir);
|
|
133
141
|
}
|
|
134
|
-
|
|
142
|
+
|
|
143
|
+
console.log('šļø Watching directories:', Array.from(watchDirs));
|
|
144
|
+
|
|
135
145
|
// Subscribe to file changes
|
|
136
146
|
const subscriptions = [];
|
|
137
|
-
|
|
147
|
+
|
|
138
148
|
for (const dir of watchDirs) {
|
|
139
149
|
const subscription = await watcher.subscribe(dir, (err, events) => {
|
|
140
150
|
if (err) {
|
|
141
151
|
console.error('ā Watcher error:', err);
|
|
142
152
|
return;
|
|
143
153
|
}
|
|
144
|
-
|
|
154
|
+
|
|
145
155
|
for (const event of events) {
|
|
146
156
|
if (event.type === 'delete') continue;
|
|
147
157
|
|
|
158
|
+
// Normalize paths for comparison
|
|
159
|
+
const normalizedPath = path.normalize(event.path).toLowerCase();
|
|
160
|
+
|
|
148
161
|
// CRITICAL: Ignore output file to prevent infinite loop
|
|
149
|
-
if (
|
|
162
|
+
if (normalizedPath === normalizedOutput) {
|
|
163
|
+
console.log('š« Ignoring output file change');
|
|
150
164
|
continue;
|
|
151
165
|
}
|
|
152
|
-
|
|
166
|
+
|
|
167
|
+
// Also ignore the entire output directory
|
|
168
|
+
if (normalizedPath.startsWith(path.dirname(normalizedOutput).toLowerCase())) {
|
|
169
|
+
const isOutputDir = path.dirname(normalizedPath) === path.dirname(normalizedOutput).toLowerCase();
|
|
170
|
+
if (isOutputDir) {
|
|
171
|
+
console.log('š« Ignoring output directory change');
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
153
176
|
const ext = path.extname(event.path);
|
|
154
|
-
const isInputFile = path.
|
|
155
|
-
|
|
177
|
+
const isInputFile = path.normalize(event.path).toLowerCase() === path.normalize(config.input).toLowerCase();
|
|
178
|
+
|
|
156
179
|
// Watch input CSS and content files
|
|
157
180
|
if (isInputFile || ['.html', '.jsx', '.js', '.ts', '.tsx', '.vue', '.css'].includes(ext)) {
|
|
158
181
|
changedFiles.add(event.path);
|
|
159
182
|
console.log('š Changed:', path.relative(projectRoot, event.path));
|
|
160
183
|
}
|
|
161
184
|
}
|
|
162
|
-
|
|
185
|
+
|
|
163
186
|
if (changedFiles.size > 0) {
|
|
164
187
|
scheduleRebuild();
|
|
165
188
|
}
|
|
166
189
|
});
|
|
167
|
-
|
|
190
|
+
|
|
168
191
|
subscriptions.push(subscription);
|
|
169
192
|
}
|
|
170
|
-
|
|
193
|
+
|
|
171
194
|
// Cleanup on exit
|
|
172
195
|
process.on('SIGINT', async () => {
|
|
173
196
|
console.log('\n\nš Shutting down...');
|
|
174
|
-
|
|
197
|
+
|
|
175
198
|
for (const sub of subscriptions) {
|
|
176
199
|
await sub.unsubscribe();
|
|
177
200
|
}
|
|
178
|
-
|
|
201
|
+
|
|
179
202
|
process.exit(0);
|
|
180
203
|
});
|
|
181
|
-
|
|
204
|
+
|
|
182
205
|
process.stdin.resume();
|
|
183
206
|
}
|
|
184
207
|
})();
|