Class JScriptProjectLayout

java.lang.Object
org.machanism.machai.project.layout.ProjectLayout
org.machanism.machai.project.layout.JScriptProjectLayout

public class JScriptProjectLayout extends ProjectLayout
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 Details

    • workspaceModules

      private List<String> workspaceModules
    • PROJECT_MODEL_FILE_NAME

      public static final String 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

      public static boolean isPackageJsonPresent(File projectDir)
      Checks if the specified directory contains a package.json file, indicating a JS/TS project.
      Parameters:
      projectDir - directory to check
      Returns:
      true if package.json is present; otherwise false
    • getModules

      public List<String> getModules()
      Returns workspace modules listed in package.json under the workspaces key.

      When workspaces is an array of glob patterns, this method searches directories under the configured project root and returns those that match a workspace pattern and contain a package.json.

      Overrides:
      getModules in class ProjectLayout
      Returns:
      relative module paths, or null when the project does not define array-form workspaces
      Throws:
      IllegalStateException - if no project root has been configured
      IllegalArgumentException - if package.json cannot be read or parsed
    • parseWorkspaceModules

      private List<String> parseWorkspaceModules(com.fasterxml.jackson.databind.JsonNode workspacesNode)
      Expands array-form workspace patterns into unique module paths.
      Parameters:
      workspacesNode - JSON node containing workspace patterns
      Returns:
      matching module paths
    • normalizeWorkspaceGlob

      private static String normalizeWorkspaceGlob(String globPattern)
      Removes the optional leading ./ from a workspace glob.
      Parameters:
      globPattern - workspace glob to normalize
      Returns:
      normalized glob
    • collectMatchingModules

      private void collectMatchingModules(Set<String> modules, String globPattern)
      Adds workspace directories matching a glob and containing package.json.
      Parameters:
      modules - destination set for discovered module paths
      globPattern - workspace glob to match
    • getPackageJson

      private com.fasterxml.jackson.databind.JsonNode getPackageJson()
      Loads and parses package.json in the current project directory.
      Returns:
      root JSON node of package.json
      Throws:
      IllegalStateException - if no project root has been configured
      IllegalArgumentException - if reading or parsing fails
    • getSources

      public List<String> getSources()
      Returns a list of conventional source directories for JS/TS projects.
      Specified by:
      getSources in class ProjectLayout
      Returns:
      empty list; not currently implemented
    • getDocuments

      public List<String> getDocuments()
      Returns a list of conventional documentation directories for JS/TS projects.
      Specified by:
      getDocuments in class ProjectLayout
      Returns:
      empty list; not currently implemented
    • getTests

      public List<String> getTests()
      Returns a list of conventional test directories for JS/TS projects.
      Specified by:
      getTests in class ProjectLayout
      Returns:
      empty list; not currently implemented
    • projectDir

      public JScriptProjectLayout projectDir(File projectDir)
      Sets the project directory and narrows the return type for fluent usage.
      Overrides:
      projectDir in class ProjectLayout
      Parameters:
      projectDir - project root directory
      Returns:
      this layout instance
    • getProjectId

      public String getProjectId()
      Returns the package name from package.json.
      Overrides:
      getProjectId in class ProjectLayout
      Returns:
      package name