Skip to content

Commit

Permalink
Release experimental version
Browse files Browse the repository at this point in the history
  • Loading branch information
filipelinhares committed Jul 31, 2014
1 parent 2a67474 commit 43398db
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 3 deletions.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# ConciseCSS - Generator
> The best way for you start your project!
# License
## Experimental version
This is an experimental version of Concise generator.

## Usage

Meke sure you have [Node.js](http://nodejs.org) and NPM.

Clone the repo
```
git clone git@github.com:ConciseCSS/concise-generator.git concise-generator
cd concise-generator
[sudo] npm link
```

Now you can use this normaly.

`concise [folder]`

It's generate:

```
myproject
|
|-js
| |-concise.min.js
|-css
| |-concise.min.css
|-image
|-index.html
|
```

## Options
```
-h, --help output usage information
-V, --version output the version number
-p, --prod use production version
```

Any issue or pull request follow the Concise [contributing](https://github.com/ConciseCSS/concise.css/blob/master/CONTRIBUTING.md) guide.

## License
MIT
58 changes: 58 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env node
'use strict';

var program = require('commander');
var path = require('path');
var fs = require('fs');

var util = require('./lib/util');
var pkg = require('./package');

program
.usage('[folder]')
.version(pkg.version)
.option('-p, --prod', 'use production version')
.parse(process.argv);

var destinationPath = program.args.shift() || '.';

var index = fs.readFileSync(__dirname + '/templates/index.html');
var css = fs.readFileSync(__dirname + '/templates/concise-css/concise.css')
var cssMin = fs.readFileSync(__dirname + '/templates/concise-css/concise.min.css')
var js = fs.readFileSync(__dirname + '/templates/js/concise.js');
var jsMin = fs.readFileSync(__dirname + '/templates/js/concise.min.js');

(function generateApp(path) {
util.emptyDirectory(path, function(empty) {
if (empty || program.force) {
createApp(path);
} else {
program.confirm('destination path is not empty, are you sure to continue?', function(ok) {
if (ok) {
process.stdin.destroy();
createApp(path);
} else {
util.abort('Process canceled!')
}
});
}
});
})(destinationPath);

function createApp(path) {
util.mkdir(path, function() {
util.mkdir(path + '/css');
util.mkdir(path + '/images');
util.mkdir(path + '/js');

util.write(path + '/index.html', index);

if (program.prod) {
util.write(path + '/css/concise.css', css)
util.write(path + '/js/concise.js', js);
} else {
util.write(path + '/css/concise.min.css', cssMin)
util.write(path + '/js/concise.min.js', jsMin);
}
});
}
30 changes: 30 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var fs = require('fs');
var mkdirp = require('mkdirp');
'use strict';

exports.emptyDirectory = function (path, fn) {
fs.readdir(path, function(err, files) {
if (err && 'ENOENT' != err.code) throw err;
fn(!files || !files.length);
});
}

exports.write = function (path, str, mode) {
fs.writeFile(path, str, {
mode: mode || 0666
});
console.log(' [\x1b[32mcreate\x1b[0m] ' + path);
}

exports.mkdir = function (path, fn) {
mkdirp(path, 0755, function(err) {
if (err) throw err;
console.log(' [\033[32mcreate\033[0m] ' + path);
fn && fn();
});
}

exports.abort = function (str) {
console.error(str);
process.exit(1);
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "concisecss-generator",
"version": "0.0.0",
"version": "0.1.0",
"description": "The best way to start your project.",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/filipelinhares/expose-npm"
},
"bin": {
"concise": "index.js"
},
"keywords": [
"generator",
"concisecss"
Expand All @@ -16,5 +19,9 @@
"bugs": {
"url": "https://github.com/ConciseCSS/concise-generator/issues"
},
"homepage": "https://github.com/ConciseCSS/concise-generator"
"homepage": "https://github.com/ConciseCSS/concise-generator",
"dependencies": {
"commander": "1.3.2",
"mkdirp": "^0.5.0"
}
}

0 comments on commit 43398db

Please sign in to comment.