Class JScriptProjectLayout
java.lang.Object
org.machanism.machai.project.layout.ProjectLayout
org.machanism.machai.project.layout.JScriptProjectLayout
Describes a JavaScript or TypeScript project that uses
package.json.
The layout detects projects by their package descriptor and discovers
workspace modules declared with the array form of workspaces. Each
matching workspace must contain its own package.json. Source, test,
and documentation roots are not inferred and return empty lists.
Configure the root with projectDir(File) before invoking methods
that read package.json.
- Since:
- 0.0.2
- Author:
- Viktor Tovstyi
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the JS/TS project model file used to detect this layout.Fields inherited from class org.machanism.machai.project.layout.ProjectLayout
NO_MODULES -
Constructor Summary
ConstructorsConstructorDescriptionCreates a JavaScript/TypeScript project layout instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcollectMatchingModules(Set<String> modules, String globPattern) Adds workspace directories matching a glob and containingpackage.json.Returns a list of conventional documentation directories for JS/TS projects.Returns workspace modules listed inpackage.jsonunder theworkspaceskey.private com.fasterxml.jackson.databind.JsonNodeLoads and parsespackage.jsonin the current project directory.Returns the package name frompackage.json.Returns a list of conventional source directories for JS/TS projects.getTests()Returns a list of conventional test directories for JS/TS projects.static booleanisPackageJsonPresent(File projectDir) Checks if the specified directory contains apackage.jsonfile, indicating a JS/TS project.private static StringnormalizeWorkspaceGlob(String globPattern) Removes the optional leading./from a workspace glob.parseWorkspaceModules(com.fasterxml.jackson.databind.JsonNode workspacesNode) Expands array-form workspace patterns into unique module paths.projectDir(File projectDir) Sets the project directory and narrows the return type for fluent usage.Methods inherited from class org.machanism.machai.project.layout.ProjectLayout
getExcludeDirs, getParentId, getProjectDir, getProjectLayoutType, getProjectName, getRelativePath, getRelativePath, getRelativePath, getTempDir, isExcludedPath, listDirectories, listFiles, setExcludeDirs
-
Field Details
-
workspaceModules
-
PROJECT_MODEL_FILE_NAME
Name of the JS/TS project model file used to detect this layout.- See Also:
-
-
Constructor Details
-
JScriptProjectLayout
public JScriptProjectLayout()Creates a JavaScript/TypeScript project layout instance.
-
-
Method Details
-
isPackageJsonPresent
Checks if the specified directory contains apackage.jsonfile, indicating a JS/TS project.- Parameters:
projectDir- directory to check- Returns:
trueifpackage.jsonis present; otherwisefalse
-
getModules
Returns workspace modules listed inpackage.jsonunder theworkspaceskey.When
workspacesis an array of glob patterns, this method searches directories under the configured project root and returns those that match a workspace pattern and contain apackage.json.- Overrides:
getModulesin classProjectLayout- Returns:
- relative module paths, or
nullwhen the project does not define array-form workspaces - Throws:
IllegalStateException- if no project root has been configuredIllegalArgumentException- ifpackage.jsoncannot be read or parsed
-
parseWorkspaceModules
Expands array-form workspace patterns into unique module paths.- Parameters:
workspacesNode- JSON node containing workspace patterns- Returns:
- matching module paths
-
normalizeWorkspaceGlob
Removes the optional leading./from a workspace glob.- Parameters:
globPattern- workspace glob to normalize- Returns:
- normalized glob
-
collectMatchingModules
Adds workspace directories matching a glob and containingpackage.json.- Parameters:
modules- destination set for discovered module pathsglobPattern- workspace glob to match
-
getPackageJson
private com.fasterxml.jackson.databind.JsonNode getPackageJson()Loads and parsespackage.jsonin the current project directory.- Returns:
- root JSON node of
package.json - Throws:
IllegalStateException- if no project root has been configuredIllegalArgumentException- if reading or parsing fails
-
getSources
Returns a list of conventional source directories for JS/TS projects.- Specified by:
getSourcesin classProjectLayout- Returns:
- empty list; not currently implemented
-
getDocuments
Returns a list of conventional documentation directories for JS/TS projects.- Specified by:
getDocumentsin classProjectLayout- Returns:
- empty list; not currently implemented
-
getTests
Returns a list of conventional test directories for JS/TS projects.- Specified by:
getTestsin classProjectLayout- Returns:
- empty list; not currently implemented
-
projectDir
Sets the project directory and narrows the return type for fluent usage.- Overrides:
projectDirin classProjectLayout- Parameters:
projectDir- project root directory- Returns:
- this layout instance
-
getProjectId
Returns the package name frompackage.json.- Overrides:
getProjectIdin classProjectLayout- Returns:
- package name
-