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.
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.
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")
27 xf, err := os.ReadDir(*inputDir)
29 fmt.Printf("Could not get lotties from %s: %s\n", *inputDir, err)
32 for _, entry := range xf {
33 inputJSON := entry.Name()
34 if !strings.HasSuffix(inputJSON, ".json") {
37 newName := strings.TrimPrefix(inputJSON, "lottiefiles.com - ")
38 newName = strings.TrimSuffix(newName, ".json")
39 newName = strings.ReplaceAll(newName, " ", "_")
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)
47 outFile, err := os.Create(filepath.Join(subDir, "data.json"))
49 fmt.Printf("Could not make output file in %s: %s\n", subDir, err)
53 inputBytes, err := os.ReadFile(filepath.Join(*inputDir, inputJSON))
55 fmt.Printf("Could not read input file %s: %s\n", inputJSON, err)
58 if _, err := outFile.Write(inputBytes); err != nil {
59 fmt.Printf("Could not copy bytes to %s: %s\n", subDir, err)