Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkmg committed May 7, 2018
2 parents e64c53e + 71a0886 commit 0da6c6a
Show file tree
Hide file tree
Showing 32 changed files with 1,227 additions and 948 deletions.
135 changes: 0 additions & 135 deletions .coffeelint.json

This file was deleted.

2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ root = true
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sudo: false
node_js:
- 10
- 9
- 8
- 7
- 6
- 5
- 4
- .12
language: node_js
script: npm test
49 changes: 29 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

A node module to edit a string with a users preferred text editor using $VISUAL or $ENVIRONMENT.

Version: 2.2.0
Version: 3.0.0

As of version 2.0.0, node 0.10 is no longer support. Minimum node version is now 0.12.
As of version 3.0.0, the minimum version of node supported is 4.

## Install

Expand All @@ -19,27 +19,27 @@ As of version 2.0.0, node 0.10 is no longer support. Minimum node version is now

A simple example using the `.edit` convenience method

var ExternalEditor = require('external-editor')
var data = ExternalEditor.edit('\n\n# Please write your text above');
import {edit} from "external-editor";
const data = edit('\n\n# Please write your text above');
console.log(data);

A full featured example

var ExternalEditor = require('external-editor');
import {ExternalEditor, CreateFileError, ReadFileError, RemoveFileError} from "external-editor"

try {
var editor = new ExternalEditor();
var text = editor.run() // the text is also available in editor.text
const editor = new ExternalEditor();
const text = editor.run() // the text is also available in editor.text
if (editor.last_exit_status !== 0) {
console.log("The editor exited with a non-zero code");
}
} catch (err) {
if (err instanceOf ExternalEditor.CreateFileError) {
if (err instanceOf CreateFileError) {
console.log('Failed to create the temporary file');
} else if (err instanceOf ExternalEditor.ReadFileError) {
} else if (err instanceOf ReadFileError) {
console.log('Failed to read the temporary file');
} else if (err instanceOf ExternalEditor.LaunchEditorError) {
} else if (err instanceOf LaunchEditorError) {
console.log('Failed to launch your editor');
} else {
throw err;
Expand All @@ -52,7 +52,7 @@ A full featured example
try {
editor.cleanup();
} catch (err) {
if (err instanceOf ExternalEditor.RemoveFileError) {
if (err instanceOf RemoveFileError) {
console.log('Failed to remove the temporary file');
} else {
throw err
Expand All @@ -61,7 +61,7 @@ A full featured example


#### API
**Static Methods**
**Convenience Methods**

- `edit(text)`
- `text` (string) *Optional* Defaults to empty string
Expand All @@ -74,14 +74,14 @@ A full featured example
- `text`(string) The contents of the file


**Static Properties**
**Errors**

- `CreateFileError` Error thrown if the temporary file could not be created.
- `ReadFileError` Error thrown if the temporary file could not be read.
- `RemoveFileError` Error thrown if the temporary file could not be removed during cleanup.
- `LaunchEditorError` Error thrown if the editor could not be launched.

**Public Methods**
**External Editor Public Methods**

- `new ExternalEditor(text)`
- `text` (string) *Optional* Defaults to empty string
Expand All @@ -96,18 +96,18 @@ A full featured example
- `cleanup()` Removes the temporary file.
- Could throw `RemoveFileError`

**Public Properties**
**External Editor Public Properties**

- `text` (string) *readonly* The text in the temporary file.
- `editor.bin` (string) The editor determined from the environment.
- `editor.args` (array) Default arguments for the bin
- `temp_file` (string) Path to temporary file. Can be changed, but be careful as the temporary file probably already
- `tempFile` (string) Path to temporary file. Can be changed, but be careful as the temporary file probably already
exists and would need be removed manually.
- `last_exit_status` (number) The last exit code emitted from the editor.
- `lastExitStatus` (number) The last exit code emitted from the editor.

## Errors

All errors have a simple message explaining what went wrong. They all also have an `original_error` property containing
All errors have a simple message explaining what went wrong. They all also have an `originalError` property containing
the original error thrown for debugging purposes.

## Why Synchronous?
Expand All @@ -120,17 +120,26 @@ please submit a PR.

If async is really needed, you can use `editAsync` or `runAsync`. If you are using readline or have anything else
listening to the stdin or you write to stdout, you will most likely have problem, so make sure to remove any other
listeners on stdin, stdout, or stdin.
listeners on stdin, stdout, or stderr.

## Demo

[![asciicast](https://asciinema.org/a/a1qh9lypbe65mj0ivfuoslz2s.png)](https://asciinema.org/a/a1qh9lypbe65mj0ivfuoslz2s)

## Breaking Changes from v2 to v3

- NodeJS 0.12 support dropped.
- Switched to named imports.
- All "snake_cased" variables and properties are now "camelCased".
- `ExternalEditor.temp_file` is now `ExternalEditor.tempFile`.
- `ExternalEditor.last_exit_status` is now `ExternalEditor.lastExitStatus`.
- `Error.original_error` is now `Error.originalError`.

## License

The MIT License (MIT)

Copyright (c) 2016 Kevin Gravier
Copyright (c) 2016-2018 Kevin Gravier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion example_async.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ExternalEditor = require('./main');
var ExternalEditor = require('./main').ExternalEditor;
var readline = require('readline');

var rl = readline.createInterface({
Expand Down
2 changes: 1 addition & 1 deletion example_sync.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ExternalEditor = require('./main');
var ExternalEditor = require('./main').ExternalEditor;
var readline = require('readline');

var rl = readline.createInterface({
Expand Down
10 changes: 10 additions & 0 deletions main/errors/CreateFileError.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/***
* Node External Editor
*
* Kevin Gravier <kevin@mrkmg.com>
* MIT 2018
*/
export declare class CreateFileError extends Error {
originalError: Error;
constructor(originalError: Error);
}
59 changes: 33 additions & 26 deletions main/errors/CreateFileError.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
// Generated by CoffeeScript 1.12.7

/*
ExternalEditor
Kevin Gravier <kevin@mrkmg.com>
MIT
"use strict";
/***
* Node External Editor
*
* Kevin Gravier <kevin@mrkmg.com>
* MIT 2018
*/

(function() {
var CreateFileError,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;

CreateFileError = (function(superClass) {
extend(CreateFileError, superClass);

CreateFileError.prototype.message = 'Failed to create temporary file for editor';

function CreateFileError(original_error) {
this.original_error = original_error;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var CreateFileError = /** @class */ (function (_super) {
__extends(CreateFileError, _super);
function CreateFileError(originalError) {
var _newTarget = this.constructor;
var _this = _super.call(this, "Failed to create temporary file for editor") || this;
_this.originalError = originalError;
var proto = _newTarget.prototype;
if (Object.setPrototypeOf) {
Object.setPrototypeOf(_this, proto);
}
else {
_this.__proto__ = _newTarget.prototype;
}
return _this;
}

return CreateFileError;

})(Error);

module.exports = CreateFileError;

}).call(this);
}(Error));
exports.CreateFileError = CreateFileError;
10 changes: 10 additions & 0 deletions main/errors/LaunchEditorError.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/***
* Node External Editor
*
* Kevin Gravier <kevin@mrkmg.com>
* MIT 2018
*/
export declare class LaunchEditorError extends Error {
originalError: Error;
constructor(originalError: Error);
}
Loading

0 comments on commit 0da6c6a

Please sign in to comment.