@groovy.transform.CompileStatic @SuppressWarnings(value: [DuplicateStringLiteral]) class PackageJson extends Object
Parses a package.json file.
This is not a complete representation. It is only meant to provide enough information for the plugin to make reasonable decisions about packages.
| Modifiers | Name | Description |
|---|---|---|
static class |
PackageJson.Element |
|
static enum |
PackageJson.Indentation |
Indentation to use when writing files. |
| Modifiers | Name | Description |
|---|---|---|
static String |
PACKAGE_JSON |
| Type Params | Return Type | Name and description |
|---|---|---|
|
java.util.Map<String, ?> |
asMap()Returns all properties as map which will be suitable for writing out as JSON again. |
|
static String |
formatName(String name)Formats a name suitable for package.json. |
|
static String |
formatVersion(String ver, boolean forceSemver)Formats a supplied version into a NPM-safe version |
|
Iterable<String> |
getBundledDependencies() |
|
java.util.Map<String, String> |
getDependencies() |
|
String |
getDescription() |
|
java.util.Map<String, String> |
getDevDependencies() |
|
String |
getHomepage() |
|
java.util.List<String> |
getKeywords() |
|
String |
getLicense() |
|
String |
getName() |
|
java.util.Map<String, String> |
getOptionalDependencies() |
|
java.util.Map<String, String> |
getPeerDependencies() |
|
java.util.Map<String, String> |
getScripts() |
|
String |
getVersion() |
|
static String |
loadVersionFromPackageJson(File packageJson)Loads the version string. |
|
static PackageJson |
of(String ver, String name)Creates a base object consisting only of a name and version. |
|
static PackageJson |
parsePackageJson(File packageJson)Parses a package.json file. |
|
static Object |
parsePackageJsonToGPath(File packageJson)Parses a package.json file. |
|
static java.util.Map<String, ?> |
parsePackageJsonToMap(File packageJson)Parses a package.json file. |
|
void |
setName(String nm) |
|
void |
setVersion(String ver) |
|
void |
writeToFile(File destFile, PackageJson.Indentation indent, boolean sortElements)Writes the contents to a package.json file |
Returns all properties as map which will be suitable for writing out as JSON again. @return
Formats a name suitable for package.json.
name - Proposed nameFormats a supplied version into a NPM-safe version
ver - Version.
When the version is unspecified or null, it uses 0.0.0-alpha.0 as the version.forceSemver - Whether semantiv versioning should be enforced.Loads the version string.
packageJson - packageJson Location of file.Creates a base object consisting only of a name and version.
ver - Versionname - Project name Parses a package.json file.
packageJson - Location of file. Parses a package.json file.
packageJson - Location of file. Parses a package.json file.
packageJson - Location of file.Writes the contents to a package.json file
destFile - File path of which the filename should be package.json.indent - Whether to use two-space or four-space indentationsortElements - Whether to sort elements by the rules of
https.