Skip to content

Commit

Permalink
🐙 mr anderson vs agent smith no more fuel injection for cat, rec, upload
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfram77 committed Jul 24, 2020
1 parent f6d49ee commit fd1a8a3
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "extra-asciinema",
"version": "1.0.21",
"version": "1.0.22",
"description": "asciinema is a terminal screen recorder.",
"main": "index.js",
"module": "index.mjs",
Expand Down
28 changes: 14 additions & 14 deletions src/_recCmd.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

function recCmd(f: string, o: any=null): string {
function recCmd(f: string, o: any=null): string[] {
var o = o||{};
// if input file given, execute on node.js
if(o.input) {
Expand All @@ -10,18 +10,18 @@ function recCmd(f: string, o: any=null): string {
}
o.overwrite = true;
o.yes = true;
var cmd = 'asciinema rec';
if(f) cmd += ` "${f}"`;
if(o.stdin) cmd += ' --stdin';
if(o.append) cmd += ' --append';
if(o.raw) cmd += ' --raw';
if(o.overwrite) cmd += ' --overwrite';
if(o.command) cmd += ` -c "${o.command}"`;
if(o.env) cmd += ` -e "${o.env}"`;
if(o.title) cmd += ` -t "${o.title}"`;
if(o.idleTimeLimit) cmd += ` -e "${o.idleTimeLimit}"`;
if(o.yes) cmd += ` -e "${o.yes}"`;
if(o.quiet) cmd += ` -e "${o.quiet}"`;
return cmd;
var args = ['rec'];
if(f) args.push(f);
if(o.stdin) args.push('--stdin');
if(o.append) args.push('--append');
if(o.raw) args.push('--raw');
if(o.overwrite) args.push('--overwrite');
if(o.command) args.push('--command', o.command);
if(o.env) args.push('-env', o.env);
if(o.title) args.push('--title', o.title);
if(o.idleTimeLimit) args.push('--idle-time-limit', ''+o.idleTimeLimit);
if(o.yes) args.push('--yes');
if(o.quiet) args.push('--quiet');
return args;
}
export default recCmd;
2 changes: 1 addition & 1 deletion src/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {callbackFn} from './_types';
*/
function cat(f: string, fn: callbackFn=null): Promise<any> {
var p = new Promise((fres, frej) => {
cp.exec(`asciinema cat ${f}`, {encoding: 'utf8'}, (err, stdout) => {
cp.execFile('asciinema', ['cat', f], {encoding: 'utf8'}, (err, stdout) => {
if(err) return frej(err);
fres(stdout);
});
Expand Down
2 changes: 1 addition & 1 deletion src/catSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import * as cp from 'child_process';
* @returns full output (including all escape sequences)
*/
function catSync(f: string): string {
return cp.execSync(`asciinema cat ${f}`, {encoding: 'utf8'});
return cp.execFileSync('asciinema', ['cat', f], {encoding: 'utf8'});
}
export default catSync;
2 changes: 1 addition & 1 deletion src/rec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {RecOptions, callbackFn} from './_types';
function rec(f: string=null, o: RecOptions=null, fn: callbackFn=null): Promise<any> {
var f = f||path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'asciinema-')), '0.cast');
var p = new Promise((fres, frej) => {
cp.exec(recCmd(f, o), {encoding: 'utf8'}, (err) => {
cp.execFile('asciinema', recCmd(f, o), {encoding: 'utf8'}, (err) => {
if(err) return frej(err);
fres(f);
});
Expand Down
2 changes: 1 addition & 1 deletion src/recSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {RecOptions} from './_types';
*/
function recSync(f: string, o: RecOptions=null): string {
var f = f||path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'asciinema-')), '0.cast');
cp.execSync(recCmd(f, o), {encoding: 'utf8'});
cp.execFileSync('asciinema', recCmd(f, o), {encoding: 'utf8'});
return f;
}
export default recSync;
2 changes: 1 addition & 1 deletion src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {callbackFn} from './_types';
*/
function upload(f: string, fn: callbackFn=null): Promise<any> {
var p = new Promise((fres, frej) => {
cp.exec(`asciinema upload ${f}`, {encoding: 'utf8'}, (err, stdout) => {
cp.execFile('asciinema', ['upload', f], {encoding: 'utf8'}, (err, stdout) => {
if(err) return frej(err);
fres(stdout.replace(/.*?(https?:\S+).*/s, '$1'));
});
Expand Down
2 changes: 1 addition & 1 deletion src/uploadSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as cp from 'child_process';
* @returns asciicast URL
*/
function uploadSync(f: string): string {
var stdout = cp.execSync(`asciinema upload ${f}`, {encoding: 'utf8'});
var stdout = cp.execFileSync('asciinema', ['upload', f], {encoding: 'utf8'});
return stdout.replace(/.*?(https?:\S+).*/s, '$1');
}
export default uploadSync;

0 comments on commit fd1a8a3

Please sign in to comment.