test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const stats='';
  2. // Merges webpack.common config with this production config
  3. const fs = require('fs');
  4. const glob = require('glob');
  5. var getDirectories = function (src, callback) {
  6. glob(src + '/**/*.gz', callback);
  7. };
  8. getDirectories('./webpack/', function (err, list) {
  9. if (err) {
  10. console.log('Error', err);
  11. } else {
  12. const regex = /^(.*\/)([^\/]*)$/
  13. const relativeRegex = /(\w+\/[^\/]*)$/
  14. const makePathRegex = /([^\.].*)$/
  15. let exportDefHead=
  16. '/***********************************\n'+
  17. 'webpack_headers\n'+
  18. stats+'\n'+
  19. '***********************************/\n'+
  20. '#pragma once\n'+
  21. '#include <inttypes.h>\n'+
  22. 'extern const char * resource_lookups[];\n'+
  23. 'extern const uint8_t * resource_map_start[];\n'+
  24. 'extern const uint8_t * resource_map_end[];\n';
  25. let exportDef= '// Automatically generated. Do not edit manually!.\n'+
  26. '#include <inttypes.h>\n';
  27. let lookupDef='const char * resource_lookups[] = {\n';
  28. let lookupMapStart='const uint8_t * resource_map_start[] = {\n';
  29. let lookupMapEnd='const uint8_t * resource_map_end[] = {\n';
  30. let cMake='';
  31. list.forEach(fileName=>{
  32. console.log(fileName);
  33. let exportName=fileName.match(regex)[2].replace(/[\. \-]/gm,'_');
  34. let relativeName=fileName.match(relativeRegex)[1];
  35. exportDef+= 'extern const uint8_t '+exportName+'_start[] asm("_binary_'+exportName+'_start");\n'+
  36. 'extern const uint8_t '+exportName+'_end[] asm("_binary_'+exportName+'_end");\n';
  37. lookupDef+='\t"/'+relativeName+'",\n';
  38. lookupMapStart+='\t'+ exportName+'_start,\n';
  39. lookupMapEnd+= '\t'+ exportName+'_end,\n';
  40. cMake+='target_add_binary_data( __idf_wifi-manager ./webapp'+fileName.match(makePathRegex)[1]+' BINARY)\n';
  41. });
  42. lookupDef+='""\n};\n';
  43. lookupMapStart=lookupMapStart.substring(0,lookupMapStart.length-2)+'\n};\n';
  44. lookupMapEnd=lookupMapEnd.substring(0,lookupMapEnd.length-2)+'\n};\n';
  45. try {
  46. fs.writeFileSync('webapp.cmake', cMake);
  47. fs.writeFileSync('webpack.c', exportDef+lookupDef+lookupMapStart+lookupMapEnd);
  48. fs.writeFileSync('webpack.h', exportDefHead);
  49. //file written successfully
  50. } catch (err) {
  51. console.error(err);
  52. }
  53. }
  54. });