Coder Social home page Coder Social logo

intuit / node-pom-parser Goto Github PK

View Code? Open in Web Editor NEW
21.0 6.0 28.0 75 KB

Parsing Java's pom.xml and properly returning the json object, including attributes and values.

License: MIT License

TypeScript 100.00%
pom javascript enterprise nexus node-pom-parser json parser hacktoberfest hacktoberfest2022

node-pom-parser's Introduction

Node.js pom.xml Parser

CI Build Status npm CodeQL Analysis Coverage Status License

NPM

pom-parser

Parsing Java's pom.xml file and properly returning the JSON object, including all it's attributes and values.

Motivation

  • Your enterprise decided to move production code written in Java to Node.js
  • Your enterprise uses a centralized Nexus repository where your Java project uses pom.xml to manage app packaging
  • Your enterprise still plans to use Nexus repository to package Node.js applications
  • Your enterprise engineers want an API to retrieve information from the pom.xml file from those Node.js apps

Features

  • Reads any pom.xml
  • All XML elements are placed into properties
  • All XML element attributes are merged into the parent element
  • Both the XML string and the parsed object are returned
  • You can provide parsing options

Contributing

Pull requests are welcome!

  • See if an issue is already open, if not open
  • Discuss with team to prevent duplicate effort
  • Work up the PR and add/update unit tests
  • Raise PR against the master branch for the next release
  • Ensure all the Github Actions/checks are passing

Installation

$ npm install --save node-pom-parser
$ yarn add node-pom-parser

Use

  • Printing the object
import parse from './lib/index.js';
import { dirname } from 'path';
import { fileURLToPath } from 'url';

//var pomParser = require("./lib/index");
// The required options, including the filePath.
// Other parsing options from https://github.com/Leonidas-from-XIV/node-xml2js#options

const __dirname = dirname(fileURLToPath(import.meta.url));

var opts = {
  filePath: __dirname + "/test/fixture/pom.xml", // The path to a pom file
};
// Parse the pom based on a path
parse(opts, function(err, pomResponse) {
  if (err) {
    console.log("ERROR: " + err);
    process.exit(1);
  }

  // The original pom xml that was loaded is provided.
  console.log("XML: " + pomResponse.pomXml);
  // The parsed pom pbject.
  console.log("OBJECT: " + JSON.stringify(pomResponse.pomObject));
});

It should print the follow object with the following properties:

  • '_' represents the text value of an element with attributes and text values.
{
  "project": {
    "xmlns": "http://maven.apache.org/POM/4.0.0",
    "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
    "xsi:schemaLocation": "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd",
    "parent": {
      "artifactid": "tynamo-parent",
      "groupid": "org.tynamo",
      "version": "0.0.9"
    },
    "modelversion": {
      "_": "4.0.0",
      "parallel": "now"
    },
    "groupid": "org.tynamo.examples",
    "artifactid": "tynamo-example-federatedaccounts",
    "version": "0.0.1-SNAPSHOT",
    "packaging": "war",
    "name": "Tynamo Example - Federated Accounts",
    "properties": {
      "tapestry-release-version": "5.3.1",
      "gae.version": "1.3.0",
      "gae.home": "${settings.localRepository}/com/google/appengine/appengine-api-1.0-sdk/${gae.version}/appengine-java-sdk-${gae.version}",
      "gae.application.version": "0"
    },
    "build": {
      "finalname": "federatedaccounts",
      "resources": {
        "resource": [
          {
            "directory": "src/main/resources"
          },
          {
            "directory": "src/main/filtered-resources",
            "filtering": "true"
          }
        ]
      },
      "plugins": {
        "plugin": [
          {
            "groupid": "org.apache.maven.plugins",
            "artifactid": "maven-compiler-plugin",
            "configuration": {
              "source": "1.6",
              "target": "1.6",
              "optimize": "true"
            }
          },
          {
            "groupid": "net.kindleit",
            "artifactid": "maven-gae-plugin",
            "version": "0.8.0",
            "configuration": {
              "serverid": "tynamo-example-federatedaccounts"
            }
          },
          {
            "groupid": "org.apache.maven.plugins",
            "artifactid": "maven-war-plugin",
            "configuration": {
              "webresources": {
                "resource": {
                  "directory": "src/main/webapp",
                  "filtering": "true",
                  "includes": {
                    "include": "**/appengine-web.xml"
                  }
                }
              }
            }
          }
        ]
      }
    },
    "reporting": {
      "plugins": {
        "plugin": {
          "groupid": "org.apache.tapestry",
          "artifactid": "tapestry-component-report",
          "version": "${tapestry-release-version}",
          "configuration": {
            "rootpackage": "org.tynamo"
          }
        }
      }
    },
    "dependencies": {
      "dependency": [
        {
          "groupid": "com.google.appengine",
          "artifactid": "appengine-api-1.0-sdk",
          "version": "${gae.version}"
        },
        {
          "groupid": "com.h2database",
          "artifactid": "h2"
        },
        {
          "groupid": "org.apache.tapestry",
          "artifactid": "tapestry-core",
          "version": "${tapestry-release-version}"
        },
        {
          "groupid": "javax.servlet",
          "artifactid": "servlet-api",
          "version": "2.5",
          "type": "jar",
          "scope": "provided"
        }
      ]
    },
    "profiles": {
      "profile": {
        "id": "repositories",
        "repositories": {
          "repository": {
            "id": "maven-gae-plugin-repo",
            "name": "maven-gae-plugin repository",
            "url": "http://maven-gae-plugin.googlecode.com/svn/repository"
          }
        },
        "pluginrepositories": {
          "pluginrepository": {
            "id": "maven-gae-plugin-repo",
            "name": "maven-gae-plugin repository",
            "url": "http://maven-gae-plugin.googlecode.com/svn/repository"
          }
        }
      }
    }
  }
}

License

node-pom-parser is provided under the MIT license.

node-pom-parser's People

Contributors

batflarrow avatar datho7561 avatar fauxfaux avatar kokikathir avatar marcellodesales avatar mkm1997 avatar nsinghal12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-pom-parser's Issues

Throws error if comment contains '--'

If given an invalid pom file with a comment like this

<!-- some comment -- with dashes inside -->

the parse() methods throws an error. Since parse() returns a Promise, I would expect this throw to be caught internally and passed to reject() so that I can access it like the example below, but the error is actually thrown so I can't catch it with .catch() of the Promise

parse()
.catch((e) => {
  // e is the thrown error
});

What's worse is that it seems to throw internally after some async action, so that you can't catch the error on the current tick of the event loop. So it's actually impossible to catch it, wrapping it in try/catch like below doesn't catch the error

try {
  parse()
catch (e) {
  // doesnt get caught here
}

add windows support

According to Stack Overflow the node-expat module which is used for parsing the xml is not Windows compatible.

Is is possible to add an option for using the xml2js or xmldoc module for parsing instead. They depend on sax.js which is a pure Javascript solution which won't cause any problem on Windows machines.

Fix the badges after the Ownership transfer

Here are some of the pending tasks for getting the badges fixed in the README.md.

  • The Travis badge is not showing.
  • The gemnasium.com badge is showing, but incorrect
  • The Coveralls badge is showing, but incorrect
  • The others are fine.

Convert code to Typescript

This will allow us to make use of interfaces to bring type-safety and object completion for parsed JS object in editors.

Update and clean up JSDocs

We need to update the JSDocs across project to reflect the newer semantics and document all usage scenarios.

Automatically deploy to npm upon merge to Master

Travis supports CD capability.

http://docs.travis-ci.com/user/deployment/npm/

Instead of forgetting to publish manually, this should be enabled. Here's our GitFlow workflow:

  1. Development occurs in the develop branch.
  2. New Pull Requests must be to to be merged against this branch. However, Pull Requests will only be reviewed If the pull request can be merged and the tests passes. Also, the milestone must be set to the associated Issue.
  3. After a new release has been planned, all the merged pull requests can be released.
  4. On a new release, Tagging is added, the version is bumped in package.json and the Develop branch will be merged to Master, triggering the npm publish on Travis.

Fix dependabot alert

Current alert reports an error in Apache Tapestry pom.xml that we use as a test fixture. Need to fix that.

Set normalizeTags to false in index.js

Would it make sense to set normalizeTags to false in index.js, so that the resulting JSON object has keys that correspond exactly to the xml tag names?
For example, artifactId instead of artifactid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.