@pikacss/integration 0.0.13 → 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 +34 -23
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +34 -23
- 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");
|
|
@@ -156,15 +156,21 @@ async function generateOverloadContent(ctx) {
|
|
|
156
156
|
async function generateTsCodegenContent(ctx) {
|
|
157
157
|
const lines = [
|
|
158
158
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
159
|
-
`import type {
|
|
160
|
-
|
|
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
|
+
"}",
|
|
161
171
|
""
|
|
162
172
|
];
|
|
163
173
|
lines.push(...generateAutocomplete(ctx));
|
|
164
|
-
lines.push(
|
|
165
|
-
"export const defineEngineConfig: ReturnType<typeof createDefineEngineConfigFn<Autocomplete>> = createDefineEngineConfigFn<Autocomplete>()",
|
|
166
|
-
""
|
|
167
|
-
);
|
|
168
174
|
lines.push(...generateStyleFn(ctx));
|
|
169
175
|
lines.push(...generateGlobalDeclaration(ctx));
|
|
170
176
|
lines.push(...generateVueDeclaration(ctx));
|
|
@@ -273,9 +279,10 @@ async function createCtx(options) {
|
|
|
273
279
|
resolvedConfigPath = configSources[0];
|
|
274
280
|
await promises.mkdir(pathe.dirname(resolvedConfigPath), { recursive: true }).catch(() => {
|
|
275
281
|
});
|
|
276
|
-
const
|
|
282
|
+
const relativeTsCodegenFilepath = tsCodegenFilepath == null ? null : `./${pathe.relative(pathe.dirname(resolvedConfigPath), tsCodegenFilepath)}`;
|
|
277
283
|
await promises.writeFile(resolvedConfigPath, [
|
|
278
|
-
|
|
284
|
+
...relativeTsCodegenFilepath == null ? [] : [`/// <reference path="${relativeTsCodegenFilepath}" />`],
|
|
285
|
+
`import { defineEngineConfig } from '${currentPackageName}'`,
|
|
279
286
|
"",
|
|
280
287
|
"export default defineEngineConfig({",
|
|
281
288
|
" // Add your PikaCSS engine config here",
|
|
@@ -291,16 +298,6 @@ async function createCtx(options) {
|
|
|
291
298
|
},
|
|
292
299
|
init: async () => {
|
|
293
300
|
ctx.isReady = false;
|
|
294
|
-
await promises.mkdir(pathe.dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
295
|
-
});
|
|
296
|
-
const isDevCssFileExists = await promises.stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
297
|
-
if (isDevCssFileExists === false)
|
|
298
|
-
await promises.writeFile(devCssFilepath, "");
|
|
299
|
-
if (tsCodegenFilepath != null) {
|
|
300
|
-
await promises.mkdir(pathe.dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
301
|
-
});
|
|
302
|
-
await promises.writeFile(tsCodegenFilepath, "export function defineEngineConfig(config: any) { return config }");
|
|
303
|
-
}
|
|
304
301
|
ctx.usages.clear();
|
|
305
302
|
const { config, file } = await ctx.loadConfig().catch((error) => {
|
|
306
303
|
core.warn(`Failed to load config file: ${error.message}`, error);
|
|
@@ -319,6 +316,20 @@ async function createCtx(options) {
|
|
|
319
316
|
atomicStyleAdded: () => ctx.hooks.styleUpdated.trigger(),
|
|
320
317
|
autocompleteConfigUpdated: () => ctx.hooks.tsCodegenUpdated.trigger()
|
|
321
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
|
+
}
|
|
322
333
|
ctx.isReady = true;
|
|
323
334
|
},
|
|
324
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
|
|
|
@@ -30,7 +30,7 @@ interface IntegrationContext {
|
|
|
30
30
|
fnUtils: FnUtils;
|
|
31
31
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
32
32
|
devCssFilepath: string;
|
|
33
|
-
tsCodegenFilepath: string |
|
|
33
|
+
tsCodegenFilepath: string | Nullish;
|
|
34
34
|
hasVue: boolean;
|
|
35
35
|
usages: Map<string, UsageRecord[]>;
|
|
36
36
|
hooks: {
|
|
@@ -50,12 +50,12 @@ interface IntegrationContext {
|
|
|
50
50
|
init: () => Promise<any>;
|
|
51
51
|
isReady: boolean;
|
|
52
52
|
configSources: string[];
|
|
53
|
-
resolvedConfigPath: string |
|
|
53
|
+
resolvedConfigPath: string | Nullish;
|
|
54
54
|
engine: Engine;
|
|
55
55
|
transform: (code: string, id: string) => Promise<{
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
|
-
} |
|
|
58
|
+
} | Nullish>;
|
|
59
59
|
writeDevCssFile: () => Promise<void>;
|
|
60
60
|
writeTsCodegenFile: () => Promise<void>;
|
|
61
61
|
}
|
|
@@ -63,7 +63,7 @@ interface IntegrationContextOptions {
|
|
|
63
63
|
cwd: string;
|
|
64
64
|
currentPackageName: string;
|
|
65
65
|
target: string[];
|
|
66
|
-
configOrPath: EngineConfig | string |
|
|
66
|
+
configOrPath: EngineConfig | string | Nullish;
|
|
67
67
|
fnName: string;
|
|
68
68
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
69
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
|
|
|
@@ -30,7 +30,7 @@ interface IntegrationContext {
|
|
|
30
30
|
fnUtils: FnUtils;
|
|
31
31
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
32
32
|
devCssFilepath: string;
|
|
33
|
-
tsCodegenFilepath: string |
|
|
33
|
+
tsCodegenFilepath: string | Nullish;
|
|
34
34
|
hasVue: boolean;
|
|
35
35
|
usages: Map<string, UsageRecord[]>;
|
|
36
36
|
hooks: {
|
|
@@ -50,12 +50,12 @@ interface IntegrationContext {
|
|
|
50
50
|
init: () => Promise<any>;
|
|
51
51
|
isReady: boolean;
|
|
52
52
|
configSources: string[];
|
|
53
|
-
resolvedConfigPath: string |
|
|
53
|
+
resolvedConfigPath: string | Nullish;
|
|
54
54
|
engine: Engine;
|
|
55
55
|
transform: (code: string, id: string) => Promise<{
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
|
-
} |
|
|
58
|
+
} | Nullish>;
|
|
59
59
|
writeDevCssFile: () => Promise<void>;
|
|
60
60
|
writeTsCodegenFile: () => Promise<void>;
|
|
61
61
|
}
|
|
@@ -63,7 +63,7 @@ interface IntegrationContextOptions {
|
|
|
63
63
|
cwd: string;
|
|
64
64
|
currentPackageName: string;
|
|
65
65
|
target: string[];
|
|
66
|
-
configOrPath: EngineConfig | string |
|
|
66
|
+
configOrPath: EngineConfig | string | Nullish;
|
|
67
67
|
fnName: string;
|
|
68
68
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
69
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
|
|
|
@@ -30,7 +30,7 @@ interface IntegrationContext {
|
|
|
30
30
|
fnUtils: FnUtils;
|
|
31
31
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
32
32
|
devCssFilepath: string;
|
|
33
|
-
tsCodegenFilepath: string |
|
|
33
|
+
tsCodegenFilepath: string | Nullish;
|
|
34
34
|
hasVue: boolean;
|
|
35
35
|
usages: Map<string, UsageRecord[]>;
|
|
36
36
|
hooks: {
|
|
@@ -50,12 +50,12 @@ interface IntegrationContext {
|
|
|
50
50
|
init: () => Promise<any>;
|
|
51
51
|
isReady: boolean;
|
|
52
52
|
configSources: string[];
|
|
53
|
-
resolvedConfigPath: string |
|
|
53
|
+
resolvedConfigPath: string | Nullish;
|
|
54
54
|
engine: Engine;
|
|
55
55
|
transform: (code: string, id: string) => Promise<{
|
|
56
56
|
code: string;
|
|
57
57
|
map: SourceMap;
|
|
58
|
-
} |
|
|
58
|
+
} | Nullish>;
|
|
59
59
|
writeDevCssFile: () => Promise<void>;
|
|
60
60
|
writeTsCodegenFile: () => Promise<void>;
|
|
61
61
|
}
|
|
@@ -63,7 +63,7 @@ interface IntegrationContextOptions {
|
|
|
63
63
|
cwd: string;
|
|
64
64
|
currentPackageName: string;
|
|
65
65
|
target: string[];
|
|
66
|
-
configOrPath: EngineConfig | string |
|
|
66
|
+
configOrPath: EngineConfig | string | Nullish;
|
|
67
67
|
fnName: string;
|
|
68
68
|
transformedFormat: 'string' | 'array' | 'inline';
|
|
69
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");
|
|
@@ -150,15 +150,21 @@ async function generateOverloadContent(ctx) {
|
|
|
150
150
|
async function generateTsCodegenContent(ctx) {
|
|
151
151
|
const lines = [
|
|
152
152
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
153
|
-
`import type {
|
|
154
|
-
|
|
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
|
+
"}",
|
|
155
165
|
""
|
|
156
166
|
];
|
|
157
167
|
lines.push(...generateAutocomplete(ctx));
|
|
158
|
-
lines.push(
|
|
159
|
-
"export const defineEngineConfig: ReturnType<typeof createDefineEngineConfigFn<Autocomplete>> = createDefineEngineConfigFn<Autocomplete>()",
|
|
160
|
-
""
|
|
161
|
-
);
|
|
162
168
|
lines.push(...generateStyleFn(ctx));
|
|
163
169
|
lines.push(...generateGlobalDeclaration(ctx));
|
|
164
170
|
lines.push(...generateVueDeclaration(ctx));
|
|
@@ -267,9 +273,10 @@ async function createCtx(options) {
|
|
|
267
273
|
resolvedConfigPath = configSources[0];
|
|
268
274
|
await mkdir(dirname(resolvedConfigPath), { recursive: true }).catch(() => {
|
|
269
275
|
});
|
|
270
|
-
const
|
|
276
|
+
const relativeTsCodegenFilepath = tsCodegenFilepath == null ? null : `./${relative(dirname(resolvedConfigPath), tsCodegenFilepath)}`;
|
|
271
277
|
await writeFile(resolvedConfigPath, [
|
|
272
|
-
|
|
278
|
+
...relativeTsCodegenFilepath == null ? [] : [`/// <reference path="${relativeTsCodegenFilepath}" />`],
|
|
279
|
+
`import { defineEngineConfig } from '${currentPackageName}'`,
|
|
273
280
|
"",
|
|
274
281
|
"export default defineEngineConfig({",
|
|
275
282
|
" // Add your PikaCSS engine config here",
|
|
@@ -285,16 +292,6 @@ async function createCtx(options) {
|
|
|
285
292
|
},
|
|
286
293
|
init: async () => {
|
|
287
294
|
ctx.isReady = false;
|
|
288
|
-
await mkdir(dirname(devCssFilepath), { recursive: true }).catch(() => {
|
|
289
|
-
});
|
|
290
|
-
const isDevCssFileExists = await stat(devCssFilepath).then((stat2) => stat2.isFile()).catch(() => false);
|
|
291
|
-
if (isDevCssFileExists === false)
|
|
292
|
-
await writeFile(devCssFilepath, "");
|
|
293
|
-
if (tsCodegenFilepath != null) {
|
|
294
|
-
await mkdir(dirname(tsCodegenFilepath), { recursive: true }).catch(() => {
|
|
295
|
-
});
|
|
296
|
-
await writeFile(tsCodegenFilepath, "export function defineEngineConfig(config: any) { return config }");
|
|
297
|
-
}
|
|
298
295
|
ctx.usages.clear();
|
|
299
296
|
const { config, file } = await ctx.loadConfig().catch((error) => {
|
|
300
297
|
warn(`Failed to load config file: ${error.message}`, error);
|
|
@@ -313,6 +310,20 @@ async function createCtx(options) {
|
|
|
313
310
|
atomicStyleAdded: () => ctx.hooks.styleUpdated.trigger(),
|
|
314
311
|
autocompleteConfigUpdated: () => ctx.hooks.tsCodegenUpdated.trigger()
|
|
315
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
|
+
}
|
|
316
327
|
ctx.isReady = true;
|
|
317
328
|
},
|
|
318
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"
|