"use strict";var fs=require('fs');var path=require('path');var reactDocs=require('react-docgen');var directoryPath="../../node_modules/native-base/src/basic/";fs.readdir(directoryPath,function(err,files){if(err){return console.log('Unable to scan directory: '+err);}var Infos=[];files.forEach(function(file,index){if(!file.endsWith('.js')||file.includes('.android')||file.includes('.ios'))return;console.log("No. "+index+" : ",file);var content=fs.readFileSync(directoryPath+file);try{var info=reactDocs.parse(content);info.componentName=file.replace('.js','');Infos.push(info);}catch(e){console.log("Error");console.log(e);}});var fileText=generateFile(Infos);fs.writeFileSync('./index.js',fileText);});function generateFile(Infos){var headers="\nimport React from 'react';\nimport Types from '../../lib/Types';\nimport Module from '../../lib/Module';\n";var IM=[],EX=[],PROPS=[],Names=[];Infos.forEach(function(info){var _createClass=createClass(info),im=_createClass.im,ex=_createClass.ex,props=_createClass.props;Names.push(info.componentName);IM.push(im);EX.push(ex);PROPS.push(props);});return headers+"\n\n"+IM.join('\n')+"\n\n"+EX.join('\n')+"\n\n"+PROPS.join('\n')+"\n\n"+"export default { \n\t".concat(Names.join(',\n\t')," \n}");}function createClass(item){var name=item.componentName;var props=generatePropsText(item.props);var s="export class ".concat(name," extends Module {\n\tconstructor(props) {\n\t\tsuper(props);\n\t}\n\tdisplay() {\n\t\treturn <").concat(name+'Ctor'," {...this.props} />\n\t}\n}");var propsText="".concat(name,".Inputs = ").concat(props);return{im:"import { ".concat(name," as ").concat(name+'Ctor'," } from 'native-base';"),ex:s,props:propsText};}function generatePropsText(props){var Props=[];for(var name in props){var p=props[name];var validator=void 0;switch(p.type&&p.type.name){case'number':validator="new Types.Real()";break;case'string':validator="new Types.Text()";break;case'bool':validator="new Types.Bool()";break;default:console.log("Style type for ",name,p.type);continue;break;}if(p.required)validator+=".require()";if(p.defaultValue)validator+=".default(".concat(p.defaultValue.value,")");var s="".concat(name,": ").concat(validator);Props.push(s);}return"{\n\t".concat(Props.join(',\n\t'),"\n}");}