@trackunit/react-graphql-tools 0.0.14 → 0.0.15

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.15](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.14...react-graphql-tools/0.0.15) (2023-05-12)
6
+
5
7
  ## [0.0.14](https://github.com/Trackunit/manager/compare/react-graphql-tools/0.0.13...react-graphql-tools/0.0.14) (2023-05-11)
6
8
 
7
9
  ### Dependency Updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-graphql-tools",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "main": "src/index.js",
5
5
  "executors": "./executors.json",
6
6
  "repository": "https://github.com/Trackunit/manager",
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.scrubFile = void 0;
3
+ exports.scrubFile = exports.scrubFileContent = void 0;
4
4
  const tslib_1 = require("tslib");
5
- /* eslint-disable no-console */
6
- /* eslint-disable import/no-extraneous-dependencies */
7
- /* eslint-disable @typescript-eslint/no-var-requires */
8
- const fs = require("fs");
5
+ const fs_1 = require("fs");
9
6
  const path_1 = require("path");
10
7
  const prettier = tslib_1.__importStar(require("prettier"));
11
8
  const ts_morph_1 = require("ts-morph");
@@ -31,6 +28,7 @@ const removeUnusedIdentifiers = (sourceFile) => {
31
28
  sourceFile.getClass(identifierName) ||
32
29
  sourceFile.getTypeAlias(identifierName);
33
30
  if (!identifier) {
31
+ // eslint-disable-next-line no-console
34
32
  console.log("Could not find: ", messageText);
35
33
  }
36
34
  else {
@@ -56,7 +54,7 @@ const convertEnumToConstObject = (enumDeclaration) => {
56
54
  /**
57
55
  * Generates React hooks from your graphql files.
58
56
  */
59
- const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
57
+ const scrubFileContent = (fileContent, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
60
58
  const start = new Date().getTime();
61
59
  const project = new ts_morph_1.Project({
62
60
  compilerOptions: {
@@ -64,8 +62,7 @@ const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0,
64
62
  noUnusedParameters: true,
65
63
  },
66
64
  });
67
- project.addSourceFileAtPath(file);
68
- const generatedFile = project.getSourceFileOrThrow(file);
65
+ const generatedFile = project.createSourceFile("tmp.ts", fileContent);
69
66
  generatedFile.insertStatements(0, "/* eslint-disable @typescript-eslint/no-explicit-any */");
70
67
  generatedFile.insertStatements(1, "/* eslint-disable @typescript-eslint/array-type */");
71
68
  // all return object types are defined as classes, where input types are defined as interfaces
@@ -94,7 +91,22 @@ const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0,
94
91
  node.setIsExported(true);
95
92
  convertEnumToConstObject(node);
96
93
  });
97
- generatedFile.formatText();
94
+ if (isVerbose) {
95
+ const end = new Date().getTime();
96
+ const time = end - start;
97
+ // eslint-disable-next-line no-console
98
+ console.log("Execution time: " + time);
99
+ }
100
+ return generatedFile.getFullText();
101
+ });
102
+ exports.scrubFileContent = scrubFileContent;
103
+ /**
104
+ * Scrubs the file content.
105
+ *
106
+ * @param file The file to scrub.
107
+ */
108
+ const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
109
+ const scrubbedFileContent = yield (0, exports.scrubFileContent)((0, fs_1.readFileSync)(file, { encoding: "utf-8" }), nxRoot, isVerbose);
98
110
  let options = null;
99
111
  try {
100
112
  options = prettier
@@ -103,26 +115,24 @@ const scrubFile = (file, nxRoot, isVerbose) => tslib_1.__awaiter(void 0, void 0,
103
115
  editorconfig: false,
104
116
  config: (0, path_1.join)(nxRoot, ".prettierrc"),
105
117
  })
118
+ // eslint-disable-next-line no-console
106
119
  .catch((error) => console.log(error));
107
120
  }
108
121
  catch (e) {
122
+ // eslint-disable-next-line no-console
109
123
  console.log(e);
110
124
  }
111
125
  if (!options) {
112
126
  throw new Error("Could not find prettier config");
113
127
  }
114
128
  const prettierOptions = yield options;
115
- let prettySrc = generatedFile.getFullText();
129
+ let prettySrc = scrubbedFileContent;
116
130
  if (prettierOptions) {
117
131
  prettierOptions.parser = "typescript";
118
- prettySrc = prettier.format(generatedFile.getFullText(), prettierOptions);
119
- }
120
- fs.writeFileSync(file, prettySrc, { encoding: "utf-8" });
121
- if (isVerbose) {
122
- const end = new Date().getTime();
123
- const time = end - start;
124
- console.log("Execution time: " + time);
132
+ prettySrc = prettier.format(scrubbedFileContent, prettierOptions);
125
133
  }
134
+ (0, fs_1.writeFileSync)(file, prettySrc, { encoding: "utf-8" });
135
+ return prettySrc;
126
136
  });
127
137
  exports.scrubFile = scrubFile;
128
138
  //# sourceMappingURL=scrubFile.js.map
@@ -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,sDAAsD;AACtD,uDAAuD;AACvD,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,+BAA4B;AAC5B,2DAAqC;AACrC,uCAAgE;AAEhE;;;;;;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,C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AE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAEzD,IAAI,SAAS,EAAE;QACb,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;KACxC;AACH,CAAC,CAAA,CAAC;AA5EW,QAAA,SAAS,aA4EpB","sourcesContent":["/* eslint-disable no-console */\n/* eslint-disable import/no-extraneous-dependencies */\n/* eslint-disable @typescript-eslint/no-var-requires */\nconst fs = require(\"fs\");\nimport { join } from \"path\";\nimport * as prettier from \"prettier\";\nimport { EnumDeclaration, Project, SourceFile } from \"ts-morph\";\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 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 constObjectText = `export const ${enumName} = {\\n ${properties.join(\n \",\\n \"\n )},\\n} as const;\\nexport type ${enumName} = typeof ${enumName}[keyof typeof ${enumName}];`;\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 scrubFile = async (file: 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 project.addSourceFileAtPath(file);\n\n const generatedFile = project.getSourceFileOrThrow(file);\n\n generatedFile.insertStatements(0, \"/* eslint-disable @typescript-eslint/no-explicit-any */\");\n generatedFile.insertStatements(1, \"/* eslint-disable @typescript-eslint/array-type */\");\n\n // all return object types are defined as classes, where input types are defined as interfaces\n // therefore we can remove all classes.\n generatedFile.getClasses().forEach(node => {\n node.remove();\n });\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.getInterfaces().forEach(node => {\n node.setIsExported(true);\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 generatedFile.formatText();\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 let prettySrc = generatedFile.getFullText();\n\n if (prettierOptions) {\n prettierOptions.parser = \"typescript\";\n prettySrc = prettier.format(generatedFile.getFullText(), prettierOptions);\n }\n fs.writeFileSync(file, prettySrc, { encoding: \"utf-8\" });\n\n if (isVerbose) {\n const end = new Date().getTime();\n const time = end - start;\n console.log(\"Execution time: \" + time);\n }\n};\n"]}
1
+ {"version":3,"file":"scrubFile.js","sourceRoot":"","sources":["../../../../../../../libs/react/graphql-tools/src/executors/createHooks/scrubFile.ts"],"names":[],"mappings":";;;;AAAA,2BAAiD;AACjD,+BAA4B;AAC5B,2DAAqC;AACrC,uCAAgE;AAEhE;;;;;;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,C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AA,CAAC;AA9BW,QAAA,SAAS,aA8BpB","sourcesContent":["import { readFileSync, writeFileSync } from \"fs\";\nimport { join } from \"path\";\nimport * as prettier from \"prettier\";\nimport { EnumDeclaration, Project, SourceFile } from \"ts-morph\";\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 constObjectText = `export const ${enumName} = {\\n ${properties.join(\n \",\\n \"\n )},\\n} as const;\\nexport type ${enumName} = typeof ${enumName}[keyof typeof ${enumName}];`;\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 // all return object types are defined as classes, where input types are defined as interfaces\n // therefore we can remove all classes.\n generatedFile.getClasses().forEach(node => {\n node.remove();\n });\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.getInterfaces().forEach(node => {\n node.setIsExported(true);\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 // eslint-disable-next-line no-console\n console.log(\"Execution time: \" + time);\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 scrubbedFileContent = await scrubFileContent(readFileSync(file, { encoding: \"utf-8\" }), 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 // eslint-disable-next-line no-console\n .catch((error: Error) => console.log(error));\n } catch (e) {\n // eslint-disable-next-line no-console\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 prettySrc = prettier.format(scrubbedFileContent, prettierOptions);\n }\n\n writeFileSync(file, prettySrc, { encoding: \"utf-8\" });\n return prettySrc;\n};\n"]}