scripts/node/build-icons.js
function sortByFileFormat(srcDir, format) {
  const initialFiles = `${srcDir}/*.${format}`
  const files = glob.sync(initialFiles);
  const dest = `${srcDir}/${format}`;
  let count = 0;

  createDirs([dest]);

  // Loop through and move each file
  const promises = files.map(f => {
    return new Promise((resolve, reject) => {
      const filename = sanitize(path.basename(f));
      const reg = /[\w-]+-(16|24|32)\.[\w]+/;
      const match = filename.match(reg);
      let thisDest = dest;

      if (match) {
        const size = match[1];
        thisDest = `${thisDest}/${size}`;
        createDirs([thisDest]);
      }

      fs.rename(f, `${thisDest}/${filename}`, err => {
        if (err) {
          reject(err);
        }
        count++;
        resolve(`${dest}/${filename}`);
      });
    });
  });

  return Promise.all(promises).then(() => {
    swlog.logTaskAction('Moved', `${count}/${files.length} ${format.toUpperCase()} files`);
  });
}
function sortByFileFormat(srcDir, format) {
  const initialFiles = `${srcDir}/*.${format}`
  const files = glob.sync(initialFiles);
  const dest = `${srcDir}/${format}`;
  let count = 0;

  createDirs([dest]);

  // Loop through and move each file
  const promises = files.map(f => {
    return new Promise((resolve, reject) => {
      const filename = sanitize(path.basename(f));
      const reg = /[\w-]+-(16|24|32)\.[\w]+/;
      const match = filename.match(reg);
      let thisDest = dest;

      if (match) {
        const size = match[1];
        thisDest = `${thisDest}/${size}`;
        createDirs([thisDest]);
      }

      fs.rename(f, `${thisDest}/${filename}`, err => {
        if (err) {
          reject(err);
        }
        count++;
        resolve(`${dest}/${filename}`);
      });
    });
  });

  return Promise.all(promises).then(() => {
    swlog.logTaskAction('Moved', `${count}/${files.length} ${format.toUpperCase()} files`);
  });
}
function sortByFileFormat ( srcDir , format ) { const initialFiles = ` ${ srcDir } ${ format } ` const files = glob . sync ( initialFiles ) ; const dest = ` ${ srcDir } ${ format } ` ; let count = 0 ; createDirs ( [ dest ] ) ; // Loop through and move each file const promises = files . map ( f => { return new Promise ( ( resolve , reject ) => { const filename = sanitize ( path . basename ( f ) ) ; const reg = / [\w-]+-(16|24|32)\.[\w]+ / ; const match = filename . match ( reg ) ; let thisDest = dest ; if ( match ) { const size = match [ 1 ] ; thisDest = ` ${ thisDest } ${ size } ` ; createDirs ( [ thisDest ] ) ; } fs . rename ( f , ` ${ thisDest } ${ filename } ` , err => { if ( err ) { reject ( err ) ; } count ++ ; resolve ( ` ${ dest } ${ filename } ` ) ; } ) ; } ) ; } ) ; return Promise . all ( promises ) . then ( ( ) => { swlog . logTaskAction ( 'Moved' , ` ${ count } ${ files . length } ${ format . toUpperCase ( ) } ` ) ; } ) ; }
Move icon types into proper directory
@param {String} srcDir - Directory of files
@param {Array} formats - Array of file formats
Move icon types into proper directory