Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e7e5fef
Showing
9 changed files
with
175 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
*.log |
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,5 @@ | ||
#!/usr/bin/env node | ||
|
||
(function() { | ||
var nativeCSS = require('../lib/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hey young padawan, please type a valid command. | ||
>> To see all commands, use: native-css [ -h, --help ] |
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,13 @@ | ||
|
||
Usage: native-css <command> | ||
|
||
Description: Convert pure CSS to react native style object | ||
|
||
More info: https://github.com/raphamorim/native-css | ||
|
||
Commands: | ||
native-css <pathFile> convert CSS file to react native style | ||
|
||
Options: | ||
-v, --version output version number | ||
-h, --help output usage information |
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,15 @@ | ||
'use strict'; | ||
|
||
var nativeCSS = require('./native-css'), | ||
verify = require('../src').verify, | ||
commands = process.argv; | ||
|
||
// Version | ||
if (verify(['-v', '--version'])) | ||
return console.log(nativeCSS.version()); | ||
|
||
// Help | ||
else if (verify(['-h', '--help'])) | ||
return console.log(nativeCSS.help()); | ||
|
||
return nativeCSS.convert(commands[2]); |
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,69 @@ | ||
'use strict'; | ||
|
||
var packageJson = require('../package.json'), | ||
src = require('../src'); | ||
|
||
var nativeCSS = function() {}; | ||
|
||
nativeCSS.prototype.default = function() { | ||
return src.readFile('/../docs/default.md') | ||
} | ||
|
||
nativeCSS.prototype.version = function() { | ||
return ('native-css version: ' + packageJson.version) | ||
} | ||
|
||
nativeCSS.prototype.help = function() { | ||
return src.readFile('/../docs/help.md') | ||
} | ||
|
||
nativeCSS.prototype.convertProperties = function(reference, property) { | ||
var properties = {}; | ||
|
||
property = property.replace(new RegExp(reference + '{', 'g'), '') | ||
.replace(new RegExp('}', 'g'), '') | ||
|
||
property = property.split(';'); | ||
|
||
property.forEach(function(item) { | ||
if (item != '') { | ||
var entry = item.split(':'); | ||
properties[entry[0]] = entry[1]; | ||
} | ||
}) | ||
|
||
return properties; | ||
} | ||
|
||
nativeCSS.prototype.convert = function(cssFile) { | ||
var path = process.cwd() + '/' + cssFile; | ||
|
||
console.log(path); | ||
|
||
if (!(require('fs').existsSync(path))) | ||
return console.log('Ooops!\nError: CSS file not found!'); | ||
|
||
var self = this, | ||
css = src.readFile(path); | ||
css = css.replace(/\s/g, ''); | ||
|
||
var classNames = css.match(/(?:#\w+\s+)?\.[\w-]+(?:\s+\w+\s*\.\w+|\s+\w+)?/ig), | ||
classNamesData = ''; | ||
|
||
var classes = []; | ||
var result = {}; | ||
|
||
classNames.forEach(function(item) { | ||
classNamesData = css | ||
.substring(css.indexOf(item),css.indexOf('}')+1); | ||
|
||
css = css.replace(classNamesData, ''); | ||
classes.push(classNamesData); | ||
|
||
result[item] = self.convertProperties(item, classNamesData); | ||
}); | ||
|
||
console.log(result) | ||
} | ||
|
||
module.exports = new nativeCSS(); |
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,32 @@ | ||
{ | ||
"name": "native-css", | ||
"version": "1.0.0", | ||
"description": "Convert pure CSS to react native style object", | ||
"main": "index.js", | ||
"bin": { | ||
"native-css": "native-css.js" | ||
}, | ||
"directories": { | ||
"doc": "docs" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/raphamorim/native-css" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"css", | ||
"react", | ||
"native", | ||
"convert" | ||
], | ||
"author": "Raphael Amorim", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/raphamorim/native-css/issues" | ||
}, | ||
"homepage": "https://github.com/raphamorim/native-css" | ||
} |
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,17 @@ | ||
# native-css | ||
|
||
Convert pure CSS to react native style object. | ||
|
||
## Contributing | ||
|
||
Don't be shy, send a Pull Request! Here is how: | ||
|
||
1. Fork it! | ||
2. Create your feature branch: `git checkout -b my-new-feature` | ||
3. Commit your changes: `git commit -m 'Add some feature'` | ||
4. Push to the branch: `git push origin my-new-feature` | ||
5. Submit a pull request :D | ||
|
||
## About | ||
|
||
**License:** MIT ® [Raphael Amorim](https://github.com/raphamorim) |
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,20 @@ | ||
var fs = require('fs'), | ||
input = process.argv[2]; | ||
|
||
exports.readFile = function(path) { | ||
return fs.readFileSync(path, 'utf8'); | ||
} | ||
|
||
exports.verify = function(args) { | ||
if (typeof args === 'object') { | ||
if (args.indexOf(input) == -1) | ||
return false; | ||
|
||
return true; | ||
} else { | ||
if (args != input) | ||
return false; | ||
|
||
return true; | ||
} | ||
}; |