OverrideAppHostingBuildScript overrides the "apphosting:build" script in package.json with the build command from the preprocessed apphosting.yaml.
(ctx *gcp.Context, preprocessedApphostingPath string)
| 554 | // OverrideAppHostingBuildScript overrides the "apphosting:build" script in package.json |
| 555 | // with the build command from the preprocessed apphosting.yaml. |
| 556 | func OverrideAppHostingBuildScript(ctx *gcp.Context, preprocessedApphostingPath string) (*PackageJSON, error) { |
| 557 | pjs, err := ReadPackageJSONIfExists(ctx.ApplicationRoot()) |
| 558 | if err != nil { |
| 559 | return nil, err |
| 560 | } |
| 561 | apphostingSchema, err := apphostingschema.ReadAndValidateFromFile(preprocessedApphostingPath) |
| 562 | if err != nil { |
| 563 | return nil, err |
| 564 | } |
| 565 | if apphostingSchema.Scripts.BuildCommand == "" { |
| 566 | return pjs, nil |
| 567 | } |
| 568 | if pjs == nil { |
| 569 | pjs = &PackageJSON{} |
| 570 | } |
| 571 | |
| 572 | if pjs.Scripts == nil { |
| 573 | pjs.Scripts = make(map[string]string) |
| 574 | } |
| 575 | |
| 576 | pjs.Scripts[ScriptApphostingBuild] = apphostingSchema.Scripts.BuildCommand |
| 577 | marshalledJSON, err := json.Marshal(pjs) |
| 578 | if err != nil { |
| 579 | return nil, gcp.InternalErrorf("marshaling package.json: %w", err) |
| 580 | } |
| 581 | |
| 582 | err = os.WriteFile(filepath.Join(ctx.ApplicationRoot(), "package.json"), marshalledJSON, 0644) |
| 583 | if err != nil { |
| 584 | return nil, gcp.InternalErrorf("writing package.json: %w", err) |
| 585 | } |
| 586 | |
| 587 | return pjs, nil |
| 588 | } |
| 589 | |
| 590 | // IsPackageManagerConfigured checks if the environment is configured to use the specified package manager. |
| 591 | func IsPackageManagerConfigured(pm string) bool { |