From 0b1a2560758eaebe44388f23844edd0458f73277 Mon Sep 17 00:00:00 2001 From: Ed Date: Thu, 20 Jul 2023 19:26:20 +0100 Subject: [PATCH 1/5] case stuff --- Source/buildimplementationjs.go | 3 +++ Source/buildimplementationts.go | 28 ++++++++++++++++------------ copy.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100755 copy.sh diff --git a/Source/buildimplementationjs.go b/Source/buildimplementationjs.go index ed980d85..06aa9026 100644 --- a/Source/buildimplementationjs.go +++ b/Source/buildimplementationjs.go @@ -477,11 +477,14 @@ func buildJSInjectionClass(component ComponentDefinition, subComponent Component } if readOnly { cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s);", getter.PropertyGet, class.ClassName, getter.MethodName) + cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s);", camelize(getter.PropertyGet), class.ClassName, getter.MethodName) } else { cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s, Cv8%s::v8%s);", setter.PropertySet, class.ClassName, getter.MethodName, class.ClassName, setter.MethodName) + cppw.Writeln(" Cv8toolsUtils::Set_proto_accessor(localClassTemplate, \"%s\", Cv8%s::v8%s, Cv8%s::v8%s);", camelize(setter.PropertySet), class.ClassName, getter.MethodName, class.ClassName, setter.MethodName) } } else { cppw.Writeln(" Cv8toolsUtils::Set_proto_method(localClassTemplate, \"%s\", Cv8%s::v8%s);", method.MethodName, class.ClassName, method.MethodName) + cppw.Writeln(" Cv8toolsUtils::Set_proto_method(localClassTemplate, \"%s\", Cv8%s::v8%s);", camelize(method.MethodName), class.ClassName, method.MethodName) } } cppw.Writeln("") diff --git a/Source/buildimplementationts.go b/Source/buildimplementationts.go index 4dfb7810..239076e0 100644 --- a/Source/buildimplementationts.go +++ b/Source/buildimplementationts.go @@ -57,7 +57,7 @@ func BuildImplementationTS( log.Printf("Creating TypeScript Implementation") options := TypeScriptOptions{ - Camelize: false, + Camelize: true, JsArrays: false, LineLength: 80, } @@ -106,11 +106,11 @@ func writeTypescriptEnum( writer LanguageWriter, options TypeScriptOptions, ) error { - writer.Writeln("const enum %s {", getId(enum.Name, options)) + writer.Writeln("const enum %s {", getTypeId(enum.Name, options)) writer.Indentation++ for _, option := range enum.Options { writeCommentEnumOption(option, writer, options) - identifier := getId(option.Name, options) + identifier := getTypeId(option.Name, options) value := option.Value writer.Writeln("%s = %d,", identifier, value) } @@ -140,7 +140,7 @@ func writeTypescriptInterface( options TypeScriptOptions, ) error { writeCommentClass(class, writer, options) - identifier := getId(class.ClassName, options) + identifier := getTypeId(class.ClassName, options) extends := "" if class.ParentClass != "" { extends = "extends " + class.ParentClass + " " @@ -178,18 +178,18 @@ func writeTypescriptMethod( writer.Writeln("") writeCommentMethod(class, method, writer, options) writer.BeginLine() - writer.Printf("%s: (", getId(method.MethodName, options)) + writer.Printf("%s: (", getName(method.MethodName, options)) for i, param := range inParams { if param.ParamOptional == "true" { writer.Printf( "%s?: %s", - getId(param.ParamName, options), + getName(param.ParamName, options), getType(param, options), ) } else { writer.Printf( "%s: %s", - getId(param.ParamName, options), + getName(param.ParamName, options), getType(param, options), ) } @@ -204,7 +204,7 @@ func writeTypescriptMethod( for i, param := range outParams { writer.Printf( "%s: %s", - getId(param.ParamName, options), + getName(param.ParamName, options), getType(param, options), ) if i+1 < len(outParams) { @@ -258,7 +258,7 @@ func writeTypescriptProperty( writer.Writeln( "%s%s: %s;", readOnly, - getId(getter.PropertyGet, options), + getName(getter.PropertyGet, options), getType(returnParams[0], options), ) return nil @@ -287,7 +287,11 @@ func filterOptional(params []ComponentDefinitionParam) []ComponentDefinitionPara return result } -func getId(identifier string, options TypeScriptOptions) string { +func getTypeId(identifier string, options TypeScriptOptions) string { + return identifier +} + +func getName(identifier string, options TypeScriptOptions) string { if options.Camelize { return camelize(identifier) } @@ -407,7 +411,7 @@ func writeCommentInParams( ) { for _, param := range params { prefix := " * @param {" + getType(param, options) + "} " + - getId(param.ParamName, options) + " " + getName(param.ParamName, options) + " " lines := getCommentLines(prefix, param.ParamDescription, writer, options) if len(lines) > 0 { writer.Writeln(prefix + lines[0]) @@ -427,7 +431,7 @@ func writeCommentOutParams( ) { for _, param := range params { prefix := " * @returns {" + getType(param, options) + "} " - prefix2 := prefix + getId(param.ParamName, options) + " " + prefix2 := prefix + getName(param.ParamName, options) + " " lines := getCommentLines(prefix2, param.ParamDescription, writer, options) if len(lines) > 0 { writer.Writeln(prefix2 + lines[0]) diff --git a/copy.sh b/copy.sh new file mode 100755 index 00000000..bd289cb0 --- /dev/null +++ b/copy.sh @@ -0,0 +1,32 @@ + +#!/bin/bash + +# Source and destination directories +source_dir="." +dest_dir="../FusionAutomationService/SandboxAddIn/ACT" + +# Source file name +source_file="act.darwin" + +# Destination file name (with modified name) +dest_file="act" + +# Copy the file to the destination directory +cp "${source_dir}/${source_file}" "${dest_dir}/${dest_file}" + +# Modify the file permissions to make it executable +chmod +x "${dest_dir}/${dest_file}" + +# Source file name +source_file="act.win64.exe" + +# Destination file name (with modified name) +dest_file="act.exe" + +# Copy the file to the destination directory +cp "${source_dir}/${source_file}" "${dest_dir}/${dest_file}" + +# Modify the file permissions to make it executable +chmod +x "${dest_dir}/${dest_file}" + +echo "File copied and modified successfully." From 2a4364ca92e293f254b6e6901b3bc3243af5b6cc Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 21 Jul 2023 12:04:31 +0100 Subject: [PATCH 2/5] better methods --- Source/buildimplementationts.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/buildimplementationts.go b/Source/buildimplementationts.go index 239076e0..5762fb9b 100644 --- a/Source/buildimplementationts.go +++ b/Source/buildimplementationts.go @@ -178,7 +178,7 @@ func writeTypescriptMethod( writer.Writeln("") writeCommentMethod(class, method, writer, options) writer.BeginLine() - writer.Printf("%s: (", getName(method.MethodName, options)) + writer.Printf("%s(", getName(method.MethodName, options)) for i, param := range inParams { if param.ParamOptional == "true" { writer.Printf( @@ -197,7 +197,7 @@ func writeTypescriptMethod( writer.Printf(", ") } } - writer.Printf(") => ") + writer.Printf("): ") if len(outParams) > 0 { writer.Printf("[") From 2e2fc3754638b35e3aa05926f152f1e42e7a9e28 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 21 Jul 2023 12:12:35 +0100 Subject: [PATCH 3/5] remove copy script --- copy.sh | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100755 copy.sh diff --git a/copy.sh b/copy.sh deleted file mode 100755 index bd289cb0..00000000 --- a/copy.sh +++ /dev/null @@ -1,32 +0,0 @@ - -#!/bin/bash - -# Source and destination directories -source_dir="." -dest_dir="../FusionAutomationService/SandboxAddIn/ACT" - -# Source file name -source_file="act.darwin" - -# Destination file name (with modified name) -dest_file="act" - -# Copy the file to the destination directory -cp "${source_dir}/${source_file}" "${dest_dir}/${dest_file}" - -# Modify the file permissions to make it executable -chmod +x "${dest_dir}/${dest_file}" - -# Source file name -source_file="act.win64.exe" - -# Destination file name (with modified name) -dest_file="act.exe" - -# Copy the file to the destination directory -cp "${source_dir}/${source_file}" "${dest_dir}/${dest_file}" - -# Modify the file permissions to make it executable -chmod +x "${dest_dir}/${dest_file}" - -echo "File copied and modified successfully." From cfcf005e64b773b4892a0c9ab8331e1a1e2a12c2 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 21 Jul 2023 12:14:14 +0100 Subject: [PATCH 4/5] remove copy script --- copy.sh | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100755 copy.sh diff --git a/copy.sh b/copy.sh deleted file mode 100755 index bd289cb0..00000000 --- a/copy.sh +++ /dev/null @@ -1,32 +0,0 @@ - -#!/bin/bash - -# Source and destination directories -source_dir="." -dest_dir="../FusionAutomationService/SandboxAddIn/ACT" - -# Source file name -source_file="act.darwin" - -# Destination file name (with modified name) -dest_file="act" - -# Copy the file to the destination directory -cp "${source_dir}/${source_file}" "${dest_dir}/${dest_file}" - -# Modify the file permissions to make it executable -chmod +x "${dest_dir}/${dest_file}" - -# Source file name -source_file="act.win64.exe" - -# Destination file name (with modified name) -dest_file="act.exe" - -# Copy the file to the destination directory -cp "${source_dir}/${source_file}" "${dest_dir}/${dest_file}" - -# Modify the file permissions to make it executable -chmod +x "${dest_dir}/${dest_file}" - -echo "File copied and modified successfully." From b6dbec3c992a0c8f99cad7588706f9c28bee068c Mon Sep 17 00:00:00 2001 From: Ed Date: Sat, 5 Aug 2023 11:57:21 +0100 Subject: [PATCH 5/5] fix camel case --- Source/buildimplementationts.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Source/buildimplementationts.go b/Source/buildimplementationts.go index 5762fb9b..dd18a2c0 100644 --- a/Source/buildimplementationts.go +++ b/Source/buildimplementationts.go @@ -37,8 +37,9 @@ import ( "errors" "log" "path" + "regexp" "strings" - "unicode" + "unicode/utf8" ) type TypeScriptOptions struct { @@ -331,13 +332,24 @@ func getTypeString( return paramType } -func camelize(identifier string) string { - if len(identifier) == 0 { - return identifier +func camelize(str string) string { + r, _ := regexp.Compile("^([A-Z]+)([A-Z])(.*)") + result := r.FindStringSubmatch(str) + + if len(result) > 0 { + if len(result) > 1 { + if len(result) == 4 && result[3] == "" { + str = strings.ToLower(str) + } else { + str = strings.ToLower(result[1]) + strings.Join(result[2:], "") + } + } + } else { + r, _ := utf8.DecodeRuneInString(str) + str = strings.ToLower(string(r)) + str[len(string(r)):] } - result := []rune(identifier) - result[0] = unicode.ToLower(result[0]) - return string(result) + + return str } func writeCommentEnumOption(