Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var callback = _callback || function () { };
if (!this.src_unzipped) {
// generate the zipped buffer
var buff = this.content.generate({
type: "nodebuffer",
compression: this.compressed ? "DEFLATE" : undefined
});
var normalized_path = path.normalize(_path);
// write the new file
if (!this.save_async) {
fs.writeFileSync(normalized_path, buff);
}
else
fs.writeFile(normalized_path, buff, function (err) {
if (err) {
callback(err);
return;
}
//invoke the callback
callback(null);
});
}
else {
function createFileSync (file) {
let stats
try {
stats = fs.statSync(file)
} catch (e) {}
if (stats && stats.isFile()) return
const dir = path.dirname(file)
if (!fs.existsSync(dir)) {
mkdir.mkdirsSync(dir)
}
fs.writeFileSync(file, '')
}
characterSvgs.forEach(function (char) {
var filename = char.name ? char.name : char.code;
//If a subset of icons set was requested, ignore any others that are not within the subset
if (config.icons && config.icons.length &&
config.icons.indexOf(char.code) == -1 &&
config.icons.indexOf(filename) == -1) {
return;
}
savedIcons.push(char);
fs.writeFileSync(path.join(svgDir, filename + '.svg'), char.svg);
});
console.info("Saved " + savedIcons.length + " files to " + svgDir);
function createYaml (options, xmlObject) {
if (!options.silent) {
console.log(yaml.stringify(xmlObject, 4));
}
if (options.yaml) {
const fileName = options.yaml.substring(0, options.yaml.length - path.extname(options.yaml).length);
fs.writeFileSync(path.join(util.licensesDir(), `${fileName}.yaml`), yaml.stringify(xmlObject, 4));
}
}
function createFileSync (file) {
let stats
try {
stats = fs.statSync(file)
} catch (e) {}
if (stats && stats.isFile()) return
const dir = path.dirname(file)
if (!fs.existsSync(dir)) {
mkdir.mkdirsSync(dir)
}
fs.writeFileSync(file, '')
}
function createFileSync (file) {
if (fs.existsSync(file)) return
var dir = path.dirname(file)
if (!fs.existsSync(dir)) {
mkdir.mkdirsSync(dir)
}
fs.writeFileSync(file, '')
}
fs.readdirSync( src ).forEach( function ( filename ) {
var srcpath = src + path.sep + filename,
destpath = dest + path.sep + filename;
if ( fs.statSync( srcpath ).isDirectory() ) {
return copydir( srcpath, destpath );
}
data = fs.readFileSync( srcpath, readOptions );
fs.writeFileSync( destpath, data, writeOptions );
});
};
function writeFileIfChanged (filePath, newFile) {
if (fs.existsSync(filePath)) {
var currentFile = fs.readFileSync(filePath);
var currentFileHash = md5(currentFile);
var newFileHash = md5(newFile);
if (newFileHash !== currentFileHash) {
fs.writeFileSync(filePath, newFile);
}
} else {
fs.writeFileSync(filePath, newFile);
}
}
function persist() {
if(fs.existsSync(instancesFile)) {
fs.truncateSync(instancesFile, 0);
}
fs.writeFileSync(instancesFile, JSON.stringify(instances, null, 2));
}
actions.forEach(({name, path}) => {
try {
log(path)
const contents = String(fs.readFileSync(path))
const patchedContents = patchHook(contents, name)
if (contents !== patchedContents) {
fs.writeFileSync(path, patchedContents)
}
} catch (_err) {
if (_err.code === 'EACCES') {
if (!process.env.ADBLOCK_SUDO && process.platform === 'linux') {
tryAgainWithSudo = true
} else {
err('\n *** Failed patching %s *** \n *** You NEED to run this script as an administrator or otherwise make the file accessible for patching! *** \n', path)
}
return
} else if (_err.code === 'EPERM') {
if (!process.env.ADBLOCK_SUDO && process.platform === 'linux') {
tryAgainWithSudo = true
} else if (!process.env.ADBLOCK_UAC && process.platform === 'win32') {
tryAgainWithUAC = true
} else {
err('\n *** Failed patching %s *** \n *** You NEED to run this script as an administrator or otherwise make the file accessible for patching! *** \n', path)