Skip to content

Commit 3b6aee2

Browse files
committed
fix(plugins): don't overwrite files created by unsupported plugin
1 parent cf0452b commit 3b6aee2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cmd/recodegen/recodegen.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"runtime"
1414
)
1515

16-
const VERSION = "v0.2.1"
16+
const VERSION = "v0.2.2"
1717

1818
func main() {
1919
configFileName := flag.String("config", "recodegen.json", "Configuration file name")
@@ -58,14 +58,16 @@ func main() {
5858

5959
func processInput(schemaAst *ast.Schema, outputFileName string, genConfig config.CodegenSchemaEntryConfig) {
6060
output := ""
61+
hadKnownPlugin := false
6162
for _, plugin := range genConfig.Plugins {
6263
if plugin == "typescript" {
63-
//generateSchema(schemaAst, outputFileName)
64+
hadKnownPlugin = true
6465
schema := typescript.Schema{Ast: schemaAst}
6566
output += schema.String()
6667
}
6768

6869
if plugin == "typescript-operations" {
70+
hadKnownPlugin = true
6971
operation := typescript.Operations{
7072
Ast: schemaAst,
7173
Config: genConfig,
@@ -75,6 +77,12 @@ func processInput(schemaAst *ast.Schema, outputFileName string, genConfig config
7577
}
7678
}
7779

80+
// don't write anything to a file if no known plugins were used
81+
if !hadKnownPlugin {
82+
fmt.Printf("[skipping] %s\n", outputFileName)
83+
return
84+
}
85+
7886
existingFileContent := getFileContentIfExists(outputFileName)
7987
if *existingFileContent != output {
8088
fmt.Printf("[writing] %s\n", outputFileName)

npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphql-recodegen/cli",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Faster GraphQL codegen for TypeScript projects",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)