Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function checkAllTutorials() {
const files = (await fs.walk('../js/tutorials/playlists')).map(x => x.path);
const jsonFiles = files.filter(x => x.endsWith('.json'));
const promises = [];
const tutorials = [];
for (const jsonFilename of jsonFiles) {
let jsonData = null;
try {
jsonData = parseJson(await fs.readFile(jsonFilename));
tutorials.push(jsonData);
} catch (e) {
console.error('Error loading ', jsonFilename, '\n', e);
continue;
}
promises.push(reportAndFix(jsonFilename, jsonData));
}
await Promise.all(promises);
// Used for testing down below
let defaultTutorials = null;
try {
defaultTutorials = require('../js/tutorials/playlistConfig.js').getTutorials(
''
);
} catch (e) {
async function checkAllTutorials() {
const files = await walk('js/learn/tutorials');
const jsonFiles = files.filter((x) => x.endsWith('.json'));
const promises = [];
const tutorials = [];
for (let jsonFilename of jsonFiles) {
let jsonData = null;
try {
jsonData = parseJson(await readFile(jsonFilename));
tutorials.push(jsonData);
} catch (e) {
console.error('Error loading ', jsonFilename, '\n', e);
continue;
}
promises.push(reportAndFix(jsonFilename, jsonData));
}
await Promise.all(promises);
// Used for testing down below
let defaultTutorials = null;
try {
defaultTutorials = require('../js/learn/learnConfig.js').defaultTutorials;
} catch (e) {
console.error('Error importing learnConfig.js\n', e);
return;
console.log(`Unable to load settings.json at ${filePath}`);
if (e.code !== 'ENOENT') {
console.log(e);
} else {
[
'It does not exist.',
'',
'You can create the file with "mup init" or add the option',
'"--settings path/to/settings.json" to load it from a',
'different location.'
].forEach(text => console.log(text));
}
process.exit(1);
}
try {
settings = parseJson(settings);
} catch (e) {
console.log('Error parsing settings file:');
console.log(e.message);
process.exit(1);
}
return settings;
}
console.log(`Unable to load settings.json at ${filePath}`);
if (e.code !== 'ENOENT') {
console.log(e);
} else {
[
'It does not exist.',
'',
'You can create the file with "mup init" or add the option',
'"--settings path/to/settings.json" to load it from a',
'different location.'
].forEach(text => console.log(text));
}
process.exit(1);
}
try {
settings = parseJson(settings);
} catch (e) {
console.log('Error parsing settings file:');
console.log(e.message);
process.exit(1);
}
return settings;
}
async function loadJson(file) {
const contents = String(await sander.readFile(file));
try {
return [null, parse(contents, file)];
} catch (error) {
const message = error.message;
const [numbers] = /(\d+:\d+)/.exec(message) || [""];
const [line = 0, column = 0] = numbers
.split(":")
.map(n => Number(n))
.filter(n => !isNaN(n));
const frame = codeFrame(contents, line, column);
const err = new Error(["", frame, message].join("\n"));
err.filename = file;
return [err];
}
}
...args
};
}
if (args.includeGlob) {
args.includeGlob = toArray(args.includeGlob);
}
if (args.globIncludePatterns) {
args.globIncludePatterns = toArray(args.globIncludePatterns);
}
if (args.config) {
const filePath = path.resolve(args.config);
const fileRawData = fs.readFileSync(filePath);
const fileConfigData = parseJSON(stripJSONComments(String(fileRawData)));
if (process.env.VERBOSE) {
console.log('Loaded config from file', filePath, fileConfigData);
}
return {
...defaultConfig,
...normalizedConfig(fileConfigData),
...args
};
}
let packageJSONPath;
try {
packageJSONPath = path.resolve(path.join(getProjectDir(args), 'package.json'));
let messageData: LocalizedMessageData;
let messageContents: string | Buffer;
let extensionName: string = manifestData.name;
try {
messageContents = await fs.readFile(messageFile, {encoding: 'utf-8'});
} catch (error) {
throw new UsageError(
`Error reading messages.json file at ${messageFile}: ${error}`);
}
messageContents = stripBom(messageContents);
try {
messageData = parseJSON(stripJsonComments(messageContents));
} catch (error) {
throw new UsageError(
`Error parsing messages.json file at ${messageFile}: ${error}`);
}
extensionName = manifestData.name.replace(
/__MSG_([A-Za-z0-9@_]+?)__/g,
(match, messageName) => {
if (!(messageData[messageName]
&& messageData[messageName].message)) {
const error = new UsageError(
`The locale file ${messageFile} ` +
`is missing key: ${messageName}`);
throw error;
} else {
return messageData[messageName].message;
export async function readConfigFile(filePath: string): Promise {
let contents = await fs.readFile(filePath);
let config = parseJson(contents);
return config;
}