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

com.danielflower.apprunner.runners.NodeRunnerFactory Maven / Gradle / Ivy

Go to download

A self-hosted platform-as-a-service that hosts web apps written in Java, Clojure, NodeJS, Python, golang and Scala.

There is a newer version: 2.4.6
Show newest version
package com.danielflower.apprunner.runners;

import com.danielflower.apprunner.Config;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.lang3.tuple.Pair;

import java.io.File;
import java.util.Optional;

class NodeRunnerFactory implements AppRunnerFactory {
    private final String versionInfo;
    private final String nodeExecutable;
    private final String npmExecutable;

    NodeRunnerFactory(String nodeExecutable, String npmExecutable, String versionInfo) {
        this.nodeExecutable = nodeExecutable;
        this.npmExecutable = npmExecutable;
        this.versionInfo = versionInfo;
    }

    @Override
    public String id() {
        return "nodejs";
    }

    @Override
    public String sampleProjectName() {
        return "nodejs.zip";
    }

    @Override
    public String description() {
        return "NodeJS apps with NPM dependencies";
    }

    @Override
    public String[] startCommands() {
        return NodeRunner.startCommands;
    }

    @Override
    public AppRunner appRunner(File folder) {
        return new NodeRunner(folder, nodeExecutable, npmExecutable);
    }

    @Override
    public String versionInfo() {
        return versionInfo;
    }

    @Override
    public boolean canRun(File appDirectory) {
        return new File(appDirectory, "package.json").isFile();
    }

    public static Optional createIfAvailable(Config config) {
        String nodeExecutable = config.nodeExecutable();
        String npmExecutable = config.npmExecutable();
        Pair node = ProcessStarter.run(new CommandLine(nodeExecutable).addArgument("--version"));
        Pair npm = ProcessStarter.run(new CommandLine(npmExecutable).addArgument("--version"));

        if (node.getLeft() && npm.getLeft()) {
            String versionInfo = "Node " + node.getRight() + " with NPM " + npm.getRight();
            return Optional.of(new NodeRunnerFactory(nodeExecutable, npmExecutable, versionInfo));
        }
        return Optional.empty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy