@looker/sdk-codegen-scripts 21.3.0 → 21.3.4

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
@@ -1,5 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ ### [21.3.4](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.3.3...sdk-codegen-scripts-v21.3.4) (2022-07-07)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * example miner github permalinks do not use `.git` in the repository name ([#1063](https://www.github.com/looker-open-source/sdk-codegen/issues/1063)) ([e150b33](https://www.github.com/looker-open-source/sdk-codegen/commit/e150b33ff974575d731f48f2f1488bdbeeb9118c))
9
+ * remove generated files from examples index ([#1076](https://www.github.com/looker-open-source/sdk-codegen/issues/1076)) ([d75bce8](https://www.github.com/looker-open-source/sdk-codegen/commit/d75bce8dc25d41fd6bc5e2e513782eaa6009fd10))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @looker/sdk bumped from ^22.4.2 to ^22.6.0
17
+ * @looker/sdk-codegen bumped from ^21.5.2 to ^21.6.0
18
+ * @looker/sdk-node bumped from ^22.4.2 to ^22.6.0
19
+ * @looker/sdk-rtl bumped from ^21.3.3 to ^21.3.4
20
+
21
+ ### [21.3.3](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.3.2...sdk-codegen-scripts-v21.3.3) (2022-04-07)
22
+
23
+
24
+ ### Dependencies
25
+
26
+ * The following workspace dependencies were updated
27
+ * dependencies
28
+ * @looker/sdk bumped from ^22.4.1 to ^22.4.2
29
+ * @looker/sdk-codegen bumped from ^21.5.1 to ^21.5.2
30
+ * @looker/sdk-node bumped from ^22.4.1 to ^22.4.2
31
+ * @looker/sdk-rtl bumped from ^21.3.2 to ^21.3.3
32
+
33
+ ### [21.3.2](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.3.1...sdk-codegen-scripts-v21.3.2) (2022-04-07)
34
+
35
+
36
+ ### Dependencies
37
+
38
+ * The following workspace dependencies were updated
39
+ * dependencies
40
+ * @looker/sdk bumped from ^22.4.0 to ^22.4.1
41
+ * @looker/sdk-codegen bumped from ^21.5.0 to ^21.5.1
42
+ * @looker/sdk-node bumped from ^22.4.0 to ^22.4.1
43
+
44
+ ### [21.3.1](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.3.0...sdk-codegen-scripts-v21.3.1) (2022-03-24)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * declaration miner (internal utility) ([#1025](https://www.github.com/looker-open-source/sdk-codegen/issues/1025)) ([9b987b2](https://www.github.com/looker-open-source/sdk-codegen/commit/9b987b2c2f24e4a43d6ff25921c5f46804b7702a))
50
+
51
+
52
+ ### Dependencies
53
+
54
+ * The following workspace dependencies were updated
55
+ * dependencies
56
+ * @looker/sdk bumped from ^22.2.0 to ^22.4.0
57
+ * @looker/sdk-node bumped from ^22.2.0 to ^22.4.0
58
+
3
59
  ## [21.3.0](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-codegen-scripts-v21.2.3...sdk-codegen-scripts-v21.3.0) (2022-03-04)
4
60
 
5
61
 
@@ -14,9 +14,10 @@ export declare class DeclarationMiner {
14
14
  readonly sourcePath: string;
15
15
  readonly methodProbe: IProbe;
16
16
  readonly typeProbe: IProbe;
17
+ private readonly originOverride;
17
18
  types: DeclarationNuggets;
18
19
  methods: DeclarationNuggets;
19
- constructor(sourcePath: string, methodProbe: IProbe, typeProbe: IProbe);
20
+ constructor(sourcePath: string, methodProbe: IProbe, typeProbe: IProbe, originOverride: string);
20
21
  execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe): IDeclarationMine;
21
22
  get commitHash(): string;
22
23
  get remoteOrigin(): string;
@@ -52,10 +52,11 @@ var rubyTypeProbe = {
52
52
  exports.rubyTypeProbe = rubyTypeProbe;
53
53
 
54
54
  class DeclarationMiner {
55
- constructor(sourcePath, methodProbe, typeProbe) {
55
+ constructor(sourcePath, methodProbe, typeProbe, originOverride) {
56
56
  this.sourcePath = sourcePath;
57
57
  this.methodProbe = methodProbe;
58
58
  this.typeProbe = typeProbe;
59
+ this.originOverride = originOverride;
59
60
 
60
61
  _defineProperty(this, "types", {});
61
62
 
@@ -87,8 +88,12 @@ class DeclarationMiner {
87
88
  }
88
89
 
89
90
  get remoteOrigin() {
91
+ if (this.originOverride) {
92
+ return this.originOverride;
93
+ }
94
+
90
95
  process.chdir(this.sourcePath);
91
- return (0, _exampleMiner.getRemoteHttpOrigin)();
96
+ return (0, _exampleMiner.getRemoteOrigin)();
92
97
  }
93
98
 
94
99
  get lode() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/declarationMiner.ts"],"names":["fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","path","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","execute","filePath","mProbe","tProbe","files","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","remoteOrigin","ExampleMiner","relate","probe","mineCode","content","lines","split","declarations","line","index","exec","sourceFile"],"mappings":";;;;;;;AAyBA;;AAGA;;;;;;;;;;;;;;;;AAeA,IAAMA,UAAU,GAAG,CACjBC,mBADiB,EAEjBC,eAFiB,EAGjBC,QAHiB,KAId;AACH,MAAMC,SAAS,GACbH,mBAAmB,CAACI,IAApB,CAAyBF,QAAzB,KAAsCD,eAAe,CAACG,IAAhB,CAAqBF,QAArB,CADxC;AAEA,SAAO,mCAAgBA,QAAhB,KAA6BC,SAApC;AACD,CARD;;AAaO,IAAME,eAAe,GAAG;AAC7BC,EAAAA,eAAe,EAAE,4BADY;AAE7BC,EAAAA,kBAAkB,cAChB,2PADgB;AAAA;AAAA;AAAA,IAFW;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8B,OAAP;AACD;;AAESI,EAAAA,QAAQ,CAACJ,OAAD,EAAkB9B,QAAlB,EAAoC2C,KAApC,EAAmD;AACnE,WAAO,KAAKC,QAAL,CAAcd,OAAd,EAAuB,4BAAS9B,QAAT,CAAvB,EAA2C2C,KAA3C,CAAP;AACD;;AAESC,EAAAA,QAAQ,CAACd,OAAD,EAAkBe,OAAlB,EAAmCF,KAAnC,EAAkD;AAClE,QAAMG,KAAK,GAAGD,OAAO,CAACE,KAAR,CAAc,IAAd,CAAd;AACA,QAAMC,YAAgC,GAAG,EAAzC;AACAF,IAAAA,KAAK,CAAClB,OAAN,CAAc,CAACqB,IAAD,EAAOC,KAAP,KAAiB;AAC7B,UAAM3C,KAAK,GAAGoC,KAAK,CAACtC,kBAAN,CAAyB8C,IAAzB,CAA8BF,IAA9B,CAAd;;AACA,UAAI1C,KAAJ,EAAW;AACT,YAAMM,GAAG,GAAG8B,KAAK,CAACrC,uBAAN,CAA8BC,KAA9B,CAAZ;AACAyC,QAAAA,YAAY,CAACnC,GAAD,CAAZ,GAAoB;AAClBoC,UAAAA,IAAI,EAAEC,KAAK,GAAG,CADI;AAElBE,UAAAA,UAAU,EAAEtB;AAFM,SAApB;AAID;AACF,KATD;AAUA,WAAOkB,YAAP;AACD;;AA5E2B","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteHttpOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n process.chdir(this.sourcePath)\n return getRemoteHttpOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declarations\n }\n}\n"],"file":"declarationMiner.js"}
1
+ {"version":3,"sources":["../src/declarationMiner.ts"],"names":["fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","path","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","originOverride","execute","filePath","mProbe","tProbe","files","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","remoteOrigin","ExampleMiner","relate","probe","mineCode","content","lines","split","declarations","line","index","exec","sourceFile"],"mappings":";;;;;;;AAyBA;;AAGA;;;;;;;;;;;;;;;;AAeA,IAAMA,UAAU,GAAG,CACjBC,mBADiB,EAEjBC,eAFiB,EAGjBC,QAHiB,KAId;AACH,MAAMC,SAAS,GACbH,mBAAmB,CAACI,IAApB,CAAyBF,QAAzB,KAAsCD,eAAe,CAACG,IAAhB,CAAqBF,QAArB,CADxC;AAEA,SAAO,mCAAgBA,QAAhB,KAA6BC,SAApC;AACD,CARD;;AAaO,IAAME,eAAe,GAAG;AAC7BC,EAAAA,eAAe,EAAE,4BADY;AAE7BC,EAAAA,kBAAkB,cAChB,2PADgB;AAAA;AAAA;AAAA,IAFW;AAI7BC,EAAAA,uBAAuB,EAAGC,KAAD,IAA4B;AACnD,QAAMC,IAAI,GAAGD,KAAK,CAACE,MAAN,CAAcD,IAAd,CAAmBE,iBAAnB,EAAb;AACA,QAAMC,IAAI,GAAGJ,KAAK,CACfE,MADU,CACFE,IADE,CACGC,OADH,CACW,IADX,EACiB,EADjB,EAEVA,OAFU,CAEF,GAFE,EAEG,EAFH,EAGVA,OAHU,CAGF,SAHE,EAGS,MAHT,CAAb;AAIA,QAAMC,GAAG,aAAML,IAAN,cAAcG,IAAd,CAAT;AACA,WAAOE,GAAP;AACD;AAZ4B,CAAxB;;AAkBA,IAAMC,aAAqB,GAAG;AACnCV,EAAAA,eAAe,EAAE,wBADkB;AAEnCC,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C,GAAG,EAAzC;AACAF,IAAAA,KAAK,CAAClB,OAAN,CAAc,CAACqB,IAAD,EAAOC,KAAP,KAAiB;AAC7B,UAAM5C,KAAK,GAAGqC,KAAK,CAACvC,kBAAN,CAAyB+C,IAAzB,CAA8BF,IAA9B,CAAd;;AACA,UAAI3C,KAAJ,EAAW;AACT,YAAMM,GAAG,GAAG+B,KAAK,CAACtC,uBAAN,CAA8BC,KAA9B,CAAZ;AACA0C,QAAAA,YAAY,CAACpC,GAAD,CAAZ,GAAoB;AAClBqC,UAAAA,IAAI,EAAEC,KAAK,GAAG,CADI;AAElBE,UAAAA,UAAU,EAAEtB;AAFM,SAApB;AAID;AACF,KATD;AAUA,WAAOkB,YAAP;AACD;;AAhF2B","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe,\n private readonly originOverride: string\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n if (this.originOverride) {\n return this.originOverride\n }\n process.chdir(this.sourcePath)\n return getRemoteOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declarations\n }\n}\n"],"file":"declarationMiner.js"}
@@ -11,7 +11,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
11
11
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
12
 
13
13
  import path from 'path';
14
- import { filterCodeFiles, getCodeFiles, ExampleMiner, readFile, getCommitHash, getRemoteHttpOrigin } from './exampleMiner';
14
+ import { filterCodeFiles, getCodeFiles, ExampleMiner, readFile, getCommitHash, getRemoteOrigin } from './exampleMiner';
15
15
 
16
16
  var fileFilter = (endpointFilePattern, typeFilePattern, fileName) => {
17
17
  var fileMatch = endpointFilePattern.test(fileName) || typeFilePattern.test(fileName);
@@ -39,10 +39,11 @@ export var rubyTypeProbe = {
39
39
  matchToSpecKeyTransform: match => match.groups.typeName
40
40
  };
41
41
  export class DeclarationMiner {
42
- constructor(sourcePath, methodProbe, typeProbe) {
42
+ constructor(sourcePath, methodProbe, typeProbe, originOverride) {
43
43
  this.sourcePath = sourcePath;
44
44
  this.methodProbe = methodProbe;
45
45
  this.typeProbe = typeProbe;
46
+ this.originOverride = originOverride;
46
47
 
47
48
  _defineProperty(this, "types", {});
48
49
 
@@ -73,8 +74,12 @@ export class DeclarationMiner {
73
74
  }
74
75
 
75
76
  get remoteOrigin() {
77
+ if (this.originOverride) {
78
+ return this.originOverride;
79
+ }
80
+
76
81
  process.chdir(this.sourcePath);
77
- return getRemoteHttpOrigin();
82
+ return getRemoteOrigin();
78
83
  }
79
84
 
80
85
  get lode() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/declarationMiner.ts"],"names":["path","filterCodeFiles","getCodeFiles","ExampleMiner","readFile","getCommitHash","getRemoteHttpOrigin","fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","execute","filePath","mProbe","tProbe","files","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","remoteOrigin","relate","probe","mineCode","content","lines","split","declarations","line","index","exec","sourceFile"],"mappings":";;;;;;;;;;;;AAyBA,OAAOA,IAAP,MAAiB,MAAjB;AAGA,SACEC,eADF,EAEEC,YAFF,EAGEC,YAHF,EAIEC,QAJF,EAKEC,aALF,EAMEC,mBANF,QAOO,gB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A5E2B","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteHttpOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n process.chdir(this.sourcePath)\n return getRemoteHttpOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declarations\n }\n}\n"],"file":"declarationMiner.js"}
1
+ {"version":3,"sources":["../../src/declarationMiner.ts"],"names":["path","filterCodeFiles","getCodeFiles","ExampleMiner","readFile","getCommitHash","getRemoteOrigin","fileFilter","endpointFilePattern","typeFilePattern","fileName","fileMatch","test","rubyMethodProbe","fileNamePattern","declarationPattern","matchToSpecKeyTransform","match","verb","groups","toLocaleUpperCase","replace","key","rubyTypeProbe","typeName","DeclarationMiner","constructor","sourcePath","methodProbe","typeProbe","originOverride","execute","filePath","mProbe","tProbe","files","undefined","bind","forEach","f","relFile","processFile","basename","methods","mineFile","types","lode","commitHash","process","chdir","remoteOrigin","relate","probe","mineCode","content","lines","split","declarations","line","index","exec","sourceFile"],"mappings":";;;;;;;;;;;;AAyBA,OAAOA,IAAP,MAAiB,MAAjB;AAGA,SACEC,eADF,EAEEC,YAFF,EAGEC,YAHF,EAIEC,QAJF,EAKEC,aALF,EAMEC,eANF,QAOO,gBAPP;;AAeA,IAAMC,UAAU,GAAG,CACjBC,mBADiB,EAEjBC,eAFiB,EAGjBC,QAHiB,KAId;AACH,MAAMC,SAAS,GACbH,mBAAmB,CAACI,IAApB,CAAyBF,QAAzB,KAAsCD,eAAe,CAACG,IAAhB,CAAqBF,QAArB,CADxC;AAEA,SAAOT,eAAe,CAACS,QAAD,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AAqB;AAC3B,WAAO;AACLC,MAAAA,UAAU,EAAE,KAAKA,UADZ;AAELG,MAAAA,YAAY,EAAE,KAAKA,YAFd;AAGLL,MAAAA,KAAK,EAAE,KAAKA,KAHP;AAILF,MAAAA,OAAO,EAAE,KAAKA;AAJT,KAAP;AAMD;;AAESF,EAAAA,WAAW,CAAC/B,QAAD,EAAmB;AACtC,QAAM8B,OAAO,GAAGrC,YAAY,CAACgD,MAAb,CAAoB,KAAKxB,UAAzB,EAAqCjB,QAArC,CAAhB;AACA,WAAO8B,OAAP;AACD;;AAESI,EAAAA,QAAQ,CAACJ,OAAD,EAAkB9B,QAAlB,EAAoC0C,KAApC,EAAmD;AACnE,WAAO,KAAKC,QAAL,CAAcb,OAAd,EAAuBpC,QAAQ,CAACM,QAAD,CAA/B,EAA2C0C,KAA3C,CAAP;AACD;;AAESC,EAAAA,QAAQ,CAACb,OAAD,EAAkBc,OAAlB,EAAmCF,KAAnC,EAAkD;AAClE,QAAMG,KAAK,GAAGD,OAAO,CAACE,KAAR,CAAc,IAAd,CAAd;AACA,QAAMC,YAAgC,GAAG,EAAzC;AACAF,IAAAA,KAAK,CAACjB,OAAN,CAAc,CAACoB,IAAD,EAAOC,KAAP,KAAiB;AAC7B,UAAM1C,KAAK,GAAGmC,KAAK,CAACrC,kBAAN,CAAyB6C,IAAzB,CAA8BF,IAA9B,CAAd;;AACA,UAAIzC,KAAJ,EAAW;AACT,YAAMK,GAAG,GAAG8B,KAAK,CAACpC,uBAAN,CAA8BC,KAA9B,CAAZ;AACAwC,QAAAA,YAAY,CAACnC,GAAD,CAAZ,GAAoB;AAClBoC,UAAAA,IAAI,EAAEC,KAAK,GAAG,CADI;AAElBE,UAAAA,UAAU,EAAErB;AAFM,SAApB;AAID;AACF,KATD;AAUA,WAAOiB,YAAP;AACD;;AAhF2B","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\nimport path from 'path'\nimport type { DeclarationNuggets, IDeclarationMine } from '@looker/sdk-codegen'\n\nimport {\n filterCodeFiles,\n getCodeFiles,\n ExampleMiner,\n readFile,\n getCommitHash,\n getRemoteOrigin,\n} from './exampleMiner'\n\n/**\n * Filter that checks if given file name matches any of the specified patterns\n * @param endpointFilePattern A pattern that matches endpoint files\n * @param typeFilePattern A pattern that matches type files\n * @param fileName File name to check against patterns\n */\nconst fileFilter = (\n endpointFilePattern: RegExp,\n typeFilePattern: RegExp,\n fileName: string\n) => {\n const fileMatch =\n endpointFilePattern.test(fileName) || typeFilePattern.test(fileName)\n return filterCodeFiles(fileName) && fileMatch\n}\n\n/**\n * Reference method probe for a Ruby controller\n */\nexport const rubyMethodProbe = {\n fileNamePattern: /^(?!test).*_controller.rb$/,\n declarationPattern:\n /(?<verb>GET|POST|DELETE|PUT|PATCH)\\s(?:\"|')\\/api\\/3\\.x(?<path>\\S+)(?:\"|')/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => {\n const verb = match.groups!.verb.toLocaleUpperCase()\n const path = match\n .groups!.path.replace(':#', '')\n .replace('#', '')\n .replace(/:(\\w+)/g, '{$1}')\n const key = `${verb} ${path}`\n return key\n },\n}\n\n/**\n * Reference type probe for a Ruby mapper\n */\nexport const rubyTypeProbe: IProbe = {\n fileNamePattern: /^(?!test).*_mapper.rb$/,\n declarationPattern: /class\\s(?<typeName>\\w+)Mapper/i,\n matchToSpecKeyTransform: (match: RegExpExecArray) => match.groups!.typeName,\n}\n\nexport interface IProbe {\n /** Pattern of file names to mine */\n fileNamePattern: RegExp\n /** Pattern matching the declaration of a method/type */\n declarationPattern: RegExp\n /** A transform lambda for transforming a declaration match into a spec key */\n matchToSpecKeyTransform: (match: RegExpExecArray) => string\n}\n\nexport class DeclarationMiner {\n types: DeclarationNuggets = {}\n methods: DeclarationNuggets = {}\n\n constructor(\n public readonly sourcePath: string,\n public readonly methodProbe: IProbe,\n public readonly typeProbe: IProbe,\n private readonly originOverride: string\n ) {}\n\n execute(sourcePath?: string, methodProbe?: IProbe, typeProbe?: IProbe) {\n const filePath = sourcePath ?? this.sourcePath\n const mProbe = methodProbe ?? this.methodProbe\n const tProbe = typeProbe ?? this.typeProbe\n\n const files = getCodeFiles(\n filePath,\n undefined,\n fileFilter.bind(null, mProbe.fileNamePattern, tProbe.fileNamePattern),\n ['node_modules', 'dist']\n )\n\n files.forEach((f) => {\n const relFile = this.processFile(f)\n const fileName = path.basename(relFile)\n if (mProbe.fileNamePattern.test(fileName)) {\n this.methods = { ...this.methods, ...this.mineFile(relFile, f, mProbe) }\n } else {\n this.types = { ...this.types, ...this.mineFile(relFile, f, tProbe) }\n }\n })\n return this.lode\n }\n\n get commitHash(): string {\n process.chdir(this.sourcePath)\n return getCommitHash()\n }\n\n get remoteOrigin(): string {\n if (this.originOverride) {\n return this.originOverride\n }\n process.chdir(this.sourcePath)\n return getRemoteOrigin()\n }\n\n get lode(): IDeclarationMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n types: this.types,\n methods: this.methods,\n }\n }\n\n protected processFile(fileName: string) {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n return relFile\n }\n\n protected mineFile(relFile: string, fileName: string, probe: IProbe) {\n return this.mineCode(relFile, readFile(fileName), probe)\n }\n\n protected mineCode(relFile: string, content: string, probe: IProbe) {\n const lines = content.split('\\n')\n const declarations: DeclarationNuggets = {}\n lines.forEach((line, index) => {\n const match = probe.declarationPattern.exec(line)\n if (match) {\n const key = probe.matchToSpecKeyTransform(match)\n declarations[key] = {\n line: index + 1,\n sourceFile: relFile,\n }\n }\n })\n return declarations\n }\n}\n"],"file":"declarationMiner.js"}
@@ -16,9 +16,10 @@ export var filterCodeFiles = fileName => {
16
16
  var ext = path.extname(fileName).toLocaleLowerCase();
17
17
  return ext in fileMiners;
18
18
  };
19
+ export var IGNORE_PATHS = ['node_modules', 'lib', 'dist', 'bazel-bin', 'build', 'bin', '.build', '.direnv', '.github', '.vscode', '.idea', '.gradle', 'results'];
19
20
 
20
21
  var skipFolder = function skipFolder(name) {
21
- var excludeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['node_modules'];
22
+ var excludeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : IGNORE_PATHS;
22
23
  return new RegExp(excludeList.join('|'), 'gi').test(name);
23
24
  };
24
25
 
@@ -28,22 +29,24 @@ export var getAllFiles = function getAllFiles(searchPath) {
28
29
  var ignorePaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
29
30
  var files = fs.readdirSync(searchPath);
30
31
  files.forEach(file => {
31
- if (fs.statSync(searchPath + '/' + file).isDirectory()) {
32
- if (!skipFolder(file, ignorePaths)) listOfFiles = getAllFiles(searchPath + '/' + file, listOfFiles, filter, ignorePaths);
33
- } else {
34
- if (filter(file)) {
35
- var _fileName = path.join(searchPath, '/', file);
36
-
37
- listOfFiles.push(_fileName);
32
+ try {
33
+ if (fs.statSync(searchPath + '/' + file).isDirectory()) {
34
+ if (!skipFolder(file, ignorePaths)) listOfFiles = getAllFiles(searchPath + '/' + file, listOfFiles, filter, ignorePaths);
35
+ } else {
36
+ if (filter(file)) {
37
+ var _fileName = path.join(searchPath, '/', file);
38
+
39
+ listOfFiles.push(_fileName);
40
+ }
38
41
  }
39
- }
42
+ } catch (_e) {}
40
43
  });
41
44
  return listOfFiles;
42
45
  };
43
46
  export var getCodeFiles = function getCodeFiles(searchPath) {
44
47
  var listOfFiles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
45
48
  var filter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : filterCodeFiles;
46
- var ignorePaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['node_modules', 'lib', 'dist'];
49
+ var ignorePaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : IGNORE_PATHS;
47
50
  return getAllFiles(searchPath, listOfFiles, filter, ignorePaths);
48
51
  };
49
52
  export var execRead = command => {
@@ -73,6 +76,11 @@ export var getRemoteHttpOrigin = () => {
73
76
 
74
77
  return "https://github.com/".concat(match[1]);
75
78
  };
79
+ export var getPermalinkRoot = () => {
80
+ var root = getRemoteHttpOrigin();
81
+ if (root.endsWith('.git')) root = root.substr(0, root.length - 4);
82
+ return root;
83
+ };
76
84
  export class CodeMiner {
77
85
  ignoreCall(call) {
78
86
  if (!/sdk/i.test(call.sdk)) return true;
@@ -221,7 +229,7 @@ export class ExampleMiner {
221
229
 
222
230
  _defineProperty(this, "commitHash", getCommitHash());
223
231
 
224
- _defineProperty(this, "remoteOrigin", getRemoteHttpOrigin());
232
+ _defineProperty(this, "remoteOrigin", getPermalinkRoot());
225
233
 
226
234
  this.execute(sourcePath);
227
235
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exampleMiner.ts"],"names":["fs","path","execSync","warn","readFile","fileName","readFileSync","encoding","sdkPattern","mdPattern","linkPattern","filterAllFiles","trim","length","filterCodeFiles","test","ext","extname","toLocaleLowerCase","fileMiners","skipFolder","name","excludeList","RegExp","join","getAllFiles","searchPath","listOfFiles","filter","ignorePaths","files","readdirSync","forEach","file","statSync","isDirectory","push","getCodeFiles","execRead","command","getCommitHash","getRemoteOrigin","getRemoteHttpOrigin","origin","gitExtractor","match","exec","httpExtractor","CodeMiner","ignoreCall","call","sdk","ignoreOps","has","operationId","mineCode","sourceCode","lines","split","result","line","index","sdkRef","column","mineFile","Set","MarkdownMiner","ignoreLink","linkFile","stripSearch","notCode","isHttp","noDash","value","dasher","replace","sourcerer","sourceFileName","startsWith","substr","base","dirname","mineContent","content","summary","localeCompare","undefined","sensitivity","sourceFile","ExampleMiner","constructor","sourcePath","execute","lode","commitHash","remoteOrigin","summaries","nuggets","addCall","relativeFile","addFileCall","nugget","fileCalls","calls","sdkCall","fileCall","find","f","s","relate","relative","processFile","coder","relFile","dirPath"],"mappings":";;AA0BA,OAAO,KAAKA,EAAZ,MAAoB,IAApB;AACA,OAAOC,IAAP,MAAiB,MAAjB;AACA,SAASC,QAAT,QAAyB,eAAzB;AACA,SAASC,IAAT,QAAqB,2BAArB;AAwBA,OAAO,IAAMC,QAAQ,GAAIC,QAAD,IACtBL,EAAE,CAACM,YAAH,CAAgBD,QAAhB,EAA0B;AAAEE,EAAAA,QAAQ,EAAE;AAAZ,CAA1B,CADK;AAGP,IAAMC,UAAU,GAAG,6CAAnB;AACA,IAAMC,SAAS,GAAG,yBAAlB;AACA,IAAMC,WAAW,GAAG,8BAApB;AAWA,OAAO,IAAMC,cAAc,GAAIN,QAAD,IAAsBA,QAAQ,CAACO,IAAT,GAAgBC,MAAhB,GAAyB,CAAtE;AAMP,OAAO,IAAMC,eAAe,GAAIT,QAAD,IAAsB;AACnD,MAAI,yBAAyBU,IAAzB,CAA8BV,QAA9B,CAAJ,EAA6C,OAAO,KAAP;AAC7C,MAAMW,GAAG,GAAGf,IAAI,CAACgB,OAAL,CAAaZ,QAAb,EAAuBa,iBAAvB,EAAZ;AAEA,SAAOF,GAAG,IAAIG,UAAd;AACD,CALM;;AAOP,IAAMC,UAAU,GAAG,S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2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as fs from 'fs'\nimport path from 'path'\nimport { execSync } from 'child_process'\nimport { warn } from '@looker/sdk-codegen-utils'\nimport type {\n IFileCall,\n INugget,\n ISDKCall,\n ISummary,\n Nuggets,\n SDKCalls,\n Summaries,\n IExampleMine,\n} from '@looker/sdk-codegen'\n\nexport interface IFileMine {\n mineFile(fileName: string): SDKCalls\n mineCode(code: string): SDKCalls\n ignoreCall(call: ISDKCall): boolean\n}\n\nexport interface IDocMine {\n mineFile(fileName: string): ISummary[]\n mineContent(sourceFile: string, content: string): ISummary[]\n ignoreLink(fileName: string): boolean\n}\n\nexport const readFile = (fileName: string) =>\n fs.readFileSync(fileName, { encoding: 'utf-8' })\n\nconst sdkPattern = /(\\b[a-z0-9_]*sdk)\\.\\s*([a-z0-9_]*)\\s*[(<]/gi\nconst mdPattern = /(\\[(.+?)\\]\\((.+?)\\))/gim\nconst linkPattern = /(.*)\\[\\[link\\]\\]\\((.+?)\\)/gim\n\nexport type IMiners = { [key: string]: IFileMine | IDocMine }\n\n/** file-filtering lambda for `getAllFiles()` and `getCodeFiles()` */\nexport type FileFilter = (fileName: string, pattern?: RegExp) => boolean\n\n/**\n * Filter to include every file that has a non-empty file name\n * @param fileName name of file to check\n */\nexport const filterAllFiles = (fileName: string) => fileName.trim().length > 0\n\n/**\n * Filter for code files\n * @param fileName name of file from which to extract its extension\n */\nexport const filterCodeFiles = (fileName: string) => {\n if (/(^|\\/)node_modules\\//gi.test(fileName)) return false\n const ext = path.extname(fileName).toLocaleLowerCase()\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return ext in fileMiners\n}\n\nconst skipFolder = (name: string, excludeList: string[] = ['node_modules']) =>\n new RegExp(excludeList.join('|'), 'gi').test(name)\n\n/**\n * Finds all file recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of current files already found\n * @param filter lambda for file inclusion in results. truthy analyzes the file\n * @param ignorePaths paths to ignore\n */\nexport const getAllFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterAllFiles,\n ignorePaths: string[] = []\n) => {\n const files = fs.readdirSync(searchPath)\n\n files.forEach((file) => {\n if (fs.statSync(searchPath + '/' + file).isDirectory()) {\n if (!skipFolder(file, ignorePaths))\n listOfFiles = getAllFiles(\n searchPath + '/' + file,\n listOfFiles,\n filter,\n ignorePaths\n )\n } else {\n if (filter(file)) {\n const fileName = path.join(searchPath, '/', file)\n listOfFiles.push(fileName)\n }\n }\n })\n\n return listOfFiles\n}\n\n/**\n * Find all source code files recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of source code files that can be mined\n * @param filter function to determine whether a file should be analyzed\n * @param ignorePaths paths to ignore\n */\nexport const getCodeFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterCodeFiles,\n ignorePaths: string[] = ['node_modules', 'lib', 'dist']\n) => {\n return getAllFiles(searchPath, listOfFiles, filter, ignorePaths)\n}\n\n/** get the trimmed output of the command as a UTF-8 string */\nexport const execRead = (command: string) => {\n return execSync(command, { encoding: 'utf-8' }).trim()\n}\n\n/** get this git repository's current commit hash */\nexport const getCommitHash = () => execRead('git rev-parse HEAD')\n\n/** get the remote origin url for this repository */\nexport const getRemoteOrigin = () => {\n return execRead('git remote get-url origin')\n}\n\n/**\n * Convert this github repository's git address to an HTTP url\n */\nexport const getRemoteHttpOrigin = () => {\n const origin = getRemoteOrigin()\n const gitExtractor = /git@github\\.com:(.*)\\.git/gi\n let match = gitExtractor.exec(origin)\n if (!match) {\n // git origin on CI: https://github.com/looker-open-source/sdk-codegen\n const httpExtractor = /(https:\\/\\/github.com.*)(|.git)/\n match = httpExtractor.exec(origin)\n if (!match) {\n return ''\n }\n return match[1]\n }\n return `https://github.com/${match[1]}`\n}\n\nexport class CodeMiner implements IFileMine {\n static ignoreOps = new Set<string>(['ok', 'init31', 'init40'])\n ignoreCall(call: ISDKCall): boolean {\n if (!/sdk/i.test(call.sdk)) return true\n return CodeMiner.ignoreOps.has(call.operationId)\n }\n\n mineCode(sourceCode: string): SDKCalls {\n const lines = sourceCode.split('\\n')\n const result: SDKCalls = []\n lines.forEach((line, index) => {\n let match = sdkPattern.exec(line)\n while (match !== null) {\n // TODO need to ignore source code comments?\n if (match && match.length > 2) {\n const sdkRef = match[1].trim()\n const call: ISDKCall = {\n sdk: sdkRef,\n operationId: match[2].trim(),\n line: index + 1,\n column: match.index,\n }\n if (!this.ignoreCall(call)) {\n result.push(call)\n }\n }\n match = sdkPattern.exec(line)\n }\n })\n return result\n }\n\n mineFile(fileName: string): SDKCalls {\n return this.mineCode(readFile(fileName))\n }\n}\n\n/**\n * Processes markdown files and extracts links to source code to use as summaries\n */\nexport class MarkdownMiner implements IDocMine {\n // TODO ensure summaries don't include markdown files\n ignoreLink(linkFile: string): boolean {\n linkFile = this.stripSearch(linkFile)\n const ext = path.extname(linkFile).toLocaleLowerCase()\n const notCode = ext === '.md' || !filterCodeFiles(linkFile)\n const isHttp = /^(http|https):/gi.test(linkFile)\n return notCode || isHttp\n }\n\n /**\n * Remove leading - from a string\n * @param value string to process\n */\n noDash(value: string) {\n value = value.trim()\n const dasher = /^\\s*-\\s*(.*)/g\n if (dasher.test(value)) {\n value = value.replace(dasher, '$1')\n }\n return value.trim()\n }\n\n stripSearch(fileName: string) {\n fileName = fileName.trim()\n const match = /(.*)#.*/gi.exec(fileName)\n if (match) fileName = match[1]\n return fileName\n }\n\n /**\n * Fully qualify the path for `linkFile`\n * @param sourceFileName\n * @param linkFile\n */\n sourcerer(sourceFileName: string, linkFile: string) {\n linkFile = this.stripSearch(linkFile)\n if (linkFile.startsWith('/')) return linkFile.substr(1)\n const base = path.dirname(sourceFileName)\n return path.join(base, '/', linkFile)\n }\n\n /**\n * Get all links from content\n * @param fileName fully qualified source file name\n * @param content markdown to parse\n */\n mineContent(fileName: string, content: string): ISummary[] {\n const result: ISummary[] = []\n let match = mdPattern.exec(content)\n let linkFile: string\n while (match !== null) {\n const summary = this.noDash(match[2])\n linkFile = this.stripSearch(match[3])\n if (!this.ignoreLink(linkFile)) {\n if (\n summary.localeCompare('[link]', undefined, {\n sensitivity: 'base',\n }) !== 0\n ) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n }\n match = mdPattern.exec(content)\n }\n\n match = linkPattern.exec(content)\n while (match != null) {\n const summary = this.noDash(match[1])\n linkFile = this.stripSearch(match[2])\n if (!this.ignoreLink(linkFile)) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n match = linkPattern.exec(content)\n }\n return result\n }\n\n mineFile(fileName: string): ISummary[] {\n return this.mineContent(fileName, readFile(fileName))\n }\n}\n\nconst fileMiners: IMiners = {\n '.cs': new CodeMiner(),\n '.kt': new CodeMiner(),\n '.py': new CodeMiner(),\n '.swift': new CodeMiner(),\n '.ts': new CodeMiner(),\n '.tsx': new CodeMiner(),\n '.rb': new CodeMiner(),\n '.md': new MarkdownMiner(),\n '.dart': new CodeMiner(),\n '.go': new CodeMiner(),\n '.java': new CodeMiner(),\n // '.rst': new MarkdownMiner(), // TODO .rst miner? Probably not needed\n}\n\nexport class ExampleMiner {\n summaries: Summaries = {}\n nuggets: Nuggets = {}\n commitHash: string = getCommitHash()\n remoteOrigin: string = getRemoteHttpOrigin()\n\n constructor(public readonly sourcePath: string) {\n this.execute(sourcePath)\n }\n\n get lode(): IExampleMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n summaries: this.summaries,\n nuggets: this.nuggets,\n }\n }\n\n addCall(ext: string, relativeFile: string, call: ISDKCall | ISummary) {\n function addFileCall(nugget: INugget) {\n // Extension is key for language\n let fileCalls = nugget.calls[ext]\n if (!fileCalls) {\n fileCalls = []\n }\n const sdkCall = call as ISDKCall\n const fileCall: IFileCall = {\n sourceFile: relativeFile,\n column: sdkCall.column,\n line: sdkCall.line,\n }\n if (\n !fileCalls.find(\n (f) =>\n f.line === fileCall.line &&\n f.column === fileCall.column &&\n f.sourceFile === fileCall.sourceFile\n )\n )\n fileCalls.push(fileCall)\n nugget.calls[ext] = fileCalls\n }\n\n if ('summary' in call) {\n const s = call as ISummary\n s.sourceFile = ExampleMiner.relate(this.sourcePath, s.sourceFile)\n this.summaries[s.sourceFile] = s\n } else {\n let nugget: INugget = this.nuggets[call.operationId]\n if (!nugget) {\n nugget = { operationId: call.operationId, calls: {} }\n }\n addFileCall(nugget)\n this.nuggets[nugget.operationId] = nugget\n }\n }\n\n /**\n * Derive relative path, retaining last directory\n * @param sourcePath original file search path\n * @param fileName fully qualified name of found file\n *\n * @example `Miner.relate('/a/b/c/', '/a/b/c/d.txt')` returns 'd.txt'\n */\n public static relate(sourcePath: string, fileName: string) {\n return path.relative(sourcePath, fileName)\n }\n\n processFile(fileName: string) {\n const ext = path.extname(fileName)\n if (ext in fileMiners) {\n const coder = fileMiners[ext]\n const calls = coder.mineFile(fileName)\n calls.forEach((call: ISDKCall | ISummary) => {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n this.addCall(ext, relFile, call)\n })\n } else {\n warn(`${fileName} cannot be mined`)\n }\n }\n\n execute(sourcePath: string | null = null) {\n const dirPath = sourcePath ?? this.sourcePath\n const files = getCodeFiles(dirPath)\n files.forEach((f) => this.processFile(f))\n return this.lode\n }\n}\n"],"file":"exampleMiner.js"}
1
+ {"version":3,"sources":["../../src/exampleMiner.ts"],"names":["fs","path","execSync","warn","readFile","fileName","readFileSync","encoding","sdkPattern","mdPattern","linkPattern","filterAllFiles","trim","length","filterCodeFiles","test","ext","extname","toLocaleLowerCase","fileMiners","IGNORE_PATHS","skipFolder","name","excludeList","RegExp","join","getAllFiles","searchPath","listOfFiles","filter","ignorePaths","files","readdirSync","forEach","file","statSync","isDirectory","push","_e","getCodeFiles","execRead","command","getCommitHash","getRemoteOrigin","getRemoteHttpOrigin","origin","gitExtractor","match","exec","httpExtractor","getPermalinkRoot","root","endsWith","substr","CodeMiner","ignoreCall","call","sdk","ignoreOps","has","operationId","mineCode","sourceCode","lines","split","result","line","index","sdkRef","column","mineFile","Set","MarkdownMiner","ignoreLink","linkFile","stripSearch","notCode","isHttp","noDash","value","dasher","replace","sourcerer","sourceFileName","startsWith","base","dirname","mineContent","content","summary","localeCompare","undefined","sensitivity","sourceFile","ExampleMiner","constructor","sourcePath","execute","lode","commitHash","remoteOrigin","summaries","nuggets","addCall","relativeFile","addFileCall","nugget","fileCalls","calls","sdkCall","fileCall","find","f","s","relate","relative","processFile","coder","relFile","dirPath"],"mappings":";;AA0BA,OAAO,KAAKA,EAAZ,MAAoB,IAApB;AACA,OAAOC,IAAP,MAAiB,MAAjB;AACA,SAASC,QAAT,QAAyB,eAAzB;AACA,SAASC,IAAT,QAAqB,2BAArB;AAwBA,OAAO,IAAMC,QAAQ,GAAIC,QAAD,IACtBL,EAAE,CAACM,YAAH,CAAgBD,QAAhB,EAA0B;AAAEE,EAAAA,QAAQ,EAAE;AAAZ,CAA1B,CADK;AAGP,IAAMC,UAAU,GA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ACD;;AAED+G,EAAAA,WAAW,CAAC/G,QAAD,EAAmB;AAC5B,QAAMW,GAAG,GAAGf,IAAI,CAACgB,OAAL,CAAaZ,QAAb,CAAZ;;AACA,QAAIW,GAAG,IAAIG,UAAX,EAAuB;AACrB,UAAMkG,KAAK,GAAGlG,UAAU,CAACH,GAAD,CAAxB;AACA,UAAM4F,KAAK,GAAGS,KAAK,CAAC/C,QAAN,CAAejE,QAAf,CAAd;AACAuG,MAAAA,KAAK,CAAC3E,OAAN,CAAeuB,IAAD,IAA+B;AAC3C,YAAM8D,OAAO,GAAGxB,YAAY,CAACoB,MAAb,CAAoB,KAAKlB,UAAzB,EAAqC3F,QAArC,CAAhB;AACA,aAAKkG,OAAL,CAAavF,GAAb,EAAkBsG,OAAlB,EAA2B9D,IAA3B;AACD,OAHD;AAID,KAPD,MAOO;AACLrD,MAAAA,IAAI,WAAIE,QAAJ,sBAAJ;AACD;AACF;;AAED4F,EAAAA,OAAO,GAAmC;AAAA,QAAlCD,UAAkC,uEAAN,IAAM;AACxC,QAAMuB,OAAO,GAAGvB,UAAH,aAAGA,UAAH,cAAGA,UAAH,GAAiB,KAAKA,UAAnC;AACA,QAAMjE,KAAK,GAAGQ,YAAY,CAACgF,OAAD,CAA1B;AACAxF,IAAAA,KAAK,CAACE,OAAN,CAAe+E,CAAD,IAAO,KAAKI,WAAL,CAAiBJ,CAAjB,CAArB;AACA,WAAO,KAAKd,IAAZ;AACD;;AAxFuB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as fs from 'fs'\nimport path from 'path'\nimport { execSync } from 'child_process'\nimport { warn } from '@looker/sdk-codegen-utils'\nimport type {\n IFileCall,\n INugget,\n ISDKCall,\n ISummary,\n Nuggets,\n SDKCalls,\n Summaries,\n IExampleMine,\n} from '@looker/sdk-codegen'\n\nexport interface IFileMine {\n mineFile(fileName: string): SDKCalls\n mineCode(code: string): SDKCalls\n ignoreCall(call: ISDKCall): boolean\n}\n\nexport interface IDocMine {\n mineFile(fileName: string): ISummary[]\n mineContent(sourceFile: string, content: string): ISummary[]\n ignoreLink(fileName: string): boolean\n}\n\nexport const readFile = (fileName: string) =>\n fs.readFileSync(fileName, { encoding: 'utf-8' })\n\nconst sdkPattern = /(\\b[a-z0-9_]*sdk)\\.\\s*([a-z0-9_]*)\\s*[(<]/gi\nconst mdPattern = /(\\[(.+?)\\]\\((.+?)\\))/gim\nconst linkPattern = /(.*)\\[\\[link\\]\\]\\((.+?)\\)/gim\n\nexport type IMiners = { [key: string]: IFileMine | IDocMine }\n\n/** file-filtering lambda for `getAllFiles()` and `getCodeFiles()` */\nexport type FileFilter = (fileName: string, pattern?: RegExp) => boolean\n\n/**\n * Filter to include every file that has a non-empty file name\n * @param fileName name of file to check\n */\nexport const filterAllFiles = (fileName: string) => fileName.trim().length > 0\n\n/**\n * Filter for code files\n * @param fileName name of file from which to extract its extension\n */\nexport const filterCodeFiles = (fileName: string) => {\n if (/(^|\\/)node_modules\\//gi.test(fileName)) return false\n const ext = path.extname(fileName).toLocaleLowerCase()\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return ext in fileMiners\n}\n\nexport const IGNORE_PATHS = [\n 'node_modules',\n 'lib',\n 'dist',\n 'bazel-bin',\n 'build',\n 'bin',\n '.build',\n '.direnv',\n '.github',\n '.vscode',\n '.idea',\n '.gradle',\n 'results',\n]\n\nconst skipFolder = (name: string, excludeList: string[] = IGNORE_PATHS) =>\n new RegExp(excludeList.join('|'), 'gi').test(name)\n\n/**\n * Finds all file recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of current files already found\n * @param filter lambda for file inclusion in results. truthy analyzes the file\n * @param ignorePaths paths to ignore\n */\nexport const getAllFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterAllFiles,\n ignorePaths: string[] = []\n) => {\n const files = fs.readdirSync(searchPath)\n\n files.forEach((file) => {\n try {\n if (fs.statSync(searchPath + '/' + file).isDirectory()) {\n if (!skipFolder(file, ignorePaths))\n listOfFiles = getAllFiles(\n searchPath + '/' + file,\n listOfFiles,\n filter,\n ignorePaths\n )\n } else {\n if (filter(file)) {\n const fileName = path.join(searchPath, '/', file)\n listOfFiles.push(fileName)\n }\n }\n } catch (_e: any) {\n // warn(`skipping ${file}: ${e}`)\n }\n })\n\n return listOfFiles\n}\n\n/**\n * Find all source code files recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of source code files that can be mined\n * @param filter function to determine whether a file should be analyzed\n * @param ignorePaths paths to ignore\n */\nexport const getCodeFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterCodeFiles,\n ignorePaths: string[] = IGNORE_PATHS\n) => {\n return getAllFiles(searchPath, listOfFiles, filter, ignorePaths)\n}\n\n/** get the trimmed output of the command as a UTF-8 string */\nexport const execRead = (command: string) => {\n return execSync(command, { encoding: 'utf-8' }).trim()\n}\n\n/** get this git repository's current commit hash */\nexport const getCommitHash = () => execRead('git rev-parse HEAD')\n\n/** get the remote origin url for this repository */\nexport const getRemoteOrigin = () => {\n return execRead('git remote get-url origin')\n}\n\n/**\n * Convert this github repository's git address to an HTTP url\n */\nexport const getRemoteHttpOrigin = () => {\n const origin = getRemoteOrigin()\n const gitExtractor = /git@github\\.com:(.*)\\.git/gi\n let match = gitExtractor.exec(origin)\n if (!match) {\n // git origin on CI: https://github.com/looker-open-source/sdk-codegen\n const httpExtractor = /(https:\\/\\/github.com.*)(|.git)/\n match = httpExtractor.exec(origin)\n if (!match) {\n return ''\n }\n return match[1]\n }\n return `https://github.com/${match[1]}`\n}\n\n/** Permalink paths should not have the `.git` ending for a repo */\nexport const getPermalinkRoot = () => {\n let root = getRemoteHttpOrigin()\n if (root.endsWith('.git')) root = root.substr(0, root.length - 4)\n return root\n}\n\nexport class CodeMiner implements IFileMine {\n static ignoreOps = new Set<string>(['ok', 'init31', 'init40'])\n ignoreCall(call: ISDKCall): boolean {\n if (!/sdk/i.test(call.sdk)) return true\n return CodeMiner.ignoreOps.has(call.operationId)\n }\n\n mineCode(sourceCode: string): SDKCalls {\n const lines = sourceCode.split('\\n')\n const result: SDKCalls = []\n lines.forEach((line, index) => {\n let match = sdkPattern.exec(line)\n while (match !== null) {\n // TODO need to ignore source code comments?\n if (match && match.length > 2) {\n const sdkRef = match[1].trim()\n const call: ISDKCall = {\n sdk: sdkRef,\n operationId: match[2].trim(),\n line: index + 1,\n column: match.index,\n }\n if (!this.ignoreCall(call)) {\n result.push(call)\n }\n }\n match = sdkPattern.exec(line)\n }\n })\n return result\n }\n\n mineFile(fileName: string): SDKCalls {\n return this.mineCode(readFile(fileName))\n }\n}\n\n/**\n * Processes markdown files and extracts links to source code to use as summaries\n */\nexport class MarkdownMiner implements IDocMine {\n // TODO ensure summaries don't include markdown files\n ignoreLink(linkFile: string): boolean {\n linkFile = this.stripSearch(linkFile)\n const ext = path.extname(linkFile).toLocaleLowerCase()\n const notCode = ext === '.md' || !filterCodeFiles(linkFile)\n const isHttp = /^(http|https):/gi.test(linkFile)\n return notCode || isHttp\n }\n\n /**\n * Remove leading - from a string\n * @param value string to process\n */\n noDash(value: string) {\n value = value.trim()\n const dasher = /^\\s*-\\s*(.*)/g\n if (dasher.test(value)) {\n value = value.replace(dasher, '$1')\n }\n return value.trim()\n }\n\n stripSearch(fileName: string) {\n fileName = fileName.trim()\n const match = /(.*)#.*/gi.exec(fileName)\n if (match) fileName = match[1]\n return fileName\n }\n\n /**\n * Fully qualify the path for `linkFile`\n * @param sourceFileName\n * @param linkFile\n */\n sourcerer(sourceFileName: string, linkFile: string) {\n linkFile = this.stripSearch(linkFile)\n if (linkFile.startsWith('/')) return linkFile.substr(1)\n const base = path.dirname(sourceFileName)\n return path.join(base, '/', linkFile)\n }\n\n /**\n * Get all links from content\n * @param fileName fully qualified source file name\n * @param content markdown to parse\n */\n mineContent(fileName: string, content: string): ISummary[] {\n const result: ISummary[] = []\n let match = mdPattern.exec(content)\n let linkFile: string\n while (match !== null) {\n const summary = this.noDash(match[2])\n linkFile = this.stripSearch(match[3])\n if (!this.ignoreLink(linkFile)) {\n if (\n summary.localeCompare('[link]', undefined, {\n sensitivity: 'base',\n }) !== 0\n ) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n }\n match = mdPattern.exec(content)\n }\n\n match = linkPattern.exec(content)\n while (match != null) {\n const summary = this.noDash(match[1])\n linkFile = this.stripSearch(match[2])\n if (!this.ignoreLink(linkFile)) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n match = linkPattern.exec(content)\n }\n return result\n }\n\n mineFile(fileName: string): ISummary[] {\n return this.mineContent(fileName, readFile(fileName))\n }\n}\n\nconst fileMiners: IMiners = {\n '.cs': new CodeMiner(),\n '.kt': new CodeMiner(),\n '.py': new CodeMiner(),\n '.swift': new CodeMiner(),\n '.ts': new CodeMiner(),\n '.tsx': new CodeMiner(),\n '.rb': new CodeMiner(),\n '.md': new MarkdownMiner(),\n '.dart': new CodeMiner(),\n '.go': new CodeMiner(),\n '.java': new CodeMiner(),\n // '.rst': new MarkdownMiner(), // TODO .rst miner? Probably not needed\n}\n\nexport class ExampleMiner {\n summaries: Summaries = {}\n nuggets: Nuggets = {}\n commitHash: string = getCommitHash()\n remoteOrigin: string = getPermalinkRoot()\n\n constructor(public readonly sourcePath: string) {\n this.execute(sourcePath)\n }\n\n get lode(): IExampleMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n summaries: this.summaries,\n nuggets: this.nuggets,\n }\n }\n\n addCall(ext: string, relativeFile: string, call: ISDKCall | ISummary) {\n function addFileCall(nugget: INugget) {\n // Extension is key for language\n let fileCalls = nugget.calls[ext]\n if (!fileCalls) {\n fileCalls = []\n }\n const sdkCall = call as ISDKCall\n const fileCall: IFileCall = {\n sourceFile: relativeFile,\n column: sdkCall.column,\n line: sdkCall.line,\n }\n if (\n !fileCalls.find(\n (f) =>\n f.line === fileCall.line &&\n f.column === fileCall.column &&\n f.sourceFile === fileCall.sourceFile\n )\n )\n fileCalls.push(fileCall)\n nugget.calls[ext] = fileCalls\n }\n\n if ('summary' in call) {\n const s = call as ISummary\n s.sourceFile = ExampleMiner.relate(this.sourcePath, s.sourceFile)\n this.summaries[s.sourceFile] = s\n } else {\n let nugget: INugget = this.nuggets[call.operationId]\n if (!nugget) {\n nugget = { operationId: call.operationId, calls: {} }\n }\n addFileCall(nugget)\n this.nuggets[nugget.operationId] = nugget\n }\n }\n\n /**\n * Derive relative path, retaining last directory\n * @param sourcePath original file search path\n * @param fileName fully qualified name of found file\n *\n * @example `Miner.relate('/a/b/c/', '/a/b/c/d.txt')` returns 'd.txt'\n */\n public static relate(sourcePath: string, fileName: string) {\n return path.relative(sourcePath, fileName)\n }\n\n processFile(fileName: string) {\n const ext = path.extname(fileName)\n if (ext in fileMiners) {\n const coder = fileMiners[ext]\n const calls = coder.mineFile(fileName)\n calls.forEach((call: ISDKCall | ISummary) => {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n this.addCall(ext, relFile, call)\n })\n } else {\n warn(`${fileName} cannot be mined`)\n }\n }\n\n execute(sourcePath: string | null = null) {\n const dirPath = sourcePath ?? this.sourcePath\n const files = getCodeFiles(dirPath)\n files.forEach((f) => this.processFile(f))\n return this.lode\n }\n}\n"],"file":"exampleMiner.js"}
@@ -16,12 +16,14 @@ export declare type IMiners = {
16
16
  export declare type FileFilter = (fileName: string, pattern?: RegExp) => boolean;
17
17
  export declare const filterAllFiles: (fileName: string) => boolean;
18
18
  export declare const filterCodeFiles: (fileName: string) => boolean;
19
+ export declare const IGNORE_PATHS: string[];
19
20
  export declare const getAllFiles: (searchPath: string, listOfFiles?: string[], filter?: FileFilter, ignorePaths?: string[]) => string[];
20
21
  export declare const getCodeFiles: (searchPath: string, listOfFiles?: string[], filter?: FileFilter, ignorePaths?: string[]) => string[];
21
22
  export declare const execRead: (command: string) => string;
22
23
  export declare const getCommitHash: () => string;
23
24
  export declare const getRemoteOrigin: () => string;
24
25
  export declare const getRemoteHttpOrigin: () => string;
26
+ export declare const getPermalinkRoot: () => string;
25
27
  export declare class CodeMiner implements IFileMine {
26
28
  static ignoreOps: Set<string>;
27
29
  ignoreCall(call: ISDKCall): boolean;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ExampleMiner = exports.MarkdownMiner = exports.CodeMiner = exports.getRemoteHttpOrigin = exports.getRemoteOrigin = exports.getCommitHash = exports.execRead = exports.getCodeFiles = exports.getAllFiles = exports.filterCodeFiles = exports.filterAllFiles = exports.readFile = void 0;
6
+ exports.ExampleMiner = exports.MarkdownMiner = exports.CodeMiner = exports.getPermalinkRoot = exports.getRemoteHttpOrigin = exports.getRemoteOrigin = exports.getCommitHash = exports.execRead = exports.getCodeFiles = exports.getAllFiles = exports.IGNORE_PATHS = exports.filterCodeFiles = exports.filterAllFiles = exports.readFile = void 0;
7
7
 
8
8
  var fs = _interopRequireWildcard(require("fs"));
9
9
 
@@ -43,9 +43,11 @@ var filterCodeFiles = fileName => {
43
43
  };
44
44
 
45
45
  exports.filterCodeFiles = filterCodeFiles;
46
+ var IGNORE_PATHS = ['node_modules', 'lib', 'dist', 'bazel-bin', 'build', 'bin', '.build', '.direnv', '.github', '.vscode', '.idea', '.gradle', 'results'];
47
+ exports.IGNORE_PATHS = IGNORE_PATHS;
46
48
 
47
49
  var skipFolder = function skipFolder(name) {
48
- var excludeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['node_modules'];
50
+ var excludeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : IGNORE_PATHS;
49
51
  return new RegExp(excludeList.join('|'), 'gi').test(name);
50
52
  };
51
53
 
@@ -55,15 +57,17 @@ var getAllFiles = function getAllFiles(searchPath) {
55
57
  var ignorePaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
56
58
  var files = fs.readdirSync(searchPath);
57
59
  files.forEach(file => {
58
- if (fs.statSync(searchPath + '/' + file).isDirectory()) {
59
- if (!skipFolder(file, ignorePaths)) listOfFiles = getAllFiles(searchPath + '/' + file, listOfFiles, filter, ignorePaths);
60
- } else {
61
- if (filter(file)) {
62
- var _fileName = _path.default.join(searchPath, '/', file);
63
-
64
- listOfFiles.push(_fileName);
60
+ try {
61
+ if (fs.statSync(searchPath + '/' + file).isDirectory()) {
62
+ if (!skipFolder(file, ignorePaths)) listOfFiles = getAllFiles(searchPath + '/' + file, listOfFiles, filter, ignorePaths);
63
+ } else {
64
+ if (filter(file)) {
65
+ var _fileName = _path.default.join(searchPath, '/', file);
66
+
67
+ listOfFiles.push(_fileName);
68
+ }
65
69
  }
66
- }
70
+ } catch (_e) {}
67
71
  });
68
72
  return listOfFiles;
69
73
  };
@@ -73,7 +77,7 @@ exports.getAllFiles = getAllFiles;
73
77
  var getCodeFiles = function getCodeFiles(searchPath) {
74
78
  var listOfFiles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
75
79
  var filter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : filterCodeFiles;
76
- var ignorePaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['node_modules', 'lib', 'dist'];
80
+ var ignorePaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : IGNORE_PATHS;
77
81
  return getAllFiles(searchPath, listOfFiles, filter, ignorePaths);
78
82
  };
79
83
 
@@ -118,6 +122,14 @@ var getRemoteHttpOrigin = () => {
118
122
 
119
123
  exports.getRemoteHttpOrigin = getRemoteHttpOrigin;
120
124
 
125
+ var getPermalinkRoot = () => {
126
+ var root = getRemoteHttpOrigin();
127
+ if (root.endsWith('.git')) root = root.substr(0, root.length - 4);
128
+ return root;
129
+ };
130
+
131
+ exports.getPermalinkRoot = getPermalinkRoot;
132
+
121
133
  class CodeMiner {
122
134
  ignoreCall(call) {
123
135
  if (!/sdk/i.test(call.sdk)) return true;
@@ -275,7 +287,7 @@ class ExampleMiner {
275
287
 
276
288
  _defineProperty(this, "commitHash", getCommitHash());
277
289
 
278
- _defineProperty(this, "remoteOrigin", getRemoteHttpOrigin());
290
+ _defineProperty(this, "remoteOrigin", getPermalinkRoot());
279
291
 
280
292
  this.execute(sourcePath);
281
293
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/exampleMiner.ts"],"names":["readFile","fileName","fs","readFileSync","encoding","sdkPattern","mdPattern","linkPattern","filterAllFiles","trim","length","filterCodeFiles","test","ext","path","extname","toLocaleLowerCase","fileMiners","skipFolder","name","excludeList","RegExp","join","getAllFiles","searchPath","listOfFiles","filter","ignorePaths","files","readdirSync","forEach","file","statSync","isDirectory","push","getCodeFiles","execRead","command","getCommitHash","getRemoteOrigin","getRemoteHttpOrigin","origin","gitExtractor","match","exec","httpExtractor","CodeMiner","ignoreCall","call","sdk","ignoreOps","has","operationId","mineCode","sourceCode","lines","split","result","line","index","sdkRef","column","mineFile","Set","MarkdownMiner","ignoreLink","linkFile","stripSearch","notCode","isHttp","noDash","value","dasher","replace","sourcerer","sourceFileName","startsWith","substr","base","dirname","mineContent","content","summary","localeCompare","undefined","sensitivity","sourceFile","ExampleMiner","constructor","sourcePath","execute","lode","commitHash","remoteOrigin","summaries","nuggets","addCall","relativeFile","addFileCall","nugget","fileCalls","calls","sdkCall","fileCall","find","f","s","relate","relative","processFile","coder","relFile","dirPath"],"mappings":";;;;;;;AA0BA;;AACA;;AACA;;AACA;;;;;;;;;;AAwBO,IAAMA,QAAQ,GAAIC,QAAD,IACtBC,EAAE,CAACC,YAAH,CAAgBF,QAAhB,EAA0B;AAAEG,EAAAA,QAAQ,EAAE;AAAZ,CAA1B,CADK;;;AAGP,IAAMC,UAAU,GAAG,6CAAnB;AACA,IAAMC,SAAS,GAAG,yBAAlB;AACA,IAAMC,WAAW,GAAG,8BAApB;;AAWO,IAAMC,cAAc,GAAIP,QAAD,IAAsBA,QAAQ,CAACQ,IAAT,GAAgBC,MAAhB,GAAyB,CAAtE;;;;AAMA,IAAMC,eAAe,GAAIV,QAAD,IAAsB;AACnD,MAAI,yBAAyBW,IAAzB,CAA8BX,QAA9B,CAAJ,EAA6C,OAAO,KAAP;;AAC7C,MAAMY,GAAG,GAAGC,cAAKC,OAAL,CAAad,QAAb,EAAuBe,iBAAvB,EAAZ;;AAEA,SAAOH,GAAG,IAAII,UAAd;AACD,CALM;;;;AAOP,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,IAAD;AAAA,MAAeC,WAAf,uEAAuC,CAAC,cAAD,CAAvC;AAAA,SACjB,IAAIC,MAAJ,CAAWD,WAAW,CAACE,IAAZ,CAAiB,GAAjB,CAAX,EAAkC,IAAlC,EAAwCV,IAAxC,CAA6CO,IAA7C,CADiB;AAAA,CAAnB;;AAUO,IAAMI,WAAW,GAAG,SAAdA,WAAc,CACzBC,UADyB,EAKtB;AAAA,MAHHC,WAGG,uEAHqB,EAGrB;AAAA,MAFHC,MAEG,uEAFkBlB,cAElB;AAAA,MADHmB,WACG,uEADqB,EACrB;A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,EAAuB;AACrB,UAAM6F,KAAK,GAAG7F,UAAU,CAACJ,GAAD,CAAxB;AACA,UAAMwF,KAAK,GAAGS,KAAK,CAAChD,QAAN,CAAe7D,QAAf,CAAd;AACAoG,MAAAA,KAAK,CAACvE,OAAN,CAAekB,IAAD,IAA+B;AAC3C,YAAM+D,OAAO,GAAGxB,YAAY,CAACoB,MAAb,CAAoB,KAAKlB,UAAzB,EAAqCxF,QAArC,CAAhB;AACA,aAAK+F,OAAL,CAAanF,GAAb,EAAkBkG,OAAlB,EAA2B/D,IAA3B;AACD,OAHD;AAID,KAPD,MAOO;AACL,2CAAQ/C,QAAR;AACD;AACF;;AAEDyF,EAAAA,OAAO,GAAmC;AAAA,QAAlCD,UAAkC,uEAAN,IAAM;AACxC,QAAMuB,OAAO,GAAGvB,UAAH,aAAGA,UAAH,cAAGA,UAAH,GAAiB,KAAKA,UAAnC;AACA,QAAM7D,KAAK,GAAGO,YAAY,CAAC6E,OAAD,CAA1B;AACApF,IAAAA,KAAK,CAACE,OAAN,CAAe2E,CAAD,IAAO,KAAKI,WAAL,CAAiBJ,CAAjB,CAArB;AACA,WAAO,KAAKd,IAAZ;AACD;;AAxFuB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as fs from 'fs'\nimport path from 'path'\nimport { execSync } from 'child_process'\nimport { warn } from '@looker/sdk-codegen-utils'\nimport type {\n IFileCall,\n INugget,\n ISDKCall,\n ISummary,\n Nuggets,\n SDKCalls,\n Summaries,\n IExampleMine,\n} from '@looker/sdk-codegen'\n\nexport interface IFileMine {\n mineFile(fileName: string): SDKCalls\n mineCode(code: string): SDKCalls\n ignoreCall(call: ISDKCall): boolean\n}\n\nexport interface IDocMine {\n mineFile(fileName: string): ISummary[]\n mineContent(sourceFile: string, content: string): ISummary[]\n ignoreLink(fileName: string): boolean\n}\n\nexport const readFile = (fileName: string) =>\n fs.readFileSync(fileName, { encoding: 'utf-8' })\n\nconst sdkPattern = /(\\b[a-z0-9_]*sdk)\\.\\s*([a-z0-9_]*)\\s*[(<]/gi\nconst mdPattern = /(\\[(.+?)\\]\\((.+?)\\))/gim\nconst linkPattern = /(.*)\\[\\[link\\]\\]\\((.+?)\\)/gim\n\nexport type IMiners = { [key: string]: IFileMine | IDocMine }\n\n/** file-filtering lambda for `getAllFiles()` and `getCodeFiles()` */\nexport type FileFilter = (fileName: string, pattern?: RegExp) => boolean\n\n/**\n * Filter to include every file that has a non-empty file name\n * @param fileName name of file to check\n */\nexport const filterAllFiles = (fileName: string) => fileName.trim().length > 0\n\n/**\n * Filter for code files\n * @param fileName name of file from which to extract its extension\n */\nexport const filterCodeFiles = (fileName: string) => {\n if (/(^|\\/)node_modules\\//gi.test(fileName)) return false\n const ext = path.extname(fileName).toLocaleLowerCase()\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return ext in fileMiners\n}\n\nconst skipFolder = (name: string, excludeList: string[] = ['node_modules']) =>\n new RegExp(excludeList.join('|'), 'gi').test(name)\n\n/**\n * Finds all file recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of current files already found\n * @param filter lambda for file inclusion in results. truthy analyzes the file\n * @param ignorePaths paths to ignore\n */\nexport const getAllFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterAllFiles,\n ignorePaths: string[] = []\n) => {\n const files = fs.readdirSync(searchPath)\n\n files.forEach((file) => {\n if (fs.statSync(searchPath + '/' + file).isDirectory()) {\n if (!skipFolder(file, ignorePaths))\n listOfFiles = getAllFiles(\n searchPath + '/' + file,\n listOfFiles,\n filter,\n ignorePaths\n )\n } else {\n if (filter(file)) {\n const fileName = path.join(searchPath, '/', file)\n listOfFiles.push(fileName)\n }\n }\n })\n\n return listOfFiles\n}\n\n/**\n * Find all source code files recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of source code files that can be mined\n * @param filter function to determine whether a file should be analyzed\n * @param ignorePaths paths to ignore\n */\nexport const getCodeFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterCodeFiles,\n ignorePaths: string[] = ['node_modules', 'lib', 'dist']\n) => {\n return getAllFiles(searchPath, listOfFiles, filter, ignorePaths)\n}\n\n/** get the trimmed output of the command as a UTF-8 string */\nexport const execRead = (command: string) => {\n return execSync(command, { encoding: 'utf-8' }).trim()\n}\n\n/** get this git repository's current commit hash */\nexport const getCommitHash = () => execRead('git rev-parse HEAD')\n\n/** get the remote origin url for this repository */\nexport const getRemoteOrigin = () => {\n return execRead('git remote get-url origin')\n}\n\n/**\n * Convert this github repository's git address to an HTTP url\n */\nexport const getRemoteHttpOrigin = () => {\n const origin = getRemoteOrigin()\n const gitExtractor = /git@github\\.com:(.*)\\.git/gi\n let match = gitExtractor.exec(origin)\n if (!match) {\n // git origin on CI: https://github.com/looker-open-source/sdk-codegen\n const httpExtractor = /(https:\\/\\/github.com.*)(|.git)/\n match = httpExtractor.exec(origin)\n if (!match) {\n return ''\n }\n return match[1]\n }\n return `https://github.com/${match[1]}`\n}\n\nexport class CodeMiner implements IFileMine {\n static ignoreOps = new Set<string>(['ok', 'init31', 'init40'])\n ignoreCall(call: ISDKCall): boolean {\n if (!/sdk/i.test(call.sdk)) return true\n return CodeMiner.ignoreOps.has(call.operationId)\n }\n\n mineCode(sourceCode: string): SDKCalls {\n const lines = sourceCode.split('\\n')\n const result: SDKCalls = []\n lines.forEach((line, index) => {\n let match = sdkPattern.exec(line)\n while (match !== null) {\n // TODO need to ignore source code comments?\n if (match && match.length > 2) {\n const sdkRef = match[1].trim()\n const call: ISDKCall = {\n sdk: sdkRef,\n operationId: match[2].trim(),\n line: index + 1,\n column: match.index,\n }\n if (!this.ignoreCall(call)) {\n result.push(call)\n }\n }\n match = sdkPattern.exec(line)\n }\n })\n return result\n }\n\n mineFile(fileName: string): SDKCalls {\n return this.mineCode(readFile(fileName))\n }\n}\n\n/**\n * Processes markdown files and extracts links to source code to use as summaries\n */\nexport class MarkdownMiner implements IDocMine {\n // TODO ensure summaries don't include markdown files\n ignoreLink(linkFile: string): boolean {\n linkFile = this.stripSearch(linkFile)\n const ext = path.extname(linkFile).toLocaleLowerCase()\n const notCode = ext === '.md' || !filterCodeFiles(linkFile)\n const isHttp = /^(http|https):/gi.test(linkFile)\n return notCode || isHttp\n }\n\n /**\n * Remove leading - from a string\n * @param value string to process\n */\n noDash(value: string) {\n value = value.trim()\n const dasher = /^\\s*-\\s*(.*)/g\n if (dasher.test(value)) {\n value = value.replace(dasher, '$1')\n }\n return value.trim()\n }\n\n stripSearch(fileName: string) {\n fileName = fileName.trim()\n const match = /(.*)#.*/gi.exec(fileName)\n if (match) fileName = match[1]\n return fileName\n }\n\n /**\n * Fully qualify the path for `linkFile`\n * @param sourceFileName\n * @param linkFile\n */\n sourcerer(sourceFileName: string, linkFile: string) {\n linkFile = this.stripSearch(linkFile)\n if (linkFile.startsWith('/')) return linkFile.substr(1)\n const base = path.dirname(sourceFileName)\n return path.join(base, '/', linkFile)\n }\n\n /**\n * Get all links from content\n * @param fileName fully qualified source file name\n * @param content markdown to parse\n */\n mineContent(fileName: string, content: string): ISummary[] {\n const result: ISummary[] = []\n let match = mdPattern.exec(content)\n let linkFile: string\n while (match !== null) {\n const summary = this.noDash(match[2])\n linkFile = this.stripSearch(match[3])\n if (!this.ignoreLink(linkFile)) {\n if (\n summary.localeCompare('[link]', undefined, {\n sensitivity: 'base',\n }) !== 0\n ) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n }\n match = mdPattern.exec(content)\n }\n\n match = linkPattern.exec(content)\n while (match != null) {\n const summary = this.noDash(match[1])\n linkFile = this.stripSearch(match[2])\n if (!this.ignoreLink(linkFile)) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n match = linkPattern.exec(content)\n }\n return result\n }\n\n mineFile(fileName: string): ISummary[] {\n return this.mineContent(fileName, readFile(fileName))\n }\n}\n\nconst fileMiners: IMiners = {\n '.cs': new CodeMiner(),\n '.kt': new CodeMiner(),\n '.py': new CodeMiner(),\n '.swift': new CodeMiner(),\n '.ts': new CodeMiner(),\n '.tsx': new CodeMiner(),\n '.rb': new CodeMiner(),\n '.md': new MarkdownMiner(),\n '.dart': new CodeMiner(),\n '.go': new CodeMiner(),\n '.java': new CodeMiner(),\n // '.rst': new MarkdownMiner(), // TODO .rst miner? Probably not needed\n}\n\nexport class ExampleMiner {\n summaries: Summaries = {}\n nuggets: Nuggets = {}\n commitHash: string = getCommitHash()\n remoteOrigin: string = getRemoteHttpOrigin()\n\n constructor(public readonly sourcePath: string) {\n this.execute(sourcePath)\n }\n\n get lode(): IExampleMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n summaries: this.summaries,\n nuggets: this.nuggets,\n }\n }\n\n addCall(ext: string, relativeFile: string, call: ISDKCall | ISummary) {\n function addFileCall(nugget: INugget) {\n // Extension is key for language\n let fileCalls = nugget.calls[ext]\n if (!fileCalls) {\n fileCalls = []\n }\n const sdkCall = call as ISDKCall\n const fileCall: IFileCall = {\n sourceFile: relativeFile,\n column: sdkCall.column,\n line: sdkCall.line,\n }\n if (\n !fileCalls.find(\n (f) =>\n f.line === fileCall.line &&\n f.column === fileCall.column &&\n f.sourceFile === fileCall.sourceFile\n )\n )\n fileCalls.push(fileCall)\n nugget.calls[ext] = fileCalls\n }\n\n if ('summary' in call) {\n const s = call as ISummary\n s.sourceFile = ExampleMiner.relate(this.sourcePath, s.sourceFile)\n this.summaries[s.sourceFile] = s\n } else {\n let nugget: INugget = this.nuggets[call.operationId]\n if (!nugget) {\n nugget = { operationId: call.operationId, calls: {} }\n }\n addFileCall(nugget)\n this.nuggets[nugget.operationId] = nugget\n }\n }\n\n /**\n * Derive relative path, retaining last directory\n * @param sourcePath original file search path\n * @param fileName fully qualified name of found file\n *\n * @example `Miner.relate('/a/b/c/', '/a/b/c/d.txt')` returns 'd.txt'\n */\n public static relate(sourcePath: string, fileName: string) {\n return path.relative(sourcePath, fileName)\n }\n\n processFile(fileName: string) {\n const ext = path.extname(fileName)\n if (ext in fileMiners) {\n const coder = fileMiners[ext]\n const calls = coder.mineFile(fileName)\n calls.forEach((call: ISDKCall | ISummary) => {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n this.addCall(ext, relFile, call)\n })\n } else {\n warn(`${fileName} cannot be mined`)\n }\n }\n\n execute(sourcePath: string | null = null) {\n const dirPath = sourcePath ?? this.sourcePath\n const files = getCodeFiles(dirPath)\n files.forEach((f) => this.processFile(f))\n return this.lode\n }\n}\n"],"file":"exampleMiner.js"}
1
+ {"version":3,"sources":["../src/exampleMiner.ts"],"names":["readFile","fileName","fs","readFileSync","encoding","sdkPattern","mdPattern","linkPattern","filterAllFiles","trim","length","filterCodeFiles","test","ext","path","extname","toLocaleLowerCase","fileMiners","IGNORE_PATHS","skipFolder","name","excludeList","RegExp","join","getAllFiles","searchPath","listOfFiles","filter","ignorePaths","files","readdirSync","forEach","file","statSync","isDirectory","push","_e","getCodeFiles","execRead","command","getCommitHash","getRemoteOrigin","getRemoteHttpOrigin","origin","gitExtractor","match","exec","httpExtractor","getPermalinkRoot","root","endsWith","substr","CodeMiner","ignoreCall","call","sdk","ignoreOps","has","operationId","mineCode","sourceCode","lines","split","result","line","index","sdkRef","column","mineFile","Set","MarkdownMiner","ignoreLink","linkFile","stripSearch","notCode","isHttp","noDash","value","dasher","replace","sourcerer","sourceFileName","startsWith","base","dirname","mineContent","content","summary","localeCompare","undefined","sensitivity","sourceFile","ExampleMiner","constructor","sourcePath","execute","lode","commitHash","remoteOrigin","summaries","nuggets","addCall","relativeFile","addFileCall","nugget","fileCalls","calls","sdkCall","fileCall","find","f","s","relate","relative","processFile","coder","relFile","dirPath"],"mappings":";;;;;;;AA0BA;;AACA;;AACA;;AACA;;;;;;;;;;AAwBO,IAAMA,QAAQ,GAAIC,QAAD,IACtBC,EAAE,CAACC,YAAH,CAAgBF,QAAhB,EAA0B;AAAEG,EAAAA,QAAQ,EAAE;AAAZ,CAA1B,CADK;;;AAGP,IAAMC,UAAU,GAAG,6CAAnB;AACA,IAAMC,SAAS,GAAG,yBAAlB;AACA,IAAMC,WAAW,GAAG,8BAApB;;AAWO,IAAMC,cAAc,GAAIP,QAAD,IAAsBA,QAAQ,CAACQ,IAAT,GAAgBC,MAAhB,GAAyB,CAAtE;;;;AAMA,IAAMC,eAAe,GAAIV,QAAD,IAAsB;AACnD,MAAI,yBAAyBW,IAAzB,CAA8BX,QAA9B,CAAJ,EAA6C,OAAO,KAAP;;AAC7C,MAAMY,GAAG,GAAGC,cAAKC,OAAL,CAAad,QAAb,EAAuBe,iBAAvB,EAAZ;;AAEA,SAAOH,GAAG,IAAII,UAAd;AACD,CALM;;;AAOA,IAAMC,YAAY,GAAG,CAC1B,cAD0B,EAE1B,KAF0B,EAG1B,MAH0B,EAI1B,WAJ0B,EAK1B,OAL0B,EAM1B,KAN0B,EAO1B,QAP0B,EAQ1B,SAR0B,EAS1B,SAT0B,EAU1B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aAAGA,UAAH,cAAGA,UAAH,GAAiB,KAAKA,UAAnC;AACA,QAAMjE,KAAK,GAAGQ,YAAY,CAACgF,OAAD,CAA1B;AACAxF,IAAAA,KAAK,CAACE,OAAN,CAAe+E,CAAD,IAAO,KAAKI,WAAL,CAAiBJ,CAAjB,CAArB;AACA,WAAO,KAAKd,IAAZ;AACD;;AAxFuB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport * as fs from 'fs'\nimport path from 'path'\nimport { execSync } from 'child_process'\nimport { warn } from '@looker/sdk-codegen-utils'\nimport type {\n IFileCall,\n INugget,\n ISDKCall,\n ISummary,\n Nuggets,\n SDKCalls,\n Summaries,\n IExampleMine,\n} from '@looker/sdk-codegen'\n\nexport interface IFileMine {\n mineFile(fileName: string): SDKCalls\n mineCode(code: string): SDKCalls\n ignoreCall(call: ISDKCall): boolean\n}\n\nexport interface IDocMine {\n mineFile(fileName: string): ISummary[]\n mineContent(sourceFile: string, content: string): ISummary[]\n ignoreLink(fileName: string): boolean\n}\n\nexport const readFile = (fileName: string) =>\n fs.readFileSync(fileName, { encoding: 'utf-8' })\n\nconst sdkPattern = /(\\b[a-z0-9_]*sdk)\\.\\s*([a-z0-9_]*)\\s*[(<]/gi\nconst mdPattern = /(\\[(.+?)\\]\\((.+?)\\))/gim\nconst linkPattern = /(.*)\\[\\[link\\]\\]\\((.+?)\\)/gim\n\nexport type IMiners = { [key: string]: IFileMine | IDocMine }\n\n/** file-filtering lambda for `getAllFiles()` and `getCodeFiles()` */\nexport type FileFilter = (fileName: string, pattern?: RegExp) => boolean\n\n/**\n * Filter to include every file that has a non-empty file name\n * @param fileName name of file to check\n */\nexport const filterAllFiles = (fileName: string) => fileName.trim().length > 0\n\n/**\n * Filter for code files\n * @param fileName name of file from which to extract its extension\n */\nexport const filterCodeFiles = (fileName: string) => {\n if (/(^|\\/)node_modules\\//gi.test(fileName)) return false\n const ext = path.extname(fileName).toLocaleLowerCase()\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return ext in fileMiners\n}\n\nexport const IGNORE_PATHS = [\n 'node_modules',\n 'lib',\n 'dist',\n 'bazel-bin',\n 'build',\n 'bin',\n '.build',\n '.direnv',\n '.github',\n '.vscode',\n '.idea',\n '.gradle',\n 'results',\n]\n\nconst skipFolder = (name: string, excludeList: string[] = IGNORE_PATHS) =>\n new RegExp(excludeList.join('|'), 'gi').test(name)\n\n/**\n * Finds all file recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of current files already found\n * @param filter lambda for file inclusion in results. truthy analyzes the file\n * @param ignorePaths paths to ignore\n */\nexport const getAllFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterAllFiles,\n ignorePaths: string[] = []\n) => {\n const files = fs.readdirSync(searchPath)\n\n files.forEach((file) => {\n try {\n if (fs.statSync(searchPath + '/' + file).isDirectory()) {\n if (!skipFolder(file, ignorePaths))\n listOfFiles = getAllFiles(\n searchPath + '/' + file,\n listOfFiles,\n filter,\n ignorePaths\n )\n } else {\n if (filter(file)) {\n const fileName = path.join(searchPath, '/', file)\n listOfFiles.push(fileName)\n }\n }\n } catch (_e: any) {\n // warn(`skipping ${file}: ${e}`)\n }\n })\n\n return listOfFiles\n}\n\n/**\n * Find all source code files recursively\n * @param searchPath starting directory for file search\n * @param listOfFiles list of source code files that can be mined\n * @param filter function to determine whether a file should be analyzed\n * @param ignorePaths paths to ignore\n */\nexport const getCodeFiles = (\n searchPath: string,\n listOfFiles: string[] = [],\n filter: FileFilter = filterCodeFiles,\n ignorePaths: string[] = IGNORE_PATHS\n) => {\n return getAllFiles(searchPath, listOfFiles, filter, ignorePaths)\n}\n\n/** get the trimmed output of the command as a UTF-8 string */\nexport const execRead = (command: string) => {\n return execSync(command, { encoding: 'utf-8' }).trim()\n}\n\n/** get this git repository's current commit hash */\nexport const getCommitHash = () => execRead('git rev-parse HEAD')\n\n/** get the remote origin url for this repository */\nexport const getRemoteOrigin = () => {\n return execRead('git remote get-url origin')\n}\n\n/**\n * Convert this github repository's git address to an HTTP url\n */\nexport const getRemoteHttpOrigin = () => {\n const origin = getRemoteOrigin()\n const gitExtractor = /git@github\\.com:(.*)\\.git/gi\n let match = gitExtractor.exec(origin)\n if (!match) {\n // git origin on CI: https://github.com/looker-open-source/sdk-codegen\n const httpExtractor = /(https:\\/\\/github.com.*)(|.git)/\n match = httpExtractor.exec(origin)\n if (!match) {\n return ''\n }\n return match[1]\n }\n return `https://github.com/${match[1]}`\n}\n\n/** Permalink paths should not have the `.git` ending for a repo */\nexport const getPermalinkRoot = () => {\n let root = getRemoteHttpOrigin()\n if (root.endsWith('.git')) root = root.substr(0, root.length - 4)\n return root\n}\n\nexport class CodeMiner implements IFileMine {\n static ignoreOps = new Set<string>(['ok', 'init31', 'init40'])\n ignoreCall(call: ISDKCall): boolean {\n if (!/sdk/i.test(call.sdk)) return true\n return CodeMiner.ignoreOps.has(call.operationId)\n }\n\n mineCode(sourceCode: string): SDKCalls {\n const lines = sourceCode.split('\\n')\n const result: SDKCalls = []\n lines.forEach((line, index) => {\n let match = sdkPattern.exec(line)\n while (match !== null) {\n // TODO need to ignore source code comments?\n if (match && match.length > 2) {\n const sdkRef = match[1].trim()\n const call: ISDKCall = {\n sdk: sdkRef,\n operationId: match[2].trim(),\n line: index + 1,\n column: match.index,\n }\n if (!this.ignoreCall(call)) {\n result.push(call)\n }\n }\n match = sdkPattern.exec(line)\n }\n })\n return result\n }\n\n mineFile(fileName: string): SDKCalls {\n return this.mineCode(readFile(fileName))\n }\n}\n\n/**\n * Processes markdown files and extracts links to source code to use as summaries\n */\nexport class MarkdownMiner implements IDocMine {\n // TODO ensure summaries don't include markdown files\n ignoreLink(linkFile: string): boolean {\n linkFile = this.stripSearch(linkFile)\n const ext = path.extname(linkFile).toLocaleLowerCase()\n const notCode = ext === '.md' || !filterCodeFiles(linkFile)\n const isHttp = /^(http|https):/gi.test(linkFile)\n return notCode || isHttp\n }\n\n /**\n * Remove leading - from a string\n * @param value string to process\n */\n noDash(value: string) {\n value = value.trim()\n const dasher = /^\\s*-\\s*(.*)/g\n if (dasher.test(value)) {\n value = value.replace(dasher, '$1')\n }\n return value.trim()\n }\n\n stripSearch(fileName: string) {\n fileName = fileName.trim()\n const match = /(.*)#.*/gi.exec(fileName)\n if (match) fileName = match[1]\n return fileName\n }\n\n /**\n * Fully qualify the path for `linkFile`\n * @param sourceFileName\n * @param linkFile\n */\n sourcerer(sourceFileName: string, linkFile: string) {\n linkFile = this.stripSearch(linkFile)\n if (linkFile.startsWith('/')) return linkFile.substr(1)\n const base = path.dirname(sourceFileName)\n return path.join(base, '/', linkFile)\n }\n\n /**\n * Get all links from content\n * @param fileName fully qualified source file name\n * @param content markdown to parse\n */\n mineContent(fileName: string, content: string): ISummary[] {\n const result: ISummary[] = []\n let match = mdPattern.exec(content)\n let linkFile: string\n while (match !== null) {\n const summary = this.noDash(match[2])\n linkFile = this.stripSearch(match[3])\n if (!this.ignoreLink(linkFile)) {\n if (\n summary.localeCompare('[link]', undefined, {\n sensitivity: 'base',\n }) !== 0\n ) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n }\n match = mdPattern.exec(content)\n }\n\n match = linkPattern.exec(content)\n while (match != null) {\n const summary = this.noDash(match[1])\n linkFile = this.stripSearch(match[2])\n if (!this.ignoreLink(linkFile)) {\n linkFile = this.sourcerer(fileName, linkFile)\n result.push({ summary, sourceFile: linkFile })\n }\n match = linkPattern.exec(content)\n }\n return result\n }\n\n mineFile(fileName: string): ISummary[] {\n return this.mineContent(fileName, readFile(fileName))\n }\n}\n\nconst fileMiners: IMiners = {\n '.cs': new CodeMiner(),\n '.kt': new CodeMiner(),\n '.py': new CodeMiner(),\n '.swift': new CodeMiner(),\n '.ts': new CodeMiner(),\n '.tsx': new CodeMiner(),\n '.rb': new CodeMiner(),\n '.md': new MarkdownMiner(),\n '.dart': new CodeMiner(),\n '.go': new CodeMiner(),\n '.java': new CodeMiner(),\n // '.rst': new MarkdownMiner(), // TODO .rst miner? Probably not needed\n}\n\nexport class ExampleMiner {\n summaries: Summaries = {}\n nuggets: Nuggets = {}\n commitHash: string = getCommitHash()\n remoteOrigin: string = getPermalinkRoot()\n\n constructor(public readonly sourcePath: string) {\n this.execute(sourcePath)\n }\n\n get lode(): IExampleMine {\n return {\n commitHash: this.commitHash,\n remoteOrigin: this.remoteOrigin,\n summaries: this.summaries,\n nuggets: this.nuggets,\n }\n }\n\n addCall(ext: string, relativeFile: string, call: ISDKCall | ISummary) {\n function addFileCall(nugget: INugget) {\n // Extension is key for language\n let fileCalls = nugget.calls[ext]\n if (!fileCalls) {\n fileCalls = []\n }\n const sdkCall = call as ISDKCall\n const fileCall: IFileCall = {\n sourceFile: relativeFile,\n column: sdkCall.column,\n line: sdkCall.line,\n }\n if (\n !fileCalls.find(\n (f) =>\n f.line === fileCall.line &&\n f.column === fileCall.column &&\n f.sourceFile === fileCall.sourceFile\n )\n )\n fileCalls.push(fileCall)\n nugget.calls[ext] = fileCalls\n }\n\n if ('summary' in call) {\n const s = call as ISummary\n s.sourceFile = ExampleMiner.relate(this.sourcePath, s.sourceFile)\n this.summaries[s.sourceFile] = s\n } else {\n let nugget: INugget = this.nuggets[call.operationId]\n if (!nugget) {\n nugget = { operationId: call.operationId, calls: {} }\n }\n addFileCall(nugget)\n this.nuggets[nugget.operationId] = nugget\n }\n }\n\n /**\n * Derive relative path, retaining last directory\n * @param sourcePath original file search path\n * @param fileName fully qualified name of found file\n *\n * @example `Miner.relate('/a/b/c/', '/a/b/c/d.txt')` returns 'd.txt'\n */\n public static relate(sourcePath: string, fileName: string) {\n return path.relative(sourcePath, fileName)\n }\n\n processFile(fileName: string) {\n const ext = path.extname(fileName)\n if (ext in fileMiners) {\n const coder = fileMiners[ext]\n const calls = coder.mineFile(fileName)\n calls.forEach((call: ISDKCall | ISummary) => {\n const relFile = ExampleMiner.relate(this.sourcePath, fileName)\n this.addCall(ext, relFile, call)\n })\n } else {\n warn(`${fileName} cannot be mined`)\n }\n }\n\n execute(sourcePath: string | null = null) {\n const dirPath = sourcePath ?? this.sourcePath\n const files = getCodeFiles(dirPath)\n files.forEach((f) => this.processFile(f))\n return this.lode\n }\n}\n"],"file":"exampleMiner.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@looker/sdk-codegen-scripts",
3
- "version": "21.3.0",
3
+ "version": "21.3.4",
4
4
  "description": "Looker SDK Codegen scripts",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -27,11 +27,11 @@
27
27
  "watch:cjs": "yarn lerna exec --scope @looker/sdk-codegen-scripts --stream 'BABEL_ENV=build_cjs babel src --root-mode upward --out-dir lib --source-maps --extensions .ts,.tsx --no-comments --watch'"
28
28
  },
29
29
  "dependencies": {
30
- "@looker/sdk": "^22.2.0",
31
- "@looker/sdk-codegen": "^21.5.0",
30
+ "@looker/sdk": "^22.6.0",
31
+ "@looker/sdk-codegen": "^21.6.0",
32
32
  "@looker/sdk-codegen-utils": "^21.0.11",
33
- "@looker/sdk-node": "^22.2.0",
34
- "@looker/sdk-rtl": "^21.3.2",
33
+ "@looker/sdk-node": "^22.6.0",
34
+ "@looker/sdk-rtl": "^21.3.4",
35
35
  "config": "^3.3.1",
36
36
  "cross-env": "^7.0.2"
37
37
  },
@@ -48,5 +48,5 @@
48
48
  "prettier": "^2.4.1",
49
49
  "swagger2openapi": "^7.0.3"
50
50
  },
51
- "gitHead": "8db44f3017f7303ad84f678a9e4999c216dfcfd9"
51
+ "gitHead": "918004bc063b73364fa2a714b14157e990fc331e"
52
52
  }