Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
};
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
async function deleteSandbox() {
if (!(await pathExists(path))) return;
await remove(sandbox.getPath());
}
});
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];
}
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)
}
}
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}`)
}
}
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}`)
}
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());
}
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 = {};
}
}
async function pathHasScopeDir(path: string): Promise {
return (await fs.pathExists(composeBitHiddenDirPath(path))) || fs.pathExists(composeBitGitHiddenDirPath(path));
}