Skip to content

Commit

Permalink
Changes to support an ES6 version as well as ES5
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Apr 17, 2023
1 parent ea0a580 commit a0fd444
Show file tree
Hide file tree
Showing 89 changed files with 673 additions and 574 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
node_modules
components/src/**/lib
js
js6
es5
es6
4 changes: 3 additions & 1 deletion components/bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const mjGlobal = path.join('..', mjPath, 'components', 'global.js');
/**
* Read the configuration for the component
*/
const config = JSON.parse(fs.readFileSync(process.argv[2] || 'build.json'));
const build = (process.argv[2] || 'build.json');
process.chdir(path.dirname(build));
const config = JSON.parse(fs.readFileSync(path.basename(build)));

function getType() {
const component = config.component || 'part';
Expand Down
10 changes: 9 additions & 1 deletion components/bin/copy
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ const path = require('path');
*/
const INDENT = ' ';

/**
* The es value (6 or empty)
*/
const es = (process.argv[2] || '').replace(/^5$/, '');

/**
* The configuration data for the copy operation
*/
const config = JSON.parse(fs.readFileSync(process.argv[2] || 'copy.json'));
const config = JSON.parse(fs.readFileSync(process.argv[3] || 'copy.json'));
if (es) {
config.to = config.to.replace(/\/es5\//, `/es${es}/`);
}

/**
* Get the directory for node modules (either the parent of the MathJax directory,
Expand Down
34 changes: 34 additions & 0 deletions components/bin/js2js6
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /usr/bin/env node

/*************************************************************
*
* Copyright (c) 2023 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Changes js to js6 in compiled js files
*
* @author dpvc@mathjax.org (Davide Cervone)
*/


const fs = require("fs");

const file = process.argv[2];

const code = String(fs.readFileSync(file)).replace(/\/js\//, '/js6/');
fs.writeFileSync(file, code);


70 changes: 54 additions & 16 deletions components/bin/makeAll
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,70 @@ const fs = require('fs');
const path = require('path');
const {execSync} = require('child_process');

/**
* The default options
*/
const options = {
recursive: true
recursive: true,
verbose: true,
es: ''
};

/**
* Get the directories to process and check for options
* Get the directories to process
*/
const dirs = process.argv.slice(2);

if (dirs[0] === '--no-subdirs') {
dirs.shift();
options.recursive = false;
/**
* Check for options
*/
while (dirs[0].substr(0, 2) === '--') {
const option = dirs.shift();
if (option === '--') {
break;
}
if (option === '--no-subdirs') {
options.recursive = false;
continue;
}
if (option.substr(0, 4) === '--es') {
options.es = option.substr(4).replace(/^5$/, '');
continue;
}
if (option === '--terse') {
options.verbose = false;
continue;
}
}

//
// Make sure there is at least one directory
//
if (dirs.length === 0) {
dirs.push('.');
}

/**
* The commads to runb the bin/build scripts
* (on Unix, could be done without the 'node ' prefix, but
* for Windows, these are needed.)
* The commads to run the various scripts
* (on Unix, could be done without the 'node ' prefix, but for Windows, these are needed.)
*/
const build = `node '${path.join(__dirname, 'build')}'`;
const copy = `node '${path.join(__dirname, 'copy')}'`;
const pack = `node '${path.join(__dirname, 'pack')}'`;
const copy = `node '${path.join(__dirname, 'copy')}' '${options.es}'`;
const pack = `node '${path.join(__dirname, 'pack')}' '${options.es}'`;

/**
* @param {string} name The file name to turn into a Regular expression
* @return {RegExp} The regular expression for the name,
*/
function fileRegExp(name) {
return new RegExp(name.replace(/([\\.{}[\]()?*^$])/g, '\\$1'), 'g');
}

/**
* Regular expression for the components directory
*/
const compRE = new RegExp(path.dirname(__dirname).replace(/([\\.{}[\]()?*^$])/g, '\\$1'));
const dirRE = new RegExp(process.cwd().replace(/([\\.{}[\]()?*^$])/g, '\\$1'));
const compRE = fileRegExp(path.dirname(__dirname));
const dirRE = fileRegExp(process.cwd());

/**
* Process the contents of an array of directories
Expand Down Expand Up @@ -117,7 +149,9 @@ function buildLib(dir) {
try {
process.chdir(dir);
const result = execSync(build);
console.info(' ' + String(result).replace(/\n/g, '\n '));
if (options.verbose) {
console.info(' ' + String(result).replace(/\n/g, '\n '));
}
} catch (err) {
console.info(' ' + err.message);
}
Expand All @@ -137,7 +171,9 @@ function webpackLib(dir) {
try {
process.chdir(dir);
const result = execSync(pack);
console.info(' ' + String(result).replace(/\n/g, '\n '));
if (options.verbose) {
console.info(' ' + String(result).replace(/\n/g, '\n '));
}
} catch (err) {
console.info(' ' + err.message);
}
Expand All @@ -152,11 +188,13 @@ function webpackLib(dir) {
function copyLib(dir) {
const file = path.join(dir, 'copy.json');
if (!fs.existsSync(file)) return;
console.info('Copying ' + dir.replace(compRE, ''));
console.info('Copying ' + dir.replace(compRE, '').replace(dirRE, '.'));
try {
process.chdir(dir);
const result = execSync(copy);
console.info(' ' + String(result).replace(/\n/g, '\n '));
if (options.verbose) {
console.info(' ' + String(result).replace(/\n/g, '\n '));
}
} catch (err) {
console.info(' ' + err.message);
}
Expand Down
24 changes: 18 additions & 6 deletions components/bin/pack
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#! /usr/bin/env node


/*************************************************************
*
* Copyright (c) 2018 The MathJax Consortium
Expand Down Expand Up @@ -29,6 +28,11 @@ const fs = require('fs');
const path = require('path');
const {spawn} = require('child_process');

/**
* The es version (6 or '')
*/
const es = (process.argv[2] || '').replace(/^5$/, '');

/**
* @param {string} name The file name to turn into a Regular expression
* @return {RegExp} The regular expression for the name,
Expand All @@ -48,17 +52,20 @@ function fileSize(file) {
/**
* Regular expressions for the components directory and the MathJax .js location
*/
const nodePath = path.join(path.dirname(path.dirname(__dirname)), 'node_modules');
const jsPath = path.join(path.dirname(path.dirname(__dirname)), 'js' + es);
const compRE = fileRegExp(path.dirname(__dirname));
const rootRE = fileRegExp(path.join(path.dirname(path.dirname(__dirname)), 'js'));
const nodeRE = fileRegExp(path.join(path.dirname(path.dirname(__dirname)), 'node_modules'));
const rootRE = fileRegExp(jsPath);
const nodeRE = fileRegExp(nodePath);
const fontRE = new RegExp(path.join('^.*\\/(mathjax-.*?)(?:-font)?', 'js' + es));

/**
* @return {JSON} The parsed JSON from webpack
*/
async function readJSON() {
return new Promise((ok, fail) => {
const buffer = [];
const child = spawn('npx', ['webpack', '--json']);
const child = spawn('npx', ['webpack', '--json', '--env', 'es=' + es]);
child.stdout.on('data', (data) => buffer.push(String(data)));
child.stdout.on('close', (code) => {
const json = JSON.parse(buffer.join(''));
Expand All @@ -83,7 +90,11 @@ async function webpackLib(dir) {
//
// Get js directory from the webpack.config.js file
//
const jsdir = require(path.resolve(dir, 'webpack.config.js')).plugins[0].definitions.__JSDIR__;
let package = require(path.resolve(dir, 'webpack.config.js'));
if (typeof package === 'function') {
package = package({es});
}
const jsdir = package.plugins?.[0]?.definitions?.__JSDIR__ || process.cwd();
const jsRE = fileRegExp(jsdir);
const libRE = fileRegExp(path.resolve(jsdir, '..', 'components'));

Expand All @@ -109,6 +120,7 @@ async function webpackLib(dir) {
let name = module.name
.replace(compRE, '[components]')
.replace(rootRE, '[mathjax]')
.replace(fontRE, '[$1]')
.replace(nodeRE, '[node]')
.replace(jsRE, '[js]')
.replace(libRE, '[lib]');
Expand All @@ -129,4 +141,4 @@ async function webpackLib(dir) {
}
}

webpackLib(process.argv[2] || '.');
webpackLib(process.argv[3] || '.');
2 changes: 1 addition & 1 deletion components/bin/version
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const version = require(package).version;

const lines = `/*************************************************************
*
* Copyright (c) 2022 The MathJax Consortium
* Copyright (c) 2023 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
11 changes: 5 additions & 6 deletions components/src/a11y/assistive-mml/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const PACKAGE = require('../../../webpack.common.js');

module.exports = PACKAGE(
'a11y/assistive-mml', // the package to build
'../../../../js', // location of the MathJax js library
[ // packages to link to
module.exports = PACKAGE({
name: 'a11y/assistive-mml',
libs: [
'components/src/input/mml/lib',
'components/src/core/lib'
],
__dirname // our directory
);
dir: __dirname
});
11 changes: 5 additions & 6 deletions components/src/a11y/complexity/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const PACKAGE = require('../../../webpack.common.js');

module.exports = PACKAGE(
'a11y/complexity', // the package to build
'../../../../js', // location of the MathJax js library
[ // packages to link to
module.exports = PACKAGE({
name: 'a11y/complexity',
libs: [
'components/src/a11y/semantic-enrich/lib',
'components/src/input/mml/lib',
'components/src/core/lib'
],
__dirname // our directory
);
dir: __dirname
});
11 changes: 5 additions & 6 deletions components/src/a11y/explorer/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const PACKAGE = require('../../../webpack.common.js');

module.exports = PACKAGE(
'a11y/explorer', // the package to build
'../../../../js', // location of the MathJax js library
[ // packages to link to
module.exports = PACKAGE({
name: 'a11y/explorer',
libs: [
'components/src/ui/menu/lib',
'components/src/a11y/semantic-enrich/lib',
'components/src/a11y/sre/lib',
'components/src/input/mml/lib',
'components/src/core/lib'
],
__dirname // our directory
);
dir: __dirname
});
11 changes: 5 additions & 6 deletions components/src/a11y/semantic-enrich/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const PACKAGE = require('../../../webpack.common.js');

module.exports = PACKAGE(
'a11y/semantic-enrich', // the package to build
'../../../../js', // location of the MathJax js library
[ // packages to link to
module.exports = PACKAGE({
name: 'a11y/semantic-enrich',
libs: [
'components/src/input/mml/lib',
'components/src/core/lib',
'components/src/a11y/sre/lib'
],
__dirname // our directory
);
dir: __dirname
});
11 changes: 5 additions & 6 deletions components/src/a11y/sre/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const PACKAGE = require('../../../webpack.common.js');

module.exports = PACKAGE(
'a11y/sre', // the package to build
'../../../../js', // location of the MathJax js library
[ // packages to link to
module.exports = PACKAGE({
name: 'a11y/sre',
libs: [
'components/src/input/mml/lib',
'components/src/core/lib',
'components/src/startup/lib'
],
__dirname // our directory
);
dir: __dirname
});
11 changes: 5 additions & 6 deletions components/src/adaptors/liteDOM/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const PACKAGE = require('../../../webpack.common.js');

module.exports = PACKAGE(
'adaptors/liteDOM', // the package to build
'../../../../js', // location of the MathJax js library
['components/src/core/lib'], // packages to link to
__dirname // our directory
);
module.exports = PACKAGE({
name: 'adaptors/liteDOM',
libs: ['components/src/core/lib'],
dir: __dirname
});
10 changes: 4 additions & 6 deletions components/src/core/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const PACKAGE = require('../../webpack.common.js');

module.exports = PACKAGE(
'core', // the package to build
'../../../js', // location of the MathJax js library
[], // packages to link to
__dirname // our directory
);
module.exports = PACKAGE({
name: 'core',
dir: __dirname
});
Loading

0 comments on commit a0fd444

Please sign in to comment.