Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const read = (input, options) => {
let data, output;
// Validate CSON
try {
data = parseCson.parse(input);
} catch (error) {
throw error;
}
output = {
scope: null,
completions: []
};
for (let k in data) {
let v = data[k];
if (options.scope !== null) {
output.scope = options.scope;
} else {
// Get scope, convert if necessary
transform: function (pattern, opts, done) {
var cson = pattern.cson;
// function support
if (_.isFunction(cson)) {
cson.call(this, function (result) {
// override cson function with value
cson = result;
});
}
try {
done({
json: CSON.parse(cson)
});
} catch (e) {
done(e);
}
}
};
configFile.on("change", (cache, file) => {
// Read config file
let _config: { [key: string]: any } = cson.parse(file) || {};
_config = _config["*"] || {};
cache.set("config", _config);
});
fs.readFile(contentPath, (_err, content) => {
var grammar = cson.parse(content);
let result = {
information_for_contributors: [
'This file is generated from ' + contentPath
]
};
let keys = ['name', 'scopeName', 'comment', 'injections', 'patterns', 'repository'];
for (let key of keys) {
if (grammar.hasOwnProperty(key)) {
result[key] = grammar[key];
}
}
try {
fs.writeFileSync(dest, JSON.stringify(result, null, '\t').replace(/\n/g, '\r\n'));
console.log('Updated ' + path.basename(dest));
files.map((file) => {
let data = cson.parse(file.contents)[TOP_LEVEL_KEY]
data = data || cson.parse(file.contents)['.source.json']
return {
path: file.path,
contents: data
}
})
)
files.map((file) => {
let data = cson.parse(file.contents)[TOP_LEVEL_KEY]
data = data || cson.parse(file.contents)['.source.json']
return {
path: file.path,
contents: data
}
})
)
function getConfig(file) {
const fs = require('fs');
const realFile = fs.realpathSync(file);
delete require.cache[realFile];
switch (require('path').extname(file)) {
case '.json':
case '.js':
return require(realFile);
case '.cson':
return require('cson-parser').parse(fs.readFileSync(realFile));
case '.yaml':
case '.yml':
return require('js-yaml').safeLoad(fs.readFileSync(realFile));
}
return {};
}
module.exports = async function () {
const cson = await readFile(path.join(__dirname, './stations.cson'));
const stations = CSON.parse(cson);
return pMap(stations.playlist.track, async station => {
try {
const stream = await getStreamInfo(station);
if (!stream) return station;
return Object.assign({}, station, { stream });
} catch (err) {
return station;
}
});
};
return download(contentPath).then(function (content) {
var ext = path.extname(repoPath);
var grammar;
if (ext === '.tmLanguage' || ext === '.plist') {
grammar = plist.parse(content);
} else if (ext === '.cson') {
grammar = cson.parse(content);
} else if (ext === '.json' || ext === '.JSON-tmLanguage') {
grammar = JSON.parse(content);
} else {
return Promise.reject(new Error('Unknown file extension: ' + ext));
}
if (modifyGrammar) {
modifyGrammar(grammar);
}
return getCommitSha(repoId, repoPath).then(function (info) {
let result = {
information_for_contributors: [
'This file has been converted from https://github.com/' + repoId + '/blob/master/' + repoPath,
'If you want to provide a fix or improvement, please create a pull request against the original repository.',
'Once accepted there, we are happy to receive an update request.'
]
};