import fs = require ( 'fs-extra' ) ; import colors = require ( 'colors' ) ; import path = require ( 'path' ) ; export function forkey ( object , func ) { Object . keys ( object ) . forEach ( key => { func ( key ) ; } ) ; } export function getFileNameForTheme ( theme ) { const name = theme . theme . project . themes [ theme . index ] . name ; return name . toLocaleLowerCase ( ) . replace ( / /g , '' ) ; } export function buildsDirectoryPath ( address ) { return path . join ( getFolderContainingProject ( address ) , path . join ( 'builds' ) ) ; } export function adaptorBuildDirectoryPath ( adaptor , address ) { return path . join ( buildsDirectoryPath ( address ) , adaptor . editorId ) ; } export function getFolderContainingProject ( address ) { return address . replace ( /\/(?:[^(\/)\\]|\\.)*$/ , '' ) ; } export function forEachThemeDo ( project , address , generatorFunction ) { for ( let __INDEX = 0 ; __INDEX < project . project . themes . length ; __INDEX ++ ) { generatorFunction ( { theme : project , index : __INDEX , path : address } ) ; } } export function parseColor ( theme , color ) { color = color . toString ( ) ; function onBadColor ( ) { return ( theme . theme . project . themes [ theme . index ] . baseColor === 'dark' ) ? '#FFFFFF' : '#000000' ; } if ( /^\#?[A-F0-9]{6}$/i . test ( color ) ) { return color . toString ( ) . startsWith ( '#' ) ? color . toUpperCase ( ) : `#${ color . toUpperCase ( ) }` ; } else if ( /^\.[a-z]([a-z0-9\-]*[a-z0-9])?$/i . test ( color ) ) { let v = theme . theme . project . themes [ theme . index ] . colors [ color . substr ( 1 ) ] . toString ( ) ; return v ? `#${ v . toUpperCase ( ) }` : onBadColor ( ) ; } return onBadColor ( ) ; } export function report ( errorMessage ) { console . log ( ` ${ colors . red ( '✕' ) } ${ errorMessage }\n` ) ; } export function print ( input ) { console . log ( ` ${ colors . green ( '✓' ) } ${ input }\n` ) ; } /** Indents the string... */ export function indent ( text ) { return text . split ( '\n' ) . map ( line => '    ' + line ) . join ( '\n' ) ; } export interface IAdaptor { name : string ; adaptorPath : string ; id : string ; generate ( project , address ) ; editorName : string ; editorId : string ; version : string ; author : string ; } export interface ICurrentTheme { theme : IBundle . base ; index : number ; path : string ; } export module IBundle { export interface project { /** Version of theme */ version : string ; /** Description of the theme */ description : string ; /** Author of the theme */ author : string ; /** Colorspace name */ colorSpaceName ? : string ; /** Theme plates */ themes : theme [ ] ; /** Rules of the theme */ rules : rule [ ] ; } export interface theme { /** Theme name */ name : string ; /** UUID */ uuid : string ; /** BaseColor, is it dark or light */ baseColor : string ; /** Base color settings for the color */ settings : themeSettings ; /** Colors of the theme */ colors : Object ; } export interface themeSettings { background : string ; caret : string ; foreground : string ; invisibles : string ; lineHighlight : string ; selection : string ; comment : string ; } export interface rule { name : string ; scope ? : string ; scopes ? : string [ ] ; color : string ; bold ? : boolean ; italic ? : boolean ; underline ? : boolean ; } export interface settings { } export interface base { project : project ; settings : settings ; path : string ; } } /** Replaces some objects keys with their values in a text */ export function replaceObjectsInString ( text , replacements ) { text . replace ( /\{\#[a-b\_0-9 ]+\#\}/gi , ( handle ) => { console . log ( handle ) ; return null ; } ) ; } /**
 * Let's you copy a **_template file_** from templates directory to the build
 * **_destination folder_** by also replacing your _replacements_ (optional)
 */ export function copy ( adaptor , template , destination , replacements ? ) { let fileContent = fs . readFileSync ( template , 'utf8' ) ; if ( fileContent === null || fileContent === undefined ) return false ; }