Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

maven-deploy

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

maven-deploy - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

px.png

5

CHANGELOG.md

@@ -5,3 +5,8 @@ # Changelog

* BREAKING CHANGE: Do not exit if `mvn` command fails. Pass error, stdout and stderr to callback instead.
* Switch to async API
## 1.4.0
* Add optional file argument to pass an archive instead of generating one
* Update dependencies
## 1.3.2

@@ -8,0 +13,0 @@ * Fix undocumented breaking change in isbinaryfile (Issue #28)

101

index.js

@@ -72,3 +72,3 @@ var fs = require('fs');

function mvnArgs (repoId, isSnapshot) {
function mvnArgs (repoId, isSnapshot, file) {
var conf = getConfig(isSnapshot);

@@ -78,3 +78,3 @@

packaging : conf.type,
file : archivePath(isSnapshot),
file : file,
groupId : conf.groupId,

@@ -123,10 +123,2 @@ artifactId : conf.artifactId,

function mvn (args, repoId, isSnapshot, done) {
command('mvn -B ' + args.concat(mvnArgs(repoId, isSnapshot)).join(' '), done);
}
function exit(){
process.exit(1);
}
function getConfig (isSnapshot) {

@@ -145,2 +137,45 @@ var configTmpl = extend({}, DEFAULT_CONFIG);

function package (isSnapshot, done) {
if (typeof isSnapshot == 'function') { done = isSnapshot; isSnapshot = false; }
var archive = new JSZip();
var conf = getConfig(isSnapshot);
walk.walkSync(conf.buildDir, function (base, file, stat) {
if (stat.isDirectory() || file.indexOf(conf.finalName + '.' + conf.type) === 0) {
return;
}
var filePath = path.join(base, file);
var data;
if(isBinaryFile.sync(filePath)) {
data = fs.readFileSync(filePath);
} else {
data = fs.readFileSync(filePath, {'encoding': conf.fileEncoding});
}
archive.file(convertPathIntoUnixLike(path.relative(conf.buildDir, filePath)), data, {createFolders: true});
});
var buffer = archive.generate({type:'nodebuffer', compression:'DEFLATE'});
var arPath = archivePath(isSnapshot);
console.log('archive path', arPath);
fs.writeFileSync(arPath, buffer);
if (done) { done(); }
return arPath;
}
function mvn (args, repoId, isSnapshot, file, done) {
if (!file) { file = package(isSnapshot); }
// check if file exists
fs.statSync(file);
command('mvn -B ' + args.concat(mvnArgs(repoId, isSnapshot, file)).join(' '), done);
}
function exit(){
process.exit(1);
}
function setUserConfig (_userConfig) {

@@ -154,39 +189,16 @@ validateConfig(_userConfig);

package: function (isSnapshot, done) {
if (typeof isSnapshot == 'function') { done = isSnapshot; isSnapshot = false; }
var archive = new JSZip();
var conf = getConfig(isSnapshot);
package: package,
walk.walkSync(conf.buildDir, function (base, file, stat) {
if (stat.isDirectory() || file.indexOf(conf.finalName + '.' + conf.type) === 0) {
return;
}
var filePath = path.join(base, file);
var data;
if(isBinaryFile.sync(filePath)) {
data = fs.readFileSync(filePath);
} else {
data = fs.readFileSync(filePath, {'encoding': conf.fileEncoding});
}
archive.file(convertPathIntoUnixLike(path.relative(conf.buildDir, filePath)), data, {createFolders: true});
});
var buffer = archive.generate({type:'nodebuffer', compression:'DEFLATE'});
var arPath = archivePath(isSnapshot);
console.log('archive path', arPath);
fs.writeFileSync(arPath, buffer);
if (done) { done(); }
install: function (file, done) {
if (typeof file == 'function') { done = file, file = undefined; }
mvn(['install:install-file'], null, true, file, done);
},
install: function (done) {
this.package(true);
mvn(['install:install-file'], null, true, done);
},
deploy: function (repoId, file, isSnapshot, done) {
var conf = getConfig();
//if (isSnapshot && typeof isSnapshot != 'boolean') { done = file, file = isSnapshot, isSnapshot = false; }
if (file && typeof file != 'string') { done = isSnapshot, isSnapshot = file, file = undefined; }
if (isSnapshot && isSnapshot != 'boolean') { done = isSnapshot, isSnapshot = false; }
//if (file && typeof file == 'function') { done = file, file = undefined; }
deploy: function (repoId, isSnapshot, done) {
var conf = getConfig();
if (typeof isSnapshot == 'function') { done = isSnapshot; isSnapshot = false; }
validateRepos(conf);

@@ -197,4 +209,3 @@ if (conf.repositories.length === 0) {

conf.repositories.forEach(validateRepo);
this.package(isSnapshot);
mvn(['deploy:deploy-file'], repoId, isSnapshot, done);
mvn(['deploy:deploy-file'], repoId, isSnapshot, file, done);
}

@@ -201,0 +212,0 @@ };

{
"name": "maven-deploy",
"version": "1.3.2",
"version": "1.4.0",
"description": "A simple Node.js module to create a war-/jar-package and install/deploy to a local/remote Maven repository",

@@ -37,11 +37,12 @@ "main": "index.js",

"devDependencies": {
"coveralls": "^2.11.2",
"buffer-equal": "^1.0.0",
"coveralls": "^2.11.8",
"finn-js-code-style": "4.3.0",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"mocha-lcov-reporter": "^1.0.0",
"mocha-lcov-reporter": "^1.2.0",
"mock-fs": "^3.7.0",
"proxyquire": "^1.7.3",
"proxyquire": "^1.7.4",
"sinon": "^1.17.3"
}
}

@@ -76,4 +76,10 @@ # maven-deploy

### Example: deploy existing archive file
var maven = require('maven-deploy');
maven.config(config);
maven.deploy('example-internal-release', 'file.jar');
## Contributing
We would love your contribution, please consult the [contributing](CONTRIBUTE.md) page for how to make your contributions land into the project as easily as possible.

@@ -9,6 +9,10 @@ /* globals describe, it, beforeEach, afterEach */

var fsMock = require('mock-fs');
var fsReal = require('fs');
var semver = require('semver');
var JSZip = require('jszip');
var bufferEqual = require('buffer-equal');
var maven, fs;
var BINARY_FILE = fsReal.readFileSync('px.png');
var lastCmd, cmdCallback;

@@ -18,9 +22,13 @@

TEST_CLASSIFIER = 'test',
DUMMY_REPO = {
DUMMY_REPO_SNAPSHOT = {
'id': 'dummy-repo',
'url': 'http://mavendummyrepo.com/dummy/'
},
DUMMY_REPO_RELEASE = {
'id': 'dummy-repo-release',
'url': 'http://mavendummyrepo.com/dummy-release/'
},
TEST_CONFIG = {
groupId: GROUP_ID,
repositories: [DUMMY_REPO],
repositories: [DUMMY_REPO_SNAPSHOT, DUMMY_REPO_RELEASE],
classifier: TEST_CLASSIFIER

@@ -34,2 +42,3 @@ },

var childProcessMock;
var execSpy;

@@ -43,3 +52,4 @@ function createFakeFS () {

},
'README.md': '## README\nlorum ipsum'
'README.md': '## README\nlorum ipsum',
'px.png': BINARY_FILE
}

@@ -79,2 +89,16 @@ });

function assertArgs (cmd, expectedArgs) {
var actualArgs = cmd.split(/\s+/);
expectedArgs.forEach(function (expectedArg) {
assert.ok(arrayContains(actualArgs, expectedArg), expectedArg + ' should be part of the command: ' + cmd);
});
}
function assertNotArgs (cmd, unexpectedArgs) {
var actualArgs = cmd.split(/\s+/);
unexpectedArgs.forEach(function (expectedArg) {
assert.ok(!arrayContains(actualArgs, expectedArg), expectedArg + ' should not be part of the command: ' + cmd);
});
}
describe('maven-deploy', function () {

@@ -91,2 +115,4 @@ beforeEach(function () {

execSpy = childProcessMock.exec;
fs = createFakeFS();

@@ -111,3 +137,3 @@

maven.config({
repositories: [DUMMY_REPO]
repositories: [DUMMY_REPO_SNAPSHOT]
});

@@ -138,8 +164,3 @@ });

describe('install', function () {
var execSpy;
beforeEach(function () {
execSpy = childProcessMock.exec;
});
it('should exec "mvn"', function () {

@@ -164,8 +185,4 @@ maven.config(TEST_CONFIG);

maven.install();
var cmd = childProcessMock.exec.args[0][0].split(/\s+/);
EXPECTED_ARGS.forEach(function (EXPECTED_ARG) {
assert.ok(arrayContains(cmd, EXPECTED_ARG), EXPECTED_ARG + ' should be part of the command: ' + cmd);
});
//expect(cmd).to.include.members(EXPECTED_ARGS);
assertArgs(execSpy.args[0][0], EXPECTED_ARGS);
});

@@ -179,11 +196,7 @@

groupId: GROUP_ID,
repositories: [DUMMY_REPO]
repositories: [DUMMY_REPO_SNAPSHOT]
});
maven.install();
var cmd = childProcessMock.exec.args[0][0].split(/\s+/);
UNEXPECTED_ARGS.forEach(function (UNEXPECTED_ARG) {
assert.ok(!arrayContains(cmd, UNEXPECTED_ARG), UNEXPECTED_ARG + ' should not be part of the command: ' + cmd);
});
//expect(cmd).to.include.members(EXPECTED_ARGS);
assertNotArgs(execSpy.args[0][0], UNEXPECTED_ARGS);
});

@@ -212,2 +225,39 @@

});
it('should install file from arguments if specified', function () {
const CUSTOM_FILE = 'file-from-args.jar';
const EXPECTED_ARGS = ['-Dfile='+CUSTOM_FILE];
var zip = new JSZip();
zip.file('test.txt', 'test');
fs.writeFileSync(CUSTOM_FILE, zip.generate({type:'nodebuffer', compression:'DEFLATE'}));
maven.config(TEST_CONFIG);
maven.install(CUSTOM_FILE);
assertArgs(execSpy.args[0][0], EXPECTED_ARGS);
});
it('should throw error if file from arguments does not exist', function () {
const CUSTOM_FILE = 'non-existing-file-from-args.jar';
const EXPECTED_ARGS = ['-Dfile='+CUSTOM_FILE];
maven.config(TEST_CONFIG);
assert.throws(function () {
maven.install(CUSTOM_FILE);
}, /ENOENT, no such file or directory/);
});
it('should call callback function when done successfully', function () {
var spy = sinon.spy();
maven.config(TEST_CONFIG);
maven.install(spy);
// fake successful exec
var execCallback = execSpy.args[0][1];
execCallback(null, 'stdout', null);
assert.ok(spy.calledOnce);
assert.equal(spy.args[0][1], 'stdout');
});
});

@@ -232,5 +282,74 @@

});
it('should add correct repositoryId and url', function () {
const EXPECTED_ARGS = [
'-DrepositoryId='+DUMMY_REPO_RELEASE.id,
'-Durl='+DUMMY_REPO_RELEASE.url
];
maven.config(TEST_CONFIG);
maven.deploy(DUMMY_REPO_RELEASE.id, false);
assertArgs(execSpy.args[0][0], EXPECTED_ARGS);
});
it('should add file argument', function () {
const EXPECTED_ARGS = ['-Dfile=dist/test-pkg.war'];
maven.config(TEST_CONFIG);
maven.deploy(DUMMY_REPO_RELEASE.id, false);
assertArgs(execSpy.args[0][0], EXPECTED_ARGS);
});
it('should add version argument', function () {
const EXPECTED_ARGS = ['-Dversion=1.0.0'];
maven.config(TEST_CONFIG);
maven.deploy(DUMMY_REPO_RELEASE.id, false);
assertArgs(execSpy.args[0][0], EXPECTED_ARGS);
});
it('should deploy file from arguments if specified', function () {
const CUSTOM_FILE = 'file-from-args.jar';
const EXPECTED_ARGS = [
'-Dfile='+CUSTOM_FILE,
'-Dversion='+TEST_PKG_JSON.version
];
var zip = new JSZip();
zip.file('test.txt', 'test');
fs.writeFileSync(CUSTOM_FILE, zip.generate({type:'nodebuffer', compression:'DEFLATE'}));
maven.config(TEST_CONFIG);
maven.deploy(DUMMY_REPO_RELEASE, CUSTOM_FILE);
maven.deploy(DUMMY_REPO_RELEASE, CUSTOM_FILE, false);
maven.deploy(DUMMY_REPO_RELEASE, CUSTOM_FILE, false, sinon.spy());
maven.deploy(DUMMY_REPO_RELEASE, CUSTOM_FILE, sinon.spy());
assert.equal(execSpy.callCount, 4);
for (var i=0; i<4; i++) {
assertArgs(execSpy.args[i][0], EXPECTED_ARGS);
}
});
it('should call callback function when done successfully', function () {
var spy = sinon.spy();
maven.config(TEST_CONFIG);
maven.deploy(DUMMY_REPO_RELEASE.id, spy);
maven.deploy(DUMMY_REPO_RELEASE.id, false, spy);
maven.deploy(DUMMY_REPO_RELEASE.id, 'package.json', spy);
maven.deploy(DUMMY_REPO_RELEASE.id, 'package.json', false, spy);
assert.equal(execSpy.callCount, 4);
for (var i=0; i<4; i++) {
// fake successful exec
execSpy.args[i][1](null, 'stdout', null);
}
assert.equal(spy.callCount, 4);
assert.equal(spy.args[0][1], 'stdout');
});
});
describe('file path', function () {
describe('archive', function () {
it('should zip file with unix-style path', function () {

@@ -251,4 +370,15 @@ maven.config(TEST_CONFIG);

});
it('should save binary files correctly', function () {
maven.config(TEST_CONFIG);
maven.package();
var zip = warFileInDistAsZip();
var image = zip.file('px.png');
assert.ok(image, 'archive should contain px.png image');
var imageEqualOriginal = bufferEqual(new Buffer( new Uint8Array(image.asArrayBuffer()) ), BINARY_FILE);
assert.ok(imageEqualOriginal, 'image data equals the original');
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc