New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@allcapsdev/cvcsv-cli

Package Overview
Dependencies
Maintainers
1
Versions
227
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@allcapsdev/cvcsv-cli - npm Package Compare versions

Comparing version 1.1.38 to 1.1.39

2

CHANGELOG.md

@@ -5,2 +5,4 @@ # Changelog

### [1.1.39](https://github.com/allcapsdev/cvcsv-cli/compare/v1.1.38...v1.1.39) (2020-06-05)
### [1.1.38](https://github.com/allcapsdev/cvcsv-cli/compare/v1.1.37...v1.1.38) (2020-06-04)

@@ -7,0 +9,0 @@

2

lib/index.js

@@ -16,2 +16,2 @@ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("fs"),i=e(t),o=e(require("path")),r=require("kleur"),s=e(require("prompts")),c=e(require("figlet")),a=require("csv-writer"),n=e(require("globby"));

***************************************************************************** */
function l(e,t,i,o){return new(i||(i=Promise))((function(r,s){function c(e){try{n(o.next(e))}catch(e){s(e)}}function a(e){try{n(o.throw(e))}catch(e){s(e)}}function n(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(c,a)}n((o=o.apply(e,t||[])).next())}))}const u={name:"rootDirectory",type:"text",message:""+r.blue("Enter the root directory: "),initial:"./",validate:e=>!!i.existsSync(e)||"😱 Sorry! The directory doesn't exist, please try again"},d={name:"bucketName",type:"text",message:""+r.blue("Enter the name of the Storage Bucket where the images are stored: "),initial:"gcp-storage-bucket"};var g;!function(e){e.HOMEGOODS="homegoods-v2",e.APPAREL="apparel-v2",e.TOYS="toys-v2",e.PACKAGEDGOODS="packagedgoods-v1"}(g||(g={}));const h=[{title:"apparel",value:g.APPAREL},{title:"home goods",value:g.HOMEGOODS},{title:"packaged goods",value:g.PACKAGEDGOODS},{title:"toys",value:g.TOYS}],p={name:"productCategory",type:"select",message:""+r.blue("Which product category are these images for?"),choices:h},f={name:"productSet",type:"text",message:""+r.blue("Enter the product set id: "),initial:"test-product-set"},y={name:"csvFileLocation",type:"text",message:""+r.blue("Where would you like the csv file to be output?"),initial:"./",validate:e=>!!i.existsSync(e)||"😱 Sorry! That location doesn't exist, please try again"},v={name:"csvFilename",type:"text",message:""+r.blue("What would you like the output file to be called?"),initial:"images.csv"};let m=(()=>{class e{static readFile(){return l(this,void 0,void 0,(function*(){const e=o.join(process.cwd(),".cvcsvrc");if(t.existsSync(e))try{const i=t.readFileSync(e,"utf-8");return JSON.parse(i)}catch(e){throw Error(e)}return null}))}static completeConfig(e){return l(this,void 0,void 0,(function*(){const t=Object.keys(e),i=[this.configKeys,t].reduce((e,t)=>e.filter(e=>!t.includes(e))).map(e=>this.configQuestions[e]);if(0===i.length)return yield Promise.resolve(e);const o=yield s(i);return Object.assign(Object.assign({},o),e)}))}}return e.configKeys=["bucketName","csvFileLocation","csvFilename","productCategory","productSet","rootDirectory"],e.configQuestions={bucketName:d,csvFileLocation:y,csvFilename:v,productCategory:p,productSet:f,rootDirectory:u},e})();var b;!function(e){e.TITLE="CV CSV",e.BANNER="Generate the csv for the Google Cloud Vision Product Search API",e.ERROR="ERROR: ",e.DONE="DONE"}(b||(b={}));class O{static showTitleAndBanner(){this.log(`${r.bold().blue(c.textSync(b.TITLE,{font:"Graffiti"}))}\n\n${r.blue(b.BANNER)}\n\n`)}static success(e){const t=e>1?"files":"file";this.log(`\n\n${r.bold().bgWhite().blue(`Added ${e} ${t} to your CSV file.`)}\n${r.bold().blue(c.textSync(b.DONE,{font:"Graffiti"}))}`)}static error(e){this.log(r.bold().red(`${b.ERROR}${e}`),!0),process.exit(1)}static log(e,t){console[t?"error":"log"](e)}}(class{static run(){return l(this,void 0,void 0,(function*(){O.showTitleAndBanner(),yield this.getConfig(),this.data=yield this.buildData(),this.file=yield this.writeToFile(),this.file&&this.data&&O.success(this.data.length)}))}static getConfig(){return l(this,void 0,void 0,(function*(){const e=yield m.readFile();let t;t=null===e?yield s(Object.values(m.configQuestions)):yield m.completeConfig(e),t.rootDirectory=this.formatDirectory(t.rootDirectory),t.csvFileLocation=this.formatDirectory(t.csvFileLocation),this.config=t}))}static formatDirectory(e){return e.match(/\/$/)?e:e+"/"}static formatRootDir(e){return e.match(/^\.\//)?e.replace("./",""):e}static buildData(){return l(this,void 0,void 0,(function*(){const{bucketName:e,rootDirectory:t,productCategory:i,productSet:r}=this.config,s=yield(c=t,l(void 0,void 0,void 0,(function*(){const e=c||"./";return yield n(e,{expandDirectories:{files:["*"],extensions:["jpg","jpeg","png"]}})})));var c;if(s.length<1)throw Error("No images");const a=[];return s.forEach(s=>{const c=o.basename(s),n=s.replace(this.formatRootDir(t),""),l=n.replace(/\/|_/g," ").replace(c,"").replace(/\w+/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).trim(),u=l.replace(/\s/g,"").toUpperCase(),d=`gs://${e}/images/${n}`,g=n.replace(c,"").split(/\//).filter(e=>""!==e).map(e=>"tag="+e).toString();a.push({"image-uri":d,"product-id":u,"product-display-name":l,"product-category":i,"product-set-id":r,labels:g})}),a}))}static writeToFile(){return l(this,void 0,void 0,(function*(){const e=o.join(this.config.csvFileLocation,this.config.csvFilename),t=a.createObjectCsvWriter({path:e,header:["image-uri","image-id","product-set-id","product-id","product-category","product-display-name","labels","bounding-poly"]});try{return yield t.writeRecords(this.data),!0}catch(e){throw new Error(e)}}))}}).run();
function l(e,t,i,o){return new(i||(i=Promise))((function(r,s){function c(e){try{n(o.next(e))}catch(e){s(e)}}function a(e){try{n(o.throw(e))}catch(e){s(e)}}function n(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(c,a)}n((o=o.apply(e,t||[])).next())}))}const u={name:"rootDirectory",type:"text",message:""+r.blue("Enter the root directory: "),initial:"./",validate:e=>!!i.existsSync(e)||"😱 Sorry! The directory doesn't exist, please try again"},d={name:"bucketName",type:"text",message:""+r.blue("Enter the name of the Storage Bucket where the images are stored: "),initial:"gcp-storage-bucket"};var g;!function(e){e.HOMEGOODS="homegoods-v2",e.APPAREL="apparel-v2",e.TOYS="toys-v2",e.PACKAGEDGOODS="packagedgoods-v1"}(g||(g={}));const h=[{title:"apparel",value:g.APPAREL},{title:"home goods",value:g.HOMEGOODS},{title:"packaged goods",value:g.PACKAGEDGOODS},{title:"toys",value:g.TOYS}],p={name:"productCategory",type:"select",message:""+r.blue("Which product category are these images for?"),choices:h},f={name:"productSet",type:"text",message:""+r.blue("Enter the product set id: "),initial:"test-product-set"},y={name:"csvFileLocation",type:"text",message:""+r.blue("Where would you like the csv file to be output?"),initial:"./",validate:e=>!!i.existsSync(e)||"😱 Sorry! That location doesn't exist, please try again"},v={name:"csvFilename",type:"text",message:""+r.blue("What would you like the output file to be called?"),initial:"images.csv"};class m{static readFile(){return l(this,void 0,void 0,(function*(){const e=o.join(process.cwd(),".cvcsvrc");if(t.existsSync(e))try{const i=t.readFileSync(e,"utf-8");return JSON.parse(i)}catch(e){throw Error(e)}return null}))}static completeConfig(e){return l(this,void 0,void 0,(function*(){const t=Object.keys(e),i=[this.configKeys,t].reduce((e,t)=>e.filter(e=>!t.includes(e))).map(e=>this.configQuestions[e]);if(0===i.length)return yield Promise.resolve(e);const o=yield s(i);return Object.assign(Object.assign({},o),e)}))}}var b;m.configKeys=["bucketName","csvFileLocation","csvFilename","productCategory","productSet","rootDirectory"],m.configQuestions={bucketName:d,csvFileLocation:y,csvFilename:v,productCategory:p,productSet:f,rootDirectory:u},function(e){e.TITLE="CV CSV",e.BANNER="Generate the csv for the Google Cloud Vision Product Search API",e.ERROR="ERROR: ",e.DONE="DONE"}(b||(b={}));class O{static showTitleAndBanner(){this.log(`${r.bold().blue(c.textSync(b.TITLE,{font:"Graffiti"}))}\n\n${r.blue(b.BANNER)}\n\n`)}static success(e){const t=e>1?"files":"file";this.log(`\n\n${r.bold().bgWhite().blue(`Added ${e} ${t} to your CSV file.`)}\n${r.bold().blue(c.textSync(b.DONE,{font:"Graffiti"}))}`)}static error(e){this.log(r.bold().red(`${b.ERROR}${e}`),!0),process.exit(1)}static log(e,t){console[t?"error":"log"](e)}}(class{static run(){return l(this,void 0,void 0,(function*(){O.showTitleAndBanner(),yield this.getConfig(),this.data=yield this.buildData(),this.file=yield this.writeToFile(),this.file&&this.data&&O.success(this.data.length)}))}static getConfig(){return l(this,void 0,void 0,(function*(){const e=yield m.readFile();let t;t=null===e?yield s(Object.values(m.configQuestions)):yield m.completeConfig(e),t.rootDirectory=this.formatDirectory(t.rootDirectory),t.csvFileLocation=this.formatDirectory(t.csvFileLocation),this.config=t}))}static formatDirectory(e){return e.match(/\/$/)?e:e+"/"}static formatRootDir(e){return e.match(/^\.\//)?e.replace("./",""):e}static buildData(){return l(this,void 0,void 0,(function*(){const{bucketName:e,rootDirectory:t,productCategory:i,productSet:r}=this.config,s=yield(c=t,l(void 0,void 0,void 0,(function*(){const e=c||"./";return yield n(e,{expandDirectories:{files:["*"],extensions:["jpg","jpeg","png"]}})})));var c;if(s.length<1)throw Error("No images");const a=[];return s.forEach(s=>{const c=o.basename(s),n=s.replace(this.formatRootDir(t),""),l=n.replace(/\/|_/g," ").replace(c,"").replace(/\w+/g,e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).trim(),u=l.replace(/\s/g,"").toUpperCase(),d=`gs://${e}/images/${n}`,g=n.replace(c,"").split(/\//).filter(e=>""!==e).map(e=>"tag="+e).toString();a.push({"image-uri":d,"product-id":u,"product-display-name":l,"product-category":i,"product-set-id":r,labels:g})}),a}))}static writeToFile(){return l(this,void 0,void 0,(function*(){const e=o.join(this.config.csvFileLocation,this.config.csvFilename),t=a.createObjectCsvWriter({path:e,header:["image-uri","image-id","product-set-id","product-id","product-category","product-display-name","labels","bounding-poly"]});try{return yield t.writeRecords(this.data),!0}catch(e){throw new Error(e)}}))}}).run();
{
"name": "@allcapsdev/cvcsv-cli",
"version": "1.1.38",
"version": "1.1.39",
"description": "CLI for creating CSV for Cloud Vision Product Search API",

@@ -60,3 +60,3 @@ "main": "lib/index.js",

"@types/jest": "25.2.3",
"@types/node": "14.0.10",
"@types/node": "14.0.11",
"@types/prompts": "2.0.8",

@@ -80,3 +80,3 @@ "babel-loader": "8.1.0",

"typedoc": "0.17.7",
"typescript": "3.9.3"
"typescript": "3.9.5"
},

@@ -83,0 +83,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc