Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Apr 1, 2015
0 parents commit e7e5fef
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules/
*.log
5 changes: 5 additions & 0 deletions bin/native-css.js
@@ -0,0 +1,5 @@
#!/usr/bin/env node

(function() {
var nativeCSS = require('../lib/index.js');
})();
2 changes: 2 additions & 0 deletions docs/default.md
@@ -0,0 +1,2 @@
Hey young padawan, please type a valid command.
>> To see all commands, use: native-css [ -h, --help ]
13 changes: 13 additions & 0 deletions docs/help.md
@@ -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
15 changes: 15 additions & 0 deletions lib/index.js
@@ -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]);
69 changes: 69 additions & 0 deletions lib/native-css.js
@@ -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();
32 changes: 32 additions & 0 deletions package.json
@@ -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"
}
17 changes: 17 additions & 0 deletions readme.md
@@ -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)
20 changes: 20 additions & 0 deletions src/index.js
@@ -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;
}
};

0 comments on commit e7e5fef

Please sign in to comment.