Socket
Socket
Sign inDemoInstall

organize-pkg

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.4 to 1.3.0

21

index.js

@@ -10,12 +10,13 @@ #!/usr/bin/env node

const utils=require("./utils"),params=utils.getExtraArgs(),cliName="organize-pkg";function help(e=`${cliName} usage`){
console.log(`\n${e}\n\n ${cliName} -keys "<key>,<key>,..." -out <output json path>\n`)}function isInvalidValue(e,a){
return void 0===e||0===e.length?(help(a),1):0}function organizePackageJson(){let e;try{
console.log(`\n${e}\n\n ${cliName} -keys "<key>,<key>,..." -out <output json path>\n`)}function isInvalidValue(e,s){
return void 0===e||0===e.length?(help(s),1):0}function organizePackageJson(){let e;try{
e=utils.readJson("./package.json")}catch(e){return void console.error(e)}if(e){
const a=params.k||params.keys||[],s=params.p||params.prod
;if(!s&&isInvalidValue(a,"ERROR: \"-keys\" parameter must be required"))return;let t=params.o||params.out
;if(!t&&s&&(t="./dist/"),isInvalidValue(t,"ERROR: \"-out\" parameter must be required"))return
;const n=s?["scripts","devDependencies"]:[],r=/^\/\//,o=Array.isArray(a)?a:[a];if(s&&Object.keys(e).forEach((a=>{
r.test(a)&&(e[a]=void 0)})),o.concat(n).forEach((a=>{if(-1===a.indexOf("/")||r.test(a))e[a]=void 0;else{
const s=a.split("/");s[1]&&(e[s[0]][s[1]]=void 0)}})),!/\.json$/.test(t)){const e=[...t].pop()
;t="/"===e||"\\"===e?t+"package.json":`${t}/package.json`}utils.writeTextUTF8(JSON.stringify(e,null,2),t)
}else help("ERROR: package.json not found")}organizePackageJson();
const s=params.k||params.keys||[],a=params.p||params.prod
;if(!a&&isInvalidValue(s,"ERROR: \"-keys\" parameter must be required"))return;let t=params.o||params.out
;if(!t&&a&&(t="./dist/"),isInvalidValue(t,"ERROR: \"-out\" parameter must be required"))return
;const r=params.kd||params.keepDevs||[],n=Array.isArray(r)?r:[r],i=a?n.length?["scripts"]:["scripts","devDependencies"]:[],o=/^\/\//
;a&&Object.keys(e).forEach((s=>{o.test(s)&&(e[s]=void 0)}));if((Array.isArray(s)?s:[s]).concat(i).forEach((s=>{
if(-1===s.indexOf("/")||o.test(s))e[s]=void 0;else{const a=s.split("/");a[1]&&(e[a[0]][a[1]]=void 0)}})),n.length){
const s=e.devDependencies;Object.keys(s).forEach((e=>{n.includes(e)||(s[e]=void 0)}))}if(!/\.json$/.test(t)){
const e=[...t].pop();t="/"===e||"\\"===e?t+"package.json":`${t}/package.json`}
utils.writeTextUTF8(JSON.stringify(e,null,2),t)}else help("ERROR: package.json not found")}organizePackageJson();
{
"name": "organize-pkg",
"description": "very simple package.json organizer",
"version": "1.2.4",
"version": "1.3.0",
"bin": {

@@ -6,0 +6,0 @@ "orgpkg": "index.js",

@@ -17,2 +17,16 @@ ![MIT](https://img.shields.io/badge/license-MIT-brightgreen)

## flags
+ `-prod|-p` {boolean} - apply production output. can omit `-out|-o` option. (output to ./dist)
+ `-keys|-k` - should be remove keys.
+ `-out|-o` - specify output path if need.
+ `-keepDevs|-kd` - If necessary, specify the key name to be retained in `devDependencies`. valid with `-prod|-p` flag. (version `1.3.0`)
```shell
# keep `devDependencies/some-enteyName` and `devDependencies/some-enteyName2`
orgpkg -kd "some-enteyName,some-enteyName2" -p
# or
# keep `devDependencies/some-enteyName`
orgpkg -kd some-enteyName -p
```
## usage

@@ -42,6 +56,4 @@

* Since version `1.2.1`, __shorthand option__ is available.
+ `-p` same as `-prod`
+ `-k` same as `-keys`
+ `-o` same as `-out`
```shell

@@ -48,0 +60,0 @@ # file name is output as "./dist/package.json"

@@ -8,3 +8,3 @@ /*!

*/
const fs=require("fs"),path=require("path"),ArgsConfig={startIndex:2,prefix:"-"};function gea(e,t=ArgsConfig){
const fs=require("fs"),path=require("path"),ArgsConfig={startIndex:2,prefix:"-"};function gea(e,t){
const r=t.prefix.length,n=new RegExp(`^${t.prefix}\\w+`),s={};for(let o=0;o<e.length;){const i=e[o++];if(i&&n.test(i)){

@@ -15,3 +15,3 @@ let n=e[o];void 0===n||n.startsWith(t.prefix)?n=!0:(/,/.test(n)&&(n=n.split(",")),o++),s[i.substring(r)]=n}}return s}

function checkParentDirectory(e){const t=path.dirname(e);fs.existsSync(t)||fs.mkdirSync(t,{recursive:!0})}
function writeTextUTF8(e,t,r=null){checkParentDirectory(t);const n=fs.createWriteStream(t);n.on("error",(function(e){
function writeTextUTF8(e,t,r){checkParentDirectory(t);const n=fs.createWriteStream(t);n.on("error",(function(e){
console.log(e)})).on("close",(function(){console.log("[close] %s, stream closed",t),r&&r()}));const s=n.write(e)

@@ -18,0 +18,0 @@ ;console.log("write: %s,",t,s),s?r&&r():n.once("drain",(function(){

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc