comment-eraser
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -1,1 +0,1 @@ | ||
const fs=require("fs-extra"),chalk=require("chalk"),readline=require("readline"),performance=require("perf_hooks")["performance"],Report=require("./lib/Report"),Prelog=require("./lib/Prelog"),{eraseComments,getLangPatterns}=require("./lib/utils"),loadConfig=require("./lib/utils/configUtils")["loadConfig"],{getFilePath,getFilePaths,removeEmptyDir}=require("./lib/utils/fileUtils"),patterns=getLangPatterns("js"),rl=readline.createInterface({input:process.stdin,output:process.stdout}),processFile=(e,r)=>{var t=performance.now(),{pattern:r,writeToOutput:s,replace:o,outputDir:i,postfix:n,excludePatterns:a}=r,l=fs.readFileSync(e,"utf-8"),i=getFilePath(e,i,n),[n,l]=eraseComments({code:l,pattern:r,excludePatterns:a}),r=(s&&(o?fs.writeFileSync(e,n):fs.writeFileSync(i,n)),performance.now());return{filePath:e,outputPath:i,commentsRemoved:n,removedCharsCount:l,elapsedTime:r-t}},processFiles=(e,r)=>{const t=new Report;return e.forEach(e=>{e=processFile(e,r);t.append(e)}),t},interactiveProcessFiles=(e,r)=>{const t=new Report;var s=`Edit ${chalk.bold.blue(e.fileName)} and then press enter to continue`;return rl.question(s,()=>{e.readLines().forEach(e=>{e=processFile(e,r);t.append(e)}),rl.close()}),t},eraseFromString=(e,r={})=>{var t=performance.now(),{type:r="both",excludePatterns:s=[],output:o=void 0}=r,r=patterns[r];let i=null;var[e,r]=eraseComments({code:e,pattern:r,excludePatterns:s}),s=(o&&({path:s="",file:o="output.js",append:n=!1}=o,o=getFilePath(o,s),s&&fs.mkdirsSync(s,{recursive:!0}),fs.writeFileSync(o,e,{flag:n?"a":"w"}),i=o),performance.now()),n=Report.formatElapsedTime(s-t);return[e,r,i,n]},erase=()=>{var e=loadConfig();const{type:r,include:t,exclude:s,writeToOutput:o,outputDir:i,postfix:n,interactive:a}=e;e.pattern=patterns[r],o&&fs.emptyDirSync(i),process.on("exit",()=>removeEmptyDir(i));var l=getFilePaths(t,s,n);if(!a){console.time(chalk.bold.green("erased")),rl.close();const c=processFiles(l,e);return c.print(),c.logs}{var p=new Prelog;p.writeLines(l);const c=interactiveProcessFiles(p,e);void rl.on("close",()=>c.print(a))}};module.exports={erase:erase,eraseFromString:eraseFromString}; | ||
const fs=require("fs-extra"),chalk=require("chalk"),readline=require("readline"),performance=require("perf_hooks")["performance"],Report=require("./lib/Report"),Prelog=require("./lib/Prelog"),{eraseComments,getLangPatterns}=require("./lib/utils"),loadConfig=require("./lib/utils/configUtils")["loadConfig"],{getFilePath,getFilePaths,removeEmptyDir}=require("./lib/utils/fileUtils"),patterns=getLangPatterns("js"),rl=readline.createInterface({input:process.stdin,output:process.stdout}),processFile=(e,r)=>{var t=performance.now(),{pattern:r,writeToOutput:s,replace:o,outputDir:i,postfix:n,excludePatterns:a}=r,l=fs.readFileSync(e,"utf-8"),i=getFilePath(e,i,n),[n,l]=eraseComments({code:l,pattern:r,excludePatterns:a}),r=(s&&(o?fs.writeFileSync(e,n):fs.writeFileSync(i,n)),performance.now());return{filePath:e,outputPath:i,commentsRemoved:n,removedCharsCount:l,elapsedTime:r-t}},processFiles=(e,r)=>{const t=new Report;return e.forEach(e=>{e=processFile(e,r);t.append(e)}),t},interactiveProcessFiles=(e,r)=>{const t=new Report;var s=`Edit ${chalk.bold.blue(e.fileName)} and then press enter to continue`;return rl.question(s,()=>{e.readLines().forEach(e=>{e=processFile(e,r);t.append(e)}),rl.close()}),t},eraseFromString=(e,r={})=>{var t=performance.now(),{type:r="both",excludePatterns:s=[],output:o=void 0}=r,r=patterns[r];let i=null;var[e,r]=eraseComments({code:e,pattern:r,excludePatterns:s}),s=(o&&({path:s="",file:o="output.js",append:n=!1}=o,o=getFilePath(o,s),s&&fs.mkdirsSync(s,{recursive:!0}),fs.writeFileSync(o,e,{flag:n?"a":"w"}),i=o),performance.now()),n=Report.formatElapsedTime(s-t);return[e,r,i,n]},erase=(e="eraser.config.json")=>{e=loadConfig(e);const{type:r,include:t,exclude:s,writeToOutput:o,outputDir:i,postfix:n,interactive:a}=e;e.pattern=patterns[r],o&&fs.emptyDirSync(i),process.on("exit",()=>removeEmptyDir(i));var l=getFilePaths(t,s,n);if(!a){console.time(chalk.bold.green("erased")),rl.close();const p=processFiles(l,e);return p.print(),p.logs}{var c=new Prelog;c.writeLines(l);const p=interactiveProcessFiles(c,e);void rl.on("close",()=>p.print(a))}};erase("test.config.json"),module.exports={erase:erase,eraseFromString:eraseFromString}; |
@@ -1,1 +0,1 @@ | ||
const fs=require("fs"),DEFAULT_CONFIG={type:"both",include:["./**/*"],exclude:[],writeToOutput:!0,replace:!1,outputDir:"no-comments",postfix:"-no-comments",excludePatterns:[],interactive:!1},checkAndSetConfig=e=>{if(!Array.isArray(e.include)){if("string"!=typeof e.include)throw new Error('"include" must be an array');e.include=[e.include]}},loadConfig=()=>{let e;try{e=JSON.parse(fs.readFileSync("eraser.config.json","utf-8"))}catch(e){return DEFAULT_CONFIG}return e={...DEFAULT_CONFIG,...e},checkAndSetConfig(e),e};module.exports={loadConfig:loadConfig}; | ||
const fs=require("fs"),DEFAULT_CONFIG={type:"both",include:["./**/*"],exclude:[],writeToOutput:!0,replace:!1,outputDir:"no-comments",postfix:"-no-comments",excludePatterns:[],interactive:!1},checkAndSetConfig=e=>{if(!Array.isArray(e.include)){if("string"!=typeof e.include)throw new Error('"include" must be an array');e.include=[e.include]}},loadConfig=(e="eraser.config.json")=>{let n={};return fs.existsSync(e)&&(n=JSON.parse(fs.readFileSync(e,"utf-8"))),n={...DEFAULT_CONFIG,...n},checkAndSetConfig(n),n};module.exports={loadConfig:loadConfig}; |
{ | ||
"name": "comment-eraser", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"main": "build/index.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12597