Check that sketchtool is available

Cleanup the destination and the temp folders

Loop on every brand and its declared group of Sketch files

Get the design tokens values for this brand

Prepare the brand's Sketch files (unzipped) and get a list of them

Unzip the Sketch file

Update the Sketch JSON files adding a prefix to the exported assets layers when inside an experiment (detected via the "XP_" prefix in the page name)

Return an ordered list of Sketch unzipped folders

Read the Sketch JSON data in the files and store it in pre-defined objects

Get the (merged) list of Shared Styles objects

Get the (merged) list of Exported Assets objects

for every Sketch folder

parse the "document" and "meta" files

from "document" get metadata for the "shared styles" list

from "meta" + "pages" get metadata for the "assets" list

loop on every page and loop on every "exported" asset ("pagesAndArtboards")

store the layer data/informations and add extra metadata (size, source)

if it's an experiment

get the experiment/variant names

add the experiment data to the asset's layer object data

update the "base" assets with the list of their experiments specified in the file

add the experiment to the list of experiments for that file

merge the lists of Shared Styles objects and the list of Assets objects

Generate the assets for the different platforms

Generate PDF for iOS

Generate VectorDrawable for Android

for every Sketch folder

create a clone/copy of the original Sketch folder, to read/update its JSON content

in the Sketch JSON files replace the Shared Styles color values with the brand-specific ones (read from the design tokens)

recompress the updated sketch folder to a Sketch file

export the assets from the updated Sketch file via sketchtool in PDF format

delete the cloned Sketch folder

for every exported asset

move the exported asset to its final folder

store the asset data in an object list of assets: asset name, file path, size, experiment/variant, etc.

generate the final output files

for every Sketch folder

create a clone/copy of the original Sketch folder, to read/update its JSON content

in the Sketch JSON files replace the Shared Styles color values with the brand-specific ones (read from the design tokens)

recompress the updated sketch folder to a Sketch file

export the assets from the updated Sketch file via sketchtool in SVG format

delete the cloned Sketch folder

for every exported asset

update the SVG file replacing hex fill values with variable names (same as design tokens)

move the exported asset to its final folder

generate the final output files

store the asset data in an object list of assets: asset name, file path, size, experiment/variant, etc.

use cheerio to read the SVG DOM tree

get the list of layers with applied a Shared Style and calculate their xpath in the SVG

use cheerio to update the fill attribute of the layers with the variable name of the design token corresponding to the Shared Style applied to it

for every Sketch folder

create a clone/copy of the original Sketch folder, to read/update its JSON content

in the Sketch JSON files replace the Shared Styles color values with the brand-specific ones (read from the design tokens)

in the Sketch JSON files for every layer replace the winding-rule property from "even-odd" to "non-zero"

recompress the updated sketch folder to a Sketch file

export the assets from the updated Sketch file via sketchtool in SVG format

for every exported asset

generate the final output files

update the SVG file replacing hex fill values with variable names (same as design tokens)

convert the SVG file to VectorDrawable

move the exported asset to its final folder

use cheerio to read the SVG DOM tree

get the list of layers with applied a Shared Style and calculate their xpath in the SVG

use cheerio to update the fill attribute of the layers with the variable name of the design token corresponding to the Shared Style applied to it

delete the cloned Sketch folder

store the asset data in an object list of assets: asset name, file path, size, experiment/variant, etc.

process the experiments and update the assets data/paths

create a "zip" file containing all the assets in a single file

write the JSON file with the map of the assets and the extra information

for every asset

if it's an experiment variant, get the experiment/variant data and attach it to the "base" asset

process the experiments and update the assets data/paths

create a "zip" file containing all the assets in a single file

write the JSON file with the map of the assets and the extra information

for every asset

if it's an experiment variant, get the experiment/variant data and attach it to the "base" asset

import the entire list of React/JSX assets in a JavaScript Module

process the experiments and update the assets data/paths

create a "zip" file containing all the assets in a single file

write the JSON file with the map of the assets and the extra information

for every asset

if it's an experiment variant, get the experiment/variant data and attach it to the "base" asset

convert the SVG file to a React component