Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

feat(expo-cli): add shortcut to open editor #1879

Merged
merged 4 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/expo-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"detect-indent": "^6.0.0",
"detect-newline": "^3.0.0",
"enquirer": "^2.3.2",
"env-editor": "^0.4.1",
"envinfo": "7.5.0",
"es6-error": "3.2.0",
"expo-optimize": "0.1.17",
Expand Down
5 changes: 5 additions & 0 deletions packages/expo-cli/src/commands/start/TerminalUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import wordwrap from 'wordwrap';
import { loginOrRegisterIfLoggedOut } from '../../accounts';
import log from '../../log';
import urlOpts from '../../urlOpts';
import { startEditorAsync } from '../utils/EditorUtils';

const CTRL_C = '\u0003';
const CTRL_D = '\u0004';
Expand Down Expand Up @@ -63,6 +64,7 @@ const printUsage = async (projectDir: string, options: Pick<StartOptions, 'webOn
}
\u203A Press ${b`p`} to toggle ${u`p`}roduction mode. (current mode: ${i(devMode)})
\u203A Press ${b`r`} to ${u`r`}estart bundler, or ${b`shift-r`} to restart and clear cache.
\u203A Press ${b`o`} to ${u`o`}pen the project in your editor.
\u203A Press ${b`s`} to ${u`s`}ign ${
username ? `out. (Signed in as ${i('@' + username)}.)` : 'in.'
}
Expand Down Expand Up @@ -324,6 +326,9 @@ Please reload the project in the Expo app for the change to take effect.`
printHelp();
break;
}
case 'o':
log('Trying to open the project in your editor...');
await startEditorAsync(projectDir);
}
}
};
27 changes: 27 additions & 0 deletions packages/expo-cli/src/commands/utils/EditorUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import spawnAsync from '@expo/spawn-async';
import editors from 'env-editor';
import log from '../../log';

export function guessEditor() {
try {
return editors.defaultEditor();
} catch {
return editors.getEditor('vscode');
}
}

export async function startEditorAsync(path: string, options: { editor?: string } = {}) {
const editor = options.editor ? editors.getEditor(options.editor) : guessEditor();

if (editor) {
try {
await spawnAsync(editor.binary, [path]);
return true;
} catch {}
}

log.error(
'Could not open editor, you can set it by defining the $EDITOR environment variable with the binary of your editor. (e.g. "code" or "atom")'
);
return false;
}
81 changes: 17 additions & 64 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4178,11 +4178,6 @@
dependencies:
"@types/node" "*"

"@types/caseless@*":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's going on here, looks like the yarn lockfile could be slightly outdated?

version "0.12.2"
resolved "https://registry.yarnpkg.com/@types/caseless/-/caseless-0.12.2.tgz#f65d3d6389e01eeb458bd54dc8f52b95a9463bc8"
integrity sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==

"@types/clean-css@*":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@types/clean-css/-/clean-css-4.2.1.tgz#cb0134241ec5e6ede1b5344bc829668fd9871a8d"
Expand Down Expand Up @@ -4698,23 +4693,6 @@
resolved "https://registry.yarnpkg.com/@types/relateurl/-/relateurl-0.2.28.tgz#6bda7db8653fa62643f5ee69e9f69c11a392e3a6"
integrity sha1-a9p9uGU/piZD9e5p6facEaOS46Y=

"@types/request-promise-native@^1.0.16":
version "1.0.17"
resolved "https://registry.yarnpkg.com/@types/request-promise-native/-/request-promise-native-1.0.17.tgz#74a2d7269aebf18b9bdf35f01459cf0a7bfc7fab"
integrity sha512-05/d0WbmuwjtGMYEdHIBZ0tqMJJQ2AD9LG2F6rKNBGX1SSFR27XveajH//2N/XYtual8T9Axwl+4v7oBtPUZqg==
dependencies:
"@types/request" "*"

"@types/request@*", "@types/request@^2.48.1":
version "2.48.3"
resolved "https://registry.yarnpkg.com/@types/request/-/request-2.48.3.tgz#970b8ed2317568c390361d29c555a95e74bd6135"
integrity sha512-3Wo2jNYwqgXcIz/rrq18AdOZUQB8cQ34CXZo+LUwPJNpvRAL86+Kc2wwI8mqpz9Cr1V+enIox5v+WZhy/p3h8w==
dependencies:
"@types/caseless" "*"
"@types/node" "*"
"@types/tough-cookie" "*"
form-data "^2.5.0"

"@types/retry@^0.12.0":
version "0.12.0"
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
Expand Down Expand Up @@ -4826,11 +4804,6 @@
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.0.33.tgz#1073c4bc824754ae3d10cfab88ab0237ba964e4d"
integrity sha1-EHPEvIJHVK49EM+riKsCN7qWTk0=

"@types/tough-cookie@*":
version "2.3.5"
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-2.3.5.tgz#9da44ed75571999b65c37b60c9b2b88db54c585d"
integrity sha512-SCcK7mvGi3+ZNz833RRjFIxrn4gI1PPR3NtuIS+6vMkvmsGjosqTJwRt5bAEFLRz+wtJMWv8+uOnZf2hi2QXTg==

"@types/uglify-js@*":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.0.4.tgz#96beae23df6f561862a830b4288a49e86baac082"
Expand Down Expand Up @@ -9686,6 +9659,11 @@ entities@^2.0.0:
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.0.tgz#68d6084cab1b079767540d80e56a39b423e4abf4"
integrity sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==

env-editor@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/env-editor/-/env-editor-0.4.1.tgz#77011e08ce45f46e404e8d996b465c684ca57502"
integrity sha512-suh+Vm00GnPQgXpmONTkcUT9LgBSL6sJrRnJxbykT0j+ONjzmIS+1U3ne467ArdZN/42/npp+GnhtwkLQ+vUjw==

env-paths@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0"
Expand Down Expand Up @@ -11148,15 +11126,6 @@ form-data@2.3.2:
combined-stream "1.0.6"
mime-types "^2.1.12"

form-data@^2.5.0:
version "2.5.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.5.1.tgz#f2cbec57b5e59e23716e128fe44d4e5dd23895f4"
integrity sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.6"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down Expand Up @@ -15258,7 +15227,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

lodash@4.17.15, "lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.0, lodash@^4.6.0:
lodash@4.17.15, "lodash@>=3.5 <5", lodash@^4.0.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.0, lodash@^4.6.0:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
Expand Down Expand Up @@ -20199,29 +20168,13 @@ request-progress@~3.0.0:
dependencies:
throttleit "^1.0.0"

request-promise-core@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.1.tgz#3eee00b2c5aa83239cfb04c5700da36f81cd08b6"
integrity sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=
dependencies:
lodash "^4.13.1"

request-promise-core@1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.3.tgz#e9a3c081b51380dfea677336061fea879a829ee9"
integrity sha512-QIs2+ArIGQVp5ZYbWD5ZLCY29D5CfWizP8eWnm8FoGD1TX61veauETVQbrV60662V0oFBkrDOuaBI8XgtuyYAQ==
dependencies:
lodash "^4.17.15"

request-promise-native@1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.5.tgz#5281770f68e0c9719e5163fd3fab482215f4fda5"
integrity sha1-UoF3D2jgyXGeUWP9P6tIIhX0/aU=
dependencies:
request-promise-core "1.1.1"
stealthy-require "^1.1.0"
tough-cookie ">=2.3.3"

request-promise-native@^1.0.5, request-promise-native@^1.0.7:
version "1.0.8"
resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.8.tgz#a455b960b826e44e2bf8999af64dff2bfe58cb36"
Expand All @@ -20231,7 +20184,7 @@ request-promise-native@^1.0.5, request-promise-native@^1.0.7:
stealthy-require "^1.1.1"
tough-cookie "^2.3.3"

request@2.88.0, request@^2.81.0, request@^2.83.0, request@^2.87.0, request@^2.88.0, request@~2.88.0:
request@^2.81.0, request@^2.83.0, request@^2.87.0, request@^2.88.0, request@~2.88.0:
version "2.88.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==
Expand Down Expand Up @@ -21378,7 +21331,7 @@ std-env@^2.2.1:
dependencies:
ci-info "^1.6.0"

stealthy-require@^1.1.0, stealthy-require@^1.1.1:
stealthy-require@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=
Expand Down Expand Up @@ -22335,15 +22288,6 @@ touch@^2.0.1:
dependencies:
nopt "~1.0.10"

tough-cookie@>=2.3.3, tough-cookie@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-3.0.1.tgz#9df4f57e739c26930a018184887f4adb7dca73b2"
integrity sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==
dependencies:
ip-regex "^2.1.0"
psl "^1.1.28"
punycode "^2.1.1"

tough-cookie@^2.3.3, tough-cookie@^2.3.4:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2"
Expand All @@ -22352,6 +22296,15 @@ tough-cookie@^2.3.3, tough-cookie@^2.3.4:
psl "^1.1.28"
punycode "^2.1.1"

tough-cookie@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-3.0.1.tgz#9df4f57e739c26930a018184887f4adb7dca73b2"
integrity sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==
dependencies:
ip-regex "^2.1.0"
psl "^1.1.28"
punycode "^2.1.1"

tough-cookie@~2.4.3:
version "2.4.3"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.4.3.tgz#53f36da3f47783b0925afa06ff9f3b165280f781"
Expand Down