import * as themeX from './themeX' ; import * as jsYaml from 'js-yaml' ; import * as fs from 'fs' ; import * as path from 'path' ; enum fileType { project , settings } export function loadProjectByCWD ( ) { return loadProjectByFile ( process . cwd ( ) ) ; } /** Loads the project main yaml file */ export function loadProjectByFile ( file ) { if ( file . toLowerCase ( ) . endsWith ( '.themex' ) ) { themeX . print ( 'parsing theme files' ) ; return { project : < themeX . IBundle . project > importFileObject ( fileType . project , file ) , settings : < themeX . IBundle . settings > importFileObject ( fileType . settings , file ) , path : file } ; } else { return undefined ; } } function importFileObject ( kind , cwd ) { const address = ( ( kind == fileType . project ) ? path . join ( cwd , 'theme.yml' ) : path . join ( cwd , 'project.yml' ) ) ; return importYAML ( address ) ; } function importYAML ( address ) { if ( fs . existsSync ( address ) ) { const fileString = fs . readFileSync ( address , 'utf8' ) ; const decodedObject = jsYaml . load ( fileString ) ; return decodedObject ; } else { return null ; } }