How to use the web-ext-native-msg.isFile 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
const spawnChildProcess = async (file, app = editorConfig.editorPath) => {
  if (!isFile(file)) {
    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();
github asamuzaK / withExEditorHost / modules / main.js View on Github external
const getEditorConfig = async editorConfigPath => {
  const func = [];
  if (isFile(editorConfigPath)) {
    const data = await readFile(editorConfigPath, {
      encoding: CHAR, flag: "r",
    });
    func.push(exportEditorConfig(data, editorConfigPath));
  } else {
    func.push(
      writeStdout(hostMsg(`No such file: ${editorConfigPath}`, "warn")),
      writeStdout({[EDITOR_CONFIG_RES]: null}),
    );
  }
  return Promise.all(func);
};
github asamuzaK / withExEditorHost / modules / main.js View on Github external
const createTmpFileResMsg = async key => {
  let func;
  if (isString(key) && isFile(key)) {
    const fileId = await getFileIdFromFilePath(key);
    if (fileId) {
      const obj = fileMap[TMP_FILES].get(fileId);
      if (obj) {
        const {data} = obj;
        if (data) {
          const value =
            await readFile(key, {encoding: CHAR, flag: "r"}) || "";
          data.timestamp = await getFileTimestamp(key);
          func = writeStdout({
            [TMP_FILE_RES]: {
              data, value,
            },
          });
        }
      }
github asamuzaK / withExEditorHost / modules / setup.js View on Github external
if (!isDir(configPath)) {
    throw new Error(`No such directory: ${configPath}.`);
  }
  const editorArgs = setupOpts.get("editorArgs");
  const editorPath = setupOpts.get("editorPath");
  const overwriteEditorConfig = setupOpts.get("overwriteEditorConfig");
  const file = path.join(configPath, EDITOR_CONFIG_FILE);
  let func;
  setupOpts.set("configPath", configPath);
  if (isString(editorPath)) {
    setupOpts.set("editorFilePath", editorPath.trim());
  }
  if (isString(editorArgs)) {
    setupOpts.set("editorCmdArgs", (new CmdArgs(editorArgs.trim())).toArray());
  }
  if (isFile(file) && !overwriteEditorConfig) {
    const ans = readline.keyInYNStrict(`${file} already exists.\nOverwrite?`);
    if (ans) {
      func = createEditorConfig().catch(throwErr);
    } else {
      func = abortSetup(`${file} already exists.`);
    }
  } else {
    func = createEditorConfig().catch(throwErr);
  }
  return func || null;
};
github asamuzaK / withExEditorHost / modules / main.js View on Github external
const viewLocalFile = async uri => {
  if (!isString(uri)) {
    throw new TypeError(`Expected String but got ${getType(uri)}.`);
  }
  let func;
  const {protocol} = new URL(uri);
  if (protocol === "file:") {
    const file = await convertUriToFilePath(uri);
    if (file && isFile(file)) {
      func = spawnChildProcess(file);
    }
  }
  return func || null;
};