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

npe

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npe - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

29

index.js
#!/usr/bin/env node
'use strict';

@@ -19,13 +20,11 @@ var fs = require("fs");

if (!args._.length) {
console.log("\nNode Package Editor");
console.log("Get: npe <property>");
console.log("Set: npe <property> <value>");
console.log("\n./package.json is used by default, but you can override:");
console.log("npe <property> --package=./some/other/package.json");
return;
return console.log(fs.readFileSync(__dirname + "/example.sh").toString());
}
// Get
if (args._.length === 1)
return console.log(steelToe(pkg).get(args._[0]));
if (args._.length === 1) {
var val = steelToe(pkg).get(args._[0]);
if (typeof(val) !== "string") {val = JSON.stringify(val, null, 2);}
return console.log(val);
}

@@ -35,5 +34,17 @@ // Set

if (typeof(pkg.keywords) === "string")
if (typeof(pkg.keywords) === "string") {
pkg.keywords = stringToArray(pkg.keywords);
}
Object.keys(pkg).forEach(function(property){
if (pkg[property] === "true") {
pkg[property] = true;
}
if (pkg[property] === "false") {
pkg[property] = false;
}
})
fs.writeFileSync(args.package, JSON.stringify(pkg, null, 2));
{
"name": "npe",
"version": "0.1.1",
"version": "0.2.0",
"description": "Node Package Editor: a CLI for one-off inspection and editing of properties in package.json files.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,1 +1,3 @@

'use strict';
var fs = require('fs');

@@ -12,3 +14,3 @@ var nixt = require('nixt');

.run('./index.js')
.stdout(/Node Package Editor/i)
.stdout(/Get values from package\.json/i)
.end(done);

@@ -31,3 +33,3 @@ });

.run('./index.js scripts')
.stdout(/test:/)
.stdout(/\"test\"/)
.end(done);

@@ -72,34 +74,46 @@ });

var pkg;
var tmpName;
var tmpFile;
beforeEach(function(done){
tmpName = util.format("/tmp/package-%s.json", Math.random()*10000);
tmpFile = util.format("/tmp/package-%s.json", Math.random()*10000);
nixt()
.run("cp test/fixtures/normal/package.json " + tmpName)
.run("cp test/fixtures/normal/package.json " + tmpFile)
.end(done);
});
// afterEach(function(done){
// pkg = null;
// nixt()
// .run('rm test/fixtures/normal/tmp.json')
// .end(done);
// });
it("sets name", function(done) {
it("sets top-level properties like 'name'", function(done) {
nixt()
.expect(function(result){
pkg = require(tmpName);
if (!pkg || pkg.name != "foo") {
pkg = require(tmpFile);
if (!pkg || pkg.name !== "foo") {
return new Error('package name should be foo');
}
})
.run("./index.js name foo --package="+tmpName)
.run("./index.js name foo --package="+tmpFile)
.end(done);
});
it("sets nested properties like 'scripts.start'", function(done) {
nixt()
.expect(function(result){
var pkg = require(tmpFile);
if (!pkg.scripts) {
console.log(pkg);
return new Error('scripts property should exist');
}
if (pkg.scripts.start !== "node index.js") {
console.log(pkg.scripts);
return new Error("scripts.start should be 'node index.js'");
}
})
.run("./index.js scripts.start \"node index.js\" --package="+tmpFile)
.end(done);
});
it("sets keywords array from a comma-delimited string", function(done) {
nixt()
.expect(function(result){
pkg = require(tmpName);
pkg = require(tmpFile);

@@ -111,3 +125,3 @@ if (!util.isArray(pkg.keywords)) {

if (pkg.keywords.length != 2) {
if (pkg.keywords.length !== 2) {
console.log(pkg.keywords);

@@ -123,3 +137,3 @@ return new Error('keywords should have two elements');

})
.run("./index.js keywords \"foo, bar\" --package="+tmpName)
.run("./index.js keywords \"foo, bar\" --package="+tmpFile)
.end(done);

@@ -131,3 +145,3 @@ });

.expect(function(result){
pkg = require(tmpName);
pkg = require(tmpFile);

@@ -139,3 +153,3 @@ if (!util.isArray(pkg.keywords)) {

if (pkg.keywords.length != 2) {
if (pkg.keywords.length !== 2) {
console.log(pkg.keywords);

@@ -156,27 +170,33 @@ return new Error('keywords should have two elements');

})
.run("./index.js keywords \"foo bar\" --package="+tmpName)
.run("./index.js keywords \"foo bar\" --package="+tmpFile)
.end(done);
});
it("sets scripts.start", function(done) {
it("sets 'false' string to a boolean false", function(done) {
nixt()
.expect(function(result){
var pkg = require(tmpName);
if (!pkg.scripts) {
console.log(pkg);
return new Error('scripts property should exist');
pkg = require(tmpFile);
if (!pkg || pkg.private !== false) {
return new Error('boolean property should be false');
}
})
.run("./index.js private false --package="+tmpFile)
.end(done);
});
if (pkg.scripts.start != "node index.js") {
console.log(pkg.scripts);
return new Error("scripts.start should be 'node index.js'");
it("sets 'true' string to boolean true", function(done) {
nixt()
.expect(function(result){
pkg = require(tmpFile);
if (!pkg || pkg.private !== true) {
return new Error('boolean property should be true');
}
})
.run("./index.js scripts.start \"node index.js\" --package="+tmpName)
.run("./index.js private true --package="+tmpFile)
.end(done);
});
});
});

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