Documentation
¶
Overview ¶
Package nodejs generates the Dockerfile for Node.js projects.
Index ¶
- Constants
- Variables
- func DetermineAppFramework(ctx *nodePlanContext) types.NodeProjectFramework
- func DetermineNeedPlaywright(ctx *nodePlanContext) bool
- func DetermineNeedPuppeteer(ctx *nodePlanContext) bool
- func FindAppDirByGlob(fs afero.Fs, pattern string) (match string, fnerr error)
- func GenerateDockerfile(meta types.PlanMeta) (string, error)
- func GetBuildCmd(ctx *nodePlanContext) string
- func GetBuildScript(ctx *nodePlanContext) string
- func GetEntry(ctx *nodePlanContext) string
- func GetInitCmd(ctx *nodePlanContext) string
- func GetInstallCmd(ctx *nodePlanContext) string
- func GetMeta(opt GetMetaOptions) types.PlanMeta
- func GetMonorepoAppRoot(ctx *nodePlanContext) string
- func GetNodeVersion(ctx *nodePlanContext) string
- func GetPredeployScript(ctx *nodePlanContext) string
- func GetScriptCommand(ctx *nodePlanContext, script string) string
- func GetStartCmd(ctx *nodePlanContext) string
- func GetStartScript(ctx *nodePlanContext) string
- func GetStaticOutputDir(ctx *nodePlanContext) string
- func NewIdentifier() plan.Identifier
- func NewPacker() packer.Packer
- type Bun
- type GetMetaOptions
- type Npm
- type PackageJSON
- type PackageJSONEngine
- type PackageManager
- type Pnpm
- type TemplateContext
- type UnspecifiedPackageManager
- type Yarn
Constants ¶
const ( // ConfigNodeFramework is the key for the configuration for specifying // the Node.js framework explicitly. // // This is an undocumented internal configuration and is subjected to change. 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 ¶
var ( // NpmLatestMajorVersion is the latest major version of npm. NpmLatestMajorVersion uint64 = 10 // NpmOldestMajorVersion is the oldest major version of npm. NpmOldestMajorVersion uint64 = 6 // YarnLatestMajorVersions is the latest major version of yarn. YarnLatestMajorVersions uint64 = 4 // YarnOldestMajorVersion is the oldest major version of yarn. YarnOldestMajorVersion uint64 = 1 // PnpmLatestMajorVersion is the latest major version of pnpm. PnpmLatestMajorVersion uint64 = 10 // PnpmOldestMajorVersion is the oldest major version of pnpm. PnpmOldestMajorVersion uint64 = 5 )
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 FindAppDirByGlob ¶
FindAppDirByGlob finds the application directory (with package.json) by the given glob pattern.
func GenerateDockerfile ¶
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 GetInitCmd ¶
func GetInitCmd(ctx *nodePlanContext) string
GetInitCmd gets the package manager initialization command 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 GetPredeployScript ¶
func GetPredeployScript(ctx *nodePlanContext) string
GetPredeployScript gets the predeploy script in package.json's `scripts` of the Node.js app.
func GetScriptCommand ¶
GetScriptCommand gets the command to run a script in the Node.js or Bun app.
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.
Types ¶
type Bun ¶
type Bun struct{}
Bun is the implementation of PackageManager for bun.
func (Bun) GetInitCommand ¶
GetInitCommand returns the command to install bun.
func (Bun) GetInstallProjectDependenciesCommand ¶
GetInstallProjectDependenciesCommand returns the command to install project dependencies.
func (Bun) GetRunScript ¶
GetRunScript returns the command to run a script.
func (Bun) GetType ¶
func (Bun) GetType() types.NodePackageManager
GetType returns the type of the package manager.
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 Npm ¶
type Npm struct {
MajorVersion uint64
}
Npm is the implementation of PackageManager for npm.
func (Npm) GetInitCommand ¶
GetInitCommand returns the command to install npm.
func (Npm) GetInstallProjectDependenciesCommand ¶
GetInstallProjectDependenciesCommand returns the command to install project dependencies.
func (Npm) GetRunScript ¶
GetRunScript returns the command to run a script.
func (Npm) GetType ¶
func (Npm) GetType() types.NodePackageManager
GetType returns the type of the package manager.
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"`
Npm string `json:"npm,omitempty"`
Yarn string `json:"yarn,omitempty"`
Pnpm string `json:"pnpm,omitempty"`
}
PackageJSONEngine is the structure of `package.json`'s `engines` field.
type PackageManager ¶
type PackageManager interface {
GetType() types.NodePackageManager
GetInitCommand() string
GetInstallProjectDependenciesCommand() string
GetRunScript(script string) string
}
PackageManager defines an interface for common package management operations. It is basically the reimplementation of Corepack + Ni (https://github.com/antfu-collective/ni)
func DeterminePackageManager ¶
func DeterminePackageManager(ctx *nodePlanContext) PackageManager
DeterminePackageManager determines the package manager of the Node.js project.
func DeterminePackageManagerUncached ¶
func DeterminePackageManagerUncached(ctx *nodePlanContext) PackageManager
DeterminePackageManagerUncached determines the package manager of the Node.js project.
type Pnpm ¶
type Pnpm struct {
MajorVersion uint64
}
Pnpm is the implementation of PackageManager for pnpm.
func (Pnpm) GetInitCommand ¶
GetInitCommand returns the command to install pnpm.
func (Pnpm) GetInstallProjectDependenciesCommand ¶
GetInstallProjectDependenciesCommand returns the command to install project dependencies.
func (Pnpm) GetRunScript ¶
GetRunScript returns the command to run a script.
func (Pnpm) GetType ¶
func (Pnpm) GetType() types.NodePackageManager
GetType returns the type of the package manager.
type TemplateContext ¶
type TemplateContext struct {
NodeVersion string
AppDir string
InitCmd string
InstallCmd string
BuildCmd string
StartCmd string
Framework string
OutputDir string
}
TemplateContext is the context for the Node.js Dockerfile template.
func (TemplateContext) Execute ¶
func (c TemplateContext) Execute() (string, error)
Execute executes the template.
type UnspecifiedPackageManager ¶
type UnspecifiedPackageManager struct {
PackageManager
}
UnspecifiedPackageManager is the implementation of PackageManager for an unspecified package manager.
The type will be set to unknown.
func (UnspecifiedPackageManager) GetType ¶
func (u UnspecifiedPackageManager) GetType() types.NodePackageManager
GetType returns the type of the package manager.
type Yarn ¶
type Yarn struct {
MajorVersion uint64
}
Yarn is the implementation of PackageManager for yarn.
func (Yarn) GetInitCommand ¶
GetInitCommand returns the command to install yarn.
func (Yarn) GetInstallProjectDependenciesCommand ¶
GetInstallProjectDependenciesCommand returns the command to install project dependencies.
func (Yarn) GetRunScript ¶
GetRunScript returns the command to run a script.
func (Yarn) GetType ¶
func (Yarn) GetType() types.NodePackageManager
GetType returns the type of the package manager.