Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function(file) {
// check for existence first
if (!fs.existsSync(file)) {
throw new Error(file + ' doesn\'t exist');
}
var ext = path.extname(file);
// YAML file
if (ext.match(/ya?ml/)) {
var res = fs.readFileSync(file, 'utf8');
var yaml = require('js-yaml');
return yaml.safeLoad(res, { schema: yaml.DEFAULT_FULL_SCHEMA });
}
// CSON file
if (ext.match(/cson/)) {
var cson = require('cson');
return cson.parseCSONFile(file);
}
// JS / JSON / CoffeeScript
if (ext.match(/json|js|coffee|ls/)) {
if (!path.isAbsolute(file)) {
file = path.join(process.cwd(), file);
}
return require(file);
}
static async readYaml (filePath: string, fullSchema: boolean = true): Promise {
const contents = await File.read(filePath)
return yaml.load(contents, {
schema: fullSchema ? yaml.DEFAULT_FULL_SCHEMA : yaml.DEFAULT_SAFE_SCHEMA
})
}
function getConfig(projPath) {
if (!cfg) {
cfg = yaml.load(fsix_js_1.fsix.readUtf8Sync('./config.yaml'), yaml.DEFAULT_FULL_SCHEMA);
cfg.paths.PROJ_PATH = fsix_js_1.fsix.toPosixSlash(projPath);
cfg.release.demosStr = cfg.release.demos.length > 1 ?
"{" + cfg.release.demos.join(',') + "}" : cfg.release.demos[0];
expandMap(cfg.webLinks);
expandMap(cfg.paths);
}
return cfg;
}
DevCfg.getConfig = getConfig;
export function getConfig(projPath: string): DevCfg.DevConfig {
if (!cfg) {
cfg = yaml.load(fsix.readUtf8Sync('./config.yaml'), yaml.DEFAULT_FULL_SCHEMA);
cfg.paths.PROJ_PATH = fsix.toPosixSlash(projPath);
cfg.release.demosStr = cfg.release.demos.length > 1 ?
`{${cfg.release.demos.join(',')}}` : cfg.release.demos[0];
expandMap(cfg.webLinks);
expandMap(cfg.paths);
}
return cfg;
}
serialize_sublime_syntax(g_def={}) {
return `%YAML 1.2\n---\n${yaml.safeDump({
...this.other,
...g_def,
name: this.name,
variables: this.export_variables(),
contexts: Object.entries(this.contexts)
.reduce((h_contexts, [si_context, k_context]) => ({
...h_contexts,
[si_context]: k_context.export(),
}), {}),
}, {
noRefs: true,
noCompatMode: true,
lineWidth: 600,
schema: yaml.DEFAULT_FULL_SCHEMA,
})}`;
}