How to use the web-ext-native-msg.CmdArgs function in web-ext-native-msg

To help you get started, we’ve selected a few web-ext-native-msg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asamuzaK / withExEditorHost / modules / main.js View on Github external
data = data && JSON.parse(data);
  if (isObjectNotEmpty(data)) {
    const {editorPath} = data;
    const editorName = await getFileNameFromFilePath(editorPath);
    const executable = isExecutable(editorPath);
    const timestamp = await getFileTimestamp(editorConfigPath);
    const reg =
      new RegExp(`\\$(?:${TMP_FILE_PLACEHOLDER}|{${TMP_FILE_PLACEHOLDER}})`);
    const keys = Object.keys(editorConfig);
    for (const key of keys) {
      const value = data[key];
      if (key === "editorPath") {
        editorConfig[key] = value;
      }
      if (key === "cmdArgs") {
        editorConfig[key] = new CmdArgs(value).toArray();
        editorConfig.hasPlaceholder = reg.test(value);
      }
    }
    const msg = {
      [EDITOR_CONFIG_RES]: {
        editorName, executable,
        [EDITOR_CONFIG_TS]: timestamp,
      },
    };
    func = writeStdout(msg);
  }
  return func || null;
};
github asamuzaK / withExEditorHost / modules / main.js View on Github external
throw new Error("Application is not executable.");
  }
  const {cmdArgs, hasPlaceholder} = editorConfig;
  const opt = {
    cwd: null,
    encoding: CHAR,
    env: process.env,
  };
  let args, proc;
  if (Array.isArray(cmdArgs)) {
    args = cmdArgs.slice();
  } else {
    args = new CmdArgs(cmdArgs).toArray();
  }
  if (hasPlaceholder) {
    const [filePath] = new CmdArgs(quoteArg(file)).toArray();
    const reg =
      new RegExp(`\\$(?:${TMP_FILE_PLACEHOLDER}|{${TMP_FILE_PLACEHOLDER}})`);
    const l = args.length;
    let i = 0;
    while (i < l) {
      const arg = args[i];
      reg.test(arg) && args.splice(i, 1, arg.replace(reg, filePath));
      i++;
    }
    proc = await new ChildProcess(app, args, opt).spawn();
  } else {
    proc = await new ChildProcess(app, args, opt).spawn(file);
  }
  proc.on("error", handleChildProcessErr);
  proc.stderr.on("data", handleChildProcessStderr);
  proc.stdout.on("data", handleChildProcessStdout);
github asamuzaK / withExEditorHost / modules / main.js View on Github external
throw new Error(`No such file: ${file}`);
  }
  if (!isExecutable(app)) {
    throw new Error("Application is not executable.");
  }
  const {cmdArgs, hasPlaceholder} = editorConfig;
  const opt = {
    cwd: null,
    encoding: CHAR,
    env: process.env,
  };
  let args, proc;
  if (Array.isArray(cmdArgs)) {
    args = cmdArgs.slice();
  } else {
    args = new CmdArgs(cmdArgs).toArray();
  }
  if (hasPlaceholder) {
    const [filePath] = new CmdArgs(quoteArg(file)).toArray();
    const reg =
      new RegExp(`\\$(?:${TMP_FILE_PLACEHOLDER}|{${TMP_FILE_PLACEHOLDER}})`);
    const l = args.length;
    let i = 0;
    while (i < l) {
      const arg = args[i];
      reg.test(arg) && args.splice(i, 1, arg.replace(reg, filePath));
      i++;
    }
    proc = await new ChildProcess(app, args, opt).spawn();
  } else {
    proc = await new ChildProcess(app, args, opt).spawn(file);
  }
github asamuzaK / withExEditorHost / modules / setup.js View on Github external
const handleCmdArgsInput = async editorArgs => {
  let cmdArgs;
  if (Array.isArray(editorArgs)) {
    cmdArgs = editorArgs;
  } else {
    const ans = readline.question("Input command line options: ");
    cmdArgs = new CmdArgs(ans.trim()).toArray();
  }
  return cmdArgs;
};
github asamuzaK / withExEditorHost / modules / setup.js View on Github external
const handleCmdArgsInput = async editorArgs => {
  let cmdArgs;
  if (Array.isArray(editorArgs)) {
    cmdArgs = editorArgs;
  } else {
    const ans = readline.question("Input command line options: ");
    cmdArgs = (new CmdArgs(ans.trim())).toArray();
  }
  return cmdArgs;
};