comment-eraser
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -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,replace:s,outputDir:i,postfix:o,excludePatterns:n}=r,a=fs.readFileSync(e,"utf-8"),i=getFilePath(i,e,o),[o,a]=eraseComments({code:a,pattern:r,excludePatterns:n}),r=(s?fs.writeFileSync(e,o):fs.writeFileSync(i,o),performance.now());return{filePath:e,outputPath:i,removedChars:a,commentsRemoved:o,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:i=void 0}=r,r=patterns[r];let o=null;var[e,r]=eraseComments({code:e,pattern:r,excludePatterns:s}),s=(i&&({path:s="cms-rm-1/cms-rm-2/cms-rm-3",file:i="output.js"}=i,i=getFilePath(i,s),s&&fs.mkdirsSync(s,{recursive:!0}),fs.writeFileSync(i,e),o=i),performance.now()),i=Report.formatElapsedTime(s-t);return[e,r,o,i]},erase=()=>{var e=loadConfig();const{type:r,include:t,exclude:s,outputDir:i,postfix:o,interactive:n}=e;e.pattern=patterns[r],fs.emptyDirSync(i),process.on("exit",()=>removeEmptyDir(i));var a=getFilePaths(t,s,o);if(n){var l=new Prelog;l.writeLines(a);const c=interactiveProcessFiles(l,e);void rl.on("close",()=>c.print(n))}else{console.time(chalk.bold.green("erased")),rl.close();const c=processFiles(a,e);c.print()}};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=()=>{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}; |
@@ -1,1 +0,1 @@ | ||
const chalk=require("chalk");class Report{constructor(t="erased"){this.label=chalk.bold.green(t),this.logs=[]}print(t){console[t?"log":"timeEnd"](this.label),this.logs.length&&console.table(this.logs)}append(t){this.logs.push(this.formatLog(t))}formatLog(t){return delete t.commentsRemoved,t.removedChars=[t.removedChars.toLocaleString(),t.removedChars],t.elapsedTime=Report.formatElapsedTime(t.elapsedTime),t}static formatElapsedTime(t){var e=Math.floor(t/36e5),o=Math.floor(t/6e4%60),r=Math.floor(t/1e3%60),t=Math.floor(t%1e3);return[e.toString().padStart(2,"0"),o.toString().padStart(2,"0"),r.toString().padStart(2,"0"),t.toString().padStart(3,"0")].join(":")}}module.exports=Report; | ||
const chalk=require("chalk");class Report{constructor(t="erased"){this.label=chalk.bold.green(t),this.logs=[],this.formattedLogs=[]}print(t){console[t?"log":"timeEnd"](this.label),this.logs.length&&console.table(this.formattedLogs)}append(t){this.logs.push(t),this.formattedLogs.push(this.formatLog(t))}formatLog(t){return delete t.commentsRemoved,t.removedCharsCount=[t.removedCharsCount.toLocaleString(),t.removedCharsCount],t.elapsedTime=Report.formatElapsedTime(t.elapsedTime),t}static formatElapsedTime(t){var o=Math.floor(t/36e5),e=Math.floor(t/6e4%60),r=Math.floor(t/1e3%60),t=Math.floor(t%1e3);return[o.toString().padStart(2,"0"),e.toString().padStart(2,"0"),r.toString().padStart(2,"0"),t.toString().padStart(3,"0")].join(":")}}module.exports=Report; |
@@ -1,1 +0,1 @@ | ||
const fs=require("fs"),DEFAULT_CONFIG={type:"both",include:["./**/*"],exclude:[],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=()=>{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}; |
{ | ||
"name": "comment-eraser", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
12468