Skip to content

Commit fb012dd

Browse files
authored
feat: MacOS open editor (umijs#3)
* init * init * rm: father-build * feat: error hanlder * feat: macos supported * add: webstorm * test: utils * rm: cache * fix: tsc build * fix: rm circle ci * rm: pkg * feat: windows * fix: return * fix: windows trim * feat: sublime
1 parent 4f42d53 commit fb012dd

24 files changed

+693
-130
lines changed

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test/
2+
dist/
3+
coverage/
4+
.github/

.eslintrc.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { strictEslint } = require('@umijs/fabric');
2+
3+
module.exports = {
4+
...strictEslint,
5+
rules: {
6+
'no-underscore-dangle': [0],
7+
'arrow-parens': [0],
8+
'import/prefer-default-export': [0],
9+
'@typescript-eslint/prefer-namespace-keyword': [0],
10+
'@typescript-eslint/explicit-function-return-type': [0],
11+
'@typescript-eslint/no-explicit-any': [0],
12+
'no-restricted-globals': [0],
13+
'@typescript-eslint/interface-name-prefix': [0],
14+
'@typescript-eslint/no-object-literal-type-assertion': [0],
15+
'@typescript-eslint/no-var-requires': [0]
16+
},
17+
};

.fatherrc.ts

-13
This file was deleted.

README.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
✏️ Launch your code editor using Node.js.
66

77
## Feature
8-
- [ ] support `async/await`
9-
- [ ] error handlers and codes
8+
- [x] support `async/await`
9+
- [x] error handlers and codes
1010
- [ ] support more editors and platforms.
11-
- [ ] specify the editor to launch
11+
- [x] specify the editor to launch
1212

1313

1414
## Install
@@ -26,7 +26,7 @@ const launchEditor = require('@umijs/launch-editor');
2626

2727
(async () => {
2828
try {
29-
await launchEditor(config)
29+
await launchEditor.default(config)
3030
} catch (e) {}
3131
})()
3232

@@ -59,17 +59,23 @@ files or project path you want to open in the editor.
5959
Type: `object`
6060

6161
##### editor
62-
Type: `string`
62+
Type: `string` | `string[]`
6363
Default: Auto-detected (current process or existed editors, envs)
6464

65-
the function return a `Promise`, if having an error when launching the editor, there are some error `code` and `description`, `editor` (if you specify) you might use.
65+
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.
6666

67-
| code | description |
67+
| code | message |
6868
|--------|------|
6969
| `EPERM` | the path is permission denied |
7070
| `UNKNOWN` | couldn't find your editor, might not install |
7171
| `OTHER` | unknown error couldn't catch |
7272

73+
##### editorOpts
74+
Type: `object`
75+
Default: `[]`
76+
77+
Extra options for the specified editor params, e.g., VSCode using `["-n"]` to force to open a new window.
78+
7379
## Development
7480

7581
```sh
@@ -90,9 +96,9 @@ $ npm run test
9096

9197
| Value | Editor | Linux | Windows | OSX |
9298
|--------|------|:------:|:------:|:------:|
93-
| `code` | [Visual Studio Code](https://code.visualstudio.com/) ||||
94-
| `atom` | [Atom](https://atom.io/) ||||
99+
| `code` | [Visual Studio Code](https://code.visualstudio.com/) ||||
100+
| `atom` | [Atom](https://atom.io/) ||||
95101
| `code-insiders` | [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/) ||||
96-
| `sublime` | [Sublime Text](https://www.sublimetext.com/) ||||
97-
| `webstorm` | [WebStorm](https://www.jetbrains.com/webstorm/) ||||
102+
| `sublime` | [Sublime Text](https://www.sublimetext.com/) ||||
103+
| `webstorm` | [WebStorm](https://www.jetbrains.com/webstorm/) ||||
98104
| `idea` | [IDEA](https://www.jetbrains.com/idea/) ||||

circle.yml

-24
This file was deleted.

package.json

+18-6
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,44 @@
44
"description": "launch your code editor using Node.js.",
55
"main": "lib/index.js",
66
"scripts": {
7-
"dev": "concurrently \"father-build -w\" \"nodemon test/test.js\"",
7+
"dev": "npm run build && node test/test.js",
88
"coveralls": "cat ./coverage/lcov.info | coveralls",
9-
"build": "father-build && tsc",
9+
"build": "tsc",
1010
"test": "umi-test --coverage"
1111
},
1212
"repository": {
1313
"type": "git",
1414
"url": "git+https://github.com/umijs/launch-editor.git"
1515
},
16-
"keywords": ["editor", "launch", "nodejs"],
17-
"author": "ycjcl868",
18-
"license": "ISC",
16+
"keywords": [
17+
"editor",
18+
"launch",
19+
"nodejs"
20+
],
21+
"authors": {
22+
"name": "ycjcl868",
23+
"email": "[email protected]"
24+
},
1925
"bugs": {
2026
"url": "https://github.com/umijs/launch-editor/issues"
2127
},
2228
"homepage": "https://github.com/umijs/launch-editor#readme",
2329
"devDependencies": {
2430
"@types/jest": "^24.0.18",
2531
"@types/node": "^12.7.3",
32+
"@umijs/fabric": "^1.1.10",
2633
"concurrently": "^4.1.2",
2734
"coverage": "^0.4.0",
28-
"father-build": "^1.8.0",
2935
"nodemon": "^1.19.2",
36+
"typescript": "^3.6.2",
3037
"umi-test": "^1.7.1"
3138
},
39+
"license": "MIT",
40+
"publishConfig": {
41+
"access": "public"
42+
},
3243
"dependencies": {
44+
"@types/chalk": "^2.2.0",
3345
"cross-spawn": "^7.0.0"
3446
}
3547
}

src/editorInfo/linux.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// import * as path from 'path';
2+
3+
export default [
4+
{
5+
name: 'code',
6+
process: ['code'],
7+
location: [
8+
],
9+
commands: [
10+
'code',
11+
'code-insiders',
12+
],
13+
opts: [],
14+
},
15+
{
16+
name: 'atom',
17+
process: ['atom'],
18+
location: [
19+
],
20+
commands: [
21+
'atom',
22+
],
23+
},
24+
{
25+
name: 'subl',
26+
process: ['sublime_text'],
27+
location: [
28+
],
29+
commands: [
30+
'subl',
31+
],
32+
},
33+
]
34+

src/editorInfo/osx.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as path from 'path';
2+
3+
export default [
4+
{
5+
name: 'code',
6+
process: ['Visual Studio Code.app'],
7+
location: [
8+
path.join('/', 'Applications', 'Visual Studio Code.app'),
9+
],
10+
commands: [
11+
'code',
12+
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
13+
'code-insiders',
14+
],
15+
opts: [],
16+
},
17+
{
18+
name: 'atom',
19+
process: ['Atom.app'],
20+
location: [
21+
path.join('/', 'Applications', 'Atom.app'),
22+
],
23+
commands: [
24+
'atom',
25+
'/Applications/Atom.app/Contents/MacOS/Atom',
26+
],
27+
},
28+
{
29+
name: 'subl',
30+
process: ['Sublime Text'],
31+
location: [
32+
path.join('/', 'Applications', 'Sublime Text.app'),
33+
path.join('/', 'Applications', 'Sublime Text 2.app'),
34+
path.join('/', 'Applications', 'Sublime Text Dev.app'),
35+
],
36+
commands: [
37+
'subl',
38+
'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
39+
'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
40+
'/Applications/Sublime Text Dev.app/Contents/SharedSupport/bin/subl',
41+
],
42+
},
43+
{
44+
name: 'webstorm',
45+
process: ['webstorm'],
46+
location: [
47+
path.join('/', 'Applications', 'WebStorm.app'),
48+
],
49+
commands: [
50+
'webstorm',
51+
'wstorm',
52+
'/Applications/WebStorm.app/Contents/MacOS/webstorm',
53+
],
54+
},
55+
]

src/editorInfo/windows.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as os from 'os';
2+
import * as path from 'path';
3+
4+
export default [
5+
{
6+
name: 'code',
7+
process: ['Code.exe'],
8+
location: [
9+
path.join(os.homedir(), 'AppData', 'Local', 'Programs', 'Microsoft VS Code'),
10+
],
11+
commands: [
12+
'code',
13+
path.join(os.homedir(), 'AppData', 'Local', 'Programs', 'Microsoft VS Code', 'bin', 'code.cmd'),
14+
'code-insiders',
15+
],
16+
opts: [],
17+
},
18+
{
19+
name: 'subl',
20+
process: ['sublime_text.exe'],
21+
location: [
22+
path.join(os.homedir(), '..', 'Program Files', 'Sublime Text 3'),
23+
path.join(os.homedir(), '..', 'Program Files', 'Sublime Text'),
24+
],
25+
commands: [
26+
'subl',
27+
path.join(os.homedir(), '..', 'Program Files', 'Sublime Text 3', 'subl.exe'),
28+
],
29+
opts: [],
30+
},
31+
]

src/enum.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export enum ERROR_CODE {
2+
UNKNOWN = 'UNKNOWN',
3+
EPERM = 'EPERM',
4+
ERROR = 'ERROR',
5+
OTHER = 'OTHER',
6+
}
7+
8+
export enum SUPPORTED_EDITTORS {
9+
'vscode' = 'VSCode',
10+
'sublime' = 'Sublime Text',
11+
'atom' = 'Atom',
12+
}
13+
14+
export type IEditor = keyof typeof SUPPORTED_EDITTORS;
15+
16+
export type IEditorExec = string[];
17+
18+
export type ISupportedEditor = {
19+
[key in IEditor]: {
20+
command: IEditorExec;
21+
};
22+
}
23+
24+
export type SYSTEMS = 'osx' | 'linux' | 'windows';

src/error.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default class EditorError extends Error {
2+
public editor: string | string[];
3+
4+
public success?: boolean;
5+
6+
public code?: string;
7+
8+
public constructor({
9+
editor = '',
10+
code = '',
11+
success = false,
12+
}, ...params) {
13+
super(...params);
14+
15+
if (Error.captureStackTrace) {
16+
Error.captureStackTrace(this, EditorError);
17+
}
18+
19+
this.name = 'EditorError';
20+
this.success = success;
21+
this.code = code;
22+
this.editor = editor;
23+
}
24+
}

0 commit comments

Comments
 (0)