示例#1
0
// GetModulePath returns the global path for the given module.
func (p Pather) GetModulePath(module typegraph.TGModule) string {
	// TODO(jschorr): We should generalize non-SRG support.
	if strings.HasSuffix(module.Path(), ".webidl") {
		return "$global"
	}

	return "$g." + p.GetRelativeModulePath(module)
}
示例#2
0
// GetRelativeModulePath returns the relative path for the given module.
func (p Pather) GetRelativeModulePath(module typegraph.TGModule) string {
	// We create the exported path based on the location of this module's source file relative
	// to the entrypoint file.
	basePath := filepath.Dir(p.graph.RootSourceFilePath)
	rel, err := filepath.Rel(basePath, module.Path())
	if err != nil {
		rel = module.Path()
	}

	rel = strings.Replace(rel, "../", "_", -1)
	rel = strings.Replace(rel, "/", ".", -1)

	if rel[0] == '.' {
		rel = rel[1:len(rel)]
	}

	if strings.HasSuffix(rel, ".seru") {
		rel = rel[0 : len(rel)-5]
	}

	return rel
}