Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / infra / bots / task_drivers / perf_puppeteer_skottie_frames / make_lotties_with_assets / make_lotties_with_assets.go
1 // Copyright 2021 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This executable is handy for transforming the structure of lottie-samples into
6 // the one used by perf_puppeteer_skottie_frames.go. It is stored to the
7 // skia/internal/lotties_with_assets CIPD package. If any lotties need assets, those should
8 // be copied in to the subfolders and appropriately named.
9 // A new version can be updated with
10 // cipd create -name skia/internal/lotties_with_assets -in ./lotties/ -tag version:NN
11 // where NN is the version number.
12 package main
13
14 import (
15         "flag"
16         "fmt"
17         "os"
18         "path/filepath"
19         "strings"
20 )
21
22 func main() {
23         inputDir := flag.String("input", "", "The input directory of lottie files")
24         outputDir := flag.String("output", "", "The output directory which will have the correct structure")
25         flag.Parse()
26
27         xf, err := os.ReadDir(*inputDir)
28         if err != nil {
29                 fmt.Printf("Could not get lotties from %s: %s\n", *inputDir, err)
30                 os.Exit(1)
31         }
32         for _, entry := range xf {
33                 inputJSON := entry.Name()
34                 if !strings.HasSuffix(inputJSON, ".json") {
35                         continue
36                 }
37                 newName := strings.TrimPrefix(inputJSON, "lottiefiles.com - ")
38                 newName = strings.TrimSuffix(newName, ".json")
39                 newName = strings.ReplaceAll(newName, " ", "_")
40
41                 subDir := filepath.Join(*outputDir, newName)
42                 if err := os.MkdirAll(subDir, 0755); err != nil {
43                         fmt.Printf("Could not make %s: %s\n", subDir, err)
44                         os.Exit(1)
45                 }
46
47                 outFile, err := os.Create(filepath.Join(subDir, "data.json"))
48                 if err != nil {
49                         fmt.Printf("Could not make output file in %s: %s\n", subDir, err)
50                         os.Exit(1)
51                 }
52
53                 inputBytes, err := os.ReadFile(filepath.Join(*inputDir, inputJSON))
54                 if err != nil {
55                         fmt.Printf("Could not read input file %s: %s\n", inputJSON, err)
56                         os.Exit(1)
57                 }
58                 if _, err := outFile.Write(inputBytes); err != nil {
59                         fmt.Printf("Could not copy bytes to %s: %s\n", subDir, err)
60                         os.Exit(1)
61                 }
62         }
63 }