Skip to content

Commit 50715a5

Browse files
committed
chore: update generated loaders
1 parent 451eee4 commit 50715a5

6 files changed

Lines changed: 499 additions & 16 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ dist/
1010
*.tsbuildinfo
1111

1212
# Auto-generated files
13-
src/version.ts
14-
src/core/generated-plugins.ts
15-
src/core/generated-resources.ts
1613

1714
# IDE and editor files
1815
.idea/

build-plugins/plugin-discovery.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async function generateWorkflowLoaders() {
8181
}
8282

8383
// Generate the content for generated-plugins.ts
84-
const generatedContent = generatePluginsFileContent(workflowLoaders, workflowMetadata);
84+
const generatedContent = await generatePluginsFileContent(workflowLoaders, workflowMetadata);
8585

8686
// Write to the generated file
8787
const outputPath = path.resolve(process.cwd(), 'src/core/generated-plugins.ts');
@@ -148,7 +148,7 @@ function extractWorkflowMetadata(content) {
148148
}
149149
}
150150

151-
function generatePluginsFileContent(workflowLoaders, workflowMetadata) {
151+
async function generatePluginsFileContent(workflowLoaders, workflowMetadata) {
152152
const loaderEntries = Object.entries(workflowLoaders)
153153
.map(([key, loader]) => {
154154
// Indent the loader function properly
@@ -170,7 +170,7 @@ function generatePluginsFileContent(workflowLoaders, workflowMetadata) {
170170
})
171171
.join(',\n');
172172

173-
return `// AUTO-GENERATED - DO NOT EDIT
173+
const content = `// AUTO-GENERATED - DO NOT EDIT
174174
// This file is generated by the plugin discovery esbuild plugin
175175
176176
// Generated based on filesystem scan
@@ -185,6 +185,7 @@ export const WORKFLOW_METADATA = {
185185
${metadataEntries}
186186
};
187187
`;
188+
return formatGenerated(content);
188189
}
189190

190191
async function generateResourceLoaders() {
@@ -222,7 +223,7 @@ async function generateResourceLoaders() {
222223
}
223224

224225
// Generate the content for generated-resources.ts
225-
const generatedContent = generateResourcesFileContent(resourceLoaders);
226+
const generatedContent = await generateResourcesFileContent(resourceLoaders);
226227

227228
// Write to the generated file
228229
const outputPath = path.resolve(process.cwd(), 'src/core/generated-resources.ts');
@@ -233,12 +234,12 @@ async function generateResourceLoaders() {
233234
console.log(`🔧 Generated resource loaders for ${Object.keys(resourceLoaders).length} resources`);
234235
}
235236

236-
function generateResourcesFileContent(resourceLoaders) {
237+
async function generateResourcesFileContent(resourceLoaders) {
237238
const loaderEntries = Object.entries(resourceLoaders)
238239
.map(([key, loader]) => ` '${key}': ${loader}`)
239240
.join(',\n');
240241

241-
return `// AUTO-GENERATED - DO NOT EDIT
242+
const content = `// AUTO-GENERATED - DO NOT EDIT
242243
// This file is generated by the plugin discovery esbuild plugin
243244
244245
export const RESOURCE_LOADERS = {
@@ -247,4 +248,36 @@ ${loaderEntries}
247248
248249
export type ResourceName = keyof typeof RESOURCE_LOADERS;
249250
`;
251+
return formatGenerated(content);
252+
}
253+
254+
async function formatGenerated(content) {
255+
try {
256+
const { resolve } = await import('node:path');
257+
const { pathToFileURL } = await import('node:url');
258+
const prettier = await import('prettier');
259+
let config = (await prettier.resolveConfig(process.cwd())) ?? null;
260+
if (!config) {
261+
try {
262+
const configUrl = pathToFileURL(resolve(process.cwd(), '.prettierrc.js')).href;
263+
const configModule = await import(configUrl);
264+
config = configModule.default ?? configModule;
265+
} catch {
266+
config = null;
267+
}
268+
}
269+
const options = {
270+
semi: true,
271+
trailingComma: 'all',
272+
singleQuote: true,
273+
printWidth: 100,
274+
tabWidth: 2,
275+
endOfLine: 'auto',
276+
...config,
277+
parser: 'typescript',
278+
};
279+
return prettier.format(content, options);
280+
} catch {
281+
return content;
282+
}
250283
}

build-plugins/plugin-discovery.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function generateWorkflowLoaders(): Promise<void> {
8686
}
8787

8888
// Generate the content for generated-plugins.ts
89-
const generatedContent = generatePluginsFileContent(workflowLoaders, workflowMetadata);
89+
const generatedContent = await generatePluginsFileContent(workflowLoaders, workflowMetadata);
9090

9191
// Write to the generated file
9292
const outputPath = path.resolve(process.cwd(), 'src/core/generated-plugins.ts');
@@ -151,10 +151,10 @@ function extractWorkflowMetadata(content: string): WorkflowMetadata | null {
151151
}
152152
}
153153

154-
function generatePluginsFileContent(
154+
async function generatePluginsFileContent(
155155
workflowLoaders: Record<string, string>,
156156
workflowMetadata: Record<string, WorkflowMetadata>,
157-
): string {
157+
): Promise<string> {
158158
const loaderEntries = Object.entries(workflowLoaders)
159159
.map(([key, loader]) => {
160160
const indentedLoader = loader
@@ -175,7 +175,7 @@ function generatePluginsFileContent(
175175
})
176176
.join(',\n');
177177

178-
return `// AUTO-GENERATED - DO NOT EDIT
178+
const content = `// AUTO-GENERATED - DO NOT EDIT
179179
// This file is generated by the plugin discovery esbuild plugin
180180
181181
// Generated based on filesystem scan
@@ -190,6 +190,7 @@ export const WORKFLOW_METADATA = {
190190
${metadataEntries}
191191
};
192192
`;
193+
return formatGenerated(content);
193194
}
194195

195196
export async function generateResourceLoaders(): Promise<void> {
@@ -223,7 +224,7 @@ export async function generateResourceLoaders(): Promise<void> {
223224
console.log(`✅ Discovered resource: ${resourceName}`);
224225
}
225226

226-
const generatedContent = generateResourcesFileContent(resourceLoaders);
227+
const generatedContent = await generateResourcesFileContent(resourceLoaders);
227228
const outputPath = path.resolve(process.cwd(), 'src/core/generated-resources.ts');
228229

229230
const fs = await import('fs');
@@ -232,12 +233,14 @@ export async function generateResourceLoaders(): Promise<void> {
232233
console.log(`🔧 Generated resource loaders for ${Object.keys(resourceLoaders).length} resources`);
233234
}
234235

235-
function generateResourcesFileContent(resourceLoaders: Record<string, string>): string {
236+
async function generateResourcesFileContent(
237+
resourceLoaders: Record<string, string>,
238+
): Promise<string> {
236239
const loaderEntries = Object.entries(resourceLoaders)
237240
.map(([key, loader]) => ` '${key}': ${loader}`)
238241
.join(',\n');
239242

240-
return `// AUTO-GENERATED - DO NOT EDIT
243+
const content = `// AUTO-GENERATED - DO NOT EDIT
241244
// This file is generated by the plugin discovery esbuild plugin
242245
243246
export const RESOURCE_LOADERS = {
@@ -246,4 +249,36 @@ ${loaderEntries}
246249
247250
export type ResourceName = keyof typeof RESOURCE_LOADERS;
248251
`;
252+
return formatGenerated(content);
253+
}
254+
255+
async function formatGenerated(content: string): Promise<string> {
256+
try {
257+
const { resolve } = await import('node:path');
258+
const { pathToFileURL } = await import('node:url');
259+
const prettier = await import('prettier');
260+
let config = (await prettier.resolveConfig(process.cwd())) ?? null;
261+
if (!config) {
262+
try {
263+
const configUrl = pathToFileURL(resolve(process.cwd(), '.prettierrc.js')).href;
264+
const configModule = await import(configUrl);
265+
config = (configModule as { default?: unknown }).default ?? configModule;
266+
} catch {
267+
config = null;
268+
}
269+
}
270+
const options = {
271+
semi: true,
272+
trailingComma: 'all' as const,
273+
singleQuote: true,
274+
printWidth: 100,
275+
tabWidth: 2,
276+
endOfLine: 'auto' as const,
277+
...(config as Record<string, unknown> | null),
278+
parser: 'typescript',
279+
};
280+
return prettier.format(content, options);
281+
} catch {
282+
return content;
283+
}
249284
}

0 commit comments

Comments
 (0)