|
| 1 | +// Copyright 2026 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package nodejs |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "fmt" |
| 20 | + "os" |
| 21 | + |
| 22 | + "github.com/googleapis/librarian/internal/command" |
| 23 | +) |
| 24 | + |
| 25 | +// TODO(https://github.com/googleapis/librarian/issues/4848): read tool |
| 26 | +// versions from google-cloud-node/librarian.yaml instead of hardcoding them. |
| 27 | +const ( |
| 28 | + // TODO(https://github.com/googleapis/librarian/issues/4904): use google-cloud-node. |
| 29 | + gapicGeneratorTypescriptRepo = "https://github.com/googleapis/google-cloud-node-core.git" |
| 30 | + gapicNodeProcessingPkg = "gapic-node-processing@0.1.7" |
| 31 | + gapicToolsPkg = "gapic-tools@1.0.5" |
| 32 | + synthtoolPkg = "gcp-synthtool@git+https://github.com/googleapis/synthtool@5aa438a342707842d11fbbb302c6277fbf9e4655" |
| 33 | +) |
| 34 | + |
| 35 | +// Install installs Node.js tool dependencies. |
| 36 | +func Install(ctx context.Context) error { |
| 37 | + if err := installGapicGeneratorTypescript(ctx); err != nil { |
| 38 | + return fmt.Errorf("installing gapic-generator-typescript: %w", err) |
| 39 | + } |
| 40 | + if err := command.Run(ctx, "npm", "install", "-g", gapicNodeProcessingPkg, gapicToolsPkg); err != nil { |
| 41 | + return fmt.Errorf("installing npm tools: %w", err) |
| 42 | + } |
| 43 | + if err := command.Run(ctx, "pip", "install", synthtoolPkg); err != nil { |
| 44 | + return fmt.Errorf("installing synthtool: %w", err) |
| 45 | + } |
| 46 | + return nil |
| 47 | +} |
| 48 | + |
| 49 | +func installGapicGeneratorTypescript(ctx context.Context) error { |
| 50 | + dir, err := os.MkdirTemp("", "gapic-generator-typescript-*") |
| 51 | + if err != nil { |
| 52 | + return err |
| 53 | + } |
| 54 | + defer os.RemoveAll(dir) |
| 55 | + if err := command.Run(ctx, "git", "clone", "--depth", "1", gapicGeneratorTypescriptRepo, dir); err != nil { |
| 56 | + return err |
| 57 | + } |
| 58 | + genDir := dir + "/generator/gapic-generator-typescript" |
| 59 | + if err := command.RunInDir(ctx, genDir, "npm", "install"); err != nil { |
| 60 | + return err |
| 61 | + } |
| 62 | + if err := command.RunInDir(ctx, genDir, "npm", "run", "compile"); err != nil { |
| 63 | + return err |
| 64 | + } |
| 65 | + return command.RunInDir(ctx, genDir, "npm", "link") |
| 66 | +} |
0 commit comments