Skip to content

Commit

Permalink
try to package to be importable or run from the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
JKirchartz committed Nov 4, 2017
1 parent 4dbf9e6 commit 5eecc3b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 45 deletions.
52 changes: 52 additions & 0 deletions bin/gleech
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node
'use strict';
/*
* Gleech
* Copyright (C) 2017 jkirchartz <[email protected]>
*
* Distributed under terms of the GPL3.0 license.
*/
var gleech = require('../dist/gleech.js');
var cmdr = require('commander');
var pkg = require('../package.json');

cmdr
.command('glitch <input> <output> [operation] [parameters...]')
.description('Glitches an image with optional type and parameters')
.action(function(input, output, operation, parameters) {
gleech.read(input, function(err, image) {
if (operation && parameters) {
image[operation].apply(this, parameters);
} else if (operation && !parameters) {
image[operation]();
} else {
console.log("please provide a function name");
}
image.write(output);
});
});

cmdr.command('list')
.description('Lists available functions')
.action(function() {
var output = "";
output += ('\nGlitches:\n\n');
for (var prop in gleech.prototype) {
if (typeof gleech.prototype[prop] === 'function' &&
gleech.prototype[prop].name){
output += gleech.prototype[prop].name + ' ';
}
}
output += ('\n\nJimp functions:\n\n');
for (var prop2 in gleech.prototype) {
if (typeof gleech.prototype[prop2] === 'function' &&
! gleech.prototype[prop2].name){
output += String(prop2) + ' ';
}
}
console.log(output);
});

cmdr.version(pkg.version)
.description(pkg.description)
.parse(process.argv);
48 changes: 3 additions & 45 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
#!/usr/bin/env node
'use strict';
/*
* Gleech
* index.js
* Copyright (C) 2017 jkirchartz <[email protected]>
*
* Distributed under terms of the GPL3.0 license.
* Distributed under terms of the NPL (Necessary Public License) license.
*/
var gleech = require('./dist/gleech.js');
var cmdr = require('commander');

cmdr
.command('glitch <input> <output> [operation] [parameters...]')
.description('Glitches an image with optional type and parameters')
.action(function(input, output, operation, parameters) {
gleech.read(input, function(err, image) {
if (operation && parameters) {
image[operation].apply(this, parameters);
} else if (operation && !parameters) {
image[operation]();
} else {
console.log("please provide a function name");
}
image.write(output);
});
});

cmdr.command('list')
.description('Lists available functions')
.action(function() {
var output = "";
output += ('\nGlitches:\n\n');
for (var prop in gleech.prototype) {
if (typeof gleech.prototype[prop] === 'function' &&
gleech.prototype[prop].name){
output += gleech.prototype[prop].name + ' ';
}
}
output += ('\n\nJimp functions:\n\n');
for (var prop2 in gleech.prototype) {
if (typeof gleech.prototype[prop2] === 'function' &&
! gleech.prototype[prop2].name){
output += String(prop2) + ' ';
}
}
console.log(output);
});

cmdr.version('0.1.0').parse(process.argv);
module.exports = require('./dist/gleech');
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"description": "Image glitching & dithering in NodeJS",
"main": "index.js",
"bin": "./bin/gleech",
"contributors": [
{
"name": "Nolan Caudill",
Expand Down

0 comments on commit 5eecc3b

Please sign in to comment.