-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use plugin runtime source for config include
- Loading branch information
1 parent
d7f666d
commit 148df35
Showing
6 changed files
with
97 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
push: | ||
branches: | ||
- next | ||
- component-fields | ||
- plugin-runtime-search | ||
|
||
env: | ||
CI: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/houdini/src/codegen/generators/runtime/pluginRuntime.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { moduleStatments } from '.' | ||
import type { Config, Document } from '../../../lib' | ||
import { fs, HoudiniError, path, houdini_mode } from '../../../lib' | ||
|
||
export async function generatePluginRuntimes({ | ||
config, | ||
docs, | ||
}: { | ||
config: Config | ||
docs: Document[] | ||
}) { | ||
if (houdini_mode.is_testing) { | ||
return | ||
} | ||
|
||
// generate the import statements | ||
const { importStatement, exportDefaultStatement, exportStarStatement } = moduleStatments(config) | ||
|
||
// generate the runtime for each plugin | ||
await Promise.all( | ||
config.plugins | ||
.filter((plugin) => plugin.includeRuntime) | ||
.map(async (plugin) => { | ||
// a plugin has told us to include a runtime then the path is relative to the plugin file | ||
const runtime_path = config.pluginRuntimeSource(plugin) | ||
if (!runtime_path) { | ||
return | ||
} | ||
|
||
// make sure the source file exists | ||
try { | ||
await fs.stat(runtime_path) | ||
} catch { | ||
throw new HoudiniError({ | ||
message: 'Cannot find runtime to generate for ' + plugin.name, | ||
description: 'Maybe it was bundled?', | ||
}) | ||
} | ||
|
||
// copy the runtime | ||
const pluginDir = config.pluginRuntimeDirectory(plugin.name) | ||
let transformMap = plugin.transformRuntime ?? {} | ||
if (transformMap && typeof transformMap === 'function') { | ||
transformMap = transformMap(docs, { config }) | ||
} | ||
|
||
await fs.mkdirp(pluginDir) | ||
await fs.recursiveCopy( | ||
runtime_path, | ||
pluginDir, | ||
Object.fromEntries( | ||
Object.entries(transformMap).map(([key, value]) => [ | ||
path.join(runtime_path, key), | ||
(content) => | ||
value({ | ||
config, | ||
content, | ||
importStatement, | ||
exportDefaultStatement, | ||
exportStarStatement, | ||
}), | ||
]) | ||
) | ||
) | ||
}) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters