create-video 3.1.0 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,28 +10,28 @@ const open_in_editor_1 = require("./open-in-editor");
10
10
  const yesno_1 = require("./yesno");
11
11
  const openInEditorFlow = async (projectRoot) => {
12
12
  const editors = await (0, open_in_editor_1.guessEditor)();
13
- const [guiEditor] = editors.filter((e) => !(0, open_in_editor_1.isTerminalEditor)(e));
13
+ const [guiEditor] = editors.filter((e) => !(0, open_in_editor_1.isTerminalEditor)(e.command));
14
14
  if (!guiEditor) {
15
15
  return;
16
16
  }
17
- const displayName = (0, open_in_editor_1.getDisplayNameForEditor)(guiEditor);
17
+ const displayName = (0, open_in_editor_1.getDisplayNameForEditor)(guiEditor.command);
18
18
  const should = await (0, yesno_1.yesOrNo)({
19
19
  defaultValue: true,
20
20
  question: `💻 Do you want to open the project in ${displayName}? (Y/n):`,
21
21
  });
22
22
  if (should) {
23
- (0, open_in_editor_1.launchEditor)({
23
+ await (0, open_in_editor_1.launchEditor)({
24
24
  colNumber: 1,
25
25
  editor: guiEditor,
26
26
  fileName: projectRoot,
27
27
  vsCodeNewWindow: true,
28
28
  lineNumber: 1,
29
29
  });
30
- if ((0, open_in_editor_1.isVsCodeDerivative)(guiEditor)) {
30
+ if ((0, open_in_editor_1.isVsCodeDerivative)(guiEditor.command)) {
31
31
  await new Promise((resolve) => {
32
32
  setTimeout(resolve, 1000);
33
33
  });
34
- (0, open_in_editor_1.launchEditor)({
34
+ await (0, open_in_editor_1.launchEditor)({
35
35
  colNumber: 1,
36
36
  editor: guiEditor,
37
37
  fileName: path_1.default.join(projectRoot, 'README.md'),
@@ -3,12 +3,16 @@ export declare function isTerminalEditor(editor: Editor): boolean;
3
3
  declare const editorNames: readonly ["atom", "/Applications/Atom Beta.app/Contents/MacOS/Atom Beta", "brackets", "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl", "/Applications/Sublime Text Dev.app/Contents/SharedSupport/bin/subl", "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl", "code", "code-insiders", "vscodium", "/Applications/AppCode.app/Contents/MacOS/appcode", "/Applications/CLion.app/Contents/MacOS/clion", "/Applications/IntelliJ IDEA.app/Contents/MacOS/idea", "/Applications/PhpStorm.app/Contents/MacOS/phpstorm", "/Applications/PyCharm.app/Contents/MacOS/pycharm", "/Applications/PyCharm CE.app/Contents/MacOS/pycharm", "/Applications/RubyMine.app/Contents/MacOS/rubymine", "/Applications/WebStorm.app/Contents/MacOS/webstorm", "/Applications/GoLand.app/Contents/MacOS/goland", "/Applications/Rider.app/Contents/MacOS/rider", "mvim", "emacs", "gvim", "idea", "phpstorm", "pycharm", "rubymine", "sublime_text", "vim", "webstorm", "goland", "rider", "Brackets.exe", "Code.exe", "Code - Insiders.exe", "VSCodium.exe", "atom.exe", "sublime_text.exe", "notepad++.exe", "clion.exe", "clion64.exe", "idea.exe", "idea64.exe", "phpstorm.exe", "phpstorm64.exe", "pycharm.exe", "pycharm64.exe", "rubymine.exe", "rubymine64.exe", "webstorm.exe", "webstorm64.exe", "goland.exe", "goland64.exe", "rider.exe", "rider64.exe", "nano"];
4
4
  export declare const getDisplayNameForEditor: (editor: Editor | undefined) => string | null;
5
5
  declare type Editor = typeof editorNames[number];
6
- export declare function guessEditor(): Promise<Editor[]>;
6
+ declare type ProcessAndCommand = {
7
+ process: string;
8
+ command: Editor;
9
+ };
10
+ export declare function guessEditor(): Promise<ProcessAndCommand[]>;
7
11
  export declare function launchEditor({ colNumber, editor, fileName, lineNumber, vsCodeNewWindow, }: {
8
12
  fileName: string;
9
13
  lineNumber: number;
10
14
  colNumber: number;
11
- editor: Editor;
15
+ editor: ProcessAndCommand;
12
16
  vsCodeNewWindow: boolean;
13
- }): boolean;
17
+ }): Promise<boolean>;
14
18
  export {};
@@ -322,7 +322,10 @@ async function guessEditor() {
322
322
  for (let i = 0; i < processNames.length; i++) {
323
323
  const processName = processNames[i];
324
324
  if (output.indexOf(processName) !== -1) {
325
- availableEditors.push(COMMON_EDITORS_OSX[processName]);
325
+ availableEditors.push({
326
+ process: processName,
327
+ command: COMMON_EDITORS_OSX[processName],
328
+ });
326
329
  }
327
330
  }
328
331
  return availableEditors;
@@ -336,7 +339,10 @@ async function guessEditor() {
336
339
  const processPath = runningProcesses[i].trim();
337
340
  const processName = path_1.default.basename(processPath);
338
341
  if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) {
339
- availableEditors.push(processPath);
342
+ availableEditors.push({
343
+ process: processPath,
344
+ command: processPath,
345
+ });
340
346
  }
341
347
  }
342
348
  return availableEditors;
@@ -350,7 +356,10 @@ async function guessEditor() {
350
356
  for (let i = 0; i < processNames.length; i++) {
351
357
  const processName = processNames[i];
352
358
  if (output.indexOf(processName) !== -1) {
353
- availableEditors.push(COMMON_EDITORS_LINUX[processName]);
359
+ availableEditors.push({
360
+ process: processName,
361
+ command: COMMON_EDITORS_LINUX[processName],
362
+ });
354
363
  }
355
364
  }
356
365
  return availableEditors;
@@ -361,16 +370,26 @@ async function guessEditor() {
361
370
  }
362
371
  // Last resort, use old skool env vars
363
372
  if (process.env.VISUAL) {
364
- return [process.env.VISUAL];
373
+ return [
374
+ {
375
+ process: process.env.VISUAL,
376
+ command: process.env.VISUAL,
377
+ },
378
+ ];
365
379
  }
366
380
  if (process.env.EDITOR) {
367
- return [process.env.EDITOR];
381
+ return [
382
+ {
383
+ process: process.env.EDITOR,
384
+ command: process.env.EDITOR,
385
+ },
386
+ ];
368
387
  }
369
388
  return [];
370
389
  }
371
390
  exports.guessEditor = guessEditor;
372
391
  let _childProcess = null;
373
- function launchEditor({ colNumber, editor, fileName, lineNumber, vsCodeNewWindow, }) {
392
+ async function launchEditor({ colNumber, editor, fileName, lineNumber, vsCodeNewWindow, }) {
374
393
  if (!fs_1.default.existsSync(fileName)) {
375
394
  return false;
376
395
  }
@@ -385,7 +404,7 @@ function launchEditor({ colNumber, editor, fileName, lineNumber, vsCodeNewWindow
385
404
  if (!(Number.isInteger(colNumber) && colNumber > 0)) {
386
405
  colNumber = 1;
387
406
  }
388
- if (editor.toLowerCase() === 'none') {
407
+ if (editor.command.toLowerCase() === 'none') {
389
408
  return false;
390
409
  }
391
410
  if (process.platform === 'linux' &&
@@ -415,25 +434,41 @@ function launchEditor({ colNumber, editor, fileName, lineNumber, vsCodeNewWindow
415
434
  console.log();
416
435
  return false;
417
436
  }
418
- const shouldOpenVsCodeNewWindow = (0, exports.isVsCodeDerivative)(editor) && vsCodeNewWindow;
437
+ const shouldOpenVsCodeNewWindow = (0, exports.isVsCodeDerivative)(editor.command) && vsCodeNewWindow;
419
438
  const args = shouldOpenVsCodeNewWindow
420
439
  ? ['--new-window', fileName]
421
440
  : lineNumber
422
- ? getArgumentsForLineNumber(editor, fileName, String(lineNumber), colNumber)
441
+ ? getArgumentsForLineNumber(editor.command, fileName, String(lineNumber), colNumber)
423
442
  : [fileName];
424
- if (_childProcess && isTerminalEditor(editor)) {
443
+ if (_childProcess && isTerminalEditor(editor.command)) {
425
444
  // There's an existing editor process already and it's attached
426
445
  // to the terminal, so go kill it. Otherwise two separate editor
427
446
  // instances attach to the stdin/stdout which gets confusing.
428
447
  _childProcess.kill('SIGKILL');
429
448
  }
449
+ const isWin = os_1.default.platform() === 'win32';
450
+ const where = isWin ? 'where' : 'which';
451
+ const binaryToUse = await new Promise((resolve) => {
452
+ if (editor.command === editor.process) {
453
+ resolve(editor.command);
454
+ return;
455
+ }
456
+ child_process_1.default.exec(`${where} "${editor.command}"`, (err) => {
457
+ if (err) {
458
+ resolve(editor.process);
459
+ }
460
+ else {
461
+ resolve(editor.command);
462
+ }
463
+ });
464
+ });
430
465
  if (process.platform === 'win32') {
431
466
  // On Windows, launch the editor in a shell because spawn can only
432
467
  // launch .exe files.
433
- _childProcess = child_process_1.default.spawn('cmd.exe', ['/C', editor].concat(args), { stdio: 'inherit', detached: true });
468
+ _childProcess = child_process_1.default.spawn('cmd.exe', ['/C', binaryToUse].concat(args), { stdio: 'inherit', detached: true });
434
469
  }
435
470
  else {
436
- _childProcess = child_process_1.default.spawn(editor, args, { stdio: 'inherit' });
471
+ _childProcess = child_process_1.default.spawn(binaryToUse, args, { stdio: 'inherit' });
437
472
  }
438
473
  _childProcess.on('exit', (errorCode) => {
439
474
  _childProcess = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-video",
3
- "version": "3.1.0",
3
+ "version": "3.1.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -35,5 +35,5 @@
35
35
  "prettier-plugin-organize-imports": "^2.3.4",
36
36
  "typescript": "^4.7.0"
37
37
  },
38
- "gitHead": "482c66127662171577aa427f10fe265fa1bc933b"
38
+ "gitHead": "d57ec16eaf33280c89b0974997946ab9ea155372"
39
39
  }