@@ -48,11 +48,10 @@ const bundle = (process.argv[3] || 'bundle');
4848const json = path . resolve ( process . argv [ 4 ] || '.' , 'config.json' ) ;
4949let configs = require ( json ) . copy ;
5050if ( ! configs ) process . exit ( ) ;
51- const wd = path . dirname ( json ) ;
52- process . chdir ( wd ) ;
5351if ( ! 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)) {
6160const parent = path . resolve ( __dirname , '..' , '..' ) ;
6261const 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 ( / ^ \[ n o d e \] / , nodeDir )
101+ . replace ( / ^ \[ t s \] / , tsDir )
102+ . replace ( / ^ \[ j s \] / , jsDir )
103+ . replace ( / ^ \[ b u n d l e \] / , 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 */
92112function processConfig ( config ) {
93- const to = path . resolve ( wd , config . to . replace ( / \/ b u n d l e ( \/ | $ ) / , '/' + bundle + '$1' ) ) ;
94- const from = path . resolve ( wd , config . from . replace ( / \[ n o d e \] / , 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 }
0 commit comments