@secondlayer/cli 0.1.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 +21 -0
- package/README.md +233 -0
- package/dist/cli.cjs +897 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +874 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/plugin-manager.cjs +368 -0
- package/dist/core/plugin-manager.cjs.map +1 -0
- package/dist/core/plugin-manager.d.cts +1 -0
- package/dist/core/plugin-manager.d.ts +1 -0
- package/dist/core/plugin-manager.js +333 -0
- package/dist/core/plugin-manager.js.map +1 -0
- package/dist/index.cjs +380 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +342 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin-manager-DBXFfyFZ.d.cts +285 -0
- package/dist/plugin-manager-DBXFfyFZ.d.ts +285 -0
- package/dist/plugins/index.cjs +2622 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +136 -0
- package/dist/plugins/index.d.ts +136 -0
- package/dist/plugins/index.js +2578 -0
- package/dist/plugins/index.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for @stacks/codegen
|
|
3
|
+
*/
|
|
4
|
+
type NetworkName = "mainnet" | "testnet" | "devnet";
|
|
5
|
+
interface ContractSource {
|
|
6
|
+
/**
|
|
7
|
+
* Contract identifier (address.name) for deployed contracts
|
|
8
|
+
*/
|
|
9
|
+
address?: string | Partial<Record<NetworkName, string>>;
|
|
10
|
+
/**
|
|
11
|
+
* Path to local Clarity file
|
|
12
|
+
*/
|
|
13
|
+
source?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional name to use in generated code
|
|
16
|
+
*/
|
|
17
|
+
name?: string;
|
|
18
|
+
}
|
|
19
|
+
interface StacksConfig {
|
|
20
|
+
/**
|
|
21
|
+
* Contracts to generate interfaces for (optional - plugins can provide these)
|
|
22
|
+
*/
|
|
23
|
+
contracts?: ContractSource[];
|
|
24
|
+
/**
|
|
25
|
+
* Output file path
|
|
26
|
+
*/
|
|
27
|
+
out: string;
|
|
28
|
+
/**
|
|
29
|
+
* Plugins to use for generation
|
|
30
|
+
*/
|
|
31
|
+
plugins?: any[];
|
|
32
|
+
/**
|
|
33
|
+
* Network to use for fetching contracts
|
|
34
|
+
*/
|
|
35
|
+
network?: NetworkName;
|
|
36
|
+
/**
|
|
37
|
+
* API key for Stacks API (if required)
|
|
38
|
+
*/
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Base URL for Stacks API (optional override)
|
|
42
|
+
*/
|
|
43
|
+
apiUrl?: string;
|
|
44
|
+
}
|
|
45
|
+
interface ResolvedContract {
|
|
46
|
+
name: string;
|
|
47
|
+
address: string;
|
|
48
|
+
contractName: string;
|
|
49
|
+
abi: any;
|
|
50
|
+
source: "api" | "local";
|
|
51
|
+
}
|
|
52
|
+
type ConfigDefiner = (config: StacksConfig) => StacksConfig;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Plugin system types for @stacks/codegen
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Core plugin interface that all plugins must implement
|
|
60
|
+
*/
|
|
61
|
+
interface StacksCodegenPlugin {
|
|
62
|
+
/** Plugin name (should be unique) */
|
|
63
|
+
name: string;
|
|
64
|
+
/** Plugin version */
|
|
65
|
+
version: string;
|
|
66
|
+
/** Called after config is resolved but before generation starts */
|
|
67
|
+
configResolved?: (config: ResolvedConfig) => void | Promise<void>;
|
|
68
|
+
/** Called before generation starts */
|
|
69
|
+
beforeGenerate?: (context: GenerateContext) => void | Promise<void>;
|
|
70
|
+
/** Called during generation phase - plugins can add their own outputs */
|
|
71
|
+
generate?: (context: GenerateContext) => void | Promise<void>;
|
|
72
|
+
/** Called after all generation is complete */
|
|
73
|
+
afterGenerate?: (context: GenerateContext) => void | Promise<void>;
|
|
74
|
+
/** Transform user config before resolution */
|
|
75
|
+
transformConfig?: (config: UserConfig) => UserConfig | Promise<UserConfig>;
|
|
76
|
+
/** Transform individual contracts during processing */
|
|
77
|
+
transformContract?: (contract: ContractConfig) => ContractConfig | Promise<ContractConfig>;
|
|
78
|
+
/** Transform generated output before writing to disk */
|
|
79
|
+
transformOutput?: (output: string, type: OutputType) => string | Promise<string>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* User configuration (before plugin transformations)
|
|
83
|
+
*/
|
|
84
|
+
type UserConfig = StacksConfig;
|
|
85
|
+
/**
|
|
86
|
+
* Resolved configuration (after plugin transformations)
|
|
87
|
+
*/
|
|
88
|
+
interface ResolvedConfig extends StacksConfig {
|
|
89
|
+
/** Resolved plugins array */
|
|
90
|
+
plugins: StacksCodegenPlugin[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Contract configuration that can be transformed by plugins
|
|
94
|
+
*/
|
|
95
|
+
interface ContractConfig {
|
|
96
|
+
name?: string;
|
|
97
|
+
address?: string | Partial<Record<NetworkName, string>>;
|
|
98
|
+
source?: string;
|
|
99
|
+
abi?: any;
|
|
100
|
+
metadata?: Record<string, any>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Processed contract with resolved ABI and metadata
|
|
104
|
+
*/
|
|
105
|
+
interface ProcessedContract extends ResolvedContract {
|
|
106
|
+
/** Additional metadata added by plugins */
|
|
107
|
+
metadata?: Record<string, any>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generated output from plugins
|
|
111
|
+
*/
|
|
112
|
+
interface GeneratedOutput {
|
|
113
|
+
/** File path where output should be written */
|
|
114
|
+
path: string;
|
|
115
|
+
/** Generated content */
|
|
116
|
+
content: string;
|
|
117
|
+
/** Output type for transformation hooks */
|
|
118
|
+
type?: OutputType;
|
|
119
|
+
/** Whether this output should overwrite existing files */
|
|
120
|
+
overwrite?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Types of outputs that can be generated
|
|
124
|
+
*/
|
|
125
|
+
type OutputType = "contracts" | "hooks" | "actions" | "types" | "utils" | "config" | "other";
|
|
126
|
+
/**
|
|
127
|
+
* Base context available to all plugin hooks
|
|
128
|
+
*/
|
|
129
|
+
interface PluginContext {
|
|
130
|
+
/** Resolved configuration */
|
|
131
|
+
config: ResolvedConfig;
|
|
132
|
+
/** Logger for plugin output */
|
|
133
|
+
logger: Logger;
|
|
134
|
+
/** Utility functions for plugins */
|
|
135
|
+
utils: PluginUtils;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Context available during generation phase
|
|
139
|
+
*/
|
|
140
|
+
interface GenerateContext extends PluginContext {
|
|
141
|
+
/** Processed contracts ready for generation */
|
|
142
|
+
contracts: ProcessedContract[];
|
|
143
|
+
/** Map of output keys to generated content */
|
|
144
|
+
outputs: Map<string, GeneratedOutput>;
|
|
145
|
+
/** Function to augment existing outputs */
|
|
146
|
+
augment: (outputKey: string, contractName: string, content: any) => void;
|
|
147
|
+
/** Function to add new outputs */
|
|
148
|
+
addOutput: (key: string, output: GeneratedOutput) => void;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Logger interface for plugin output
|
|
152
|
+
*/
|
|
153
|
+
interface Logger {
|
|
154
|
+
info: (message: string) => void;
|
|
155
|
+
warn: (message: string) => void;
|
|
156
|
+
error: (message: string) => void;
|
|
157
|
+
debug: (message: string) => void;
|
|
158
|
+
success: (message: string) => void;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Utility functions available to plugins
|
|
162
|
+
*/
|
|
163
|
+
interface PluginUtils {
|
|
164
|
+
/** Convert kebab-case to camelCase */
|
|
165
|
+
toCamelCase: (str: string) => string;
|
|
166
|
+
/** Convert camelCase to kebab-case */
|
|
167
|
+
toKebabCase: (str: string) => string;
|
|
168
|
+
/** Validate Stacks address format */
|
|
169
|
+
validateAddress: (address: string) => boolean;
|
|
170
|
+
/** Parse contract identifier (address.contract-name) */
|
|
171
|
+
parseContractId: (contractId: string) => {
|
|
172
|
+
address: string;
|
|
173
|
+
contractName: string;
|
|
174
|
+
};
|
|
175
|
+
/** Format TypeScript code using prettier */
|
|
176
|
+
formatCode: (code: string) => Promise<string>;
|
|
177
|
+
/** Resolve file path relative to project root */
|
|
178
|
+
resolvePath: (relativePath: string) => string;
|
|
179
|
+
/** Check if file exists */
|
|
180
|
+
fileExists: (path: string) => Promise<boolean>;
|
|
181
|
+
/** Read file content */
|
|
182
|
+
readFile: (path: string) => Promise<string>;
|
|
183
|
+
/** Write file content */
|
|
184
|
+
writeFile: (path: string, content: string) => Promise<void>;
|
|
185
|
+
/** Create directory recursively */
|
|
186
|
+
ensureDir: (path: string) => Promise<void>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Plugin factory function type for creating plugins with options
|
|
190
|
+
*/
|
|
191
|
+
type PluginFactory<TOptions = any> = (options?: TOptions) => StacksCodegenPlugin;
|
|
192
|
+
/**
|
|
193
|
+
* Plugin options base interface
|
|
194
|
+
*/
|
|
195
|
+
interface PluginOptions {
|
|
196
|
+
/** Include only specific contracts/functions */
|
|
197
|
+
include?: string[];
|
|
198
|
+
/** Exclude specific contracts/functions */
|
|
199
|
+
exclude?: string[];
|
|
200
|
+
/** Enable debug output */
|
|
201
|
+
debug?: boolean;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Hook execution result
|
|
205
|
+
*/
|
|
206
|
+
interface HookResult<T = any> {
|
|
207
|
+
/** Whether the hook was successful */
|
|
208
|
+
success: boolean;
|
|
209
|
+
/** Result data from the hook */
|
|
210
|
+
data?: T;
|
|
211
|
+
/** Error if hook failed */
|
|
212
|
+
error?: Error;
|
|
213
|
+
/** Plugin that executed the hook */
|
|
214
|
+
plugin: string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Plugin Manager for @stacks/codegen
|
|
219
|
+
* Handles plugin registration, lifecycle execution, and output management
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Core plugin manager that orchestrates plugin execution
|
|
224
|
+
*/
|
|
225
|
+
declare class PluginManager {
|
|
226
|
+
private plugins;
|
|
227
|
+
private logger;
|
|
228
|
+
private utils;
|
|
229
|
+
private executionContext;
|
|
230
|
+
constructor();
|
|
231
|
+
/**
|
|
232
|
+
* Register a plugin
|
|
233
|
+
*/
|
|
234
|
+
register(plugin: StacksCodegenPlugin): void;
|
|
235
|
+
/**
|
|
236
|
+
* Get all registered plugins
|
|
237
|
+
*/
|
|
238
|
+
getPlugins(): StacksCodegenPlugin[];
|
|
239
|
+
/**
|
|
240
|
+
* Transform user config through all plugins
|
|
241
|
+
*/
|
|
242
|
+
transformConfig(config: UserConfig): Promise<ResolvedConfig>;
|
|
243
|
+
/**
|
|
244
|
+
* Transform contracts through all plugins
|
|
245
|
+
*/
|
|
246
|
+
transformContracts(contracts: ContractConfig[], _config: ResolvedConfig): Promise<ProcessedContract[]>;
|
|
247
|
+
/**
|
|
248
|
+
* Execute lifecycle hooks
|
|
249
|
+
*/
|
|
250
|
+
executeHook(hookName: keyof StacksCodegenPlugin, context: any): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Execute generation phase with full context
|
|
253
|
+
*/
|
|
254
|
+
executeGeneration(contracts: ProcessedContract[], config: ResolvedConfig): Promise<Map<string, GeneratedOutput>>;
|
|
255
|
+
/**
|
|
256
|
+
* Transform outputs through plugins
|
|
257
|
+
*/
|
|
258
|
+
transformOutputs(outputs: Map<string, GeneratedOutput>): Promise<Map<string, GeneratedOutput>>;
|
|
259
|
+
/**
|
|
260
|
+
* Write outputs to disk
|
|
261
|
+
*/
|
|
262
|
+
writeOutputs(outputs: Map<string, GeneratedOutput>): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Get execution results for debugging
|
|
265
|
+
*/
|
|
266
|
+
getExecutionResults(): Map<string, HookResult[]>;
|
|
267
|
+
/**
|
|
268
|
+
* Augment existing output with additional content
|
|
269
|
+
*/
|
|
270
|
+
private augmentOutput;
|
|
271
|
+
/**
|
|
272
|
+
* Record hook execution result
|
|
273
|
+
*/
|
|
274
|
+
private recordHookResult;
|
|
275
|
+
/**
|
|
276
|
+
* Create logger instance
|
|
277
|
+
*/
|
|
278
|
+
private createLogger;
|
|
279
|
+
/**
|
|
280
|
+
* Create utils instance
|
|
281
|
+
*/
|
|
282
|
+
private createUtils;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export { type ConfigDefiner as C, type GenerateContext as G, type Logger as L, type NetworkName as N, type OutputType as O, type PluginFactory as P, type ResolvedConfig as R, type StacksConfig as S, type UserConfig as U, type ContractSource as a, type StacksCodegenPlugin as b, type PluginOptions as c, type PluginContext as d, type PluginUtils as e, type GeneratedOutput as f, type ProcessedContract as g, type ContractConfig as h, PluginManager as i };
|