func buildFn()

in cmd/nodejs/firebasebundle/main.go [61:123]


func buildFn(ctx *gcp.Context) error {
	bundlePath := filepath.Join(ctx.ApplicationRoot(), ".apphosting", "bundle.yaml")
	bundleYaml, err := readBundleYaml(ctx, bundlePath)
	if err != nil {
		return err
	}

	outputBundleDir, ok := os.LookupEnv(firebaseOutputBundleDir)

	if !ok {
		return gcp.InternalErrorf("looking up output bundle env %s", firebaseOutputBundleDir)
	}

	workspacePublicDir := filepath.Join(ctx.ApplicationRoot(), defaultPublicDir)
	outputPublicDir := filepath.Join(outputBundleDir, defaultPublicDir)
	appDir := util.ApplicationDirectory(ctx)

	apphostingYamlPathTests, ok := os.LookupEnv(apphostingYamlPathTestsEnv)

	var apphostingYaml *apphostingYaml
	if ok {
		apphostingYaml, err = readAppHostingYaml(ctx, apphostingYamlPathTests)
	} else {
		apphostingYaml, err = readAppHostingYaml(ctx, apphostingPreprocessedPathForPack)
	}

	if err != nil {
		return err
	}
	if bundleYaml == nil {
		ctx.Logf("bundle.yaml does not exist, assuming default configs")

		err = generateDefaultBundleYaml(bundlePath, ctx)
		if err != nil {
			return err
		}
	}

	ctx.Logf("Copying static assets.")
	err = fileutil.CopyFile(filepath.Join(outputBundleDir, "bundle.yaml"), bundlePath)
	if err != nil {
		return gcp.InternalErrorf("copying output bundle dir %s: %w", outputBundleDir, err)
	}
	err = copyPublicDirToOutputBundleDir(outputPublicDir, workspacePublicDir, ctx)
	if err != nil {
		return err
	}
	nodeDeps, err := nodejs.ReadNodeDependencies(ctx, appDir)
	// We don't want to fail builds for failing to collect optional metadata. Ignore error.
	if err == nil {
		setMetadata(nodeDeps.PackageJSON)
	}
	err = deleteFilesNotIncluded(apphostingYaml, bundleYaml, ctx.ApplicationRoot())
	if err != nil {
		return err
	}

	err = SetRunCommand(apphostingYaml, bundleYaml, ctx)
	if err != nil {
		return err
	}
	return nil
}