aseprite-cli
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -26,3 +26,3 @@ const childProcess = require('child_process'); | ||
async exec(args) { | ||
async exec(...args) { | ||
const path = await this.binPath(); | ||
@@ -32,3 +32,3 @@ return this.raw(path, this.flattenArgs(args)); | ||
execSync(args) { | ||
execSync(...args) { | ||
const path = this.binPathSync(); | ||
@@ -104,6 +104,18 @@ return this.rawSync(path, this.flattenArgs(args)); | ||
flattenArgs(args) { | ||
let source; | ||
if (args.length === 1) { | ||
args = args[0]; | ||
} else if (args.length === 2) { | ||
source = args[0]; | ||
args = args[1]; | ||
} else if (args.length > 2) { | ||
throw new Error('Invalid arguments: pass (string, array/object/string) or (array/object/string): ' + args); | ||
} | ||
if (Array.isArray(args)) { | ||
args = ['--batch'].concat(args); | ||
if (source) args.unshift(source); | ||
args.unshift('--batch'); | ||
} else if (typeof args === 'object') { | ||
args = ['--batch'].concat(Object.entries(args).reduce((out, [key, value]) => { | ||
args = Object.entries(args).reduce((out, [key, value]) => { | ||
if (!key.startsWith('--')) { | ||
@@ -114,5 +126,9 @@ key = '--' + key.replace(/([A-Z])/g, (_, char) => `-${char.toLowerCase()}`); | ||
return out; | ||
}, [])); | ||
}, []); | ||
if (source) args.unshift(source); | ||
args.unshift('--batch'); | ||
} else { | ||
args = '--batch ' + String(args); | ||
args = String(args); | ||
if (source) args = `${source} ${args}`; | ||
args = `--batch ${args}`; | ||
} | ||
@@ -119,0 +135,0 @@ return args; |
{ | ||
"name": "aseprite-cli", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Simple wrapper for the Aseprite CLI", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,8 +34,7 @@ # aseprite-cli | ||
await Aseprite.exec( | ||
'*.aseprite', | ||
await Aseprite.exec('*.aseprite', [ | ||
'--sheet-type', 'packed', | ||
'--sheet', 'out.png', | ||
'--data', 'out.json' | ||
); | ||
]); | ||
// => Aseprite --batch *.aseprite --sheet-type packed --sheet out.png --data out.json | ||
@@ -42,0 +41,0 @@ ``` |
8982
131
114