-
Notifications
You must be signed in to change notification settings - Fork 8
/
plugin.d.ts
177 lines (162 loc) · 4.07 KB
/
plugin.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { PrismLang } from "./prism";
/**
* @public
*/
export interface LeveledLogMethod {
(message: string): void;
(message: string, meta: unknown): void;
(message: string, ...meta: any[]): void;
(infoObject: object): void;
}
/**
* Contains custom plugin configuration and logger
*
* @public
*/
export interface PluginContext {
/** {@inheritdoc PluginConfig} */
config?: PluginConfig;
/** {@inheritdoc ComponentConfig} */
components: ComponentConfig[];
logger: Logger;
}
/**
* Custom created link for a component
*
* @public
*/
export interface Link {
/** Name of the link */
name?: string;
/** Full URL to the resource */
url: string;
/**
* Type of the link.
* Required to show a pretty link for certain types of links on Zeplin.
*/
type: LinkType;
metadata?: Record<string, unknown>;
}
/**
* Link types for application link logo
* Use `LinkType.custom` if you are not sure what to do
* @public
*/
export const enum LinkType {
storybook = "storybook",
github = "github",
gitlab = "gitlab",
bitbucket = "bitbucket",
custom = "custom"
}
/**
* Contains processed component data
*
* @public
*/
export interface ComponentData {
/** Description of the component */
description?: string;
/** Language of the snippet for highlighting */
lang?: PrismLang;
/** Code snippet of the component */
snippet?: string;
/** {@inheritdoc Link} */
links?: Link[];
}
/**
* Arbitrary key/values for custom plugin configuration.
*
* @public
*/
export interface PluginConfig {
[key: string]: unknown;
}
/**
* Contains basic configuration for a component.
*
* @public
*/
export interface ComponentConfigBase {
/** Path to the file, relative to project folder. */
path: string;
/** Zeplin component names related to this component file */
zeplinNames?: string[];
/** Zeplin component source IDs related to this component file */
zeplinIds?: string[];
/** Name for the component */
name?: string;
}
/**
* Use it as a value of {@link ComponentConfigCustom} keys for custom link composition
*
* @public
*/
export interface CustomUrlConfig {
urlPath: string;
}
/**
* Custom key/value configuration for a component.
* Can be used to compose custom links for components
* or can be processed by plugins for custom usage.
*
* @public
*/
export interface ComponentConfigCustom {
[key: string]: CustomUrlConfig | unknown;
}
/**
* Union of {@link ComponentConfigBase} and {@link ComponentConfigCustom}
*
* @public
*/
export type ComponentConfig = ComponentConfigBase & ComponentConfigCustom;
/**
* Interface for Zeplin CLI Connected Components plugins
*
* @public
*/
export interface ConnectPlugin {
/**
* CLI invokes this method once the package is loaded.
* PluginContext contains arbitrary configuration set for the plugin
* on components config file.
*
* This method is optional. Implement it to initialize plugin locals etc.
* based on plugin configuration.
*
*
* @param pluginContext - {@link PluginContext}
*/
init?(pluginContext: PluginContext): Promise<void>;
/**
* CLI invokes this method for each component in the configuration file.
*
* @param componentConfig - {@link ComponentConfig}
* @returns - {@link ComponentData}
*/
process(componentConfig: ComponentConfig): Promise<ComponentData>;
/**
* CLI invokes this method for each component in the configuration file
* to determine if this plugin should process this component
*
* @param componentConfig - {@link ComponentConfig}
* @returns true if the plugin supports the component, false otherwise
*/
supports(componentConfig: ComponentConfig): boolean;
/**
* CLI gets this data to create a global metadata object
*/
metadata?: Record<string, unknown>;
}
/**
* Interface for Zeplin CLI's logger.
*
* @public
*/
export interface Logger {
error: LeveledLogMethod;
warn: LeveledLogMethod;
info: LeveledLogMethod;
debug: LeveledLogMethod;
}