organize-pkg
Advanced tools
Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "organize-pkg", | ||
"description": "very simple package.json organizer", | ||
"version": "1.2.1", | ||
"bin": "index.js", | ||
"version": "1.2.2", | ||
"bin": { | ||
"orgpkg": "index.js", | ||
"organize-pkg": "index.js" | ||
}, | ||
"files": [ | ||
@@ -7,0 +10,0 @@ "index.js", |
@@ -17,2 +17,7 @@ # organize package json (organize-pkg) ![MIT](https://img.shields.io/badge/license-MIT-brightgreen) | ||
* version `1.2.2`, synonym command `orgpkg` | ||
``` | ||
orgpkg -p -o ./output.json [-k "<key>,<key>,..."] | ||
``` | ||
* Since version `1.2.1`, __shorthand option__ is available. | ||
@@ -19,0 +24,0 @@ + `-p` same as `-prod` |
@@ -9,3 +9,2 @@ /*! | ||
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);if(n.on("error",(function(e){console.log("WriteStream.error evnet!",arguments)})).on("close",(function(){console.log("[close] %s, stream closed",r),t&&t()})),e instanceof Buffer&&(e=e.toString()),"string"==typeof e){const s=n.write(e);console.log("writeTextUTF8: write: %s,",r,s),s?t&&t():n.once("drain",(function(){console.log("[drain] file written: %s,",r,n.bytesWritten),n.end()}))}else"readable"in e&&e.pipe(n)}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))})}module.exports={getExtraArgs,writeTextUTF8,readTextUTF8,readJson}; | ||
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))})}module.exports={getExtraArgs,writeTextUTF8,readTextUTF8,readJson}; |
6187
67
22