import themeX = require ( './themeX' ) ; import check = require ( './checkcore' ) ; import fs = require ( 'fs' ) ; import path = require ( 'path' ) ; import colors = require ( 'colors' ) ; export = ( project , address ) : boolean => { if ( ! check ( project ) ) return false ; applyBuild ( project , address ) ; } ; function applyBuild ( project , address ) { setupBuildsDirectory ( address ) ; let adaptorDirectory = getAdaptorDirectoryLocation ( ) ; fs . readdir ( adaptorDirectory , ( err , files ) => { files . forEach ( adaptorDirectoryName => { if ( /.adaptorX$/ . test ( adaptorDirectoryName ) ) { runAdaptor ( adaptorDirectory , adaptorDirectoryName , address , project ) ; } } ) ; } ) ; } function runAdaptor ( adaptorDirectory , adaptorDirectoryName , address , project ) { try { const adaptorPath = path . join ( adaptorDirectory , adaptorDirectoryName ) ; const adaptor = < themeX . IAdaptor > require ( adaptorPath ) ; adaptor [ 'name' ] = adaptorDirectoryName ; adaptor [ 'adaptorPath' ] = adaptorPath ; setupAdaptorEnvironment ( adaptor , address ) ; themeX . print ( `running adaptor ${ adaptor . name . underline } (v${ adaptor . version })` ) ; adaptor . generate ( project , address ) ; } catch ( error ) { themeX . report ( `Internal Error: "${ error }"` ) ; } } function setupBuildsDirectory ( address ) { let dir = themeX . buildsDirectoryPath ( address ) ; if ( ! fs . existsSync ( dir ) ) fs . mkdirSync ( dir ) ; } function setupAdaptorEnvironment ( adaptor , address ) { const projectDir = themeX . adaptorBuildDirectoryPath ( adaptor , address ) ; if ( ! fs . existsSync ( projectDir ) ) fs . mkdirSync ( projectDir ) ; } function getAdaptorDirectoryLocation ( ) { return path . join ( __dirname , 'adaptors' ) ; }