scripts/node/build-icons.js
function createPagesMetadata(src, dest) {
  return new Promise((resolve, reject) => {
    const thisTaskName = swlog.logSubStart('create metadata file');
    const outputStr = sketchtoolExec(`metadata ${src}`)
    const ignoredPages = ['Symbols', 'Icon Sheet', '------------']

    let customObj = { categories: [] };
    const dataObj = JSON.parse(outputStr);

    // Loop through pages, then arboards, to create a
    // simple mapping of names (ignoring certain pages)
    // and naming pages "categories" and artboards "icons"
    for (const pageId in dataObj.pagesAndArtboards) {
      if (dataObj.pagesAndArtboards.hasOwnProperty(pageId)
        && ! ignoredPages.includes(dataObj.pagesAndArtboards[pageId].name)) {

        const tempObj = {
          name: dataObj.pagesAndArtboards[pageId].name,
          icons: []
        };

        for (const ab in dataObj.pagesAndArtboards[pageId].artboards) {
          if (dataObj.pagesAndArtboards[pageId].artboards.hasOwnProperty(ab)) {
            tempObj.icons.push(dataObj.pagesAndArtboards[pageId].artboards[ab].name);
          }
        }
        tempObj.icons.sort();
        customObj.categories.push(tempObj);
      }
    }
    fs.writeFileSync(`${dest}/metadata.json`, JSON.stringify(customObj, null, 4), 'utf-8');
    swlog.logSubEnd(thisTaskName);
    resolve();
  });
}
function createPagesMetadata(src, dest) {
  return new Promise((resolve, reject) => {
    const thisTaskName = swlog.logSubStart('create metadata file');
    const outputStr = sketchtoolExec(`metadata ${src}`)
    const ignoredPages = ['Symbols', 'Icon Sheet', '------------']

    let customObj = { categories: [] };
    const dataObj = JSON.parse(outputStr);

    // Loop through pages, then arboards, to create a
    // simple mapping of names (ignoring certain pages)
    // and naming pages "categories" and artboards "icons"
    for (const pageId in dataObj.pagesAndArtboards) {
      if (dataObj.pagesAndArtboards.hasOwnProperty(pageId)
        && ! ignoredPages.includes(dataObj.pagesAndArtboards[pageId].name)) {

        const tempObj = {
          name: dataObj.pagesAndArtboards[pageId].name,
          icons: []
        };

        for (const ab in dataObj.pagesAndArtboards[pageId].artboards) {
          if (dataObj.pagesAndArtboards[pageId].artboards.hasOwnProperty(ab)) {
            tempObj.icons.push(dataObj.pagesAndArtboards[pageId].artboards[ab].name);
          }
        }
        tempObj.icons.sort();
        customObj.categories.push(tempObj);
      }
    }
    fs.writeFileSync(`${dest}/metadata.json`, JSON.stringify(customObj, null, 4), 'utf-8');
    swlog.logSubEnd(thisTaskName);
    resolve();
  });
}
function createPagesMetadata ( src , dest ) { return new Promise ( ( resolve , reject ) => { const thisTaskName = swlog . logSubStart ( 'create metadata file' ) ; const outputStr = sketchtoolExec ( ` ${ src } ` ) const ignoredPages = [ 'Symbols' , 'Icon Sheet' , '------------' ] let customObj = { categories : [ ] } ; const dataObj = JSON . parse ( outputStr ) ; // Loop through pages, then arboards, to create a // simple mapping of names (ignoring certain pages) // and naming pages "categories" and artboards "icons" for ( const pageId in dataObj . pagesAndArtboards ) { if ( dataObj . pagesAndArtboards . hasOwnProperty ( pageId ) && ! ignoredPages . includes ( dataObj . pagesAndArtboards [ pageId ] . name ) ) { const tempObj = { name : dataObj . pagesAndArtboards [ pageId ] . name , icons : [ ] } ; for ( const ab in dataObj . pagesAndArtboards [ pageId ] . artboards ) { if ( dataObj . pagesAndArtboards [ pageId ] . artboards . hasOwnProperty ( ab ) ) { tempObj . icons . push ( dataObj . pagesAndArtboards [ pageId ] . artboards [ ab ] . name ) ; } } tempObj . icons . sort ( ) ; customObj . categories . push ( tempObj ) ; } } fs . writeFileSync ( ` ${ dest } ` , JSON . stringify ( customObj , null , 4 ) , 'utf-8' ) ; swlog . logSubEnd ( thisTaskName ) ; resolve ( ) ; } ) ; }
Get the metadata from the sketch file to map
icons names to page names
@param {String} src - The source of the sketch file
@param {String} dest - The destination
@returns {Promise}
Get the metadata from the sketch file to map icons names to page names