Skip to content

Commit

Permalink
Integrated AutoAtom functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
src-code committed Feb 28, 2015
1 parent 235e519 commit 1e02f75
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ node_modules/
artifacts/
npm-debug.log
dist/
*.log
58 changes: 46 additions & 12 deletions bin/atomizer
Expand Up @@ -14,16 +14,30 @@ var path = require('path');
var fs = require('fs');
var chalk = require('chalk');
var atomizer = require('../src/atomizer');
var configObjs = [];
var _ = require('lodash');
var content = '';
var config;
var parsedConfig = {};

var params = require('minimist')(process.argv.slice(2));

if (process.argv.slice(2).length === 0 || params.help) {
var usage = ['usage: ', process.title, '[-o|--outfile=<file>] [--help] configfile ...'].join(' ');
var usage = ['usage: ', process.title, ' -c|--config=<file> [-o|--outfile=<file>] [--help] [--verbose] [<files-to-parse> ...]'].join(' ');
console.log(usage);
return;
}

function handleMergeArrays (a, b) {
if (_.isArray(a) && _.isArray(b)) {
a.forEach(function(item){
if(_.findIndex(b, item) === -1) {
b.push(item);
}
});
return b;
}
}

// TODO
var options = {
require: []
Expand All @@ -35,19 +49,39 @@ if (options.require.length > 0) {
});
}

var srcFiles = params._ || [];
srcFiles = srcFiles.filter(function(filepath) {
if (!fs.existsSync(filepath)) {
console.warn('Configuration file ' + chalk.cyan(filepath) + ' not found.');
// Static config should contain the general 'config' options, along with any
// statically defined configuration. It is required.
var configFile = params.c || params.config;
if (configFile) {
if (!fs.existsSync(configFile)) {
throw new Error('Configuration file ' + chalk.cyan(configFile) + ' not found.');
return false;
} else {
configObjs.push(require(path.resolve(filepath)));
return true;
}
});
config = require(path.resolve(configFile));
} else {
throw new Error('Configuration file not provided.');
return false;
}

// Generate config from parsed src files
var parseFiles = params._ || [];
if (parseFiles.length) {
var classNamesObj = {};
parseFiles.forEach(function (filepath) {
console.warn('Parsing file ' + chalk.cyan(filepath) + ' for Atomic CSS classes');
var fileContents = fs.readFileSync(path.resolve(filepath), {encoding: 'utf-8'});
atomizer.parse(fileContents, classNamesObj);
});
parsedConfig = atomizer.getConfig(classNamesObj, config, !!params.verbose);
}

// Merge the static config with the generated config
config = _.merge(parsedConfig, config, handleMergeArrays);

var content = atomizer(configObjs, options);
// Create the CSS
content = atomizer.createCSS(config, options);

// Output the CSS
var outfile = params.o || params.outfile;
if (outfile) {
fs.mkdir(path.dirname(outfile), function (err) {
Expand All @@ -58,5 +92,5 @@ if (outfile) {
});
});
} else {
process.stdout.write(content);
process.stdout.write("\n" + content);
}
24 changes: 24 additions & 0 deletions examples/basic-config.js
@@ -0,0 +1,24 @@
module.exports = {
'config': {
'namespace': '#atomic',
'start': 'left',
'end': 'right',
'breakPoints': {
'sm': '767px',
'md': '992px',
'lg': '1200px'
}
},

// pattern
'display': {
'b': true
},

// pattern
'border-top': {
custom: [
{suffix: '1', values: ['1px solid #ccc']}
]
}
};
1 change: 1 addition & 0 deletions examples/html/sample-0.html
@@ -0,0 +1 @@
<div class="D-ib Fz-13px P-10px Bdb-1 C-fff">Test</div>
1 change: 1 addition & 0 deletions examples/html/sample-1.html
@@ -0,0 +1 @@
<div class="H-100% W-500px">Test</div>
8 changes: 4 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "atomizer",
"version": "0.2.5",
"version": "1.0.0-alpha.1",
"description": "A tool for creating Atomic CSS, a collection of single purpose styling units for maximum reuse",
"main": "./lib/atomic.js",
"contributors": [
Expand Down Expand Up @@ -30,12 +30,12 @@
"object-assign": "^2.0.0",
"absurd": "~0.3.34",
"minimist": "~1.1.0",
"chalk": "~0.5.1",
"lodash": "~3.2.0"
"chalk": "~1.0.0",
"lodash": "~3.3.0"
},
"devDependencies": {
"mocha": "~2.1.0",
"chai": "~2.0.0",
"chai": "~2.1.0",
"sinon": "~1.12.2",
"sinon-chai": "~2.7.0",
"istanbul": "~0.3.5",
Expand Down

0 comments on commit 1e02f75

Please sign in to comment.