Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async getConfig({ config = this.defaultConfig }: { readonly config?: TConfig } = {}): Promise {
let contents;
try {
contents = await fs.readFile(this.configPath, 'utf8');
} catch (error) {
if (error.code === 'ENOENT') {
return this.update({ config });
}
throw error;
}
const currentConfig = JSON.parse(contents);
await this.validate(currentConfig);
if (config !== undefined) {
// tslint:disable-next-line no-any
return (SeamlessImmutable as any).merge(config, currentConfig, {
deep: true,
});
.then(data => {
// Src can either be absolute or relative to opts.base
if (opts.src !== path.resolve(data) && !isExternal(opts.src)) {
file.path = path.join(opts.base, opts.src);
} else {
file.path = path.relative(process.cwd(), data);
}
return fs.readFile(file.path).then(contents => {
file.contents = contents;
return file;
});
});
}
toolUtils.insertContentIntoFile = async function(filePath, markerOpen, markerClose, contentToInsert) {
const fs = require('fs-extra');
let content = await fs.readFile(filePath, 'utf-8');
// [^]* matches any character including new lines
const regex = new RegExp(`${markerOpen}[^]*?${markerClose}`);
content = content.replace(regex, markerOpen + contentToInsert + markerClose);
await fs.writeFile(filePath, content);
};
async getAsync(): Promise {
let mtime: Date;
try {
const stats = await fs.stat(this.filename);
mtime = stats.mtime;
} catch (e) {
try {
await fs.mkdirp(getCacheDir());
if (this.bootstrapFile) {
const bootstrapContents = (await fs.readFile(this.bootstrapFile)).toString();
await fs.writeFile(this.filename, bootstrapContents, 'utf8');
}
} catch (e) {
// intentional no-op
}
mtime = new Date(1989, 10, 19);
}
let fromCache: T | null = null;
let failedRefresh = null;
// if mtime + ttl >= now, attempt to fetch the value, otherwise read from disk
if (new Date().getTime() - mtime.getTime() > this.ttlMilliseconds) {
try {
fromCache = await this.refresher();
return Promise.all(assets.map(async ({ filePath, src, hash }) => {
const imageOptions = processQueue.images.createImageOptions(options)
const filename = processQueue.images.createFileName(filePath, imageOptions, hash)
const cachePath = path.join(imageCacheDir, filename)
const destPath = path.join(context, src)
const buffer = await fs.readFile(destPath)
return { filePath, destPath, cachePath, buffer }
}))
}
return new Promise((resolve, reject) => {
fs.readFile("php/authlist.php", {encoding: "utf-8"}, (err, data) => {
var authList = auths.map(a => '"' + a.name + '" => "' + a.php_verifier + '"').join(",");
data = data.replace("$auth_list = array();", "$auth_list = array(" + authList + ");")
const outputFile = path.join(options.userConfig.output_directory, "authlist.php");
fs.writeFile(outputFile, data, {encoding: "utf8"}, err => {
if (err) {
return reject(NICE_ERRORS.COULD_NOT_WRITE_API(err, outputFile));
}
return resolve(options);
});
})
});
}
export async function logKeystoreHashes(keystoreInfo: KeystoreInfo, linePrefix: string = '') {
const { keystorePath, keystorePassword, keyAlias } = keystoreInfo;
const certFile = `${keystorePath}.cer`;
try {
await exportCertBinary(keystoreInfo, certFile);
const data = await fs.readFile(certFile);
const googleHash = crypto
.createHash('sha1')
.update(data)
.digest('hex')
.toUpperCase();
const googleHash256 = crypto
.createHash('sha256')
.update(data)
.digest('hex')
.toUpperCase();
const fbHash = crypto
.createHash('sha1')
.update(data)
.digest('base64');
log.info(
`${linePrefix}Google Certificate Fingerprint: ${googleHash.replace(
async function extractCustomProperties (filePath) {
const contents = await readFile(filePath, 'utf-8')
const root = postcss.parse(contents, { from: filePath })
const customProps = {}
root.walkDecls(node => {
const { prop, value } = node
if (prop.startsWith('--')) {
const prev = node.prev()
const comment = prev && prev.type === 'comment' ? prev.text : undefined
const { variable, fallbacks } = extractVarDefinition(value)
customProps[prop] = {
prop,
value,
comment,
variable,
fallbacks
async function getProjectToken (tokenPath, config) {
var token;
try {
token = await fs.readFile(tokenPath, { encoding: 'utf-8' });
} catch (err) {
let deployment = await request.post({
url: urljoin(IDYLL_PUB_API, 'create'),
body: {
name: config.name
},
json: true
});
token = deployment.token;
await fs.writeFile(tokenPath, token, { encoding: 'utf-8' });
}
return token;
}