generate_implemented_properties.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use strict';
  2. const fs = require('fs');
  3. const path = require('path');
  4. const t = require('babel-types');
  5. const generate = require('babel-generator').default;
  6. const camelToDashed = require('../lib/parsers').camelToDashed;
  7. const dashedProperties = fs
  8. .readdirSync(path.resolve(__dirname, '../lib/properties'))
  9. .filter(propertyFile => propertyFile.substr(-3) === '.js')
  10. .map(propertyFile => camelToDashed(propertyFile.replace('.js', '')));
  11. const out_file = fs.createWriteStream(path.resolve(__dirname, '../lib/implementedProperties.js'), {
  12. encoding: 'utf-8',
  13. });
  14. var date_today = new Date();
  15. out_file.write(
  16. "'use strict';\n\n// autogenerated - " +
  17. (date_today.getMonth() + 1 + '/' + date_today.getDate() + '/' + date_today.getFullYear()) +
  18. '\n\n'
  19. );
  20. out_file.write('/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\n');
  21. const statements = [];
  22. statements.push(
  23. t.variableDeclaration('var', [
  24. t.variableDeclarator(
  25. t.identifier('implementedProperties'),
  26. t.newExpression(t.identifier('Set'), [])
  27. ),
  28. ])
  29. );
  30. dashedProperties.forEach(property => {
  31. statements.push(
  32. t.expressionStatement(
  33. t.callExpression(
  34. t.memberExpression(t.identifier('implementedProperties'), t.identifier('add')),
  35. [t.stringLiteral(property)]
  36. )
  37. )
  38. );
  39. });
  40. statements.push(
  41. t.expressionStatement(
  42. t.assignmentExpression(
  43. '=',
  44. t.memberExpression(t.identifier('module'), t.identifier('exports')),
  45. t.identifier('implementedProperties')
  46. )
  47. )
  48. );
  49. out_file.write(generate(t.program(statements)).code + '\n');
  50. out_file.end(function(err) {
  51. if (err) {
  52. throw err;
  53. }
  54. });