Giter Site home page Giter Site logo

launch-editor's Introduction

launch-editor

Coverage Status NPM version NPM downloads

✏️ Launch your code editor using Node.js.

Feature

  • support async/await
  • error handlers and codes
  • support more editors and platforms.
  • specify the editor to launch

Install

$ npm install @umijs/launch-editor -S

Usage

Commonjs

const launchEditor = require('@umijs/launch-editor');

(async () => {
  try {
   const res = await launchEditor.default(config)
  } catch (e) {}
})()

ES6 / TypeScript

import launchEditor from '@umijs/launch-editor';

(async () => {
  try {
   const res = await launchEditor(config)
  } catch (e) {}
})()

Configuration

launchEditor(path, [options]): Promise

path

Type: string | object | Array<string | object>

files or project path you want to open in the editor.

options

Type: object

editor

Type: string | string[] Default: Auto-detected (current process or existed editors, envs)

the function return a Promise, if having an error when launching the editor, there are some error code and message, editor (if you specify) you might use.

code message
EPERM the path is permission denied
UNKNOWN couldn't find your editor, might not install
OTHER unknown error couldn't catch
editorOpts

Type: object Default: []

Extra options for the specified editor params, e.g., VSCode using ["-n"] to force to open a new window.

getEditors(): void

guess how many editors you have in current system.

Commonjs

const { getEditors }  = require('@umijs/launch-editor');

guessEditor();

=>

[
  { name: 'subl', commands: [''] },
  { name: 'vscode', commands: [''] },
  { name: 'idea', commands: [''] },
  { name: 'atom', commands: [''] },
]

Development

$ npm install
$ npm run dev

Test

$ npm install
$ npm run test

Supported editors

Value Editor Linux Windows OSX
code Visual Studio Code
atom Atom
code-insiders Visual Studio Code Insiders
sublime Sublime Text
webstorm WebStorm
idea IDEA

launch-editor's People

Contributors

sorrycc avatar xiaohuoni avatar ycjcl868 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

launch-editor's Issues

Prettify Code and create .prettierrc

Right now forking code and saving creates a lot of unnecessary changes if you have prettier in your system

Creating a .prettierrc file and formatting all code and will be easier in the future to deal with Pull Requests.

Handle errors instead of trying to open in default text editor

In my use case, I have a dropdown for the user to select a particular editor and open file in that.

But if that fails, launch-editor does not show any error. It silently fails and tries to open the file in the default text-editor.

This needs to be optional. Trying to open the file in "Sublime Text" and it opening up in "VS Code" does not suit every use case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.