bin/copy-modules.js
function createMozBuildFiles() {
  const builds = {};

  getFiles()
    .filter(file => file.match(/.js$/))
    .filter(file => {
      if (file.match(/\/workers\.js/)) {
        return true;
      }

     // We exclude worker files because they are bundled and we include
     // worker/index.js files because are required by the debugger app in order
     // to communicate with the worker.
     if (file.match(/\/workers/)) {
       return file.match(/workers\/(\w|-)*\/index.js/);
     }

     return !file.match(/(test|types|packages)/)

   })
    .forEach(file => {
      // console.log(file)
      let dir = path.dirname(file);
      builds[dir] = builds[dir] || { files: [], dirs: [] };

      // Add the current file to its parent dir moz.build
      builds[dir].files.push(path.basename(file));

      // There should be a moz.build in every folder between the root and this
      // file. Climb up the folder hierarchy and make sure a each folder of the
      // chain is listing in its parent dir moz.build.
      while (path.dirname(dir) != ".") {
        const parentDir = path.dirname(dir);
        const dirName = path.basename(dir);

        builds[parentDir] = builds[parentDir] || { files: [], dirs: [] };
        if (!builds[parentDir].dirs.includes(dirName)) {
          builds[parentDir].dirs.push(dirName);
        }
        dir = parentDir;
      }
    });

  Object.keys(builds).forEach(build => {
    const { files, dirs } = builds[build];

    const buildPath = path.join(mcDebuggerPath, build);
    shell.mkdir("-p", buildPath);

    // Files and folders should be alphabetically sorted in moz.build
    const fileStr = files
      .sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
      .map(file => `    '${file}',`)
      .join("\n");

    const dirStr = dirs
      .sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
      .map(dir => `    '${dir}',`)
      .join("\n");

    const src = MOZ_BUILD_TEMPLATE.replace("__DIRS__", dirStr).replace(
      "__FILES__",
      fileStr
    );

    fs.writeFileSync(path.join(buildPath, "moz.build"), src);
  });
}
function createMozBuildFiles() {
  const builds = {};

  getFiles()
    .filter(file => file.match(/.js$/))
    .filter(file => {
      if (file.match(/\/workers\.js/)) {
        return true;
      }

     // We exclude worker files because they are bundled and we include
     // worker/index.js files because are required by the debugger app in order
     // to communicate with the worker.
     if (file.match(/\/workers/)) {
       return file.match(/workers\/(\w|-)*\/index.js/);
     }

     return !file.match(/(test|types|packages)/)

   })
    .forEach(file => {
      // console.log(file)
      let dir = path.dirname(file);
      builds[dir] = builds[dir] || { files: [], dirs: [] };

      // Add the current file to its parent dir moz.build
      builds[dir].files.push(path.basename(file));

      // There should be a moz.build in every folder between the root and this
      // file. Climb up the folder hierarchy and make sure a each folder of the
      // chain is listing in its parent dir moz.build.
      while (path.dirname(dir) != ".") {
        const parentDir = path.dirname(dir);
        const dirName = path.basename(dir);

        builds[parentDir] = builds[parentDir] || { files: [], dirs: [] };
        if (!builds[parentDir].dirs.includes(dirName)) {
          builds[parentDir].dirs.push(dirName);
        }
        dir = parentDir;
      }
    });

  Object.keys(builds).forEach(build => {
    const { files, dirs } = builds[build];

    const buildPath = path.join(mcDebuggerPath, build);
    shell.mkdir("-p", buildPath);

    // Files and folders should be alphabetically sorted in moz.build
    const fileStr = files
      .sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
      .map(file => `    '${file}',`)
      .join("\n");

    const dirStr = dirs
      .sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
      .map(dir => `    '${dir}',`)
      .join("\n");

    const src = MOZ_BUILD_TEMPLATE.replace("__DIRS__", dirStr).replace(
      "__FILES__",
      fileStr
    );

    fs.writeFileSync(path.join(buildPath, "moz.build"), src);
  });
}
function createMozBuildFiles ( ) { const builds = { } ; getFiles ( ) . filter ( file => file . match ( / .js$ / ) ) . filter ( file => { if ( file . match ( / \/workers\.js / ) ) { return true ; } // We exclude worker files because they are bundled and we include // worker/index.js files because are required by the debugger app in order // to communicate with the worker. if ( file . match ( / \/workers / ) ) { return file . match ( / workers\/(\w|-)*\/index.js / ) ; } return ! file . match ( / (test|types|packages) / ) } ) . forEach ( file => { // console.log(file) let dir = path . dirname ( file ) ; builds [ dir ] = builds [ dir ] || { files : [ ] , dirs : [ ] } ; // Add the current file to its parent dir moz.build builds [ dir ] . files . push ( path . basename ( file ) ) ; // There should be a moz.build in every folder between the root and this // file. Climb up the folder hierarchy and make sure a each folder of the // chain is listing in its parent dir moz.build. while ( path . dirname ( dir ) != "." ) { const parentDir = path . dirname ( dir ) ; const dirName = path . basename ( dir ) ; builds [ parentDir ] = builds [ parentDir ] || { files : [ ] , dirs : [ ] } ; if ( ! builds [ parentDir ] . dirs . includes ( dirName ) ) { builds [ parentDir ] . dirs . push ( dirName ) ; } dir = parentDir ; } } ) ; Object . keys ( builds ) . forEach ( build => { const { files , dirs } = builds [ build ] ; const buildPath = path . join ( mcDebuggerPath , build ) ; shell . mkdir ( "-p" , buildPath ) ; // Files and folders should be alphabetically sorted in moz.build const fileStr = files . sort ( ( a , b ) => ( a . toLowerCase ( ) < b . toLowerCase ( ) ? - 1 : 1 ) ) . map ( file => ` ${ file } ` ) . join ( "\n" ) ; const dirStr = dirs . sort ( ( a , b ) => ( a . toLowerCase ( ) < b . toLowerCase ( ) ? - 1 : 1 ) ) . map ( dir => ` ${ dir } ` ) . join ( "\n" ) ; const src = MOZ_BUILD_TEMPLATE . replace ( "__DIRS__" , dirStr ) . replace ( "__FILES__" , fileStr ) ; fs . writeFileSync ( path . join ( buildPath , "moz.build" ) , src ) ; } ) ; }
Create the mandatory manifest file that should exist in each folder to
list files and subfolders that should be packaged in Firefox.
Create the mandatory manifest file that should exist in each folder to list files and subfolders that should be packaged in Firefox .