Class JScriptProjectLayout
java.lang.Object
org.machanism.machai.project.layout.ProjectLayout
org.machanism.machai.project.layout.JScriptProjectLayout
A project layout utility for JavaScript/TypeScript-based projects.
Scans for workspace modules defined in package.json, and
determines project sources, documents, and test directories.
- 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. -
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
-
Field Details
-
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:
- list of relative module path, or empty list when the project does not define workspaces
- Throws:
IllegalArgumentException- 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:
IllegalArgumentException- if reading/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
-