Skip to content

Commit 03f61b0

Browse files
authored
Merge pull request #1406 from mathjax/update/copy-config
Simplify copy component configurations.
2 parents f7a0757 + c207665 commit 03f61b0

6 files changed

Lines changed: 31 additions & 11 deletions

File tree

components/bin/copy

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ const bundle = (process.argv[3] || 'bundle');
4848
const json = path.resolve(process.argv[4] || '.', 'config.json');
4949
let configs = require(json).copy;
5050
if (!configs) process.exit();
51-
const wd = path.dirname(json);
52-
process.chdir(wd);
5351
if (!Array.isArray(configs)) {
5452
configs = [configs];
5553
}
54+
process.chdir(path.dirname(json));
5655

5756
/**
5857
* Get the directory for node modules (either the parent of the MathJax directory,
@@ -61,6 +60,13 @@ if (!Array.isArray(configs)) {
6160
const parent = path.resolve(__dirname, '..', '..');
6261
const nodeDir = (dir => (fs.existsSync(dir) ? dir : path.resolve(parent, '..')))(path.join(parent, 'node_modules'));
6362

63+
/**
64+
* Other top-level directories
65+
*/
66+
const tsDir = path.resolve(parent, 'ts');
67+
const jsDir = path.resolve(parent, target);
68+
const bundleDir = path.resolve(parent, bundle);
69+
6470
/**
6571
* Copy a file or directory tree
6672
*
@@ -84,14 +90,28 @@ function copyFile(from, to, name, space) {
8490
}
8591
}
8692

93+
/**
94+
* @param {string} name The file name to process
95+
* @returns {string} The name with paths replaced by full directories
96+
*/
97+
function resolvePaths(name) {
98+
return path.resolve(
99+
process.cwd(),
100+
name.replace(/^\[node\]/, nodeDir)
101+
.replace(/^\[ts\]/, tsDir)
102+
.replace(/^\[js\]/, jsDir)
103+
.replace(/^\[bundle\]/, bundleDir)
104+
);
105+
}
106+
87107
/**
88108
* Handle the copying for a given configuration
89109
*
90110
* @param {{from: string, to: string, copy: string[]}} config The configuration for the copy operation
91111
*/
92112
function processConfig(config) {
93-
const to = path.resolve(wd, config.to.replace(/\/bundle(\/|$)/, '/' + bundle + '$1'));
94-
const from = path.resolve(wd, config.from.replace(/\[node\]/, nodeDir));
113+
const to = resolvePaths(config.to);
114+
const from = resolvePaths(config.from);
95115
for (const name of config.copy) {
96116
copyFile(from, to, name, '');
97117
}

components/mjs/a11y/sre/worker/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"name": "sre/speech-worker"
44
},
55
"copy": {
6-
"to": "../../../../../bundle/sre",
7-
"from": "../../../../../ts/a11y/sre",
6+
"to": "[bundle]/sre",
7+
"from": "[ts]/a11y/sre",
88
"copy": [
99
"require.mjs",
1010
"require.d.mts"

components/mjs/input/mml/extensions/mml3/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"excludeSubdirs": true
77
},
88
"copy": {
9-
"to": "../../../../../../bundle/input/mml/extensions",
10-
"from": "../../../../../../ts/input/mathml/mml3",
9+
"to": "[bundle]/input/mml/extensions",
10+
"from": "[ts]/input/mathml/mml3",
1111
"copy": [
1212
"mml3.sef.json"
1313
]

components/mjs/node-main/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"copy": {
3-
"to": "../../../bundle",
3+
"to": "[bundle]",
44
"from": ".",
55
"copy": [
66
"node-main.mjs",

components/mjs/require/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"copy": {
3-
"to": "../../../bundle",
3+
"to": "[bundle]",
44
"from": "../..",
55
"copy": [
66
"require.mjs"

components/mjs/sre/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"copy": {
3-
"to": "../../../bundle/sre",
3+
"to": "[bundle]/sre",
44
"from": "[node]/speech-rule-engine/lib",
55
"copy": [
66
"mathmaps"

0 commit comments

Comments
 (0)