Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
kenwheeler committed Aug 29, 2016
0 parents commit 0b92278
Show file tree
Hide file tree
Showing 21 changed files with 941 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .babelrc
@@ -0,0 +1,12 @@
{
"presets": [
"babel-preset-es2015",
"babel-preset-stage-0",
"babel-preset-react",
],
"env": {
"coverage": {
"plugins": [ [ "istanbul", { "ignore": "test" } ] ]
}
}
}
12 changes: 12 additions & 0 deletions .eslintrc
@@ -0,0 +1,12 @@
---
"extends":
- "formidable/configurations/es6-node"
- "formidable/configurations/es6-react"
"env":
"browser": true
"node": true
"mocha": true
"globals":
"expect": true
"rules":
"no-console": 0
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
# dependencies
node_modules

# misc
.DS_Store
npm-debug.log
2 changes: 2 additions & 0 deletions .npmignore
@@ -0,0 +1,2 @@
test
node_modules
76 changes: 76 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,76 @@
# Contributing to victory-cli

## Contributor Covenant Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at lauren.eastridge@formidable.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

### Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
21 changes: 21 additions & 0 deletions LICENSE.md
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015-2016 Formidable Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file added README.md
Empty file.
85 changes: 85 additions & 0 deletions bin/victory-cli.js
@@ -0,0 +1,85 @@
#!/usr/bin/env node
"use strict";

require("babel-register");

const path = require("path");
const commander = require("commander");
const termIMG = require("term-img");

const generatePng = require("../lib/generate-png.js");
const generateSvg = require("../lib/generate-svg.js");
const wrapperComponent = require("../lib/wrapper-component.js");

const program = new commander.Command("victory-cli");

const DEFAULT_DIMENSIONS = 500;

const pkg = require("../package.json");
program.version(pkg.version);
program.option(
"-c, --charttype [charttype]",
"'area', 'bar', 'line', 'scatter' or 'pie'",
"line"
);
program.option("-f, --format [format]", "png' or 'svg'", "png");
program.option("-p, --print", "Prints chart to console (iTerm3 & .png format only!)");
program.option("-h, --h [h]", "Chart height", DEFAULT_DIMENSIONS);
program.option("-w, --w [w]", "Chart width", DEFAULT_DIMENSIONS);
program.option("-x, --x [x]", "Data x value");
program.option("-y, --y [y]", "Data y value");
program.option("-t, --theme [theme]", "'light', 'dark' or 'hacker'", "hacker");

program.usage("[data] [script] [options]");
program.parse(process.argv);

if (!program.args.length) {
program.outputHelp();
return;
}

const cliOptions = {
charttype: program.charttype,
format: program.format,
print: program.print,
height: program.h,
width: program.w,
x: program.x,
y: program.y,
theme: program.theme
};

const DATA_ARG = 0;
const SCRIPT_ARG = 1;

const dataPath = path.join(process.cwd(), program.args[DATA_ARG]);
const data = require(dataPath);

let component;

if (program.args[SCRIPT_ARG] !== undefined) {
const scriptPath = path.join(process.cwd(), program.args[SCRIPT_ARG]);
const script = require(scriptPath);

component = script(data.data, cliOptions);
} else {
component = wrapperComponent(data.data, cliOptions);
}

const SVG = generateSvg(component);

if (cliOptions.format === "svg") {
process.stdout.write(SVG);
} else {
generatePng(SVG, cliOptions)
.then((output) => {
if (cliOptions.print) {
termIMG(output);
} else {
process.stdout.write(output);
}
})
.catch((err) => {
throw new Error(err);
});
}
30 changes: 30 additions & 0 deletions lib/generate-png.js
@@ -0,0 +1,30 @@
"use strict";

const childProcess = require("child_process");
const path = require("path");
const phantomjs = require("phantomjs2");

const binPath = phantomjs.path;

module.exports = function generatePng(markup, options) {
return new Promise((resolve, reject) => {
try {
const childArgs = [
path.join(__dirname, "rasterizer.js"),
new Buffer(markup),
options.height,
options.width
];

childProcess.execFile(binPath, childArgs, (err, stderr, stdout) => {
if (err) {
reject(err);
}
const output = new Buffer(stdout, "base64");
resolve(output);
});
} catch (e) {
reject(e);
}
});
};
6 changes: 6 additions & 0 deletions lib/generate-svg.js
@@ -0,0 +1,6 @@
const React = require("react");
const ReactDOM = require("react-dom/server");

module.exports = function generateSVG(comp) {
return ReactDOM.renderToString(React.createElement(comp));
};
22 changes: 22 additions & 0 deletions lib/rasterizer.js
@@ -0,0 +1,22 @@
/* eslint-disable */
// ^ phantom is funny about es6

"use strict";

var page = require("webpage").create();
var system = require("system");
var fs = require("fs");

var markup = system.args[1];
var HEIGHT = system.args[2];
var WIDTH = system.args[3];

page.viewportSize = { width: WIDTH, height: HEIGHT };
page.clipRect = { top: 0, left: 0, width: WIDTH, height: HEIGHT };
page.content = markup;

setTimeout(function () {
var base64 = page.renderBase64("PNG");
fs.write("/dev/stderr", base64);
phantom.exit();
}, 200);

0 comments on commit 0b92278

Please sign in to comment.