@vertesia/plugin-builder 0.56.0

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Composable
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/lib/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ interface VertesiaPluginBuilderOptions {
2
+ cssVar?: string;
3
+ input?: string;
4
+ output?: string;
5
+ }
6
+ export declare function vertesiaPluginBuilder({ cssVar, input, output, }?: VertesiaPluginBuilderOptions): {
7
+ name: string;
8
+ apply: "build";
9
+ enforce: "post";
10
+ resolveId(this: import("rollup").PluginContext, id: string): "virtual:vertesia-plugin-css-entry" | null;
11
+ load(this: import("rollup").PluginContext, id: string): string | null;
12
+ buildStart(this: import("rollup").PluginContext): void;
13
+ generateBundle(this: import("rollup").PluginContext, _options: import("rollup").NormalizedOutputOptions, bundle: import("rollup").OutputBundle): void;
14
+ writeBundle(this: import("rollup").PluginContext, options: import("rollup").NormalizedOutputOptions, bundle: import("rollup").OutputBundle): void;
15
+ };
16
+ export {};
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,UAAU,4BAA4B;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AACD,wBAAgB,qBAAqB,CAAC,EAClC,MAAM,EACN,KAAK,EACL,MAAM,GACT,GAAE,4BAAiC;;WAQV,OAAO;;;;;;;EA8ChC"}
package/lib/index.js ADDED
@@ -0,0 +1,61 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { extractTailwindUtilitiesLayer } from "./parse-css.js";
4
+ export function vertesiaPluginBuilder({ cssVar, input, output, } = {}) {
5
+ const CSS_VAR = cssVar || 'css';
6
+ if (!input)
7
+ input = 'src/index.css';
8
+ if (!output)
9
+ output = 'plugin.css';
10
+ const inputRelative = input.startsWith('./') ? input : `./${input}`;
11
+ const jsOutput = output.replace('.css', '.js');
12
+ return {
13
+ name: 'vertesia-plugin-builder',
14
+ apply: 'build',
15
+ enforce: 'post',
16
+ resolveId(id) {
17
+ // Create a virtual CSS entry module
18
+ if (id === 'virtual:vertesia-plugin-css-entry') {
19
+ return id;
20
+ }
21
+ return null;
22
+ },
23
+ load(id) {
24
+ if (id === 'virtual:vertesia-plugin-css-entry') {
25
+ // This creates a virtual JS file that imports your actual CSS
26
+ return `import "${inputRelative}";`;
27
+ }
28
+ return null;
29
+ },
30
+ buildStart() {
31
+ // This emits the file into the build pipeline
32
+ this.emitFile({
33
+ type: 'chunk',
34
+ fileName: 'virtual-vertesia-plugin-css-entry.js',
35
+ id: 'virtual:vertesia-plugin-css-entry',
36
+ });
37
+ },
38
+ generateBundle(_options, bundle) {
39
+ delete bundle['virtual-vertesia-plugin-css-entry.js'];
40
+ },
41
+ writeBundle(options, bundle) {
42
+ // Look for the generated CSS file in the output directory
43
+ const keys = Object.keys(bundle).filter(k => k === output);
44
+ if (keys.length === 1) {
45
+ const asset = bundle[jsOutput];
46
+ if (asset) {
47
+ const cssContent = readFileSync(join(options.dir, output), 'utf8');
48
+ if (cssContent) {
49
+ const exportedContent = extractTailwindUtilitiesLayer(cssContent);
50
+ if (exportedContent) {
51
+ const jsFile = join(options.dir, jsOutput);
52
+ const jsContent = readFileSync(jsFile, 'utf8');
53
+ writeFileSync(jsFile, `${jsContent}\nexport const ${CSS_VAR} = \`\n${exportedContent}\n\`;\n`);
54
+ }
55
+ }
56
+ }
57
+ }
58
+ },
59
+ };
60
+ }
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAS/D,MAAM,UAAU,qBAAqB,CAAC,EAClC,MAAM,EACN,KAAK,EACL,MAAM,MACwB,EAAE;IAChC,MAAM,OAAO,GAAG,MAAM,IAAI,KAAK,CAAC;IAChC,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,eAAe,CAAC;IACpC,IAAI,CAAC,MAAM;QAAE,MAAM,GAAG,YAAY,CAAC;IACnC,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO;QACH,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE,OAAkB;QACzB,OAAO,EAAE,MAAM;QACf,SAAS,CAAC,EAAE;YACR,oCAAoC;YACpC,IAAI,EAAE,KAAK,mCAAmC,EAAE,CAAC;gBAC7C,OAAO,EAAE,CAAC;YACd,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,EAAE;YACH,IAAI,EAAE,KAAK,mCAAmC,EAAE,CAAC;gBAC7C,8DAA8D;gBAC9D,OAAO,WAAW,aAAa,IAAI,CAAC;YACxC,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD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0 +1 @@
1
+ {"version":3,"file":"parse-css.d.ts","sourceRoot":"","sources":["../src/parse-css.ts"],"names":[],"mappings":"AAGA,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,UAiB5D"}
@@ -0,0 +1,20 @@
1
+ import { parse, stringify } from '@adobe/css-tools';
2
+ export function extractTailwindUtilitiesLayer(content) {
3
+ let obj = parse(content, {});
4
+ let result = '';
5
+ for (const rule of obj.stylesheet.rules) {
6
+ if (rule.type === 'layer' && rule.layer === 'utilities') {
7
+ if (rule.rules) {
8
+ const output = {
9
+ type: 'stylesheet',
10
+ stylesheet: {
11
+ rules: rule.rules
12
+ }
13
+ };
14
+ result = stringify(output, {});
15
+ }
16
+ }
17
+ }
18
+ return result;
19
+ }
20
+ //# sourceMappingURL=parse-css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-css.js","sourceRoot":"","sources":["../src/parse-css.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEtE,MAAM,UAAU,6BAA6B,CAAC,OAAe;IACzD,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;YACtD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,MAAM,MAAM,GAAG;oBACX,IAAI,EAAE,YAAY;oBAClB,UAAU,EAAE;wBACR,KAAK,EAAE,IAAI,CAAC,KAAK;qBACpB;iBACgB,CAAC;gBACtB,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACnC,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@vertesia/plugin-builder",
3
+ "version": "0.56.0",
4
+ "description": "A vite plugin to build vertesia UI plugins",
5
+ "type": "module",
6
+ "types": "./lib/index.d.ts",
7
+ "main": "./lib/index.js",
8
+ "files": [
9
+ "lib",
10
+ "src"
11
+ ],
12
+ "license": "MIT",
13
+ "homepage": "https://composableprompts.com/docs",
14
+ "keywords": [
15
+ "llm",
16
+ "streaming",
17
+ "composable",
18
+ "prompt",
19
+ "ai",
20
+ "react"
21
+ ],
22
+ "devDependencies": {
23
+ "typescript": "^5.0.2"
24
+ },
25
+ "dependencies": {
26
+ "@adobe/css-tools": "^4.4.1",
27
+ "@types/node": "^22.13.1"
28
+ },
29
+ "peerDependencies": {
30
+ "vite": ">=4.2.0"
31
+ },
32
+ "scripts": {
33
+ "eslint": "eslint './src/**/*.{jsx,js,tsx,ts}'",
34
+ "build": "rm -rf ./lib ./tsconfig.tsbuildinfo && tsc",
35
+ "clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo"
36
+ }
37
+ }
package/src/index.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { Plugin } from "vite";
4
+ import { extractTailwindUtilitiesLayer } from "./parse-css.js";
5
+
6
+ interface VertesiaPluginBuilderOptions {
7
+ cssVar?: string;
8
+ // the input file. defaults to src/index.css
9
+ input?: string;
10
+ // the output file name. Defaults to index.css
11
+ output?: string;
12
+ }
13
+ export function vertesiaPluginBuilder({
14
+ cssVar,
15
+ input,
16
+ output,
17
+ }: VertesiaPluginBuilderOptions = {}) {
18
+ const CSS_VAR = cssVar || 'css';
19
+ if (!input) input = 'src/index.css';
20
+ if (!output) output = 'plugin.css';
21
+ const inputRelative = input.startsWith('./') ? input : `./${input}`;
22
+ const jsOutput = output.replace('.css', '.js');
23
+ return {
24
+ name: 'vertesia-plugin-builder',
25
+ apply: 'build' as 'build',
26
+ enforce: 'post',
27
+ resolveId(id) {
28
+ // Create a virtual CSS entry module
29
+ if (id === 'virtual:vertesia-plugin-css-entry') {
30
+ return id;
31
+ }
32
+ return null;
33
+ },
34
+ load(id) {
35
+ if (id === 'virtual:vertesia-plugin-css-entry') {
36
+ // This creates a virtual JS file that imports your actual CSS
37
+ return `import "${inputRelative}";`;
38
+ }
39
+ return null;
40
+ },
41
+ buildStart(this) {
42
+ // This emits the file into the build pipeline
43
+ this.emitFile({
44
+ type: 'chunk',
45
+ fileName: 'virtual-vertesia-plugin-css-entry.js',
46
+ id: 'virtual:vertesia-plugin-css-entry',
47
+ });
48
+ },
49
+ generateBundle(_options, bundle) {
50
+ delete bundle['virtual-vertesia-plugin-css-entry.js'];
51
+ },
52
+ writeBundle(this, options, bundle) {
53
+ // Look for the generated CSS file in the output directory
54
+ const keys = Object.keys(bundle).filter(k => k === output);
55
+ if (keys.length === 1) {
56
+ const asset = bundle[jsOutput];
57
+ if (asset) {
58
+ const cssContent = readFileSync(join(options.dir!, output), 'utf8')
59
+ if (cssContent) {
60
+ const exportedContent = extractTailwindUtilitiesLayer(cssContent);
61
+ if (exportedContent) {
62
+ const jsFile = join(options.dir!, jsOutput);
63
+ const jsContent = readFileSync(jsFile, 'utf8');
64
+ writeFileSync(jsFile, `${jsContent}\nexport const ${CSS_VAR} = \`\n${exportedContent}\n\`;\n`);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ },
70
+ } satisfies Plugin;
71
+ }
@@ -0,0 +1,21 @@
1
+
2
+ import { CssStylesheetAST, parse, stringify } from '@adobe/css-tools';
3
+
4
+ export function extractTailwindUtilitiesLayer(content: string) {
5
+ let obj = parse(content, {});
6
+ let result = '';
7
+ for (const rule of obj.stylesheet.rules) {
8
+ if (rule.type === 'layer' && rule.layer === 'utilities') {
9
+ if (rule.rules) {
10
+ const output = {
11
+ type: 'stylesheet',
12
+ stylesheet: {
13
+ rules: rule.rules
14
+ }
15
+ } as CssStylesheetAST;
16
+ result = stringify(output, {});
17
+ }
18
+ }
19
+ }
20
+ return result;
21
+ }