headcr4sh / node-maven

Maven for Node.js
Apache License 2.0
18 stars 14 forks source link

error mvn execute is not a function #11

Closed deshazer72 closed 6 years ago

deshazer72 commented 7 years ago

This may not be an error it could be just because I am not using maven correctly. I am trying to put a zip file that I create inside a repository by using maven

this is my code

const mvn = require('maven');

const appName = 'RapVideoUpload';
    const groupId = 'com.sco.rapvideozip';
    const appVersion = '0.0.2-SNAPSHOT';
    const appPackaging = 'zip';
    const appRepositoryId = 'internal-repository';
    const appRepositoryUrl = 'myrepo';
    const appLocation = 'C:\toolbox\RapVideoUpload\sco-rap-video-upload\dist\videos.zip';
    mvn.execute(['deploy:deploy-file'], {'artifactId': `${appName}`}, {'groupId': `${groupId}`}, {'version': `${appVersion}`}, {'packaging': `${appPackaging}`},
     {'repositoryId': `${appRepositoryId}`}, {'url': `${appRepositoryUrl}`}, {'file': `${appLocation}`});

when I run this I get mvn.execute is not a function..... and I am lost here I have written a .sh script that runs fine but what I am wanting to do is after someone upload a video and I create a zip of that video I want to put it in my repository automatically same thing as when they delete it and this mvn command does this for me with my .sh script

APP_NAME="RapVideoUpload"
APP_GROUP_ID="com.sco.rapvideozip"
APP_VERSION="0.0.1-SNAPSHOT"
APP_PACKAGING=zip
APP_REPOSITORY_ID="internal-repository"
APP_REPOSITORY_URL="myrepo"
APP_LOCATION="C:\toolbox\RapVideoUpload\sco-rap-video-upload\dist\videos.zip"
if [ ! "${MAVEN_HOME}" ];
 MAVEN_HOME=/opt/walmart/maven/apache-maven-3.1.1/bin
fi
# Once the file has been packaged well, Configure path for maven and deploy to Nexus

 export PATH=$PATH:(cygpath "${MAVEN_HOME}")
 #export PATH=$PATH:${MAVEN_HOME}

mvn -X \
    -q deploy:deploy-file \
    -DartifactId=${APP_NAME} \
    -DgroupId=${APP_GROUP_ID} \
    -Dversion=${APP_VERSION} \
    -Dpackaging=${APP_PACKAGING} \
    -DrepositoryId=${APP_REPOSITORY_ID} \
    -Durl=${APP_REPOSITORY_URL} \
    -Dfile=${APP_LOCATION} 

I am thinking I may be using the command wrong if I am I apologize I just do not see what I am doing wrong by looking at the documentation.

headcr4sh commented 7 years ago

You seem to be missing the call to mvn.create() which is necessary to initialize the Maven wapper correctly.

Example:

const mvn = require ("maven").create();
mvn.execute(/*...*/);

I think the documentation in README.md is quite clear about that.... hopefully.... ;-)

deshazer72 commented 7 years ago

sorry you are correct I was thrown off by the other parameters not know what to pass there I am still getting errors but I think it is because I am not using the package correctly

deshazer72 commented 7 years ago

so after I put on some debugging I seen some of my issues which I dont understand I did this on the create

const mvn = require('maven').create({
  debug: true,
  generatePom: false,
  repositoryId: 'internal-repository'
});

then this on my code to execute 

function sendZipToNexus() { const newdirName = 'c:\toolbox\RapVideoUpload\sco-rap-video-upload\dist\'; const appName = 'RapVideoUpload'; const groupId = 'com.sco.rapvideozip'; const appVersion = '0.0.2-SNAPSHOT'; const appPackaging = 'zip'; const appRepositoryUrl = 'repo'; const appLocation = newdirName + 'videos.zip'; console.log(appRepositoryUrl); console.log(appLocation); mvn.execute(['deploy:deploy-file'], {'artifactId': ${appName}}, {'url': ${appRepositoryUrl}}, {'file': ${appLocation}}, {'groupId': ${groupId}}, {'version': ${appVersion}}, {'packaging': ${appPackaging}});


this is my error 
![image](https://cloud.githubusercontent.com/assets/20157793/25107602/09aa1ddc-2396-11e7-8902-d6d22d9b9ca7.png)

it sasys I am not passing these but I am. I also noticed that on remote repositoryId = remote-repository when I am setting that to 'internal-repository'

![image](https://cloud.githubusercontent.com/assets/20157793/25107641/43ee0d28-2396-11e7-9f0f-8a36b8d58cf5.png)
deshazer72 commented 7 years ago

node2 node1

headcr4sh commented 6 years ago

Ooops. Sorry for this very late reply...

It seems as if you are using the API in a very ... errr... unexpected/wrong way. ;-)

The correct way to invoke Maven would have been:

const mvn = require('maven').create({
  debug: true
});
mvn.execute([ 'clean', 'install' ], {
  generatePom: false,
  repositoryId: 'internal-repository'
});

Thus: defines must be passed to the execute-call instead to the create call.

Again: Sorry for the very late reply. I am now closing this ticket, because I assume there is no "bug" to be hunted.