How to use the fs-extra.pathExists function in fs-extra

To help you get started, we’ve selected a few fs-extra 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 computestdev / Openrunner / building / buildFirefoxProfile.js View on Github external
const buildCachedFirefoxExtensionDirectory = async ({tempDirectory, extensionOptions = {}, buildCacheDirectory}) => {
    const cacheName = `firefox-extension-${packageVersion}-${Number(extensionOptions.cncPort)}`;
    const extensionPath = joinPath(buildCacheDirectory, cacheName);

    // quick check to see if the extension directory looks valid
    const manifestValid = await fs.pathExists(joinPath(extensionPath, 'manifest.json'));
    const buildConfigValid = await fs.pathExists(joinPath(extensionPath, 'build', 'buildConfig.json'));
    const scriptEnvValid = await fs.pathExists(joinPath(extensionPath, 'build', 'script-env.js'));

    if (manifestValid && buildConfigValid && scriptEnvValid) {
        log.debug({cncPort: extensionOptions.cncPort, extensionPath}, 'Using cached extension directory');
        return extensionPath;
    }

    await fs.mkdirp(extensionPath).catch(err => {
        err[ERROR_FAILED_TO_CREATE_EXTENSION_CACHE] = true;
        throw err;
    });

    await buildFirefoxExtension({tempDirectory, extensionOptions, outputPath: extensionPath, zipped: false});
    return extensionPath;
};
github Tangerine-Community / Tangerine / server-v3 / index.js View on Github external
async function saveFormsJson(formParameters, group) {
  console.log("formParameters: " + JSON.stringify(formParameters))
  let contentRoot = config.contentRoot
  let formsJsonPath = contentRoot + '/' + group + '/forms.json'
  console.log("formsJsonPath:" + formsJsonPath)
  let formJson
  try {
    const exists = await fs.pathExists(formsJsonPath)
    if (exists) {
      console.log("formsJsonPath exists")
      // read formsJsonPath and add formParameters to formJson
        try {
          formJson = await fs.readJson(formsJsonPath)
          console.log("formJson: " + JSON.stringify(formJson))
          console.log("formParameters: " + JSON.stringify(formParameters))
          if (formParameters !== null) {
            formJson.push(formParameters)
          }
          console.log("formJson with new formParameters: " + JSON.stringify(formJson))
        } catch (err) {
          console.error("An error reading the json form: " + err)
        }
    } else {
      // create an empty formJson
github strongloop / loopback-next / packages / testlab / src / __tests__ / integration / test-sandbox.integration.ts View on Github external
async function deleteSandbox() {
    if (!(await pathExists(path))) return;
    await remove(sandbox.getPath());
  }
});
github microsoft / botbuilder-tools / packages / CogLint / src / schemaTracker.ts View on Github external
processRole(def.$role, type);
                                    } else {
                                        for (let role of def.$role) {
                                            processRole(role, type);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            let metaSchemaName = schemaObject.$schema;
            let metaSchemaCache = path.join(__dirname, path.basename(metaSchemaName));
            let metaSchema: any;
            if (!await fs.pathExists(metaSchemaCache)) {
                metaSchema = JSON.parse(await this.getURL(metaSchemaName));
                await fs.writeJSON(metaSchemaCache, metaSchema, { spaces: 4 });
            } else {
                metaSchema = await fs.readJSON(metaSchemaCache);
            }
            if (!this.validator.getSchema(metaSchemaName)) {
                this.validator.addSchema(metaSchema, metaSchemaName);
            }
            this.validator.addSchema(schemaObject, schemaPath);
            validator = this.validator.getSchema(schemaPath);
        }
        return [validator, added];
    }
github Akryum / nodepack / packages / @nodepack / utils / src / configFiles.js View on Github external
exports.ensureConfigFile = async (cwd, name, defaultContent, checkConfigFolder = true) => {
  if (checkConfigFolder) {
    await exports.ensureConfigFolder(cwd)
  }
  const base = exports.getConfigFolder(cwd)
  const file = path.join(base, name)
  if (!await fs.pathExists(file)) {
    await exports.writeConfigFile(cwd, name, defaultContent)
  }
}
github microsoft / BotBuilder-Samples / experimental / generation / generator / packages / library / src / dialogGenerator.ts View on Github external
async function generateFile(path: string, val: any, force: boolean, feedback: Feedback) {
    if (force || !await fs.pathExists(path)) {
        feedback(FeedbackType.info, `Generating ${path}`)
        await writeFile(path, val, feedback)
    } else {
        feedback(FeedbackType.warning, `Skipping already existing ${path}`)
    }
}
github timberio / gitdocs / src / bundler / routing.js View on Github external
export async function generateRouteTree (baseDir, outputDir) {
  if (!await fs.pathExists(baseDir)) {
    throw new Error(`Could not find any documentation in ${baseDir}`)
  }

  const files = await megaGlob(`${baseDir}/**/*.md`, {
    nodir: true,
    ignore: ['**/_*/**'],
  })

  const tree = await Promise.all(
    files.map(async file => {
      const ext = path.extname(file)
      const index = `${removeExt(file)}/index${ext}`

      if (await fs.pathExists(index)) {
        throw new Error(`Conflicting files were found:\n\t- ${file}\n\t- ${index}`)
      }
github Open-EO / openeo-earthengine-driver / src / models / jobstore.js View on Github external
removeResults(jobId) {
		var p = this.makeFolder(this.jobFolder, [jobId]);
		if (!p) {
			return Promise.reject(new Errors.NotFound());
		}

		return fse.pathExists(p)
		.then((exists) => exists ? fse.remove(p) : Promise.resolve());
	}
github eclipse / codewind / src / pfe / file-watcher / server / src / utils / utils.ts View on Github external
export async function asyncReadJSONFile(filePath: string): Promise {
let contents: any = {};
    try {
        if (await fse.pathExists(filePath)) {
            contents = await fse.readJson(filePath);
        }
        return contents;
    } catch (err) {
        logger.logError("Error reading file " + filePath);
        logger.logError(err);
        return contents = {};
    }
}
github teambit / bit / src / consumer / consumer-locator.ts View on Github external
async function pathHasScopeDir(path: string): Promise {
    return (await fs.pathExists(composeBitHiddenDirPath(path))) || fs.pathExists(composeBitGitHiddenDirPath(path));
  }