All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.seovic.maven.plugins.npm.Package Maven / Gradle / Ivy

Go to download

A simple Maven plugin that defines 'npm' packaging type and delegates all phases of a default lifecycle to npm. As long as there is a script for the lifecycle phase in package.json, it will be executed.

There is a newer version: 1.0.4
Show newest version
package com.seovic.maven.plugins.npm;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * Simple wrapper around package.json.
 *
 * @author Aleksandar Seovic  2015.09.22
 */
public class Package
        extends LinkedHashMap
    {
    // ---- factory method --------------------------------------------------

    /**
     * Parse package.json.
     *
     * @param file  the file to parse
     *
     * @return a new Package instance for the specified file
     *
     * @throws IOException  if an error occurs
     */
    public static Package parse(File file) throws IOException
        {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(file, Package.class);
        }

    // ---- accessors -------------------------------------------------------

    public String getName()
        {
        return (String) get("name");
        }

    public String getVersion()
        {
        return (String) get("version");
        }

    public String getDescription()
        {
        return (String) get("description");
        }

    public Map getScripts()
        {
        Map scripts = (Map) get("scripts");
        return scripts == null
               ? Collections.emptyMap()
               : scripts;
        }

    public String getScript(String sName)
        {
        return (String) getScripts().get(sName);
        }

    public boolean hasScript(String script)
        {
        return getScripts().containsKey(script);
        }
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy