in codegen/module.go [1006:1084]
func readPackageInfo(
packageRoot string,
baseDirectory string,
targetGenDir string,
className string,
instanceDirectory string,
config *ClassConfig,
options Options,
) (*PackageInfo, error) {
qualifiedClassName := strings.Title(CamelCase(className))
qualifiedInstanceName := strings.Title(CamelCase(config.Name))
defaultAlias := packageName(qualifiedInstanceName + qualifiedClassName)
relativeGeneratedPath, err := filepath.Rel(baseDirectory, targetGenDir)
if err != nil {
return nil, errors.Wrapf(
err,
"Error computing generated import string for %q",
targetGenDir,
)
}
// The module system presently has special reservations for the "custom"
// type. We should really extrapolate from the class type info what the
// default export type is for this instance
var isExportGenerated bool
if config.Type == "custom" {
if config.IsExportGenerated == nil {
isExportGenerated = false
} else {
isExportGenerated = *config.IsExportGenerated
}
} else if config.IsExportGenerated == nil {
isExportGenerated = true
} else {
isExportGenerated = *config.IsExportGenerated
}
var customInitialisation bool
if config.CustomInitialisation == nil || options.EnableCustomInitialisation == false {
customInitialisation = false
} else {
customInitialisation = *config.CustomInitialisation
}
return &PackageInfo{
// The package name is assumed to be the lower case of the instance
// Name plus the titular class name, such as fooClient
PackageName: defaultAlias,
// The prefixes "Static" and "Generated" are used to ensure global
// uniqueness of the provided package aliases. Note that the default
// package is "PackageName".
PackageAlias: defaultAlias + "static",
PackageRoot: packageRoot,
GeneratedPackageAlias: defaultAlias + "generated",
GeneratedModulePackageAlias: defaultAlias + "module",
PackagePath: path.Join(
packageRoot,
instanceDirectory,
),
GeneratedPackagePath: filepath.Join(
packageRoot,
relativeGeneratedPath,
instanceDirectory,
),
GeneratedModulePackagePath: filepath.Join(
packageRoot,
relativeGeneratedPath,
instanceDirectory,
"module",
),
ExportName: "New" + qualifiedClassName,
InitializerName: "Initialize" + qualifiedClassName,
QualifiedInstanceName: qualifiedInstanceName,
ExportType: qualifiedClassName,
IsExportGenerated: isExportGenerated,
CustomInitialisation: customInitialisation,
}, nil
}