nodejs

package
v0.0.0-...-74e17ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2025 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package nodejs generates the Dockerfile for Node.js projects.

Index

Constants

View Source
const (
	// ConfigCacheDependencies is the key for the configuration of
	// whether to cache dependencies.
	// It is true by default.
	ConfigCacheDependencies = "cache_dependencies"

	// ConfigNodeFramework is the key for the configuration for specifying
	// the Node.js framework explicitly.
	ConfigNodeFramework = "node.framework"

	// ConfigAppDir indicates the relative path of the app to deploy.
	//
	// For example, if the app to deploy is located at `apps/api`,
	// the value of this configuration should be `apps/api`.
	ConfigAppDir = "app_dir"
)

Variables

This section is empty.

Functions

func DetermineAppFramework

func DetermineAppFramework(ctx *nodePlanContext) types.NodeProjectFramework

DetermineAppFramework determines the framework of the Node.js app.

func DetermineNeedPlaywright

func DetermineNeedPlaywright(ctx *nodePlanContext) bool

DetermineNeedPlaywright determines whether the app needs Playwright.

func DetermineNeedPuppeteer

func DetermineNeedPuppeteer(ctx *nodePlanContext) bool

DetermineNeedPuppeteer determines whether the app needs Puppeteer.

func DeterminePackageManager

func DeterminePackageManager(ctx *nodePlanContext) types.NodePackageManager

DeterminePackageManager determines the package manager of the Node.js project.

func FindAppDirByGlob

func FindAppDirByGlob(fs afero.Fs, pattern string) (match string, fnerr error)

FindAppDirByGlob finds the application directory (with package.json) by the given glob pattern.

func GenerateDockerfile

func GenerateDockerfile(meta types.PlanMeta) (string, error)

GenerateDockerfile generates the Dockerfile for Node.js projects.

func GetBuildCmd

func GetBuildCmd(ctx *nodePlanContext) string

GetBuildCmd gets the build command of the Node.js app.

func GetBuildScript

func GetBuildScript(ctx *nodePlanContext) string

GetBuildScript gets the build command in package.json's `scripts` of the Node.js app.

func GetEntry

func GetEntry(ctx *nodePlanContext) string

GetEntry gets the entry file of the Node.js app.

func GetInstallCmd

func GetInstallCmd(ctx *nodePlanContext) string

GetInstallCmd gets the installation command of the Node.js app.

func GetMeta

func GetMeta(opt GetMetaOptions) types.PlanMeta

GetMeta gets the metadata of the Node.js project.

func GetMonorepoAppRoot

func GetMonorepoAppRoot(ctx *nodePlanContext) string

GetMonorepoAppRoot gets the app root of the monorepo project in the Node.js project.

func GetNodeVersion

func GetNodeVersion(ctx *nodePlanContext) string

GetNodeVersion gets the Node.js version of the project.

func GetStartCmd

func GetStartCmd(ctx *nodePlanContext) string

GetStartCmd gets the start command of the Node.js app.

func GetStartScript

func GetStartScript(ctx *nodePlanContext) string

GetStartScript gets the start command in package.json's `scripts` of the Node.js app.

func GetStaticOutputDir

func GetStaticOutputDir(ctx *nodePlanContext) string

GetStaticOutputDir returns the output directory for static application. If empty string is returned, the application is not deployed as static files.

func NewIdentifier

func NewIdentifier() plan.Identifier

NewIdentifier returns a new NodeJS identifier.

func NewPacker

func NewPacker() packer.Packer

NewPacker returns a new Node.js packer.

Types

type GetMetaOptions

type GetMetaOptions struct {
	Src    afero.Fs
	Config plan.ImmutableProjectConfiguration

	Bun          bool
	BunFramework optional.Option[types.BunFramework]
}

GetMetaOptions is the options for GetMeta.

type PackageJSON

type PackageJSON struct {
	PackageManager  *string           `json:"packageManager,omitempty"`
	Dependencies    map[string]string `json:"dependencies,omitempty"`
	DevDependencies map[string]string `json:"devDependencies,omitempty"`
	Scripts         map[string]string `json:"scripts,omitempty"`
	Engines         PackageJSONEngine `json:"engines"`
	Main            string            `json:"main"`
	Module          string            `json:"module"`

	// yarn workspace
	Workspaces []string `json:"workspaces,omitempty"`
}

PackageJSON is the structure of `package.json`.

func DeserializePackageJSON

func DeserializePackageJSON(source afero.Fs) (PackageJSON, error)

DeserializePackageJSON deserializes a package.json file from source. When the deserialization failed, it returns an empty PackageJson with the error.

func NewPackageJSON

func NewPackageJSON() PackageJSON

NewPackageJSON returns a new instance of PackageJson with some default values.

func (PackageJSON) FindDependency

func (p PackageJSON) FindDependency(name string) (string, bool)

FindDependency checks if the package.json contains the given dependency in "dependency" and "devDependencies", and returns the version of the dependency.

type PackageJSONEngine

type PackageJSONEngine struct {
	Node string `json:"node"`
	Bun  string `json:"bun,omitempty"`
}

PackageJSONEngine is the structure of `package.json`'s `engines` field.

type TemplateContext

type TemplateContext struct {
	NodeVersion string
	BunVersion  string

	AppDir string

	InstallCmd string
	BuildCmd   string
	StartCmd   string

	Framework  string
	Serverless bool
	OutputDir  string

	Bun bool
}

TemplateContext is the context for the Node.js Dockerfile template.

func (TemplateContext) Execute

func (c TemplateContext) Execute() (string, error)

Execute executes the template.

Directories

Path Synopsis
Package nextjs is used to transform build output of Next.js app to the serverless build output format of Zeabur
Package nextjs is used to transform build output of Next.js app to the serverless build output format of Zeabur
Package waku is used to transform build output of Waku app to the serverless build output format of Zeabur
Package waku is used to transform build output of Waku app to the serverless build output format of Zeabur

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL