Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Usage: cloudTool [options] [command]
list|s [options] Search files and list them
rename|r <public_id_old> <public_id_new> Remane your public_id
delete|d [options] <public_id> Delete your file(s)
transform|t <transformation_name> <transformation_string> Create a transformation

```

Run `cloudTool <command> -h` to see particular commands usage
Expand All @@ -53,6 +55,12 @@ Run `cloudTool <command> -h` to see particular commands usage
**Multiple files**
- `cloudTool u -a <path to file1> <path to file2> <path to file3> ...`

```
Options:

-f, --folder upload to a specific folder on cloudinary

```
# How to fetch

**Help command**
Expand Down Expand Up @@ -90,3 +98,8 @@ Options:

**Multiple files**
- `cloudTool d -a <public_id1> <public_id3> <public_id3> ...`

# How to create a transformation

`cloudTool transform <transformation_name> <transformation_string>`
e.g. `cloudTool transform boximg w_220,h_140,c_fill`
13 changes: 13 additions & 0 deletions config/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const cloudinary = require('./configCloudinary')

function createTransform (name, parameters, next) {
cloudinary.v2.api.create_transformation(name, parameters, (error, result) => {
if (error) {
return console.log(error)
} else {
console.log(`transformation ${name} created!`)
}
return next
})
}
module.exports = createTransform
4 changes: 2 additions & 2 deletions config/upload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cloudinary = require('./configCloudinary')

function upload (data, next) {
function upload (data, next, options) {
data.forEach(filePath => {
cloudinary.uploader.upload(filePath, (result, next) => {
if (result.error) {
Expand All @@ -13,7 +13,7 @@ height: ${result.height}
url: ${result.url || result.secure_url}`)
}
return next
})
}, options)
})
}

Expand Down
28 changes: 26 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const upload = require('./config/upload')
const search = require('./config/search')
const update = require('./config/update')
const deleteFile = require('./config/delete')
const createTransform = require('./config/transform')
const program = require('commander')
const {prompt} = require('inquirer')

Expand Down Expand Up @@ -86,15 +87,20 @@ program
.command('upload <file>')
.alias('u')
.description('Upload file(s)')
.option('-f, --folder <folder>', 'upload to the following folder on cloudinary')
.option('-a, --array', 'Upload more than 1 file')
.action((file, options, next) => {
var uploadOptions = {}
if (options.folder) {
uploadOptions.folder = options.folder
}
if (options.array) {
const array = []
array.push(file, program.args)
const files = array.toString().split(',')
upload(files, next)
upload(files, next, uploadOptions)
} else {
upload([file], next)
upload([file], next, uploadOptions)
}
console.log('Uploading...')
})
Expand Down Expand Up @@ -162,4 +168,22 @@ program
})
})

/**
* Setting command to create a transformation
* @param {String} name:parameters
* e.g. $ cloudTool transform small_fill w_150,h_100,c_fill
*/
program
.command('transform <name> <parameters>')
.alias('t')
.description('create a transformation')
.action((name, parameters, next) => {
if (name && parameters) {
createTransform(name, parameters, next)
} else {
console.log('name and parameter should be defined!')
}
console.log('Creating transformation...')
})

program.parse(process.argv)
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.1",
"description": "Manage images from cloudinary.com using your command line.",
"bin": {
"cloudTool": "index.js"
"cloudTool": "./index.js"
},
"main": "index.js",
"scripts": {
Expand All @@ -18,6 +18,10 @@
"type": "git",
"url": "git+https://github.com/knrt10/cloudinary-cli"
},

"jest": {
"testURL": "http://localhost/"
},
"author": "Kautilya Tripathi <tripathi.kautilya@gmail.com>",
"license": "ISC",
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createTransform successfully create a transformation 1`] = `undefined`;

exports[`delete return error if wrong publicId 1`] = `undefined`;

exports[`delete successfully delete file 1`] = `undefined`;
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const file = require('../config/file')
let upload = require('../config/upload')
let update = require('../config/update')
let deleteFun = require('../config/delete')
let createTransform = require('../config/transform')

describe('env', () => {
const data = {
Expand Down Expand Up @@ -60,3 +61,12 @@ describe('delete', () => {
expect(deleteFun(['oldname'])).toMatchSnapshot()
})
})

describe('createTransform', () => {
it('successfully create a transformation', () => {
createTransform = jest.fn().mockImplementation((name, parameters) => {
console.log('transformation testTransform created!')
})
expect(createTransform('testTransform', 'w_100,h_200')).toMatchSnapshot()
})
})