-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a prepublish script that generates the properties.js file
This file will lazy-load properties but also specify the filename in the require explicitly so that it plays better with browserify. Should solve #11
- Loading branch information
Showing
5 changed files
with
67 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
lib/properties.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var camelToDashed = require('../lib/parsers').camelToDashed; | ||
|
||
var property_files = fs.readdirSync(path.resolve(__dirname, '../lib/properties')); | ||
var out_file = fs.createWriteStream(path.resolve(__dirname, '../lib/properties.js'), {encoding: 'utf-8'}); | ||
|
||
out_file.write('\'use strict\';\n\n// autogenerated\n\n'); | ||
out_file.write('/*\n *\n * http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties\n */\n\n'); | ||
out_file.write('module.exports = function (prototype) {\n'); | ||
|
||
property_files.forEach(function (property) { | ||
var dashed; | ||
if (property.substr(-3) === '.js') { | ||
property = path.basename(property, '.js'); | ||
dashed = camelToDashed(property); | ||
out_file.write(' Object.defineProperty(prototype, \'' + property + '\', {\n'); | ||
out_file.write(' get: function () {\n'); | ||
out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); | ||
out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); | ||
out_file.write(' return this.' + property + ';\n'); | ||
out_file.write(' },\n'); | ||
out_file.write(' set: function (v) {\n'); | ||
out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); | ||
out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); | ||
out_file.write(' this.' + property + ' = v;\n'); | ||
out_file.write(' },\n'); | ||
out_file.write(' enumerable: true,\n'); | ||
out_file.write(' configurable: true\n'); | ||
out_file.write(' });\n'); | ||
if (property !== dashed) { | ||
out_file.write(' Object.defineProperty(prototype, \'' + dashed + '\', {\n'); | ||
out_file.write(' get: function () {\n'); | ||
out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); | ||
out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); | ||
out_file.write(' return this.' + property + ';\n'); | ||
out_file.write(' },\n'); | ||
out_file.write(' set: function (v) {\n'); | ||
out_file.write(' var definition = require(\'./properties/' + property + '\').definition;\n'); | ||
out_file.write(' Object.defineProperty(prototype, \'' + property + '\', definition);\n'); | ||
out_file.write(' this.' + property + ' = v;\n'); | ||
out_file.write(' },\n'); | ||
out_file.write(' enumerable: true,\n'); | ||
out_file.write(' configurable: true\n'); | ||
out_file.write(' });\n'); | ||
} | ||
} | ||
}); | ||
|
||
out_file.write('};\n'); | ||
out_file.end(function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
node ./scripts/generate_properties.js | ||
nodeunit tests |