diff --git a/components/bin/copy b/components/bin/copy index 8f41e5a08..f3bb6fc16 100755 --- a/components/bin/copy +++ b/components/bin/copy @@ -48,11 +48,10 @@ const bundle = (process.argv[3] || 'bundle'); const json = path.resolve(process.argv[4] || '.', 'config.json'); let configs = require(json).copy; if (!configs) process.exit(); -const wd = path.dirname(json); -process.chdir(wd); if (!Array.isArray(configs)) { configs = [configs]; } +process.chdir(path.dirname(json)); /** * Get the directory for node modules (either the parent of the MathJax directory, @@ -61,6 +60,13 @@ if (!Array.isArray(configs)) { const parent = path.resolve(__dirname, '..', '..'); const nodeDir = (dir => (fs.existsSync(dir) ? dir : path.resolve(parent, '..')))(path.join(parent, 'node_modules')); +/** + * Other top-level directories + */ +const tsDir = path.resolve(parent, 'ts'); +const jsDir = path.resolve(parent, target); +const bundleDir = path.resolve(parent, bundle); + /** * Copy a file or directory tree * @@ -84,14 +90,28 @@ function copyFile(from, to, name, space) { } } +/** + * @param {string} name The file name to process + * @returns {string} The name with paths replaced by full directories + */ +function resolvePaths(name) { + return path.resolve( + process.cwd(), + name.replace(/^\[node\]/, nodeDir) + .replace(/^\[ts\]/, tsDir) + .replace(/^\[js\]/, jsDir) + .replace(/^\[bundle\]/, bundleDir) + ); +} + /** * Handle the copying for a given configuration * * @param {{from: string, to: string, copy: string[]}} config The configuration for the copy operation */ function processConfig(config) { - const to = path.resolve(wd, config.to.replace(/\/bundle(\/|$)/, '/' + bundle + '$1')); - const from = path.resolve(wd, config.from.replace(/\[node\]/, nodeDir)); + const to = resolvePaths(config.to); + const from = resolvePaths(config.from); for (const name of config.copy) { copyFile(from, to, name, ''); } diff --git a/components/mjs/a11y/sre/worker/config.json b/components/mjs/a11y/sre/worker/config.json index c1303a29f..69b8c1079 100644 --- a/components/mjs/a11y/sre/worker/config.json +++ b/components/mjs/a11y/sre/worker/config.json @@ -3,8 +3,8 @@ "name": "sre/speech-worker" }, "copy": { - "to": "../../../../../bundle/sre", - "from": "../../../../../ts/a11y/sre", + "to": "[bundle]/sre", + "from": "[ts]/a11y/sre", "copy": [ "require.mjs", "require.d.mts" diff --git a/components/mjs/input/mml/extensions/mml3/config.json b/components/mjs/input/mml/extensions/mml3/config.json index 4a0f06a9a..8afb7362f 100644 --- a/components/mjs/input/mml/extensions/mml3/config.json +++ b/components/mjs/input/mml/extensions/mml3/config.json @@ -6,8 +6,8 @@ "excludeSubdirs": true }, "copy": { - "to": "../../../../../../bundle/input/mml/extensions", - "from": "../../../../../../ts/input/mathml/mml3", + "to": "[bundle]/input/mml/extensions", + "from": "[ts]/input/mathml/mml3", "copy": [ "mml3.sef.json" ] diff --git a/components/mjs/node-main/config.json b/components/mjs/node-main/config.json index da639e122..e5c5cea38 100644 --- a/components/mjs/node-main/config.json +++ b/components/mjs/node-main/config.json @@ -1,6 +1,6 @@ { "copy": { - "to": "../../../bundle", + "to": "[bundle]", "from": ".", "copy": [ "node-main.mjs", diff --git a/components/mjs/require/config.json b/components/mjs/require/config.json index 599ec23e9..7e23a1374 100644 --- a/components/mjs/require/config.json +++ b/components/mjs/require/config.json @@ -1,6 +1,6 @@ { "copy": { - "to": "../../../bundle", + "to": "[bundle]", "from": "../..", "copy": [ "require.mjs" diff --git a/components/mjs/sre/config.json b/components/mjs/sre/config.json index 5cca64ca2..ba603b8d9 100644 --- a/components/mjs/sre/config.json +++ b/components/mjs/sre/config.json @@ -1,6 +1,6 @@ { "copy": { - "to": "../../../bundle/sre", + "to": "[bundle]/sre", "from": "[node]/speech-rule-engine/lib", "copy": [ "mathmaps"