import { AtlasOptions , generateSprites , generateSpritesAtlas , ProcessingOptions } from "@here/harp-atlas-tools/src" ; import * as os from "os" ; import * as path from "path" ; const tmp = require ( "tmp" ) ; function downloadMakiIcons ( targetDir ) { const ghdownload = require ( "github-download" ) ; const makiPath = path . join ( __dirname , ".." ) ; return new Promise ( ( resolve , reject ) => { ghdownload ( "https://github.com/mapbox/maki#master" , targetDir ) . on ( "error" , ( err ) => { reject ( new Error ( err ) ) ; } ) . on ( "end" , ( ) => { resolve ( path . join ( makiPath , targetDir ) ) ; } ) ; } ) ; } async function generateMakiAtlas ( makiDir , atlasPath , smallIconsConfig , bigIconsConfig ) { const cpus = os . cpus ( ) ? os . cpus ( ) . length : 4 ; const tmpDir = tmp . dirSync ( { template : "sprites-XXXXXX" , dir : makiDir , unsafeCleanup : true } ) ; const spritesInputPath = path . join ( makiDir , "icons" ) ; const spritesOutputPath = tmpDir . name ; const spritesDaySmallOpt = { input : path . join ( spritesInputPath , "*-11.svg" ) , output : spritesOutputPath , width : 0 , height : 0 , verbose : false , jobs : cpus , processConfig : smallIconsConfig } ; const spritesDayBigOpt = { ... spritesDaySmallOpt , input : path . join ( spritesInputPath , "*-15.svg" ) , processConfig : bigIconsConfig } ; try { await generateSprites ( spritesDaySmallOpt ) ; await generateSprites ( spritesDayBigOpt ) ; const atlasDayOpt = { input : path . join ( spritesOutputPath , "*.png" ) , output : atlasPath , width : 0 , height : 0 , verbose : false , jobs : cpus , processConfig : "" , padding : 1 , minify : false } ; await generateSpritesAtlas ( atlasDayOpt ) ; } finally { tmpDir . removeCallback ( ) ; } } async function prepareIcons ( ) { const tmpDir = tmp . dirSync ( { template : "resources-tmp-XXXXXX" , dir : "." , unsafeCleanup : true } ) ; try { const makiDir = await downloadMakiIcons ( tmpDir . name ) ; const atlasDay = "resources/maki_icons_day" ; const configDaySmall = "resources-dev/icons/configs/icons-day-maki-11.json" ; const configDayBig = "resources-dev/icons/configs/icons-day-maki-15.json" ; await generateMakiAtlas ( makiDir , atlasDay , configDaySmall , configDayBig ) ; const atlasNight = "resources/maki_icons_night" ; const configNightSmall = "resources-dev/icons/configs/icons-night-maki-11.json" ; const configNightBig = "resources-dev/icons/configs/icons-night-maki-15.json" ; await generateMakiAtlas ( makiDir , atlasNight , configNightSmall , configNightBig ) ; } finally { tmpDir . removeCallback ( ) ; } } prepareIcons ( ) . then ( ( ) => { console . log ( "Assets prepare successful" ) ; } ) . catch ( err => { console . error ( "Could not prepare assets! " , err ) ; } ) ;