• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / videobrew / 8171994845

06 Mar 2024 12:24PM UTC coverage: 25.12% (-19.2%) from 44.313%
8171994845

Pull #25

github

web-flow
Merge 792373961 into 00419a58c
Pull Request #25: Feature/install playwright

356 of 537 branches covered (66.29%)

Branch coverage included in aggregate %.

18 of 93 new or added lines in 7 files covered. (19.35%)

1730 existing lines in 23 files now uncovered.

2003 of 8854 relevant lines covered (22.62%)

461.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/cli/src/editor.ts
UNCOV
1
import { exec, spawn, ChildProcess } from 'child_process';
×
UNCOV
2
import { debug, panic } from './utils/logging.js';
×
UNCOV
3
import path from 'path';
×
UNCOV
4
import util from 'util';
×
UNCOV
5
import fs from 'fs';
×
UNCOV
6

×
UNCOV
7
const execAsync = util.promisify(exec);
×
UNCOV
8

×
UNCOV
9
export const EDITOR_PACKAGE_NAME = '@videobrew/editor';
×
UNCOV
10
const FILE_PREFIX = 'file:';
×
UNCOV
11
const PORT = 8087;
×
UNCOV
12
const HOST = 'localhost';
×
UNCOV
13

×
UNCOV
14
export type EditorInstance = {
×
UNCOV
15
  server: ChildProcess,
×
UNCOV
16
  port: number,
×
UNCOV
17
  host: string,
×
UNCOV
18
}
×
UNCOV
19

×
UNCOV
20
/**
×
UNCOV
21
 * Gets where the editor is installed (globally)
×
UNCOV
22
 */
×
23
export async function getEditorInstallPath(installedGlobally: boolean): Promise<string | null> {
×
24
  const globalOption = installedGlobally ? '-g ' : '';
×
25
  let json: string;
×
26

×
27
  try {
×
28
    const {
×
29
      stdout,
×
30
    } = await execAsync(`npm list ${globalOption}${EDITOR_PACKAGE_NAME} --json`);
×
31
    json = stdout;
×
32
  } catch (e) {
×
33
    // If the editor is not installed, npm list will exit with code 1
×
34
    return null;
×
35
  }
×
36

×
37
  const { dependencies } = JSON.parse(json);
×
38
  let npmPath: string | undefined;
×
39
  
×
40
  let editorPath = dependencies[EDITOR_PACKAGE_NAME].resolved;
×
41

×
42
  if (!installedGlobally) {
×
43
    editorPath = path.join(process.cwd(), 'node_modules', EDITOR_PACKAGE_NAME);
×
44
  } else if (editorPath) {
×
45
    // Individual dependencies can be resolved when they're symlinked with `npm link`
×
46
    if (!editorPath.startsWith(FILE_PREFIX)) {
×
47
      // TODO: support other protocols
×
48
      panic(`[Videobrew | Editor Server] Unsupported protocol for package: ${editorPath} (only ${FILE_PREFIX} is supported)`);
×
49
    }
×
50
  
×
51
    editorPath = editorPath.substring(FILE_PREFIX.length);
×
52
  } else {
×
53
    // Otherwise they're relative to the where global npm packages are installed 
×
54
    const { stdout } = await execAsync('npm root -g');
×
55
    npmPath = stdout.trim();
×
56
    editorPath = path.join(npmPath, EDITOR_PACKAGE_NAME);
×
57
  }
×
58

×
59
  if (!fs.existsSync(editorPath)) {
×
60
    console.log({
×
61
      npmPath,
×
62
      dependencies,
×
63
      editorPath,
×
64
    });
×
65
    panic(`[Videobrew | Editor Server] Editor package not found at ${editorPath} (but it was installed according to npm list)`);
×
66
  }
×
67

×
68
  return editorPath;
×
69
}
×
UNCOV
70

×
UNCOV
71
/**
×
UNCOV
72
 * Installs the editor globally with npm and returns the path
×
UNCOV
73
 */
×
UNCOV
74
export function getEditorInstaller(installGlobally: boolean) {
×
75
  const installOption = installGlobally ? '-g' : '--save-dev';
×
76
  const command = `npm install ${installOption} ${EDITOR_PACKAGE_NAME}`;
×
77

×
78
  return {
×
79
    command,
×
80
    install: async () => {
×
81
      return new Promise((resolve, reject) => {
×
82
        const { stdout, stderr } = exec(command, async (exception, stdout, stderr) => {
×
83
          if (exception) {
×
84
            reject(exception);
×
85
          }
×
86
          
×
87
          resolve(await getEditorInstallPath(installGlobally));
×
88
        });
×
89
      });
×
90
    },
×
91
  };
×
92
}
×
UNCOV
93

×
UNCOV
94
/**
×
UNCOV
95
 * Starts the editor server
×
UNCOV
96
 */
×
97
export async function startEditor(videoAppUrl: string, isGloballyInstalled: boolean): Promise<EditorInstance> {
×
98
  let editorPath = await getEditorInstallPath(isGloballyInstalled);
×
99
    
×
100
  if (!editorPath) {
×
101
    throw new Error('Editor not installed!');
×
102
  }
×
103

×
104
  const editorServer = spawn('node', [editorPath], {
×
105
    stdio: ['inherit', 'pipe', 'pipe'],
×
106
    env: {
×
107
      'PORT': `${PORT}`,
×
108
      'HOST': HOST,
×
109
      'VIDEOBREW_VIDEO_APP_URL': videoAppUrl,
×
110
    },
×
111
  });
×
112

×
113
  return {
×
114
    server: editorServer,
×
115
    port: PORT,
×
116
    host: HOST,
×
117
  }
×
118
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc