2020-04-30 08:47:18 +02:00
|
|
|
const fs = require('fs');
|
2020-04-30 09:01:04 +02:00
|
|
|
const process = require('process');
|
2020-04-30 08:47:18 +02:00
|
|
|
const request = require('request');
|
|
|
|
|
|
|
|
request('https://p5js.org/reference/data.json', (err, res) => {
|
|
|
|
if (!err) {
|
|
|
|
const result = res.toJSON();
|
|
|
|
const data = JSON.parse(result.body);
|
|
|
|
|
|
|
|
const arr = data.classitems;
|
|
|
|
const p5VariableKeywords = {};
|
|
|
|
const p5FunctionKeywords = {};
|
|
|
|
|
|
|
|
arr.forEach((obj) => {
|
|
|
|
if (obj.class === 'p5' && obj.module !== 'Foundation') {
|
|
|
|
if (obj.itemtype === 'property') {
|
|
|
|
p5VariableKeywords[`${obj.name}`] = 'p5Variable';
|
|
|
|
}
|
|
|
|
if (obj.itemtype === 'method') {
|
|
|
|
p5FunctionKeywords[`${obj.name}`] = 'p5Function';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let p5VariablePart = JSON.stringify(p5VariableKeywords);
|
|
|
|
let p5FunctionPart = JSON.stringify(p5FunctionKeywords);
|
|
|
|
p5VariablePart = p5VariablePart.replace(/"p5Variable"/g, 'p5Variable');
|
|
|
|
p5FunctionPart = p5FunctionPart.replace(/"p5Function"/g, 'p5Function');
|
|
|
|
|
2020-05-06 20:41:08 +02:00
|
|
|
let generatedCode = '/* eslint-disable */ \n';
|
|
|
|
generatedCode += '/* generated: do not edit! helper file for syntax highlighting. generated by update-syntax-highlighting script */ \n';
|
2020-04-30 08:47:18 +02:00
|
|
|
generatedCode += 'var p5Function = {type: "variable", style: "p5-function"};\n';
|
|
|
|
generatedCode += 'var p5Variable = {type: "variable", style: "p5-variable"};\n';
|
|
|
|
generatedCode += `let p5VariableKeywords = ${p5VariablePart}; \n`;
|
|
|
|
generatedCode += `let p5FunctionKeywords = ${p5FunctionPart}; \n`;
|
|
|
|
generatedCode += 'exports.p5FunctionKeywords = p5FunctionKeywords;\n';
|
|
|
|
generatedCode += 'exports.p5VariableKeywords = p5VariableKeywords;\n';
|
2020-05-06 20:41:08 +02:00
|
|
|
fs.writeFile(`${process.cwd()}/client/utils/p5-keywords.js`, generatedCode, (error) => {
|
2020-04-30 08:47:18 +02:00
|
|
|
if (error) {
|
|
|
|
console.log("Error!! Couldn't write to the file", error);
|
|
|
|
} else {
|
|
|
|
console.log('Syntax highlighting files updated successfully');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log("Error!! Couldn't fetch the data.json file");
|
|
|
|
}
|
|
|
|
});
|