github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/nodejs/gen_fileinfo.go (about) 1 // Copyright 2016-2022, Pulumi Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // When GeneratePackage generates TypeScript files, there is a need to track 16 // internally which definitions are emitted into these files to 17 // re-export them efficiently. This file defines helper structs for 18 // this information. The tracking is approximate. 19 package nodejs 20 21 // Packages information about a TypeScript file generated by 22 // GeneratePackage. 23 type fileInfo struct { 24 fileType fileType 25 pathToNodeModule string // path understood by require() in Node 26 resourceFileInfo resourceFileInfo // required if fileType == resourceFileType 27 functionFileInfo functionFileInfo // required if fileType == functionFileType 28 } 29 30 type fileType int 31 32 const ( 33 resourceFileType fileType = iota // files that define Pulumi Resources 34 functionFileType // files that define Pulumi functions 35 otherFileType // everything else 36 ) 37 38 type resourceFileInfo struct { 39 resourceClassName string 40 resourceArgsInterfaceName string 41 stateInterfaceName string // may be empty 42 methodsNamespaceName string // may be empty 43 } 44 45 // TypeScript interface names exported from the file. 46 func (ri resourceFileInfo) interfaces() []string { 47 return nonEmptyStrings([]string{ 48 ri.resourceArgsInterfaceName, 49 ri.stateInterfaceName, 50 }) 51 } 52 53 type functionFileInfo struct { 54 functionName string 55 functionArgsInterfaceName string // may be empty 56 functionResultInterfaceName string // may be empty 57 functionOutputVersionName string // may be empty 58 functionOutputVersionArgsInterfaceName string // may be empty 59 } 60 61 // TypeScript function names exported from the file. 62 func (fi functionFileInfo) functions() []string { 63 return nonEmptyStrings([]string{ 64 fi.functionName, 65 fi.functionOutputVersionName, 66 }) 67 } 68 69 // TypeScript interface names exported from the file. 70 func (fi functionFileInfo) interfaces() []string { 71 return nonEmptyStrings([]string{ 72 fi.functionArgsInterfaceName, 73 fi.functionResultInterfaceName, 74 fi.functionOutputVersionArgsInterfaceName, 75 }) 76 }