organize-pkg
Advanced tools
Comparing version 1.2.3 to 1.2.4
13
index.js
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
*/ | ||
const utils=require("./utils"),params=utils.getExtraArgs(),cliName="organize-pkg";function help(e=cliName+" usage"){ | ||
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){ | ||
@@ -16,6 +16,7 @@ return void 0===e||0===e.length?(help(a),1):0}function organizePackageJson(){let e;try{ | ||
;if(!s&&isInvalidValue(a,"ERROR: \"-keys\" parameter must be required"))return;let t=params.o||params.out | ||
;if(isInvalidValue(t,"ERROR: \"-out\" parameter must be required"))return | ||
;const n=s?["scripts","devDependencies"]:[],r=Array.isArray(a)?a:[a];if(s&&Object.keys(e).forEach(a=>{ | ||
/^\/\//.test(a)&&delete e[a]}),r.concat(n).forEach(a=>{if(-1!==a.indexOf("/")){const s=a.split("/");e[s[0]][s[1]]=void 0 | ||
}else delete e[a]}),!/\.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(); | ||
;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(); |
{ | ||
"name": "organize-pkg", | ||
"description": "very simple package.json organizer", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"bin": { | ||
@@ -6,0 +6,0 @@ "orgpkg": "index.js", |
@@ -1,3 +0,9 @@ | ||
# organize package json (organize-pkg) ![MIT](https://img.shields.io/badge/license-MIT-brightgreen) | ||
![MIT](https://img.shields.io/badge/license-MIT-brightgreen) | ||
[![npm version](https://badge.fury.io/js/organize-pkg.svg)](https://badge.fury.io/js/organize-pkg) | ||
![node](https://img.shields.io/node/v/organize-pkg?style=plastic) | ||
![npm bundle size](https://img.shields.io/bundlephobia/min/organize-pkg?style=plastic) | ||
![npm](https://img.shields.io/npm/dm/organize-pkg?style=plastic) | ||
# organize package json (organize-pkg) | ||
Assists in creating package.json for **production**. | ||
@@ -13,8 +19,20 @@ | ||
``` | ||
```shell | ||
organize-pkg -keys "<key>,<key>,..." -out ./output.json | ||
# or | ||
orgpkg -k "<key>,<key>,..." -out ./output.json | ||
``` | ||
* version `1.2.4`, When specify `-prod|-p` option can omit `-out|-o` option | ||
```shell | ||
# output to "./dist/package.json" | ||
orgpkg -k "dependencies/some-module,bin/organize-pkg" -p | ||
``` | ||
* version `1.2.3`, support command like: `orgpkg -k "dependencies/some-module" -p -o ./dist` | ||
```shell | ||
orgpkg -k "dependencies/some-module,bin/organize-pkg" -p -o ./dist | ||
``` | ||
* version `1.2.2`, synonym command `orgpkg` | ||
``` | ||
```shell | ||
orgpkg -p -o ./output.json [-k "<key>,<key>,..."] | ||
@@ -21,0 +39,0 @@ ``` |
27
utils.js
@@ -8,17 +8,14 @@ /*! | ||
*/ | ||
const fs=require("fs"),path=require("path"),ArgsConfig={startIndex:2,prefix:"-"} | ||
;function gea(args,args_config=ArgsConfig){ | ||
const varIndex=args_config.prefix.length,re=new RegExp(`^${args_config.prefix}\\w+`),params={} | ||
;for(let index=0;index<args.length;){const opt=args[index++];if(opt&&re.test(opt)){let value=args[index] | ||
;void 0===value||value.startsWith(args_config.prefix)?value=!0:(/\[.+\]/.test(value)||/^\/[^/]+\/[gimuy]{0,5}/.test(value)?value=eval(value):/,/.test(value)&&(value=value.split(",")), | ||
index++),params[opt.substring(varIndex)]=value}}return params}function getExtraArgs(e,r=!1){ | ||
return r&&console.log("process.argv: ",process.argv),e=e||{},e=Object.assign(ArgsConfig,e), | ||
process.argv.length>e.startIndex?gea(process.argv.slice(e.startIndex),e):{}}function checkParentDirectory(e){ | ||
const r=path.dirname(e);fs.existsSync(r)||fs.mkdirSync(r,{recursive:!0})}function writeTextUTF8(e,r,t=null){ | ||
checkParentDirectory(r);const n=fs.createWriteStream(r);n.on("error",(function(e){console.log(e) | ||
})).on("close",(function(){console.log("[close] %s, stream closed",r),t&&t()}));const s=n.write(e) | ||
;console.log("write: %s,",r,s),s?t&&t():n.once("drain",(function(){ | ||
console.log("[drain] file written: %s,",r,n.bytesWritten),n.end()}))}function readTextUTF8(e,r){ | ||
if("function"!=typeof r)return fs.readFileSync(e,"utf8");fs.readFile(e,"utf8",r)}function readJson(e,r){ | ||
if("function"!=typeof r){const r=readTextUTF8(e);return JSON.parse(r)}readTextUTF8(e,(e,t)=>{r(e,JSON.parse(t))})} | ||
const fs=require("fs"),path=require("path"),ArgsConfig={startIndex:2,prefix:"-"};function gea(e,t=ArgsConfig){ | ||
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)){ | ||
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 getExtraArgs(e,t=!1){return t&&console.log("process.argv: ",process.argv),e=e||{}, | ||
e=Object.assign(ArgsConfig,e),process.argv.length>e.startIndex?gea(process.argv.slice(e.startIndex),e):{}} | ||
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){ | ||
console.log(e)})).on("close",(function(){console.log("[close] %s, stream closed",t),r&&r()}));const s=n.write(e) | ||
;console.log("write: %s,",t,s),s?r&&r():n.once("drain",(function(){ | ||
console.log("[drain] file written: %s,",t,n.bytesWritten),n.end()}))}function readTextUTF8(e,t){ | ||
if("function"!=typeof t)return fs.readFileSync(e,"utf8");fs.readFile(e,"utf8",t)}function readJson(e,t){ | ||
if("function"!=typeof t){const t=readTextUTF8(e);return JSON.parse(t)}readTextUTF8(e,((e,r)=>{t(e,JSON.parse(r))}))} | ||
module.exports={getExtraArgs,writeTextUTF8,readTextUTF8,readJson}; |
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
6881
85
0
38