Skip to content

Commit

Permalink
feat(cli): add cli for power-doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Aug 9, 2015
1 parent 8cb3f90 commit d9e1a7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node
var convertCode = require('../').convertCode;
var concat = require('concat-stream');
var fs = require('fs');
var path = require("path");
var file = process.argv[2];
var input = file && file !== '-'
? fs.createReadStream(process.argv[2])
: process.stdin
;
input.pipe(concat(function (buf) {
var filePath = path.join(process.cwd(), file);
console.log(convertCode(buf.toString('utf8'), filePath));
}));
9 changes: 9 additions & 0 deletions src/power-doctest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import {toAssertFromAST} from "comment-to-assert"
import {injectAssertModule} from "./inject-assert"
import empower from "empower"
import assert from "assert"
import ASTSource from "ast-source"
export function convertCode(code, filePath) {
var source = new ASTSource(code, {
filePath: filePath,
disableSourceMap: typeof filePath === "undefined"
});
var output = source.transform(convertAST).output();
return output.codeWithMap;
}

export function convertAST(AST) {
var empowerOptions = {modifyMessageOnRethrow: true, saveContextOnRethrow: true};
Expand Down

0 comments on commit d9e1a7c

Please sign in to comment.