@pikacss/integration 0.0.12 → 0.0.14
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/index.cjs +62 -30
- package/dist/index.d.cts +6 -5
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +62 -30
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -41,23 +41,23 @@ function formatUnionStringType(list) {
|
|
|
41
41
|
function generateAutocomplete(ctx) {
|
|
42
42
|
const autocomplete = ctx.engine.config.autocomplete;
|
|
43
43
|
return [
|
|
44
|
-
"export
|
|
44
|
+
"export type Autocomplete = DefineAutocomplete<{",
|
|
45
45
|
` Selector: ${formatUnionStringType([...autocomplete.selectors])}`,
|
|
46
46
|
` StyleItemString: ${formatUnionStringType([...autocomplete.styleItemStrings])}`,
|
|
47
47
|
` ExtraProperty: ${formatUnionStringType([...autocomplete.extraProperties])}`,
|
|
48
48
|
` ExtraCssProperty: ${formatUnionStringType([...autocomplete.extraCssProperties])}`,
|
|
49
49
|
` PropertiesValue: { ${Array.from(autocomplete.properties.entries(), ([k, v]) => `'${k}': ${v.join(" | ")}`).join(",")} }`,
|
|
50
50
|
` CssPropertiesValue: { ${Array.from(autocomplete.cssProperties.entries(), ([k, v]) => `'${k}': ${formatUnionStringType(v)}`).join(",")} }`,
|
|
51
|
-
"}",
|
|
51
|
+
"}>",
|
|
52
52
|
""
|
|
53
53
|
];
|
|
54
54
|
}
|
|
55
55
|
function generateStyleFn(ctx) {
|
|
56
56
|
const { transformedFormat } = ctx;
|
|
57
57
|
const lines = [
|
|
58
|
-
"type StyleFn_Array = (...params: StyleItem
|
|
59
|
-
"type StyleFn_String = (...params: StyleItem
|
|
60
|
-
"type StyleFn_Inline = (...params: StyleItem
|
|
58
|
+
"type StyleFn_Array = (...params: StyleItem[]) => string[]",
|
|
59
|
+
"type StyleFn_String = (...params: StyleItem[]) => string",
|
|
60
|
+
"type StyleFn_Inline = (...params: StyleItem[]) => void"
|
|
61
61
|
];
|
|
62
62
|
if (transformedFormat === "array")
|
|
63
63
|
lines.push("type StyleFn_Normal = StyleFn_Array");
|
|
@@ -66,6 +66,11 @@ function generateStyleFn(ctx) {
|
|
|
66
66
|
else if (transformedFormat === "inline")
|
|
67
67
|
lines.push("type StyleFn_Normal = StyleFn_Inline");
|
|
68
68
|
lines.push(
|
|
69
|
+
"type StyleFn = StyleFn_Normal & {",
|
|
70
|
+
" str: StyleFn_String",
|
|
71
|
+
" arr: StyleFn_Array",
|
|
72
|
+
" inl: StyleFn_Inline",
|
|
73
|
+
"}",
|
|
69
74
|
`type StyleFnWithPreview = PreviewOverloads<StyleFn_Normal>['fn'] & {`,
|
|
70
75
|
` str: PreviewOverloads<StyleFn_String>['fn']`,
|
|
71
76
|
` arr: PreviewOverloads<StyleFn_Array>['fn']`,
|
|
@@ -82,7 +87,12 @@ function generateGlobalDeclaration(ctx) {
|
|
|
82
87
|
" /**",
|
|
83
88
|
" * PikaCSS",
|
|
84
89
|
" */",
|
|
85
|
-
` const ${fnName}:
|
|
90
|
+
` const ${fnName}: StyleFn`,
|
|
91
|
+
"",
|
|
92
|
+
" /**",
|
|
93
|
+
" * PikaCSS Preview",
|
|
94
|
+
" */",
|
|
95
|
+
` const ${fnName}p: StyleFnWithPreview`,
|
|
86
96
|
"}",
|
|
87
97
|
""
|
|
88
98
|
];
|
|
@@ -97,7 +107,12 @@ function generateVueDeclaration(ctx) {
|
|
|
97
107
|
" /**",
|
|
98
108
|
" * PikaCSS",
|
|
99
109
|
" */",
|
|
100
|
-
` ${fnName}:
|
|
110
|
+
` ${fnName}: StyleFn`,
|
|
111
|
+
"",
|
|
112
|
+
" /**",
|
|
113
|
+
" * PikaCSS Preview",
|
|
114
|
+
" */",
|
|
115
|
+
` ${fnName}p: StyleFnWithPreview`,
|
|
101
116
|
" }",
|
|
102
117
|
"}",
|
|
103
118
|
""
|
|
@@ -141,15 +156,21 @@ async function generateOverloadContent(ctx) {
|
|
|
141
156
|
async function generateTsCodegenContent(ctx) {
|
|
142
157
|
const lines = [
|
|
143
158
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
144
|
-
`import type {
|
|
145
|
-
|
|
159
|
+
`import type { CSSProperty, CSSSelectors, DefineAutocomplete, Properties, StyleDefinition, StyleItem } from '${ctx.currentPackageName}'`,
|
|
160
|
+
"",
|
|
161
|
+
`declare module '${ctx.currentPackageName}' {`,
|
|
162
|
+
" interface PikaAugment {",
|
|
163
|
+
" Autocomplete: Autocomplete",
|
|
164
|
+
" Selector: Autocomplete['Selector'] | CSSSelectors",
|
|
165
|
+
" CSSProperty: Autocomplete['ExtraCssProperty'] | CSSProperty",
|
|
166
|
+
" Properties: Properties",
|
|
167
|
+
" StyleDefinition: StyleDefinition",
|
|
168
|
+
" StyleItem: StyleItem",
|
|
169
|
+
" }",
|
|
170
|
+
"}",
|
|
146
171
|
""
|
|
147
172
|
];
|
|
148
173
|
lines.push(...generateAutocomplete(ctx));
|
|
149
|
-
lines.push(
|
|
150
|
-
"export const defineEngineConfig: ReturnType<typeof createDefineEngineConfigFn<Autocomplete>> = createDefineEngineConfigFn<Autocomplete>()",
|
|
151
|
-
""
|
|
152
|
-
);
|
|
153
174
|
lines.push(...generateStyleFn(ctx));
|
|
154
175
|
lines.push(...generateGlobalDeclaration(ctx));
|
|
155
176
|
lines.push(...generateVueDeclaration(ctx));
|
|
@@ -189,14 +210,20 @@ function createFnUtils(fnName) {
|
|
|
189
210
|
normal: /* @__PURE__ */ new Set([fnName]),
|
|
190
211
|
forceString: /* @__PURE__ */ new Set([`${fnName}.str`, `${fnName}['str']`, `${fnName}["str"]`, `${fnName}[\`str\`]`]),
|
|
191
212
|
forceArray: /* @__PURE__ */ new Set([`${fnName}.arr`, `${fnName}['arr']`, `${fnName}["arr"]`, `${fnName}[\`arr\`]`]),
|
|
192
|
-
forceInline: /* @__PURE__ */ new Set([`${fnName}.inl`, `${fnName}['inl']`, `${fnName}["inl"]`, `${fnName}[\`inl\`]`])
|
|
213
|
+
forceInline: /* @__PURE__ */ new Set([`${fnName}.inl`, `${fnName}['inl']`, `${fnName}["inl"]`, `${fnName}[\`inl\`]`]),
|
|
214
|
+
// preview
|
|
215
|
+
normalPreview: /* @__PURE__ */ new Set([`${fnName}p`]),
|
|
216
|
+
forceStringPreview: /* @__PURE__ */ new Set([`${fnName}p.str`, `${fnName}p['str']`, `${fnName}p["str"]`, `${fnName}p[\`str\`]`]),
|
|
217
|
+
forceArrayPreview: /* @__PURE__ */ new Set([`${fnName}p.arr`, `${fnName}p['arr']`, `${fnName}p["arr"]`, `${fnName}p[\`arr\`]`]),
|
|
218
|
+
forceInlinePreview: /* @__PURE__ */ new Set([`${fnName}p.inl`, `${fnName}p['inl']`, `${fnName}p["inl"]`, `${fnName}p[\`inl\`]`])
|
|
193
219
|
};
|
|
194
220
|
const RE = new RegExp(`\\b(${Object.values(available).flatMap((s) => [...s].map((f) => `(${f.replace(ESCAPE_REPLACE_RE, "\\$&")})`)).join("|")})\\(`, "g");
|
|
195
221
|
return {
|
|
196
|
-
isNormal: (fnName2) => available.normal.has(fnName2),
|
|
197
|
-
isForceString: (fnName2) => available.forceString.has(fnName2),
|
|
198
|
-
isForceArray: (fnName2) => available.forceArray.has(fnName2),
|
|
199
|
-
isForceInline: (fnName2) => available.forceInline.has(fnName2),
|
|
222
|
+
isNormal: (fnName2) => available.normal.has(fnName2) || available.normalPreview.has(fnName2),
|
|
223
|
+
isForceString: (fnName2) => available.forceString.has(fnName2) || available.forceStringPreview.has(fnName2),
|
|
224
|
+
isForceArray: (fnName2) => available.forceArray.has(fnName2) || available.forceArrayPreview.has(fnName2),
|
|
225
|
+
isForceInline: (fnName2) => available.forceInline.has(fnName2) || available.forceInlinePreview.has(fnName2),
|
|
226
|
+
isPreview: (fnName2) => available.normalPreview.has(fnName2) || available.forceStringPreview.has(fnName2) || available.forceArrayPreview.has(fnName2) || available.forceInlinePreview.has(fnName2),
|
|
200
227
|
RE
|
|
201
228
|
};
|
|
202
229
|
}
|
|
@@ -252,9 +279,10 @@ async function createCtx(options) {
|
|
|
252
279
|
resolvedConfigPath = configSources[0];
|
|
253
280
|
await promises.mkdir(pathe.dirname(resolvedConfigPath), { recursive: true }).catch(() => {
|
|
254
281
|
});
|
|
255
|
-
const
|
|
282
|
+
const relativeTsCodegenFilepath = tsCodegenFilepath == null ? null : `./${pathe.relative(pathe.dirname(resolvedConfigPath), tsCodegenFilepath)}`;
|
|
256
283
|
await promises.writeFile(resolvedConfigPath, [
|
|
257
|
-
|
|
284
|
+
...relativeTsCodegenFilepath == null ? [] : [`/// <reference path="${relativeTsCodegenFilepath}" />`],
|
|
285
|
+
`import { defineEngineConfig } from '${currentPackageName}'`,
|
|
258
286
|
"",
|
|
259
287
|
"export default defineEngineConfig({",
|
|
260
288
|
" // Add your PikaCSS engine config here",
|
|
@@ -270,16 +298,6 @@ async function createCtx(options) {
|
|
|
270
298
|
},
|
|
271
299
|
init: async () => {
|
|
272
300
|
ctx.isReady = false;
|
|
273
|
-
await promises.mkdir(pathe.dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
274
|
-
});
|
|
275
|
-
const isDevCssFileExists = await promises.stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
276
|
-
if (isDevCssFileExists === false)
|
|
277
|
-
await promises.writeFile(devCssFilepath, "");
|
|
278
|
-
if (tsCodegenFilepath != null) {
|
|
279
|
-
await promises.mkdir(pathe.dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
280
|
-
});
|
|
281
|
-
await promises.writeFile(tsCodegenFilepath, "export function defineEngineConfig(config: any) { return config }");
|
|
282
|
-
}
|
|
283
301
|
ctx.usages.clear();
|
|
284
302
|
const { config, file } = await ctx.loadConfig().catch((error) => {
|
|
285
303
|
core.warn(`Failed to load config file: ${error.message}`, error);
|
|
@@ -298,6 +316,20 @@ async function createCtx(options) {
|
|
|
298
316
|
atomicStyleAdded: () => ctx.hooks.styleUpdated.trigger(),
|
|
299
317
|
autocompleteConfigUpdated: () => ctx.hooks.tsCodegenUpdated.trigger()
|
|
300
318
|
});
|
|
319
|
+
await promises.mkdir(pathe.dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
320
|
+
});
|
|
321
|
+
const isDevCssFileExists = await promises.stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
322
|
+
if (isDevCssFileExists === false)
|
|
323
|
+
await promises.writeFile(devCssFilepath, "");
|
|
324
|
+
if (tsCodegenFilepath != null) {
|
|
325
|
+
await promises.mkdir(pathe.dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
326
|
+
});
|
|
327
|
+
const isGenTsFileExists = await promises.stat(tsCodegenFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
328
|
+
if (isGenTsFileExists === false) {
|
|
329
|
+
const content = await generateTsCodegenContent(ctx);
|
|
330
|
+
await promises.writeFile(tsCodegenFilepath, content);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
301
333
|
ctx.isReady = true;
|
|
302
334
|
},
|
|
303
335
|
isReady: false,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EngineConfig, Engine } from '@pikacss/core';
|
|
1
|
+
import { EngineConfig, Nullish, Engine } from '@pikacss/core';
|
|
2
2
|
export * from '@pikacss/core';
|
|
3
3
|
import { SourceMap } from 'magic-string';
|
|
4
4
|
|
|
@@ -20,6 +20,7 @@ interface FnUtils {
|
|
|
20
20
|
isForceString: (fnName: string) => boolean;
|
|
21
21
|
isForceArray: (fnName: string) => boolean;
|
|
22
22
|
isForceInline: (fnName: string) => boolean;
|
|
23
|
+
isPreview: (fnName: string) => boolean;
|
|
23
24
|
RE: RegExp;
|
|
24
25
|
}
|
|
25
26
|
interface IntegrationContext {
|
|
@@ -29,7 +30,7 @@ interface IntegrationContext {
|
|
|
29
30
|
fnUtils: FnUtils;
|
|
30
31
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
31
32
|
devCssFilepath: string;
|
|
32
|
-
tsCodegenFilepath: string |
|
|
33
|
+
tsCodegenFilepath: string | Nullish;
|
|
33
34
|
hasVue: boolean;
|
|
34
35
|
usages: Map<string, UsageRecord[]>;
|
|
35
36
|
hooks: {
|
|
@@ -49,12 +50,12 @@ interface IntegrationContext {
|
|
|
49
50
|
init: () => Promise<any>;
|
|
50
51
|
isReady: boolean;
|
|
51
52
|
configSources: string[];
|
|
52
|
-
resolvedConfigPath: string |
|
|
53
|
+
resolvedConfigPath: string | Nullish;
|
|
53
54
|
engine: Engine;
|
|
54
55
|
transform: (code: string, id: string) => Promise<{
|
|
55
56
|
code: string;
|
|
56
57
|
map: SourceMap;
|
|
57
|
-
} |
|
|
58
|
+
} | Nullish>;
|
|
58
59
|
writeDevCssFile: () => Promise<void>;
|
|
59
60
|
writeTsCodegenFile: () => Promise<void>;
|
|
60
61
|
}
|
|
@@ -62,7 +63,7 @@ interface IntegrationContextOptions {
|
|
|
62
63
|
cwd: string;
|
|
63
64
|
currentPackageName: string;
|
|
64
65
|
target: string[];
|
|
65
|
-
configOrPath: EngineConfig | string |
|
|
66
|
+
configOrPath: EngineConfig | string | Nullish;
|
|
66
67
|
fnName: string;
|
|
67
68
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
68
69
|
tsCodegen: false | string;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EngineConfig, Engine } from '@pikacss/core';
|
|
1
|
+
import { EngineConfig, Nullish, Engine } from '@pikacss/core';
|
|
2
2
|
export * from '@pikacss/core';
|
|
3
3
|
import { SourceMap } from 'magic-string';
|
|
4
4
|
|
|
@@ -20,6 +20,7 @@ interface FnUtils {
|
|
|
20
20
|
isForceString: (fnName: string) => boolean;
|
|
21
21
|
isForceArray: (fnName: string) => boolean;
|
|
22
22
|
isForceInline: (fnName: string) => boolean;
|
|
23
|
+
isPreview: (fnName: string) => boolean;
|
|
23
24
|
RE: RegExp;
|
|
24
25
|
}
|
|
25
26
|
interface IntegrationContext {
|
|
@@ -29,7 +30,7 @@ interface IntegrationContext {
|
|
|
29
30
|
fnUtils: FnUtils;
|
|
30
31
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
31
32
|
devCssFilepath: string;
|
|
32
|
-
tsCodegenFilepath: string |
|
|
33
|
+
tsCodegenFilepath: string | Nullish;
|
|
33
34
|
hasVue: boolean;
|
|
34
35
|
usages: Map<string, UsageRecord[]>;
|
|
35
36
|
hooks: {
|
|
@@ -49,12 +50,12 @@ interface IntegrationContext {
|
|
|
49
50
|
init: () => Promise<any>;
|
|
50
51
|
isReady: boolean;
|
|
51
52
|
configSources: string[];
|
|
52
|
-
resolvedConfigPath: string |
|
|
53
|
+
resolvedConfigPath: string | Nullish;
|
|
53
54
|
engine: Engine;
|
|
54
55
|
transform: (code: string, id: string) => Promise<{
|
|
55
56
|
code: string;
|
|
56
57
|
map: SourceMap;
|
|
57
|
-
} |
|
|
58
|
+
} | Nullish>;
|
|
58
59
|
writeDevCssFile: () => Promise<void>;
|
|
59
60
|
writeTsCodegenFile: () => Promise<void>;
|
|
60
61
|
}
|
|
@@ -62,7 +63,7 @@ interface IntegrationContextOptions {
|
|
|
62
63
|
cwd: string;
|
|
63
64
|
currentPackageName: string;
|
|
64
65
|
target: string[];
|
|
65
|
-
configOrPath: EngineConfig | string |
|
|
66
|
+
configOrPath: EngineConfig | string | Nullish;
|
|
66
67
|
fnName: string;
|
|
67
68
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
68
69
|
tsCodegen: false | string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EngineConfig, Engine } from '@pikacss/core';
|
|
1
|
+
import { EngineConfig, Nullish, Engine } from '@pikacss/core';
|
|
2
2
|
export * from '@pikacss/core';
|
|
3
3
|
import { SourceMap } from 'magic-string';
|
|
4
4
|
|
|
@@ -20,6 +20,7 @@ interface FnUtils {
|
|
|
20
20
|
isForceString: (fnName: string) => boolean;
|
|
21
21
|
isForceArray: (fnName: string) => boolean;
|
|
22
22
|
isForceInline: (fnName: string) => boolean;
|
|
23
|
+
isPreview: (fnName: string) => boolean;
|
|
23
24
|
RE: RegExp;
|
|
24
25
|
}
|
|
25
26
|
interface IntegrationContext {
|
|
@@ -29,7 +30,7 @@ interface IntegrationContext {
|
|
|
29
30
|
fnUtils: FnUtils;
|
|
30
31
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
31
32
|
devCssFilepath: string;
|
|
32
|
-
tsCodegenFilepath: string |
|
|
33
|
+
tsCodegenFilepath: string | Nullish;
|
|
33
34
|
hasVue: boolean;
|
|
34
35
|
usages: Map<string, UsageRecord[]>;
|
|
35
36
|
hooks: {
|
|
@@ -49,12 +50,12 @@ interface IntegrationContext {
|
|
|
49
50
|
init: () => Promise<any>;
|
|
50
51
|
isReady: boolean;
|
|
51
52
|
configSources: string[];
|
|
52
|
-
resolvedConfigPath: string |
|
|
53
|
+
resolvedConfigPath: string | Nullish;
|
|
53
54
|
engine: Engine;
|
|
54
55
|
transform: (code: string, id: string) => Promise<{
|
|
55
56
|
code: string;
|
|
56
57
|
map: SourceMap;
|
|
57
|
-
} |
|
|
58
|
+
} | Nullish>;
|
|
58
59
|
writeDevCssFile: () => Promise<void>;
|
|
59
60
|
writeTsCodegenFile: () => Promise<void>;
|
|
60
61
|
}
|
|
@@ -62,7 +63,7 @@ interface IntegrationContextOptions {
|
|
|
62
63
|
cwd: string;
|
|
63
64
|
currentPackageName: string;
|
|
64
65
|
target: string[];
|
|
65
|
-
configOrPath: EngineConfig | string |
|
|
66
|
+
configOrPath: EngineConfig | string | Nullish;
|
|
66
67
|
fnName: string;
|
|
67
68
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
68
69
|
tsCodegen: false | string;
|
package/dist/index.mjs
CHANGED
|
@@ -35,23 +35,23 @@ function formatUnionStringType(list) {
|
|
|
35
35
|
function generateAutocomplete(ctx) {
|
|
36
36
|
const autocomplete = ctx.engine.config.autocomplete;
|
|
37
37
|
return [
|
|
38
|
-
"export
|
|
38
|
+
"export type Autocomplete = DefineAutocomplete<{",
|
|
39
39
|
` Selector: ${formatUnionStringType([...autocomplete.selectors])}`,
|
|
40
40
|
` StyleItemString: ${formatUnionStringType([...autocomplete.styleItemStrings])}`,
|
|
41
41
|
` ExtraProperty: ${formatUnionStringType([...autocomplete.extraProperties])}`,
|
|
42
42
|
` ExtraCssProperty: ${formatUnionStringType([...autocomplete.extraCssProperties])}`,
|
|
43
43
|
` PropertiesValue: { ${Array.from(autocomplete.properties.entries(), ([k, v]) => `'${k}': ${v.join(" | ")}`).join(",")} }`,
|
|
44
44
|
` CssPropertiesValue: { ${Array.from(autocomplete.cssProperties.entries(), ([k, v]) => `'${k}': ${formatUnionStringType(v)}`).join(",")} }`,
|
|
45
|
-
"}",
|
|
45
|
+
"}>",
|
|
46
46
|
""
|
|
47
47
|
];
|
|
48
48
|
}
|
|
49
49
|
function generateStyleFn(ctx) {
|
|
50
50
|
const { transformedFormat } = ctx;
|
|
51
51
|
const lines = [
|
|
52
|
-
"type StyleFn_Array = (...params: StyleItem
|
|
53
|
-
"type StyleFn_String = (...params: StyleItem
|
|
54
|
-
"type StyleFn_Inline = (...params: StyleItem
|
|
52
|
+
"type StyleFn_Array = (...params: StyleItem[]) => string[]",
|
|
53
|
+
"type StyleFn_String = (...params: StyleItem[]) => string",
|
|
54
|
+
"type StyleFn_Inline = (...params: StyleItem[]) => void"
|
|
55
55
|
];
|
|
56
56
|
if (transformedFormat === "array")
|
|
57
57
|
lines.push("type StyleFn_Normal = StyleFn_Array");
|
|
@@ -60,6 +60,11 @@ function generateStyleFn(ctx) {
|
|
|
60
60
|
else if (transformedFormat === "inline")
|
|
61
61
|
lines.push("type StyleFn_Normal = StyleFn_Inline");
|
|
62
62
|
lines.push(
|
|
63
|
+
"type StyleFn = StyleFn_Normal & {",
|
|
64
|
+
" str: StyleFn_String",
|
|
65
|
+
" arr: StyleFn_Array",
|
|
66
|
+
" inl: StyleFn_Inline",
|
|
67
|
+
"}",
|
|
63
68
|
`type StyleFnWithPreview = PreviewOverloads<StyleFn_Normal>['fn'] & {`,
|
|
64
69
|
` str: PreviewOverloads<StyleFn_String>['fn']`,
|
|
65
70
|
` arr: PreviewOverloads<StyleFn_Array>['fn']`,
|
|
@@ -76,7 +81,12 @@ function generateGlobalDeclaration(ctx) {
|
|
|
76
81
|
" /**",
|
|
77
82
|
" * PikaCSS",
|
|
78
83
|
" */",
|
|
79
|
-
` const ${fnName}:
|
|
84
|
+
` const ${fnName}: StyleFn`,
|
|
85
|
+
"",
|
|
86
|
+
" /**",
|
|
87
|
+
" * PikaCSS Preview",
|
|
88
|
+
" */",
|
|
89
|
+
` const ${fnName}p: StyleFnWithPreview`,
|
|
80
90
|
"}",
|
|
81
91
|
""
|
|
82
92
|
];
|
|
@@ -91,7 +101,12 @@ function generateVueDeclaration(ctx) {
|
|
|
91
101
|
" /**",
|
|
92
102
|
" * PikaCSS",
|
|
93
103
|
" */",
|
|
94
|
-
` ${fnName}:
|
|
104
|
+
` ${fnName}: StyleFn`,
|
|
105
|
+
"",
|
|
106
|
+
" /**",
|
|
107
|
+
" * PikaCSS Preview",
|
|
108
|
+
" */",
|
|
109
|
+
` ${fnName}p: StyleFnWithPreview`,
|
|
95
110
|
" }",
|
|
96
111
|
"}",
|
|
97
112
|
""
|
|
@@ -135,15 +150,21 @@ async function generateOverloadContent(ctx) {
|
|
|
135
150
|
async function generateTsCodegenContent(ctx) {
|
|
136
151
|
const lines = [
|
|
137
152
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
138
|
-
`import type {
|
|
139
|
-
|
|
153
|
+
`import type { CSSProperty, CSSSelectors, DefineAutocomplete, Properties, StyleDefinition, StyleItem } from '${ctx.currentPackageName}'`,
|
|
154
|
+
"",
|
|
155
|
+
`declare module '${ctx.currentPackageName}' {`,
|
|
156
|
+
" interface PikaAugment {",
|
|
157
|
+
" Autocomplete: Autocomplete",
|
|
158
|
+
" Selector: Autocomplete['Selector'] | CSSSelectors",
|
|
159
|
+
" CSSProperty: Autocomplete['ExtraCssProperty'] | CSSProperty",
|
|
160
|
+
" Properties: Properties",
|
|
161
|
+
" StyleDefinition: StyleDefinition",
|
|
162
|
+
" StyleItem: StyleItem",
|
|
163
|
+
" }",
|
|
164
|
+
"}",
|
|
140
165
|
""
|
|
141
166
|
];
|
|
142
167
|
lines.push(...generateAutocomplete(ctx));
|
|
143
|
-
lines.push(
|
|
144
|
-
"export const defineEngineConfig: ReturnType<typeof createDefineEngineConfigFn<Autocomplete>> = createDefineEngineConfigFn<Autocomplete>()",
|
|
145
|
-
""
|
|
146
|
-
);
|
|
147
168
|
lines.push(...generateStyleFn(ctx));
|
|
148
169
|
lines.push(...generateGlobalDeclaration(ctx));
|
|
149
170
|
lines.push(...generateVueDeclaration(ctx));
|
|
@@ -183,14 +204,20 @@ function createFnUtils(fnName) {
|
|
|
183
204
|
normal: /* @__PURE__ */ new Set([fnName]),
|
|
184
205
|
forceString: /* @__PURE__ */ new Set([`${fnName}.str`, `${fnName}['str']`, `${fnName}["str"]`, `${fnName}[\`str\`]`]),
|
|
185
206
|
forceArray: /* @__PURE__ */ new Set([`${fnName}.arr`, `${fnName}['arr']`, `${fnName}["arr"]`, `${fnName}[\`arr\`]`]),
|
|
186
|
-
forceInline: /* @__PURE__ */ new Set([`${fnName}.inl`, `${fnName}['inl']`, `${fnName}["inl"]`, `${fnName}[\`inl\`]`])
|
|
207
|
+
forceInline: /* @__PURE__ */ new Set([`${fnName}.inl`, `${fnName}['inl']`, `${fnName}["inl"]`, `${fnName}[\`inl\`]`]),
|
|
208
|
+
// preview
|
|
209
|
+
normalPreview: /* @__PURE__ */ new Set([`${fnName}p`]),
|
|
210
|
+
forceStringPreview: /* @__PURE__ */ new Set([`${fnName}p.str`, `${fnName}p['str']`, `${fnName}p["str"]`, `${fnName}p[\`str\`]`]),
|
|
211
|
+
forceArrayPreview: /* @__PURE__ */ new Set([`${fnName}p.arr`, `${fnName}p['arr']`, `${fnName}p["arr"]`, `${fnName}p[\`arr\`]`]),
|
|
212
|
+
forceInlinePreview: /* @__PURE__ */ new Set([`${fnName}p.inl`, `${fnName}p['inl']`, `${fnName}p["inl"]`, `${fnName}p[\`inl\`]`])
|
|
187
213
|
};
|
|
188
214
|
const RE = new RegExp(`\\b(${Object.values(available).flatMap((s) => [...s].map((f) => `(${f.replace(ESCAPE_REPLACE_RE, "\\$&")})`)).join("|")})\\(`, "g");
|
|
189
215
|
return {
|
|
190
|
-
isNormal: (fnName2) => available.normal.has(fnName2),
|
|
191
|
-
isForceString: (fnName2) => available.forceString.has(fnName2),
|
|
192
|
-
isForceArray: (fnName2) => available.forceArray.has(fnName2),
|
|
193
|
-
isForceInline: (fnName2) => available.forceInline.has(fnName2),
|
|
216
|
+
isNormal: (fnName2) => available.normal.has(fnName2) || available.normalPreview.has(fnName2),
|
|
217
|
+
isForceString: (fnName2) => available.forceString.has(fnName2) || available.forceStringPreview.has(fnName2),
|
|
218
|
+
isForceArray: (fnName2) => available.forceArray.has(fnName2) || available.forceArrayPreview.has(fnName2),
|
|
219
|
+
isForceInline: (fnName2) => available.forceInline.has(fnName2) || available.forceInlinePreview.has(fnName2),
|
|
220
|
+
isPreview: (fnName2) => available.normalPreview.has(fnName2) || available.forceStringPreview.has(fnName2) || available.forceArrayPreview.has(fnName2) || available.forceInlinePreview.has(fnName2),
|
|
194
221
|
RE
|
|
195
222
|
};
|
|
196
223
|
}
|
|
@@ -246,9 +273,10 @@ async function createCtx(options) {
|
|
|
246
273
|
resolvedConfigPath = configSources[0];
|
|
247
274
|
await mkdir(dirname(resolvedConfigPath), { recursive: true }).catch(() => {
|
|
248
275
|
});
|
|
249
|
-
const
|
|
276
|
+
const relativeTsCodegenFilepath = tsCodegenFilepath == null ? null : `./${relative(dirname(resolvedConfigPath), tsCodegenFilepath)}`;
|
|
250
277
|
await writeFile(resolvedConfigPath, [
|
|
251
|
-
|
|
278
|
+
...relativeTsCodegenFilepath == null ? [] : [`/// <reference path="${relativeTsCodegenFilepath}" />`],
|
|
279
|
+
`import { defineEngineConfig } from '${currentPackageName}'`,
|
|
252
280
|
"",
|
|
253
281
|
"export default defineEngineConfig({",
|
|
254
282
|
" // Add your PikaCSS engine config here",
|
|
@@ -264,16 +292,6 @@ async function createCtx(options) {
|
|
|
264
292
|
},
|
|
265
293
|
init: async () => {
|
|
266
294
|
ctx.isReady = false;
|
|
267
|
-
await mkdir(dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
268
|
-
});
|
|
269
|
-
const isDevCssFileExists = await stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
270
|
-
if (isDevCssFileExists === false)
|
|
271
|
-
await writeFile(devCssFilepath, "");
|
|
272
|
-
if (tsCodegenFilepath != null) {
|
|
273
|
-
await mkdir(dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
274
|
-
});
|
|
275
|
-
await writeFile(tsCodegenFilepath, "export function defineEngineConfig(config: any) { return config }");
|
|
276
|
-
}
|
|
277
295
|
ctx.usages.clear();
|
|
278
296
|
const { config, file } = await ctx.loadConfig().catch((error) => {
|
|
279
297
|
warn(`Failed to load config file: ${error.message}`, error);
|
|
@@ -292,6 +310,20 @@ async function createCtx(options) {
|
|
|
292
310
|
atomicStyleAdded: () => ctx.hooks.styleUpdated.trigger(),
|
|
293
311
|
autocompleteConfigUpdated: () => ctx.hooks.tsCodegenUpdated.trigger()
|
|
294
312
|
});
|
|
313
|
+
await mkdir(dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
314
|
+
});
|
|
315
|
+
const isDevCssFileExists = await stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
316
|
+
if (isDevCssFileExists === false)
|
|
317
|
+
await writeFile(devCssFilepath, "");
|
|
318
|
+
if (tsCodegenFilepath != null) {
|
|
319
|
+
await mkdir(dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
320
|
+
});
|
|
321
|
+
const isGenTsFileExists = await stat(tsCodegenFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
322
|
+
if (isGenTsFileExists === false) {
|
|
323
|
+
const content = await generateTsCodegenContent(ctx);
|
|
324
|
+
await writeFile(tsCodegenFilepath, content);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
295
327
|
ctx.isReady = true;
|
|
296
328
|
},
|
|
297
329
|
isReady: false,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.14",
|
|
8
8
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"magic-string": "^0.30.12",
|
|
41
41
|
"micromatch": "^4.0.8",
|
|
42
42
|
"pathe": "^2.0.3",
|
|
43
|
-
"@pikacss/core": "0.0.
|
|
43
|
+
"@pikacss/core": "0.0.14"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/micromatch": "^4.0.9"
|