@ryanatkn/gro 0.151.1 → 0.151.2
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/dist/gro.config.default.d.ts.map +1 -1
- package/dist/gro.config.default.js +3 -1
- package/dist/package.d.ts +3 -14
- package/dist/package.d.ts.map +1 -1
- package/dist/package.js +4 -15
- package/package.json +5 -6
- package/src/lib/gro.config.default.ts +3 -1
- package/src/lib/package.ts +4 -15
- package/dist/gro_plugin_moss.d.ts +0 -15
- package/dist/gro_plugin_moss.d.ts.map +0 -1
- package/dist/gro_plugin_moss.js +0 -70
- package/src/lib/gro_plugin_moss.ts +0 -105
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gro.config.default.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro.config.default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAQvD;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"gro.config.default.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro.config.default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAQvD;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,EAAE,iBA0Bb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -23,7 +23,9 @@ const config = async (cfg) => {
|
|
|
23
23
|
]);
|
|
24
24
|
cfg.plugins = async () => [
|
|
25
25
|
// put things that generate files before SvelteKit so it can see them
|
|
26
|
-
has_moss_dep
|
|
26
|
+
has_moss_dep
|
|
27
|
+
? (await import('@ryanatkn/moss/gro_plugin_moss.js')).gro_plugin_moss()
|
|
28
|
+
: null, // lazy load to avoid errors if it's not installed
|
|
27
29
|
gro_plugin_gen(),
|
|
28
30
|
has_server_result.ok ? gro_plugin_server() : null,
|
|
29
31
|
has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
|
package/dist/package.d.ts
CHANGED
|
@@ -75,6 +75,9 @@ export declare const package_json: {
|
|
|
75
75
|
'typescript-eslint': string;
|
|
76
76
|
uvu: string;
|
|
77
77
|
};
|
|
78
|
+
optionalDependencies: {
|
|
79
|
+
'@ryanatkn/moss': string;
|
|
80
|
+
};
|
|
78
81
|
prettier: {
|
|
79
82
|
plugins: string[];
|
|
80
83
|
useTabs: boolean;
|
|
@@ -232,10 +235,6 @@ export declare const package_json: {
|
|
|
232
235
|
types: string;
|
|
233
236
|
default: string;
|
|
234
237
|
};
|
|
235
|
-
'./gro_plugin_moss.js': {
|
|
236
|
-
types: string;
|
|
237
|
-
default: string;
|
|
238
|
-
};
|
|
239
238
|
'./gro_plugin_server.js': {
|
|
240
239
|
types: string;
|
|
241
240
|
default: string;
|
|
@@ -747,16 +746,6 @@ export declare const src_json: {
|
|
|
747
746
|
kind: "function";
|
|
748
747
|
})[];
|
|
749
748
|
};
|
|
750
|
-
'./gro_plugin_moss.js': {
|
|
751
|
-
path: string;
|
|
752
|
-
declarations: ({
|
|
753
|
-
name: string;
|
|
754
|
-
kind: "type";
|
|
755
|
-
} | {
|
|
756
|
-
name: string;
|
|
757
|
-
kind: "function";
|
|
758
|
-
})[];
|
|
759
|
-
};
|
|
760
749
|
'./gro_plugin_server.js': {
|
|
761
750
|
path: string;
|
|
762
751
|
declarations: ({
|
package/dist/package.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY
|
|
1
|
+
{"version":3,"file":"package.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmQD,CAAC;AAEzB,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwwBD,CAAC"}
|
package/dist/package.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// generated by src/lib/package.gen.ts
|
|
2
2
|
export const package_json = {
|
|
3
3
|
name: '@ryanatkn/gro',
|
|
4
|
-
version: '0.151.
|
|
4
|
+
version: '0.151.2',
|
|
5
5
|
description: 'task runner and toolkit extending SvelteKit',
|
|
6
6
|
motto: 'generate, run, optimize',
|
|
7
7
|
glyph: '🌰',
|
|
@@ -57,7 +57,7 @@ export const package_json = {
|
|
|
57
57
|
'@changesets/types': '^6.1.0',
|
|
58
58
|
'@ryanatkn/eslint-config': '^0.8.0',
|
|
59
59
|
'@ryanatkn/fuz': '^0.139.0',
|
|
60
|
-
'@ryanatkn/moss': '^0.
|
|
60
|
+
'@ryanatkn/moss': '^0.26.0',
|
|
61
61
|
'@sveltejs/adapter-static': '^3.0.8',
|
|
62
62
|
'@sveltejs/kit': '^2.20.7',
|
|
63
63
|
'@sveltejs/package': '^2.3.11',
|
|
@@ -72,6 +72,7 @@ export const package_json = {
|
|
|
72
72
|
'typescript-eslint': '^8.30.1',
|
|
73
73
|
uvu: '^0.5.6',
|
|
74
74
|
},
|
|
75
|
+
optionalDependencies: { '@ryanatkn/moss': '^0.26.0' },
|
|
75
76
|
prettier: {
|
|
76
77
|
plugins: ['prettier-plugin-svelte'],
|
|
77
78
|
useTabs: true,
|
|
@@ -155,10 +156,6 @@ export const package_json = {
|
|
|
155
156
|
types: './dist/gro_plugin_gen.d.ts',
|
|
156
157
|
default: './dist/gro_plugin_gen.js',
|
|
157
158
|
},
|
|
158
|
-
'./gro_plugin_moss.js': {
|
|
159
|
-
types: './dist/gro_plugin_moss.d.ts',
|
|
160
|
-
default: './dist/gro_plugin_moss.js',
|
|
161
|
-
},
|
|
162
159
|
'./gro_plugin_server.js': {
|
|
163
160
|
types: './dist/gro_plugin_server.d.ts',
|
|
164
161
|
default: './dist/gro_plugin_server.js',
|
|
@@ -263,7 +260,7 @@ export const package_json = {
|
|
|
263
260
|
};
|
|
264
261
|
export const src_json = {
|
|
265
262
|
name: '@ryanatkn/gro',
|
|
266
|
-
version: '0.151.
|
|
263
|
+
version: '0.151.2',
|
|
267
264
|
modules: {
|
|
268
265
|
'.': {
|
|
269
266
|
path: 'index.ts',
|
|
@@ -603,14 +600,6 @@ export const src_json = {
|
|
|
603
600
|
{ name: 'gro_plugin_gen', kind: 'function' },
|
|
604
601
|
],
|
|
605
602
|
},
|
|
606
|
-
'./gro_plugin_moss.js': {
|
|
607
|
-
path: 'gro_plugin_moss.ts',
|
|
608
|
-
declarations: [
|
|
609
|
-
{ name: 'Task_Args', kind: 'type' },
|
|
610
|
-
{ name: 'Gro_Plugin_Moss_Options', kind: 'type' },
|
|
611
|
-
{ name: 'gro_plugin_moss', kind: 'function' },
|
|
612
|
-
],
|
|
613
|
-
},
|
|
614
603
|
'./gro_plugin_server.js': {
|
|
615
604
|
path: 'gro_plugin_server.ts',
|
|
616
605
|
declarations: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryanatkn/gro",
|
|
3
|
-
"version": "0.151.
|
|
3
|
+
"version": "0.151.2",
|
|
4
4
|
"description": "task runner and toolkit extending SvelteKit",
|
|
5
5
|
"motto": "generate, run, optimize",
|
|
6
6
|
"glyph": "🌰",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@changesets/types": "^6.1.0",
|
|
71
71
|
"@ryanatkn/eslint-config": "^0.8.0",
|
|
72
72
|
"@ryanatkn/fuz": "^0.139.0",
|
|
73
|
-
"@ryanatkn/moss": "^0.
|
|
73
|
+
"@ryanatkn/moss": "^0.26.0",
|
|
74
74
|
"@sveltejs/adapter-static": "^3.0.8",
|
|
75
75
|
"@sveltejs/kit": "^2.20.7",
|
|
76
76
|
"@sveltejs/package": "^2.3.11",
|
|
@@ -85,6 +85,9 @@
|
|
|
85
85
|
"typescript-eslint": "^8.30.1",
|
|
86
86
|
"uvu": "^0.5.6"
|
|
87
87
|
},
|
|
88
|
+
"optionalDependencies": {
|
|
89
|
+
"@ryanatkn/moss": "^0.26.0"
|
|
90
|
+
},
|
|
88
91
|
"prettier": {
|
|
89
92
|
"plugins": [
|
|
90
93
|
"prettier-plugin-svelte"
|
|
@@ -253,10 +256,6 @@
|
|
|
253
256
|
"types": "./dist/gro_plugin_gen.d.ts",
|
|
254
257
|
"default": "./dist/gro_plugin_gen.js"
|
|
255
258
|
},
|
|
256
|
-
"./gro_plugin_moss.js": {
|
|
257
|
-
"types": "./dist/gro_plugin_moss.d.ts",
|
|
258
|
-
"default": "./dist/gro_plugin_moss.js"
|
|
259
|
-
},
|
|
260
259
|
"./gro_plugin_server.js": {
|
|
261
260
|
"types": "./dist/gro_plugin_server.d.ts",
|
|
262
261
|
"default": "./dist/gro_plugin_server.js"
|
|
@@ -29,7 +29,9 @@ const config: Create_Gro_Config = async (cfg) => {
|
|
|
29
29
|
cfg.plugins = async () =>
|
|
30
30
|
[
|
|
31
31
|
// put things that generate files before SvelteKit so it can see them
|
|
32
|
-
has_moss_dep
|
|
32
|
+
has_moss_dep
|
|
33
|
+
? ((await import('@ryanatkn/moss/gro_plugin_moss.js')) as any).gro_plugin_moss()
|
|
34
|
+
: null, // lazy load to avoid errors if it's not installed
|
|
33
35
|
gro_plugin_gen(),
|
|
34
36
|
has_server_result.ok ? gro_plugin_server() : null,
|
|
35
37
|
has_sveltekit_library_result.ok ? gro_plugin_sveltekit_library() : null,
|
package/src/lib/package.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {Src_Json} from './src_json.js';
|
|
|
5
5
|
|
|
6
6
|
export const package_json = {
|
|
7
7
|
name: '@ryanatkn/gro',
|
|
8
|
-
version: '0.151.
|
|
8
|
+
version: '0.151.2',
|
|
9
9
|
description: 'task runner and toolkit extending SvelteKit',
|
|
10
10
|
motto: 'generate, run, optimize',
|
|
11
11
|
glyph: '🌰',
|
|
@@ -62,7 +62,7 @@ export const package_json = {
|
|
|
62
62
|
'@changesets/types': '^6.1.0',
|
|
63
63
|
'@ryanatkn/eslint-config': '^0.8.0',
|
|
64
64
|
'@ryanatkn/fuz': '^0.139.0',
|
|
65
|
-
'@ryanatkn/moss': '^0.
|
|
65
|
+
'@ryanatkn/moss': '^0.26.0',
|
|
66
66
|
'@sveltejs/adapter-static': '^3.0.8',
|
|
67
67
|
'@sveltejs/kit': '^2.20.7',
|
|
68
68
|
'@sveltejs/package': '^2.3.11',
|
|
@@ -77,6 +77,7 @@ export const package_json = {
|
|
|
77
77
|
'typescript-eslint': '^8.30.1',
|
|
78
78
|
uvu: '^0.5.6',
|
|
79
79
|
},
|
|
80
|
+
optionalDependencies: {'@ryanatkn/moss': '^0.26.0'},
|
|
80
81
|
prettier: {
|
|
81
82
|
plugins: ['prettier-plugin-svelte'],
|
|
82
83
|
useTabs: true,
|
|
@@ -160,10 +161,6 @@ export const package_json = {
|
|
|
160
161
|
types: './dist/gro_plugin_gen.d.ts',
|
|
161
162
|
default: './dist/gro_plugin_gen.js',
|
|
162
163
|
},
|
|
163
|
-
'./gro_plugin_moss.js': {
|
|
164
|
-
types: './dist/gro_plugin_moss.d.ts',
|
|
165
|
-
default: './dist/gro_plugin_moss.js',
|
|
166
|
-
},
|
|
167
164
|
'./gro_plugin_server.js': {
|
|
168
165
|
types: './dist/gro_plugin_server.d.ts',
|
|
169
166
|
default: './dist/gro_plugin_server.js',
|
|
@@ -269,7 +266,7 @@ export const package_json = {
|
|
|
269
266
|
|
|
270
267
|
export const src_json = {
|
|
271
268
|
name: '@ryanatkn/gro',
|
|
272
|
-
version: '0.151.
|
|
269
|
+
version: '0.151.2',
|
|
273
270
|
modules: {
|
|
274
271
|
'.': {
|
|
275
272
|
path: 'index.ts',
|
|
@@ -609,14 +606,6 @@ export const src_json = {
|
|
|
609
606
|
{name: 'gro_plugin_gen', kind: 'function'},
|
|
610
607
|
],
|
|
611
608
|
},
|
|
612
|
-
'./gro_plugin_moss.js': {
|
|
613
|
-
path: 'gro_plugin_moss.ts',
|
|
614
|
-
declarations: [
|
|
615
|
-
{name: 'Task_Args', kind: 'type'},
|
|
616
|
-
{name: 'Gro_Plugin_Moss_Options', kind: 'type'},
|
|
617
|
-
{name: 'gro_plugin_moss', kind: 'function'},
|
|
618
|
-
],
|
|
619
|
-
},
|
|
620
609
|
'./gro_plugin_server.js': {
|
|
621
610
|
path: 'gro_plugin_server.ts',
|
|
622
611
|
declarations: [
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from './plugin.js';
|
|
2
|
-
import type { Args } from './args.js';
|
|
3
|
-
import type { File_Filter } from './path.js';
|
|
4
|
-
export interface Task_Args extends Args {
|
|
5
|
-
watch?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface Gro_Plugin_Moss_Options {
|
|
8
|
-
include_classes?: Array<string> | Set<string> | null;
|
|
9
|
-
outfile?: string;
|
|
10
|
-
filter_file?: File_Filter | null;
|
|
11
|
-
flush_debounce_delay?: number;
|
|
12
|
-
banner?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare const gro_plugin_moss: ({ include_classes, outfile, filter_file, flush_debounce_delay, banner, }?: Gro_Plugin_Moss_Options) => Plugin;
|
|
15
|
-
//# sourceMappingURL=gro_plugin_moss.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gro_plugin_moss.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_moss.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAGpC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAI3C,MAAM,WAAW,SAAU,SAAQ,IAAI;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,uBAAuB;IACvC,eAAe,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACjC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,eAAe,GAAI,2EAM7B,uBAAsC,KAAG,MAmE3C,CAAC"}
|
package/dist/gro_plugin_moss.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { EMPTY_OBJECT } from '@ryanatkn/belt/object.js';
|
|
2
|
-
import { throttle } from '@ryanatkn/belt/throttle.js';
|
|
3
|
-
import { Unreachable_Error } from '@ryanatkn/belt/error.js';
|
|
4
|
-
import { writeFileSync } from 'node:fs';
|
|
5
|
-
import { collect_css_classes, Css_Classes, generate_classes_css, } from '@ryanatkn/moss/css_class_helpers.js';
|
|
6
|
-
import { css_classes_by_name } from '@ryanatkn/moss/css_classes.js';
|
|
7
|
-
import { format_file } from './format_file.js';
|
|
8
|
-
const FLUSH_DEBOUNCE_DELAY = 500;
|
|
9
|
-
export const gro_plugin_moss = ({ include_classes = null, outfile = 'src/routes/moss.css', // TODO maybe support multiple files using file filters to check where to collect them?
|
|
10
|
-
filter_file = (p) => !p.includes('.test.') && !p.includes('/test/'), // TODO hacky, centralize this and maybe exclude other things like `.gen.` files
|
|
11
|
-
flush_debounce_delay = FLUSH_DEBOUNCE_DELAY, banner = 'generated by gro_plugin_moss', } = EMPTY_OBJECT) => {
|
|
12
|
-
const css_classes = new Css_Classes(Array.isArray(include_classes) ? new Set(include_classes) : include_classes);
|
|
13
|
-
let previous_output;
|
|
14
|
-
let flushing_timeout;
|
|
15
|
-
const queue_gen = () => {
|
|
16
|
-
if (flushing_timeout === undefined) {
|
|
17
|
-
flushing_timeout = setTimeout(() => {
|
|
18
|
-
flushing_timeout = undefined;
|
|
19
|
-
void flush_gen_queue();
|
|
20
|
-
}); // the timeout batches synchronously
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const flush_gen_queue = throttle(async () => {
|
|
24
|
-
const css = generate_classes_css(css_classes.get(), css_classes_by_name);
|
|
25
|
-
const contents = `/* ${banner} */\n\n${css}\n\n/* ${banner} */`;
|
|
26
|
-
const output = await format_file(contents, { filepath: outfile });
|
|
27
|
-
// TODO think about using gen to implement this, would have some nice benefits like automatic change detection
|
|
28
|
-
if (output === previous_output)
|
|
29
|
-
return;
|
|
30
|
-
previous_output = output;
|
|
31
|
-
writeFileSync(outfile, output);
|
|
32
|
-
}, { delay: flush_debounce_delay, when: 'trailing' });
|
|
33
|
-
let cleanup;
|
|
34
|
-
return {
|
|
35
|
-
name: 'gro_plugin_moss',
|
|
36
|
-
setup: async ({ filer }) => {
|
|
37
|
-
// When a file builds, check it and its tree of dependents
|
|
38
|
-
// for any `.gen.` files that need to run.
|
|
39
|
-
cleanup = await filer.watch((change, source_file) => {
|
|
40
|
-
if (filter_file && !filter_file(source_file.id)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
switch (change.type) {
|
|
44
|
-
case 'add':
|
|
45
|
-
case 'update': {
|
|
46
|
-
if (source_file.contents !== null) {
|
|
47
|
-
const classes = collect_css_classes(source_file.contents);
|
|
48
|
-
css_classes.add(source_file.id, classes);
|
|
49
|
-
queue_gen();
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
case 'delete': {
|
|
54
|
-
css_classes.delete(source_file.id);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
default:
|
|
58
|
-
throw new Unreachable_Error(change.type);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
queue_gen();
|
|
62
|
-
},
|
|
63
|
-
teardown: async () => {
|
|
64
|
-
if (cleanup !== undefined) {
|
|
65
|
-
await cleanup();
|
|
66
|
-
cleanup = undefined;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {EMPTY_OBJECT} from '@ryanatkn/belt/object.js';
|
|
2
|
-
import {throttle} from '@ryanatkn/belt/throttle.js';
|
|
3
|
-
import {Unreachable_Error} from '@ryanatkn/belt/error.js';
|
|
4
|
-
import {writeFileSync} from 'node:fs';
|
|
5
|
-
import {
|
|
6
|
-
collect_css_classes,
|
|
7
|
-
Css_Classes,
|
|
8
|
-
generate_classes_css,
|
|
9
|
-
} from '@ryanatkn/moss/css_class_helpers.js';
|
|
10
|
-
import {css_classes_by_name} from '@ryanatkn/moss/css_classes.js';
|
|
11
|
-
|
|
12
|
-
import type {Plugin} from './plugin.js';
|
|
13
|
-
import type {Args} from './args.js';
|
|
14
|
-
import type {Cleanup_Watch} from './filer.js';
|
|
15
|
-
import {format_file} from './format_file.js';
|
|
16
|
-
import type {File_Filter} from './path.js';
|
|
17
|
-
|
|
18
|
-
const FLUSH_DEBOUNCE_DELAY = 500;
|
|
19
|
-
|
|
20
|
-
export interface Task_Args extends Args {
|
|
21
|
-
watch?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface Gro_Plugin_Moss_Options {
|
|
25
|
-
include_classes?: Array<string> | Set<string> | null;
|
|
26
|
-
outfile?: string;
|
|
27
|
-
filter_file?: File_Filter | null;
|
|
28
|
-
flush_debounce_delay?: number;
|
|
29
|
-
banner?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const gro_plugin_moss = ({
|
|
33
|
-
include_classes = null,
|
|
34
|
-
outfile = 'src/routes/moss.css', // TODO maybe support multiple files using file filters to check where to collect them?
|
|
35
|
-
filter_file = (p) => !p.includes('.test.') && !p.includes('/test/'), // TODO hacky, centralize this and maybe exclude other things like `.gen.` files
|
|
36
|
-
flush_debounce_delay = FLUSH_DEBOUNCE_DELAY,
|
|
37
|
-
banner = 'generated by gro_plugin_moss',
|
|
38
|
-
}: Gro_Plugin_Moss_Options = EMPTY_OBJECT): Plugin => {
|
|
39
|
-
const css_classes = new Css_Classes(
|
|
40
|
-
Array.isArray(include_classes) ? new Set(include_classes) : include_classes,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
let previous_output: string | undefined;
|
|
44
|
-
|
|
45
|
-
let flushing_timeout: NodeJS.Timeout | undefined;
|
|
46
|
-
const queue_gen = () => {
|
|
47
|
-
if (flushing_timeout === undefined) {
|
|
48
|
-
flushing_timeout = setTimeout(() => {
|
|
49
|
-
flushing_timeout = undefined;
|
|
50
|
-
void flush_gen_queue();
|
|
51
|
-
}); // the timeout batches synchronously
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const flush_gen_queue = throttle(
|
|
55
|
-
async () => {
|
|
56
|
-
const css = generate_classes_css(css_classes.get(), css_classes_by_name);
|
|
57
|
-
const contents = `/* ${banner} */\n\n${css}\n\n/* ${banner} */`;
|
|
58
|
-
const output = await format_file(contents, {filepath: outfile});
|
|
59
|
-
// TODO think about using gen to implement this, would have some nice benefits like automatic change detection
|
|
60
|
-
if (output === previous_output) return;
|
|
61
|
-
previous_output = output;
|
|
62
|
-
writeFileSync(outfile, output);
|
|
63
|
-
},
|
|
64
|
-
{delay: flush_debounce_delay, when: 'trailing'},
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
let cleanup: Cleanup_Watch | undefined;
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
name: 'gro_plugin_moss',
|
|
71
|
-
setup: async ({filer}) => {
|
|
72
|
-
// When a file builds, check it and its tree of dependents
|
|
73
|
-
// for any `.gen.` files that need to run.
|
|
74
|
-
cleanup = await filer.watch((change, source_file) => {
|
|
75
|
-
if (filter_file && !filter_file(source_file.id)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
switch (change.type) {
|
|
79
|
-
case 'add':
|
|
80
|
-
case 'update': {
|
|
81
|
-
if (source_file.contents !== null) {
|
|
82
|
-
const classes = collect_css_classes(source_file.contents);
|
|
83
|
-
css_classes.add(source_file.id, classes);
|
|
84
|
-
queue_gen();
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
case 'delete': {
|
|
89
|
-
css_classes.delete(source_file.id);
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
default:
|
|
93
|
-
throw new Unreachable_Error(change.type);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
queue_gen();
|
|
97
|
-
},
|
|
98
|
-
teardown: async () => {
|
|
99
|
-
if (cleanup !== undefined) {
|
|
100
|
-
await cleanup();
|
|
101
|
-
cleanup = undefined;
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
};
|