Skip to content

Commit

Permalink
Migrated error messages for debugger extension to TypeScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 authored and TorsteinHonsi committed Feb 18, 2021
1 parent 0079b14 commit 15be6ea
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 149 deletions.
28 changes: 0 additions & 28 deletions errors/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,5 @@
"32": {
"title": "Deprecated function or property",
"text": "<h1>Deprecated function or property</h1><p>This error occurs when using a deprecated function or property. Consult the <a href=\"https://api.highcharts.com/\">API documentation</a> for alternatives, if no replacement is mentioned by the error itself.</p>"
},
"meta": {
"files": [
"errors/10/readme.md",
"errors/10/enduser.md",
"errors/11/readme.md",
"errors/12/readme.md",
"errors/13/readme.md",
"errors/14/readme.md",
"errors/15/readme.md",
"errors/16/readme.md",
"errors/17/readme.md",
"errors/18/readme.md",
"errors/19/readme.md",
"errors/20/readme.md",
"errors/21/readme.md",
"errors/22/readme.md",
"errors/23/readme.md",
"errors/24/readme.md",
"errors/25/readme.md",
"errors/26/readme.md",
"errors/27/readme.md",
"errors/28/readme.md",
"errors/29/readme.md",
"errors/30/readme.md",
"errors/31/readme.md",
"errors/32/readme.md"
]
}
}
11 changes: 8 additions & 3 deletions js/Extensions/Debugger.js → js/Extensions/Debugger/Debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
*
* */
'use strict';
import H from '../Core/Globals.js';
import Chart from '../Core/Chart/Chart.js';
import U from '../Core/Utilities.js';
import Chart from '../../Core/Chart/Chart.js';
import H from '../../Core/Globals.js';
import U from '../../Core/Utilities.js';
var addEvent = U.addEvent, isNumber = U.isNumber, setOptions = U.setOptions;
/* *
*
* Compositions
*
* */
setOptions({
/**
* @optionparent chart
Expand Down
106 changes: 106 additions & 0 deletions js/Extensions/Debugger/ErrorMessages.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions js/masters/modules/debugger.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@

'use strict';

import '../../error-messages.js';
import '../../Extensions/Debugger.js';
import Highcharts from '../../Core/Globals.js';
import ErrorMessages from '../../Extensions/Debugger/ErrorMessages.js';
Highcharts.errorMessages = ErrorMessages;

import '../../Extensions/Debugger/Debugger.js';
1 change: 0 additions & 1 deletion tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ const fnFirstBuild = options => {
version
});
const promises = [];
promises.push(require('./error-messages')());
types.forEach(type => {
const pathSource = mapTypeToSource[type];
const pathESMasters = join(pathSource, 'masters');
Expand Down
85 changes: 22 additions & 63 deletions tools/error-messages.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
/* eslint-env node,es6 */
/**
* (c) 2010-2019 Torstein Honsi
* (c) 2010-2021 Torstein Honsi
*
* License: www.highcharts.com/license
*
Expand Down Expand Up @@ -166,33 +166,6 @@ function parseMarkdown (text, extractTitle) {
};
}


/**
* @function parseArguments
* @param {Array<string>} args
*/
function parseArguments(args) {

let parsedArgs = {},
lastKey;

args.forEach(arg => {
if (arg[0] === '-') {
lastKey = arg.substr(arg[1] === '-' ? 2 : 1);
parsedArgs[lastKey] = true;
} else {
lastKey = (lastKey || '_');
if (parsedArgs[lastKey] instanceof Array) {
parsedArgs[lastKey].push(arg);
} else {
parsedArgs[lastKey] = [arg];
}
}
});

return parsedArgs;
}

/**
* @function parseErrorDirectory
* @param {number} errorCode
Expand Down Expand Up @@ -226,8 +199,6 @@ function parseErrorDirectory (directoryPath) {
readme.enduser = enduser.text;
} catch (err) {}

readme.files = files;

return readme;
}

Expand All @@ -246,12 +217,7 @@ function parseErrorsDirectory (directoryPath) {
return;
}

let parsedErrors = {
meta: {
files: []
//, version: require(rootPath + '/package.json').version
}
};
let parsedErrors = {};

directories
.map(directory => path.join(directoryPath, directory))
Expand All @@ -262,10 +228,6 @@ function parseErrorsDirectory (directoryPath) {
return;
}
parsedErrors[errorCode] = parseErrorDirectory(directory);
parsedErrors.meta.files.push(
...parsedErrors[errorCode].files
);
delete(parsedErrors[errorCode].files);
});

resolve(parsedErrors);
Expand All @@ -291,36 +253,33 @@ function writeErrorsJson (parsedErrors, jsonPath, modulePath) {
oldErrorsJson[error].enduser === parsedErrors[error].enduser
));
const version = require(rootPath + '/package.json').version;

if (same &&
(!oldErrorsJson.meta.version ||
oldErrorsJson.meta.version === version)
) {
return Promise.resolve();
}
}

return Promise.all([
new Promise((resolve, reject) => fs.writeFile(jsonPath,
JSON.stringify(parsedErrors, undefined, '\t'),
err => (err ? reject(err) : resolve())
)),
new Promise((resolve, reject) => fs.writeFile(modulePath, (
'/* eslint-disable */\n' +
'/* *\n' +
' * Error information for the debugger module\n' +
' * (c) 2010-2019 Torstein Honsi\n' +
' * License: www.highcharts.com/license\n' +
' */\n\n' +
'// DO NOT EDIT!\n' +
'// Automatically generated by ./tools/error-messages.js\n' +
'// Sources can be found in ./errors/*/*.md\n\n' +
'\'use strict\';\n\n' +
'import H from \'./Core/Globals.js\';\n\n' +
'H.errorMessages = ' +
new Promise((resolve, reject) => fs.writeFile(modulePath, [
'/* eslint-disable */',
'/* *',
' * Error information for the debugger module',
' * (c) 2010-2021 Torstein Honsi',
' * License: www.highcharts.com/license',
' */',
,
'// DO NOT EDIT!',
'// Automatically generated by ./tools/error-messages.js',
'// Sources can be found in ./errors/*/*.md',
,
'\'use strict\';',
,
'const errorMessages: Record<string, Record<string, string>> = ' +
JSON.stringify(parsedErrors, undefined, ' ') +
';\n'
),
';',
,
'export default errorMessages;'
].join('\n'),
err => (err ? reject(err) : resolve())
))
]);
Expand All @@ -332,7 +291,7 @@ module.exports = function () {
.then(parsedErrors => writeErrorsJson(
parsedErrors,
path.join(rootPath, 'errors', 'errors.json'),
path.join(rootPath, 'js', 'error-messages.js')
path.join(rootPath, 'ts', 'Extensions', 'Debugger', 'ErrorMessages.ts')
))
.catch(err => {
console.error(err);
Expand Down
1 change: 1 addition & 0 deletions tools/gulptasks/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require('./jsdoc-websearch');
gulp.task(
'jsdoc',
gulp.series(
'scripts',
'jsdoc-clean',
'jsdoc-classes',
'jsdoc-namespace',
Expand Down
Loading

0 comments on commit 15be6ea

Please sign in to comment.