Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Oct 8, 2024
1 parent fcd9a84 commit db9cea9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib/gro_plugin_moss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export const gro_plugin_moss = ({
Array.isArray(include_classes) ? new Set(include_classes) : include_classes,
);

let previous_output: string | undefined;

let flushing_timeout: NodeJS.Timeout | undefined;
const queue_gen = () => {
console.log(`queue_gen`);
if (flushing_timeout === undefined) {
flushing_timeout = setTimeout(() => {
flushing_timeout = undefined;
Expand All @@ -67,9 +68,11 @@ export const gro_plugin_moss = ({
const flush_gen_queue = throttle(
async () => {
const css = generate_classes_css(css_classes.get_sorted_array());
console.log('WRITING FILE', css.length);
const formatted = await format_file(css, {filepath: outfile});
writeFileSync(outfile, formatted); // TODO BLOCK what if this was implemented using gen?
const output = await format_file(css, {filepath: outfile});
// TODO think about using gen to implement this, would have some nice benefits like automatic change detection
if (output === previous_output) return;
previous_output = output;
writeFileSync(outfile, output);
},
flush_debounce_delay,
false,
Expand All @@ -86,13 +89,11 @@ export const gro_plugin_moss = ({
if (filter_file && !filter_file(source_file.id)) {
return;
}
console.log(`change, source_file.id`, change.type, source_file.id);
switch (change.type) {
case 'add':
case 'update': {
if (source_file.contents !== null) {
const classes = collect_css_classes(source_file.contents);
console.log(`COLLECTED classes`, classes);
css_classes.add(source_file.id, classes);
queue_gen();
}
Expand All @@ -106,7 +107,6 @@ export const gro_plugin_moss = ({
throw new Unreachable_Error(change.type);
}
});
console.log('inited'); // TODO BLOCK should this re-enable generation now?
queue_gen();
},
teardown: async () => {
Expand Down

0 comments on commit db9cea9

Please sign in to comment.