|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var fs = require('fs'); |
| 4 | +var path = require('path'); |
| 5 | + |
| 6 | +var camelToDashed = require('../lib/parsers').camelToDashed; |
| 7 | + |
| 8 | +var property_files = fs.readdirSync(path.resolve(__dirname, '../lib/properties')); |
| 9 | +var out_file = fs.createWriteStream(path.resolve(__dirname, '../lib/properties.js'), {encoding: 'utf-8'}); |
| 10 | + |
| 11 | +out_file.write('\'use strict\';\n\n// autogenerated\n\n'); |
| 12 | +out_file.write('/*\n *\n * http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties\n */\n\n'); |
| 13 | +out_file.write('module.exports = function (prototype) {\n'); |
| 14 | + |
| 15 | +property_files.forEach(function (property) { |
| 16 | + var dashed; |
| 17 | + if (property.substr(-3) === '.js') { |
| 18 | + property = path.basename(property, '.js'); |
| 19 | + dashed = camelToDashed(property); |
| 20 | + out_file.write(' Object.defineProperty(prototype, \'' + property + '\', {\n'); |
| 21 | + out_file.write(' get: function () {\n'); |
| 22 | + out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); |
| 23 | + out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); |
| 24 | + out_file.write(' return this.' + property + ';\n'); |
| 25 | + out_file.write(' },\n'); |
| 26 | + out_file.write(' set: function (v) {\n'); |
| 27 | + out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); |
| 28 | + out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); |
| 29 | + out_file.write(' this.' + property + ' = v;\n'); |
| 30 | + out_file.write(' },\n'); |
| 31 | + out_file.write(' enumerable: true,\n'); |
| 32 | + out_file.write(' configurable: true\n'); |
| 33 | + out_file.write(' });\n'); |
| 34 | + if (property !== dashed) { |
| 35 | + out_file.write(' Object.defineProperty(prototype, \'' + dashed + '\', {\n'); |
| 36 | + out_file.write(' get: function () {\n'); |
| 37 | + out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); |
| 38 | + out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); |
| 39 | + out_file.write(' return this.' + property + ';\n'); |
| 40 | + out_file.write(' },\n'); |
| 41 | + out_file.write(' set: function (v) {\n'); |
| 42 | + out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); |
| 43 | + out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); |
| 44 | + out_file.write(' this.' + property + ' = v;\n'); |
| 45 | + out_file.write(' },\n'); |
| 46 | + out_file.write(' enumerable: true,\n'); |
| 47 | + out_file.write(' configurable: true\n'); |
| 48 | + out_file.write(' });\n'); |
| 49 | + } |
| 50 | + } |
| 51 | +}); |
| 52 | + |
| 53 | +out_file.write('};\n'); |
| 54 | +out_file.end(function (err) { |
| 55 | + if (err) { |
| 56 | + throw err; |
| 57 | + } |
| 58 | +}); |
0 commit comments