Skip to content

Commit 995b35c

Browse files
authored
Merge branch 'develop' into empheq-numcases
2 parents 3ddd6c3 + 115a7be commit 995b35c

173 files changed

Lines changed: 11066 additions & 4411 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/bin/build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const config = JSON.parse(fs.readFileSync(process.argv[2] || 'build.json'));
5656
const TARGETS = config.targets || []; // the files to include in the component
5757
const EXCLUDE = new Map((config.exclude || []).map(name => [name, true])); // files to exclude from the component
5858
const EXCLUDESUBDIRS = config.excludeSubdirs === 'true'; // exclude subdirectories
59-
const MATHJAX = config.mathjax || mjPath; // path to the MathJax .js files
59+
const MATHJAX = config.js || config.mathjax || mjPath; // path to the compiled .js files
6060
const LIB = config.lib || './lib'; // path to the lib directory to create
6161
const COMPONENT = path.basename(config.component || 'part'); // name of the component
6262
const GLOBAL = config.global || `../${MATHJAX}/components/global.js`; // the location of global.js
63-
const SRC = MATHJAX.replace(/js$/, 'ts'); // path to the MathJax .ts files
63+
const SRC = config.ts || MATHJAX.replace(/js$/, 'ts'); // path to the .ts files
6464

6565
/**
6666
* The list of files that need to be added to the lib directory

components/bin/makeAll

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ if (dirs.length === 0) {
4242
* (on Unix, could be done without the 'node ' prefix, but
4343
* for Windows, these are needed.)
4444
*/
45-
const build = 'node ' + path.join(__dirname, 'build');
46-
const copy = 'node ' + path.join(__dirname, 'copy');
45+
const build = `node '${path.join(__dirname, 'build')}'`;
46+
const copy = `node '${path.join(__dirname, 'copy')}'`;
47+
const pack = `node '${path.join(__dirname, 'pack')}'`;
4748

4849
/**
49-
* Regular expressions for the components directory, the MathJax .js location, and the node_modules directory
50+
* Regular expression for the components directory
5051
*/
51-
const compRE = new RegExp(path.dirname(__dirname).replace(/([\\.{}[\]()?*^$])/g, '\$1'), 'g');
52-
const rootRE = new RegExp(path.join(path.dirname(path.dirname(__dirname)), 'js')
53-
.replace(/([\\.{}[\]()?*^$])/g, '\$1'), 'g');
54-
const nodeRE = new RegExp(path.join(path.dirname(path.dirname(__dirname)), 'node_modules')
55-
.replace(/([\\.{}[\]()?*^$])/g, '\$1'), 'g');
52+
const compRE = new RegExp(path.dirname(__dirname).replace(/([\\.{}[\]()?*^$])/g, '\\$1'));
53+
const dirRE = new RegExp(process.cwd().replace(/([\\.{}[\]()?*^$])/g, '\\$1'));
5654

5755
/**
5856
* Process the contents of an array of directories
@@ -102,7 +100,7 @@ function processSubdirs(dir, action) {
102100
function buildLib(dir) {
103101
const file = path.join(dir, 'build.json');
104102
if (!fs.existsSync(file)) return;
105-
console.info('Building ' + dir.replace(compRE, ''));
103+
console.info('Building ' + dir.replace(compRE, '').replace(dirRE, '.'));
106104
const wd = process.cwd();
107105
try {
108106
process.chdir(dir);
@@ -122,16 +120,12 @@ function buildLib(dir) {
122120
function webpackLib(dir) {
123121
const file = path.join(dir, 'webpack.config.js');
124122
if (!fs.existsSync(file)) return;
125-
console.info('Webpacking ' + dir.replace(compRE, ''));
123+
console.info('Webpacking ' + dir.replace(compRE, '').replace(dirRE, '.'));
126124
const wd = process.cwd();
127125
try {
128126
process.chdir(dir);
129-
const result = execSync('npx webpack --display-modules');
130-
console.info(' ' + String(result).replace(/\n/g, '\n ')
131-
.replace(/ \.\.\//g, ' ' + path.dirname(path.resolve(dir)) + '/')
132-
.replace(compRE, '[components]')
133-
.replace(rootRE, '[js]')
134-
.replace(nodeRE, '[node]'));
127+
const result = execSync(pack);
128+
console.info(' ' + String(result).replace(/\n/g, '\n '));
135129
} catch (err) {
136130
console.info(' ' + err.message);
137131
}

components/bin/pack

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,95 @@
2727

2828
const fs = require('fs');
2929
const path = require('path');
30-
const {execSync} = require('child_process');
30+
const {spawn} = require('child_process');
31+
32+
/**
33+
* @param {string} name The file name to turn into a Regular expression
34+
* @return {RegExp} The regular expression for the name,
35+
*/
36+
function fileRegExp(name) {
37+
return new RegExp(name.replace(/([\\.{}[\]()?*^$])/g, '\\$1'), 'g');
38+
}
39+
40+
/**
41+
* @param {Object} The file or asset data whose size is to be returned
42+
* @return {string} The string giving the size in KB
43+
*/
44+
function fileSize(file) {
45+
return ' (' + (file.size / 1024).toFixed(2).replace(/\.?0+$/, '') + ' KB)';
46+
}
3147

3248
/**
3349
* Regular expressions for the components directory and the MathJax .js location
3450
*/
35-
const compRE = new RegExp(path.dirname(__dirname).replace(/([\\.{}[\]()?*^$])/g, '\\$1'), 'g');
36-
const rootRE = new RegExp(path.join(path.dirname(path.dirname(__dirname)), 'js')
37-
.replace(/([\\.{}[\]()?*^$])/g, '\\$1'), 'g');
38-
const nodeRE = new RegExp(path.join(path.dirname(path.dirname(__dirname)), 'node_modules')
39-
.replace(/([\\.{}[\]()?*^$])/g, '\\$1'), 'g');
51+
const compRE = fileRegExp(path.dirname(__dirname));
52+
const rootRE = fileRegExp(path.join(path.dirname(path.dirname(__dirname)), 'js'));
53+
const nodeRE = fileRegExp(path.join(path.dirname(path.dirname(__dirname)), 'node_modules'));
54+
55+
/**
56+
* @return {JSON} The parsed JSON from webpack
57+
*/
58+
async function readJSON() {
59+
return new Promise((ok, fail) => {
60+
const buffer = [];
61+
const child = spawn('npx', ['webpack', '--json']);
62+
child.stdout.on('data', (data) => buffer.push(String(data)));
63+
child.stdout.on('close', (code) => {
64+
const json = JSON.parse(buffer.join(''));
65+
if (json.errors && json.errors.length) {
66+
fail(json.errors[0].message);
67+
}
68+
ok(json);
69+
});
70+
});
71+
}
4072

4173
/**
4274
* Run webpack if there is a configuration file for it
4375
*
4476
* @param {string} dir The directory to pack
4577
*/
46-
function webpackLib(dir) {
78+
async function webpackLib(dir) {
4779
try {
4880
process.chdir(dir);
49-
const result = execSync('npx webpack --display-modules');
50-
console.info(String(result).replace(/\n/g, '\n ')
51-
.replace(/ \.\.\//g, ' ' + path.dirname(path.resolve(dir)) + '/')
52-
.replace(compRE, '[components]')
53-
.replace(rootRE, '[js]')
54-
.replace(nodeRE, '[node]'));
81+
const dirRE = fileRegExp(path.resolve(dir));
82+
83+
//
84+
// Get js directory from the webpack.config.js file
85+
//
86+
const jsdir = require(path.resolve(dir, 'webpack.config.js')).plugins[0].definitions.jsdir;
87+
const jsRE = fileRegExp(jsdir);
88+
const libRE = fileRegExp(path.resolve(jsdir, '..', 'components'));
89+
90+
//
91+
// Get the json from webpack and print the asset name and size
92+
//
93+
const json = await readJSON();
94+
for (const asset of json.assets) {
95+
console.log(asset.name + fileSize(asset));
96+
}
97+
//
98+
// Sort the modules and print their names and sizes
99+
//
100+
const modules = json.modules;
101+
for (const module of modules) {
102+
module.name = path.resolve(dir, module.name)
103+
.replace(/ \+ \d+ modules/, '')
104+
.replace(dirRE, '.');
105+
}
106+
for (const module of modules.sort((a,b) => a.name < b.name ? -1 : 1)) {
107+
if (module.moduleType.match(/javascript/)) {
108+
const name = module.name
109+
.replace(compRE, '[components]')
110+
.replace(rootRE, '[mathjax]')
111+
.replace(nodeRE, '[node]')
112+
.replace(jsRE, '[js]')
113+
.replace(libRE, '[lib]');
114+
console.log(' ' + name + fileSize(module));
115+
}
116+
}
55117
} catch (err) {
56-
console.error(err.message);
118+
console.error(err);
57119
}
58120
}
59121

components/src/dependencies.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const dependencies = {
22
'a11y/semantic-enrich': ['input/mml', '[sre]'],
33
'a11y/complexity': ['a11y/semantic-enrich'],
44
'a11y/explorer': ['a11y/semantic-enrich', 'ui/menu'],
5+
'[mml]/mml3': ['input/mml'],
56
'[tex]/all-packages': ['input/tex-base'],
67
'[tex]/action': ['input/tex-base', '[tex]/newcommand'],
78
'[tex]/autoload': ['input/tex-base', '[tex]/require'],
@@ -12,8 +13,10 @@ export const dependencies = {
1213
'[tex]/braket': ['input/tex-base'],
1314
'[tex]/bussproofs': ['input/tex-base'],
1415
'[tex]/cancel': ['input/tex-base', '[tex]/enclose'],
16+
'[tex]/centernot': ['input/tex-base'],
1517
'[tex]/color': ['input/tex-base'],
1618
'[tex]/colorv2': ['input/tex-base'],
19+
'[tex]/colortbl': ['input/tex-base', '[tex]/color'],
1720
'[tex]/configmacros': ['input/tex-base', '[tex]/newcommand'],
1821
'[tex]/enclose': ['input/tex-base'],
1922
'[tex]/extpfeil': ['input/tex-base', '[tex]/newcommand', '[tex]/ams'],
@@ -24,6 +27,7 @@ export const dependencies = {
2427
'[tex]/noundefined': ['input/tex-base'],
2528
'[tex]/physics': ['input/tex-base'],
2629
'[tex]/require': ['input/tex-base'],
30+
'[tex]/setoptions': ['input/tex-base'],
2731
'[tex]/tagformat': ['input/tex-base'],
2832
'[tex]/textmacros': ['input/tex-base'],
2933
'[tex]/unicode': ['input/tex-base'],
@@ -34,6 +38,7 @@ export const dependencies = {
3438

3539
export const paths = {
3640
tex: '[mathjax]/input/tex/extensions',
41+
mml: '[mathjax]/input/mml/extensions',
3742
sre: '[mathjax]/sre/' + (typeof window === 'undefined' ? 'sre-node' : 'sre_browser')
3843
};
3944

@@ -46,7 +51,9 @@ const allPackages = [
4651
'[tex]/braket',
4752
'[tex]/bussproofs',
4853
'[tex]/cancel',
54+
'[tex]/centernot',
4955
'[tex]/color',
56+
'[tex]/colortbl',
5057
'[tex]/configmacros',
5158
'[tex]/enclose',
5259
'[tex]/extpfeil',
@@ -57,6 +64,7 @@ const allPackages = [
5764
'[tex]/noundefined',
5865
'[tex]/physics',
5966
'[tex]/require',
67+
'[tex]/setoptions',
6068
'[tex]/tagformat',
6169
'[tex]/textmacros',
6270
'[tex]/unicode',
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": "input/mml/extensions/mml3",
3+
"targets": ["input/mathml/mml3"]
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"to": "../../../../../../es5/input/mml/extensions",
3+
"from": "../../../../../../ts/input/mathml/mml3",
4+
"copy": [
5+
"mml3.sef.json"
6+
]
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import './lib/mml3.js';
2+
3+
import {Mml3Handler} from '../../../../../../js/input/mathml/mml3/mml3.js';
4+
5+
if (MathJax.startup) {
6+
MathJax.startup.extendHandler(handler => Mml3Handler(handler));
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const PACKAGE = require('../../../../../webpack.common.js');
2+
3+
module.exports = PACKAGE(
4+
'input/mml/extensions/mml3', // the package to build
5+
'../../../../../../js', // location of the MathJax js library
6+
[ // packages to link to
7+
'components/src/input/mml/lib',
8+
'components/src/core/lib'
9+
],
10+
__dirname // our directory
11+
);

components/src/input/mml/mml.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ if (MathJax.startup) {
66
MathJax.startup.registerConstructor('mml', MathML);
77
MathJax.startup.useInput('mml');
88
}
9+
if (MathJax.loader) {
10+
//
11+
// Install a path-filter to cause loading of an entity file to load all entities,
12+
// since the individual files don't have individual components.
13+
//
14+
MathJax.loader.pathFilters.add((data) => {
15+
data.name = data.name.replace(/\/util\/entities\/.*?\.js/, '/input/mml/entities.js');
16+
return true;
17+
});
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": "input/tex/extensions/centernot",
3+
"targets": ["input/tex/centernot"]
4+
}

0 commit comments

Comments
 (0)