@trackunit/react-graphql-tools 0.0.49-alpha-9c359562be.0 → 0.0.50
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/CHANGELOG.md +9 -1
- package/package.json +1 -1
- package/src/executors/createHooks/executor.js +1 -1
- package/src/executors/createHooks/executor.js.map +1 -1
- package/src/executors/createHooks/scrubFile.js +1 -0
- package/src/executors/createHooks/scrubFile.js.map +1 -1
- package/src/executors/createHooks/scrubMockFile.js +6 -4
- package/src/executors/createHooks/scrubMockFile.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
-
## [0.0.
|
|
5
|
+
## [0.0.50](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.49...react-graphql-tools/0.0.50) (2023-11-28)
|
|
6
6
|
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `test-setup` updated to version `0.0.49`
|
|
10
|
+
## [0.0.49](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.48...react-graphql-tools/0.0.49) (2023-11-28)
|
|
11
|
+
|
|
12
|
+
### Dependency Updates
|
|
13
|
+
|
|
14
|
+
* `test-setup` updated to version `0.0.48`
|
|
7
15
|
## [0.0.48](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.47...react-graphql-tools/0.0.48) (2023-11-23)
|
|
8
16
|
|
|
9
17
|
|
package/package.json
CHANGED
|
@@ -48,7 +48,7 @@ export default config;
|
|
|
48
48
|
}
|
|
49
49
|
yield (0, scrubFile_1.scrubFile)(pathToGenerateFile, nxRoot, context.isVerbose);
|
|
50
50
|
}
|
|
51
|
-
const pathToGenerateInternalFile = (0, path_1.join)(fullLibRoot, "src", "generated", "graphql-api
|
|
51
|
+
const pathToGenerateInternalFile = (0, path_1.join)(fullLibRoot, "src", "generated", "internal-graphql-api", "graphql.ts");
|
|
52
52
|
if ((0, fs_1.existsSync)(pathToGenerateInternalFile)) {
|
|
53
53
|
if (context.isVerbose) {
|
|
54
54
|
console.log("Scrubbing internal file: ", pathToGenerateInternalFile);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/executor.ts"],"names":[],"mappings":";;;;AACA,2BAAgC;AAChC,+BAA4B;AAC5B,mDAAgD;AAChD,2CAAwC;AAExC;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAAO,OAAgB,EAAE,OAAwB,EAAE,EAAE;IACrF,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IACjC,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE;QACnC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAY,CAAC,CAAC,IAAI,CAAC;IAEnF,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,IAAA,eAAU,EAAC,IAAA,WAAI,EAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QACrE,CAAC,CAAC,IAAA,WAAI,EAAC,WAAW,EAAE,mBAAmB,CAAC;QACxC,CAAC,CAAC,IAAA,WAAI,EAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;IAE3C,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IAED,MAAM,eAAe,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACxD,IAAI,CAAC,IAAA,eAAU,EAAC,eAAe,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,gCAAgC,WAAW;;;;;;;;;CAS9D,CAAC,CAAC;KACA;IAED,MAAM,IAAA,6BAAa,EAAC,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;IAC3G,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,MAAM,EAAE;QACrC,MAAM,kBAAkB,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;QAC9F,IAAI,IAAA,eAAU,EAAC,kBAAkB,CAAC,EAAE;YAClC,IAAI,OAAO,CAAC,SAAS,EAAE;gBACrB,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;aACrD;YACD,MAAM,IAAA,qBAAS,EAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;SAChE;QACD,MAAM,0BAA0B,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,YAAY,CAAC,CAAC;QAC/G,IAAI,IAAA,eAAU,EAAC,0BAA0B,CAAC,EAAE;YAC1C,IAAI,OAAO,CAAC,SAAS,EAAE;gBACrB,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,0BAA0B,CAAC,CAAC;aACtE;YACD,MAAM,IAAA,qBAAS,EAAC,0BAA0B,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;SACxE;KACF;IACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACxB,CAAC,CAAA,CAAC;AAhDW,QAAA,kBAAkB,sBAgD7B;AAEF,kBAAe,0BAAkB,CAAC","sourcesContent":["import { ExecutorContext } from \"@nx/devkit\";\nimport { existsSync } from \"fs\";\nimport { join } from \"path\";\nimport { generateHooks } from \"./generateHooks\";\nimport { scrubFile } from \"./scrubFile\";\n\n/**\n * This executor generates react hooks for all graphql files.\n *\n * @param _unused unused props from nx\n * @param context The execution context for this executor\n * @returns {Promise<{ success: number; }>} success when finished\n */\nexport const CreateGraphqlHooks = async (_unused: unknown, context: ExecutorContext) => {\n const nxRoot = `${context.root}`;\n if (!context.projectsConfigurations) {\n throw new Error(\"context projectsConfigurations is required\");\n }\n const libRoot = context.projectsConfigurations.projects[context.projectName!].root;\n\n const fullLibRoot = join(nxRoot, libRoot);\n const tsConfigPath = existsSync(join(fullLibRoot, \"tsconfig.lib.json\"))\n ? join(fullLibRoot, \"tsconfig.lib.json\")\n : join(fullLibRoot, \"tsconfig.app.json\");\n\n if (!tsConfigPath) {\n throw new Error(\"context projectsConfigurations is required\");\n }\n\n const codeGenFilePath = join(fullLibRoot, \"codegen.ts\");\n if (!existsSync(codeGenFilePath)) {\n throw new Error(`codegen.ts file not found in ${fullLibRoot} please add this file and run again to generate hooks. The content should be\nimport { type CodegenConfig } from \"@graphql-codegen/cli\";\nimport { getGraphqlCodegenConfig } from \"@trackunit/iris-app-build-utilities\";\n\nconst config: CodegenConfig = {\n ...getGraphqlCodegenConfig(__dirname),\n // You can override codegen default config here\n};\nexport default config;\n`);\n }\n\n await generateHooks({ nxRoot: context.root, codeGenFilePath, isVerbose: context.isVerbose, tsConfigPath });\n if (process.env.SKIP_SCRUB !== \"true\") {\n const pathToGenerateFile = join(fullLibRoot, \"src\", \"generated\", \"graphql-api\", \"graphql.ts\");\n if (existsSync(pathToGenerateFile)) {\n if (context.isVerbose) {\n console.log(\"Scrubbing file: \", pathToGenerateFile);\n }\n await scrubFile(pathToGenerateFile, nxRoot, context.isVerbose);\n }\n const pathToGenerateInternalFile = join(fullLibRoot, \"src\", \"generated\", \"graphql-api
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/executor.ts"],"names":[],"mappings":";;;;AACA,2BAAgC;AAChC,+BAA4B;AAC5B,mDAAgD;AAChD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AE,aAAa,EAAE,YAAY,CAAC,CAAC;QAC9F,IAAI,IAAA,eAAU,EAAC,kBAAkB,CAAC,EAAE;YAClC,IAAI,OAAO,CAAC,SAAS,EAAE;gBACrB,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;aACrD;YACD,MAAM,IAAA,qBAAS,EAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;SAChE;QACD,MAAM,0BAA0B,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,YAAY,CAAC,CAAC;QAC/G,IAAI,IAAA,eAAU,EAAC,0BAA0B,CAAC,EAAE;YAC1C,IAAI,OAAO,CAAC,SAAS,EAAE;gBACrB,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,0BAA0B,CAAC,CAAC;aACtE;YACD,MAAM,IAAA,qBAAS,EAAC,0BAA0B,EAAE,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;SACxE;KACF;IACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACxB,CAAC,CAAA,CAAC;AAhDW,QAAA,kBAAkB,sBAgD7B;AAEF,kBAAe,0BAAkB,CAAC","sourcesContent":["import { ExecutorContext } from \"@nx/devkit\";\nimport { existsSync } from \"fs\";\nimport { join } from \"path\";\nimport { generateHooks } from \"./generateHooks\";\nimport { scrubFile } from \"./scrubFile\";\n\n/**\n * This executor generates react hooks for all graphql files.\n *\n * @param _unused unused props from nx\n * @param context The execution context for this executor\n * @returns {Promise<{ success: number; }>} success when finished\n */\nexport const CreateGraphqlHooks = async (_unused: unknown, context: ExecutorContext) => {\n const nxRoot = `${context.root}`;\n if (!context.projectsConfigurations) {\n throw new Error(\"context projectsConfigurations is required\");\n }\n const libRoot = context.projectsConfigurations.projects[context.projectName!].root;\n\n const fullLibRoot = join(nxRoot, libRoot);\n const tsConfigPath = existsSync(join(fullLibRoot, \"tsconfig.lib.json\"))\n ? join(fullLibRoot, \"tsconfig.lib.json\")\n : join(fullLibRoot, \"tsconfig.app.json\");\n\n if (!tsConfigPath) {\n throw new Error(\"context projectsConfigurations is required\");\n }\n\n const codeGenFilePath = join(fullLibRoot, \"codegen.ts\");\n if (!existsSync(codeGenFilePath)) {\n throw new Error(`codegen.ts file not found in ${fullLibRoot} please add this file and run again to generate hooks. The content should be\nimport { type CodegenConfig } from \"@graphql-codegen/cli\";\nimport { getGraphqlCodegenConfig } from \"@trackunit/iris-app-build-utilities\";\n\nconst config: CodegenConfig = {\n ...getGraphqlCodegenConfig(__dirname),\n // You can override codegen default config here\n};\nexport default config;\n`);\n }\n\n await generateHooks({ nxRoot: context.root, codeGenFilePath, isVerbose: context.isVerbose, tsConfigPath });\n if (process.env.SKIP_SCRUB !== \"true\") {\n const pathToGenerateFile = join(fullLibRoot, \"src\", \"generated\", \"graphql-api\", \"graphql.ts\");\n if (existsSync(pathToGenerateFile)) {\n if (context.isVerbose) {\n console.log(\"Scrubbing file: \", pathToGenerateFile);\n }\n await scrubFile(pathToGenerateFile, nxRoot, context.isVerbose);\n }\n const pathToGenerateInternalFile = join(fullLibRoot, \"src\", \"generated\", \"internal-graphql-api\", \"graphql.ts\");\n if (existsSync(pathToGenerateInternalFile)) {\n if (context.isVerbose) {\n console.log(\"Scrubbing internal file: \", pathToGenerateInternalFile);\n }\n await scrubFile(pathToGenerateInternalFile, nxRoot, context.isVerbose);\n }\n }\n return { success: 1 };\n};\n\nexport default CreateGraphqlHooks;\n"]}
|
|
@@ -78,6 +78,7 @@ const scrubFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__awaiter(v
|
|
|
78
78
|
node.getName() === "Site" ||
|
|
79
79
|
node.getName() === "Event" ||
|
|
80
80
|
node.getName() === "Account" ||
|
|
81
|
+
node.getName() === "Operator" ||
|
|
81
82
|
node.getName() === "Asset") {
|
|
82
83
|
node.remove();
|
|
83
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrubFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubFile.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,2BAAiD;AACjD,+BAA4B;AAC5B,2DAAqC;AACrC,uCAAgE;AAChE,mDAAuD;AAEvD;;;;;;GAMG;AACH,MAAM,uBAAuB,GAAG,CAAC,UAAsB,EAAE,EAAE;IACzD,MAAM,WAAW,GAAG,UAAU,CAAC,qBAAqB,EAAE,CAAC;IACvD,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;;QAC/B,MAAM,WAAW,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;QAEhD,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAClE,MAAM,cAAc,GAAG,MAAA,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,0CAAG,CAAC,CAAC,CAAC;YAC3D,IAAI,cAAc,EAAE;gBAClB,IAAI,WAAW,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE;oBACtD,MAAM,UAAU,GACd,UAAU,CAAC,sBAAsB,CAAC,cAAc,CAAC;wBACjD,UAAU,CAAC,YAAY,CAAC,cAAc,CAAC;wBACvC,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC;wBAClC,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC;wBACnC,UAAU,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;oBAE1C,IAAI,CAAC,UAAU,EAAE;wBACf,sCAAsC;wBACtC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAC;qBAC9C;yBAAM;wBACL,UAAU,CAAC,MAAM,EAAE,CAAC;qBACrB;iBACF;aACF;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,eAAgC,EAAE,EAAE;IACpE,MAAM,QAAQ,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Aa,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5E,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA,CAAC;AAjDW,QAAA,SAAS,aAiDpB","sourcesContent":["/* eslint-disable no-console */\nimport { readFileSync, writeFileSync } from \"fs\";\nimport { join } from \"path\";\nimport * as prettier from \"prettier\";\nimport { EnumDeclaration, Project, SourceFile } from \"ts-morph\";\nimport { scrubMockFileContent } from \"./scrubMockFile\";\n\n/**\n * Removes unused identifiers from the source file.\n *\n * This does more then sourceFile.fixUnusedIdentifiers(diagnostic) as it also removes unused enums and interfaces.\n *\n * @param sourceFile The source file to remove unused identifiers from.\n */\nconst removeUnusedIdentifiers = (sourceFile: SourceFile) => {\n const diagnostics = sourceFile.getPreEmitDiagnostics();\n diagnostics.forEach(diagnostic => {\n const messageText = diagnostic.getMessageText();\n\n if (typeof messageText === \"string\" && messageText.startsWith(\"'\")) {\n const identifierName = messageText.match(/'([^']+)'/)?.[1];\n if (identifierName) {\n if (messageText.includes(\"is declared but never used\")) {\n const identifier =\n sourceFile.getVariableDeclaration(identifierName) ||\n sourceFile.getInterface(identifierName) ||\n sourceFile.getEnum(identifierName) ||\n sourceFile.getClass(identifierName) ||\n sourceFile.getTypeAlias(identifierName);\n\n if (!identifier) {\n // eslint-disable-next-line no-console\n console.log(\"Could not find: \", messageText);\n } else {\n identifier.remove();\n }\n }\n }\n }\n });\n};\n\nconst convertEnumToConstObject = (enumDeclaration: EnumDeclaration) => {\n const enumName = enumDeclaration.getName();\n const members = enumDeclaration.getMembers();\n\n const properties = members.map(member => {\n const name = member.getName();\n const value = member.getValue();\n return `${name}: '${value}'`;\n });\n\n const lowerCaseFirstLetter = enumName[0].toLowerCase() + enumName.slice(1);\n const constObjectText = `export const ${lowerCaseFirstLetter} = {\\n ${properties.join(\n \",\\n \"\n )},\\n} as const;\\nexport type ${enumName} = typeof ${lowerCaseFirstLetter}[keyof typeof ${lowerCaseFirstLetter}];`;\n\n // Replace the EnumDeclaration with the const object text\n enumDeclaration.replaceWithText(constObjectText);\n};\n\n/**\n * Generates React hooks from your graphql files.\n */\nexport const scrubFileContent = async (fileContent: string, nxRoot: string, isVerbose?: boolean) => {\n const start = new Date().getTime();\n\n const project = new Project({\n compilerOptions: {\n noUnusedLocals: true,\n noUnusedParameters: true,\n },\n });\n const generatedFile = project.createSourceFile(\"tmp.ts\", fileContent);\n\n generatedFile.insertStatements(0, \"/* eslint-disable @typescript-eslint/no-explicit-any */\");\n generatedFile.insertStatements(1, \"/* eslint-disable @typescript-eslint/array-type */\");\n\n generatedFile.getTypeAliases().forEach(node => {\n if (!node.getName().startsWith(\"Incremental\")) {\n node.setIsExported(false);\n }\n\n if (\n node.getName().startsWith(\"Query\") ||\n node.getName().startsWith(\"Mutation\") ||\n // Since they reference each other we remove them here.\n node.getName() === \"Site\" ||\n node.getName() === \"Event\" ||\n node.getName() === \"Account\" ||\n node.getName() === \"Asset\"\n ) {\n node.remove();\n }\n });\n generatedFile.getEnums().forEach(node => {\n node.setIsExported(false);\n });\n let lastWidth = 0;\n do {\n lastWidth = generatedFile.getFullWidth();\n removeUnusedIdentifiers(generatedFile);\n if (isVerbose) {\n console.log(\"Cleanup\", lastWidth, generatedFile.getFullWidth());\n }\n } while (lastWidth !== generatedFile.getFullWidth());\n\n generatedFile.getTypeAliases().forEach(node => {\n node.setIsExported(true);\n });\n generatedFile.getVariableStatements().forEach(variableStatement => {\n variableStatement.setIsExported(true);\n });\n generatedFile.getEnums().forEach(node => {\n node.setIsExported(true);\n convertEnumToConstObject(node);\n });\n\n if (isVerbose) {\n const end = new Date().getTime();\n const time = end - start;\n console.log(\"Execution time: \" + time);\n }\n\n return generatedFile.getFullText();\n};\n\n/**\n * Scrubs the file content.\n *\n * @param file The file to scrub.\n */\nexport const scrubFile = async (file: string, nxRoot: string, isVerbose?: boolean) => {\n const fileContent = readFileSync(file, { encoding: \"utf-8\" });\n if (fileContent.length === 0) {\n console.warn(`File ${file} is empty`);\n }\n const scrubbedMockFileContent = await scrubMockFileContent(fileContent, nxRoot, isVerbose);\n\n const scrubbedFileContent = await scrubFileContent(fileContent, nxRoot, isVerbose);\n\n let options = null;\n try {\n options = prettier\n .resolveConfig(join(nxRoot, \".prettierrc\"), {\n useCache: false,\n editorconfig: false,\n config: join(nxRoot, \".prettierrc\"),\n })\n .catch((error: Error) => console.log(error));\n } catch (e) {\n console.log(e);\n }\n if (!options) {\n throw new Error(\"Could not find prettier config\");\n }\n const prettierOptions = await options;\n\n let prettySrc = scrubbedFileContent;\n if (prettierOptions) {\n prettierOptions.parser = \"typescript\";\n try {\n prettySrc = await prettier.format(scrubbedFileContent, prettierOptions);\n } catch (error) {\n console.error(\"Error in prettier.format:\", error);\n }\n }\n writeFileSync(file, prettySrc, { encoding: \"utf-8\" });\n\n let prettyMockSrc = scrubbedMockFileContent;\n if (prettierOptions) {\n prettierOptions.parser = \"typescript\";\n try {\n prettyMockSrc = await prettier.format(scrubbedMockFileContent, prettierOptions);\n } catch (error) {\n console.error(\"Error in prettier.format:\", error);\n }\n }\n const parentDir = file.split(\"/\").slice(0, -1).join(\"/\");\n writeFileSync(parentDir + \"/mock.ts\", prettyMockSrc, { encoding: \"utf-8\" });\n return prettySrc;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"scrubFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubFile.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,2BAAiD;AACjD,+BAA4B;AAC5B,2DAAqC;AACrC,uCAAgE;AAChE,mDAAuD;AAEvD;;;;;;GAMG;AACH,MAAM,uBAAuB,GAAG,CAAC,UAAsB,EAAE,EAAE;IACzD,MAAM,WAAW,GAAG,UAAU,CAAC,qBAAqB,EAAE,CAAC;IACvD,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;;QAC/B,MAAM,WAAW,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;QAEhD,IAAI,OAAO,WAAW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,eAAe,CAAC,MAAM,GAAG,YAAY,CAAC;QACtC,IAAI;YACF,SAAS,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;SACzE;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;SACnD;KACF;IACD,IAAA,kBAAa,EAAC,IAAI,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAEtD,IAAI,aAAa,GAAG,uBAAuB,CAAC;IAC5C,IAAI,eAAe,EAAE;QACnB,eAAe,CAAC,MAAM,GAAG,YAAY,CAAC;QACtC,IAAI;YACF,aAAa,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,uBAAuB,EAAE,eAAe,CAAC,CAAC;SACjF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;SACnD;KACF;IACD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzD,IAAA,kBAAa,EAAC,SAAS,GAAG,UAAU,EAAE,aAAa,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5E,OAAO,SAAS,CAAC;AACnB,CAAC,CAAA,CAAC;AAjDW,QAAA,SAAS,aAiDpB","sourcesContent":["/* eslint-disable no-console */\nimport { readFileSync, writeFileSync } from \"fs\";\nimport { join } from \"path\";\nimport * as prettier from \"prettier\";\nimport { EnumDeclaration, Project, SourceFile } from \"ts-morph\";\nimport { scrubMockFileContent } from \"./scrubMockFile\";\n\n/**\n * Removes unused identifiers from the source file.\n *\n * This does more then sourceFile.fixUnusedIdentifiers(diagnostic) as it also removes unused enums and interfaces.\n *\n * @param sourceFile The source file to remove unused identifiers from.\n */\nconst removeUnusedIdentifiers = (sourceFile: SourceFile) => {\n const diagnostics = sourceFile.getPreEmitDiagnostics();\n diagnostics.forEach(diagnostic => {\n const messageText = diagnostic.getMessageText();\n\n if (typeof messageText === \"string\" && messageText.startsWith(\"'\")) {\n const identifierName = messageText.match(/'([^']+)'/)?.[1];\n if (identifierName) {\n if (messageText.includes(\"is declared but never used\")) {\n const identifier =\n sourceFile.getVariableDeclaration(identifierName) ||\n sourceFile.getInterface(identifierName) ||\n sourceFile.getEnum(identifierName) ||\n sourceFile.getClass(identifierName) ||\n sourceFile.getTypeAlias(identifierName);\n\n if (!identifier) {\n // eslint-disable-next-line no-console\n console.log(\"Could not find: \", messageText);\n } else {\n identifier.remove();\n }\n }\n }\n }\n });\n};\n\nconst convertEnumToConstObject = (enumDeclaration: EnumDeclaration) => {\n const enumName = enumDeclaration.getName();\n const members = enumDeclaration.getMembers();\n\n const properties = members.map(member => {\n const name = member.getName();\n const value = member.getValue();\n return `${name}: '${value}'`;\n });\n\n const lowerCaseFirstLetter = enumName[0].toLowerCase() + enumName.slice(1);\n const constObjectText = `export const ${lowerCaseFirstLetter} = {\\n ${properties.join(\n \",\\n \"\n )},\\n} as const;\\nexport type ${enumName} = typeof ${lowerCaseFirstLetter}[keyof typeof ${lowerCaseFirstLetter}];`;\n\n // Replace the EnumDeclaration with the const object text\n enumDeclaration.replaceWithText(constObjectText);\n};\n\n/**\n * Generates React hooks from your graphql files.\n */\nexport const scrubFileContent = async (fileContent: string, nxRoot: string, isVerbose?: boolean) => {\n const start = new Date().getTime();\n\n const project = new Project({\n compilerOptions: {\n noUnusedLocals: true,\n noUnusedParameters: true,\n },\n });\n const generatedFile = project.createSourceFile(\"tmp.ts\", fileContent);\n\n generatedFile.insertStatements(0, \"/* eslint-disable @typescript-eslint/no-explicit-any */\");\n generatedFile.insertStatements(1, \"/* eslint-disable @typescript-eslint/array-type */\");\n\n generatedFile.getTypeAliases().forEach(node => {\n if (!node.getName().startsWith(\"Incremental\")) {\n node.setIsExported(false);\n }\n\n if (\n node.getName().startsWith(\"Query\") ||\n node.getName().startsWith(\"Mutation\") ||\n // Since they reference each other we remove them here.\n node.getName() === \"Site\" ||\n node.getName() === \"Event\" ||\n node.getName() === \"Account\" ||\n node.getName() === \"Operator\" ||\n node.getName() === \"Asset\"\n ) {\n node.remove();\n }\n });\n generatedFile.getEnums().forEach(node => {\n node.setIsExported(false);\n });\n let lastWidth = 0;\n do {\n lastWidth = generatedFile.getFullWidth();\n removeUnusedIdentifiers(generatedFile);\n if (isVerbose) {\n console.log(\"Cleanup\", lastWidth, generatedFile.getFullWidth());\n }\n } while (lastWidth !== generatedFile.getFullWidth());\n\n generatedFile.getTypeAliases().forEach(node => {\n node.setIsExported(true);\n });\n generatedFile.getVariableStatements().forEach(variableStatement => {\n variableStatement.setIsExported(true);\n });\n generatedFile.getEnums().forEach(node => {\n node.setIsExported(true);\n convertEnumToConstObject(node);\n });\n\n if (isVerbose) {\n const end = new Date().getTime();\n const time = end - start;\n console.log(\"Execution time: \" + time);\n }\n\n return generatedFile.getFullText();\n};\n\n/**\n * Scrubs the file content.\n *\n * @param file The file to scrub.\n */\nexport const scrubFile = async (file: string, nxRoot: string, isVerbose?: boolean) => {\n const fileContent = readFileSync(file, { encoding: \"utf-8\" });\n if (fileContent.length === 0) {\n console.warn(`File ${file} is empty`);\n }\n const scrubbedMockFileContent = await scrubMockFileContent(fileContent, nxRoot, isVerbose);\n\n const scrubbedFileContent = await scrubFileContent(fileContent, nxRoot, isVerbose);\n\n let options = null;\n try {\n options = prettier\n .resolveConfig(join(nxRoot, \".prettierrc\"), {\n useCache: false,\n editorconfig: false,\n config: join(nxRoot, \".prettierrc\"),\n })\n .catch((error: Error) => console.log(error));\n } catch (e) {\n console.log(e);\n }\n if (!options) {\n throw new Error(\"Could not find prettier config\");\n }\n const prettierOptions = await options;\n\n let prettySrc = scrubbedFileContent;\n if (prettierOptions) {\n prettierOptions.parser = \"typescript\";\n try {\n prettySrc = await prettier.format(scrubbedFileContent, prettierOptions);\n } catch (error) {\n console.error(\"Error in prettier.format:\", error);\n }\n }\n writeFileSync(file, prettySrc, { encoding: \"utf-8\" });\n\n let prettyMockSrc = scrubbedMockFileContent;\n if (prettierOptions) {\n prettierOptions.parser = \"typescript\";\n try {\n prettyMockSrc = await prettier.format(scrubbedMockFileContent, prettierOptions);\n } catch (error) {\n console.error(\"Error in prettier.format:\", error);\n }\n }\n const parentDir = file.split(\"/\").slice(0, -1).join(\"/\");\n writeFileSync(parentDir + \"/mock.ts\", prettyMockSrc, { encoding: \"utf-8\" });\n return prettySrc;\n};\n"]}
|
|
@@ -75,6 +75,9 @@ const scrubMockFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__await
|
|
|
75
75
|
if (node.getName().endsWith("Query") && node.getName().length > "Query".length) {
|
|
76
76
|
mockThese.push(node);
|
|
77
77
|
}
|
|
78
|
+
if (node.getName().endsWith("Mutation") && node.getName().length > "Mutation".length) {
|
|
79
|
+
mockThese.push(node);
|
|
80
|
+
}
|
|
78
81
|
});
|
|
79
82
|
if (isVerbose) {
|
|
80
83
|
const end = new Date().getTime();
|
|
@@ -82,12 +85,11 @@ const scrubMockFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__await
|
|
|
82
85
|
console.log("Mock Execution time: " + time);
|
|
83
86
|
}
|
|
84
87
|
const mock = mockThese.map(mocker => {
|
|
88
|
+
const postFix = (mocker.getName().includes("Query") ? "Query" : "Mutation").length;
|
|
85
89
|
return `
|
|
86
90
|
|
|
87
91
|
export const mockFor${mocker.getName()} = (variables: gql.${mocker.getName()}Variables, data?: DeepPartialNullable<gql.${mocker.getName()}> ) => {
|
|
88
|
-
return queryFor(gql.${mocker
|
|
89
|
-
.getName()
|
|
90
|
-
.substring(0, mocker.getName().length - "Query".length)}Document, variables,
|
|
92
|
+
return queryFor(gql.${mocker.getName().substring(0, mocker.getName().length - postFix)}Document, variables,
|
|
91
93
|
mergeDeep(
|
|
92
94
|
${JSON.stringify(generateMockFromType(mocker.getType(), ""), null, 4)}
|
|
93
95
|
, data || {}) as gql.${mocker.getName()}
|
|
@@ -98,7 +100,7 @@ const scrubMockFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__await
|
|
|
98
100
|
import { OperationVariables } from "@apollo/client";
|
|
99
101
|
import { mergeDeep } from "@apollo/client/utilities";
|
|
100
102
|
import { queryFor, DeepPartialNullable } from "@trackunit/react-core-contexts-test";
|
|
101
|
-
import * as gql from "
|
|
103
|
+
import * as gql from "./graphql";
|
|
102
104
|
|
|
103
105
|
${mock.join("\n")}
|
|
104
106
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrubMockFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubMockFile.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,2CAAwC;AACxC,uCAAyD;AAEzD,8DAA8D;AAC9D,MAAM,oBAAoB,GAAG,CAAC,IAAS,EAAE,IAAY,EAAO,EAAE;IAC5D,aAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,wDAAwD;IACxD,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnE,IAAI,aAAa,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE;QACjD,OAAO,0BAA0B,CAAC;KACnC;IACD,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,sCAAsC;KACvE;IACD,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;KAC5C;IACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,KAA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AAC,MAAM,CAAC,EAAE;QAClC,OAAO;;0BAEe,MAAM,CAAC,OAAO,EAAE,sBAAsB,MAAM,CAAC,OAAO,EAAE,6CAA6C,MAAM,CAAC,OAAO,EAAE;4BACjH,MAAM
|
|
1
|
+
{"version":3,"file":"scrubMockFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubMockFile.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,2CAAwC;AACxC,uCAAyD;AAEzD,8DAA8D;AAC9D,MAAM,oBAAoB,GAAG,CAAC,IAAS,EAAE,IAAY,EAAO,EAAE;IAC5D,aAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,wDAAwD;IACxD,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnE,IAAI,aAAa,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAE;QACjD,OAAO,0BAA0B,CAAC;KACnC;IACD,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,sCAAsC;KACvE;IACD,IAAI,IAAI,CAAC,eAAe,EAAE,EAAE;QAC1B,OAAO,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;KAC5C;IACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,MAAM,CAAC;KAC3C;IAED,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC/B,OAAO,aAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;KAC3B;IACD,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC/B,OAAO,aAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;K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M,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;QACnF,OAAO;;0BAEe,MAAM,CAAC,OAAO,EAAE,sBAAsB,MAAM,CAAC,OAAO,EAAE,6CAA6C,MAAM,CAAC,OAAO,EAAE;4BACjH,MAAM,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC;;YAEhF,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;+BAChD,MAAM,CAAC,OAAO,EAAE;;MAEzC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;;;;;;IAML,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;GAChB,CAAC;AACJ,CAAC,CAAA,CAAC;AAnDW,QAAA,oBAAoB,wBAmD/B","sourcesContent":["/* eslint-disable no-console */\nimport { faker } from \"@faker-js/faker\";\nimport { Project, TypeAliasDeclaration } from \"ts-morph\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst generateMockFromType = (type: any, text: string): any => {\n faker.seed(123);\n // type aliases are not working well so using text here.\n const rightSideText = text.substring(text.indexOf(\":\") + 1).trim();\n if (rightSideText.startsWith(\"DateTimeISOString\")) {\n return \"2023-01-22T15:08:12.527Z\";\n }\n if (type.isStringLiteral()) {\n return type.compilerType.value; // Get the value of the string literal\n }\n if (type.isNumberLiteral()) {\n return parseFloat(type.compilerType.value);\n }\n if (type.isBooleanLiteral()) {\n return type.compilerType.value === \"true\";\n }\n\n if (type.getText() === \"string\") {\n return faker.lorem.word();\n }\n if (type.getText() === \"number\") {\n return faker.number.int();\n }\n if (type.getText() === \"Date\" || type.getText() === \"DateTime\") {\n return \"2023-01-22T15:08:12.527Z\";\n }\n\n if (type.isUnion()) {\n // We'll take the first type in the union for simplicity\n return generateMockFromType(type.getUnionTypes()[0], \"\");\n }\n if (type.isArray()) {\n return [generateMockFromType(type.getArrayElementTypeOrThrow(), \"\")];\n }\n if (type.isObject()) {\n const properties = type.getProperties();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const obj: any = {};\n for (const prop of properties) {\n const declaration = prop.getValueDeclarationOrThrow();\n const propType = declaration.getType();\n if (prop.getName() === \"__typename\") {\n obj[prop.getName()] = propType.getText().replace(/\"/g, \"\");\n } else {\n obj[prop.getName()] = generateMockFromType(propType, declaration.getText());\n }\n }\n return obj;\n }\n return null; // Default\n};\n\n/**\n * Generates React hooks from your graphql files.\n */\nexport const scrubMockFileContent = async (fileContent: string, nxRoot: string, isVerbose?: boolean) => {\n const start = new Date().getTime();\n\n const project = new Project({\n compilerOptions: {\n noUnusedLocals: true,\n noUnusedParameters: true,\n },\n });\n const generatedFile = project.createSourceFile(\"tmpMock.ts\", fileContent);\n const mockThese: TypeAliasDeclaration[] = [];\n\n generatedFile.insertStatements(0, \"/* eslint-disable @typescript-eslint/no-explicit-any */\");\n generatedFile.insertStatements(1, \"/* eslint-disable @typescript-eslint/array-type */\");\n\n generatedFile.getTypeAliases().forEach(node => {\n if (node.getName().endsWith(\"Query\") && node.getName().length > \"Query\".length) {\n mockThese.push(node);\n }\n if (node.getName().endsWith(\"Mutation\") && node.getName().length > \"Mutation\".length) {\n mockThese.push(node);\n }\n });\n\n if (isVerbose) {\n const end = new Date().getTime();\n const time = end - start;\n console.log(\"Mock Execution time: \" + time);\n }\n\n const mock = mockThese.map(mocker => {\n const postFix = (mocker.getName().includes(\"Query\") ? \"Query\" : \"Mutation\").length;\n return `\n \n export const mockFor${mocker.getName()} = (variables: gql.${mocker.getName()}Variables, data?: DeepPartialNullable<gql.${mocker.getName()}> ) => {\n return queryFor(gql.${mocker.getName().substring(0, mocker.getName().length - postFix)}Document, variables, \n mergeDeep(\n ${JSON.stringify(generateMockFromType(mocker.getType(), \"\"), null, 4)}\n , data || {}) as gql.${mocker.getName()}\n );\n }`;\n });\n\n return `\n import { OperationVariables } from \"@apollo/client\";\n import { mergeDeep } from \"@apollo/client/utilities\";\n import { queryFor, DeepPartialNullable } from \"@trackunit/react-core-contexts-test\";\n import * as gql from \"./graphql\";\n \n ${mock.join(\"\\n\")}\n `;\n};\n"]}
|