Skip to content

Commit

Permalink
0.2: API changed, format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yu committed Sep 10, 2014
1 parent b705a1f commit 10dbc18
Showing 9 changed files with 99 additions and 171 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013 turing
Copyright (c) 2013 turing <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
31 changes: 9 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
## ![logo](https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/doctor.png) docor ![npm](https://badge.fury.io/js/docor.png)
## ![docor](https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/doctor.png) docor ![npm](https://badge.fury.io/js/docor.png)

[![NPM](https://nodei.co/npm/docor.png)](https://nodei.co/npm/docor/) [![NPM](https://nodei.co/npm-dl/docor.png?months=6)](https://nodei.co/npm/docor/)

a smart and tiny doc-maker using default package.json.
a smart and tiny README maker using default manifest `package.json`.

### Installation
````
```bash
$ [sudo] npm install docor -g
````
```

### Use CLI
### Useage

ensure excutes in dirs have package.json. docor will create README.md ,license .gitignore & .npmignore
the very first, ensure excutes in dirs which have `package.json`.
docor will create these files: `README.md` ,`license` `.gitignore` and `.npmignore`

````
```bash
$ docor
````
create README.md in Chinese:

```
$ docor -c
```

### API

- docor.ignore()
- docor.readme()
- docor.license()
- docor.cli()

### Contributing
- Fork this repo
@@ -39,7 +26,7 @@ $ docor -c
- Open a pull request, and enjoy <3

### MIT license
Copyright (c) 2013 turing
Copyright (c) 2013 turing &lt;[email protected]&gt;

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
62 changes: 0 additions & 62 deletions README.zh-cn.md

This file was deleted.

15 changes: 14 additions & 1 deletion bin/cli
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#!/usr/bin/env node

require('../index').cli();
var dir = process.cwd();
var docor = require('../index');
var files = ['README.md', 'LICENSE', '.gitignore', '.npmignore'];

if (!docor.checkPackage('/package.json'))
return consoler.error('Docor.init(); `package.json` file not found');

files.forEach(function(file) {
docor.createFile(file, function(err) {
if (err)
return consoler.error(err);
consoler.success('file created successful => ' + file);
});
});
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./libs/docor');
module.exports = require('./lib/docor');
64 changes: 64 additions & 0 deletions lib/docor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var fs = require('fs');
var path = require('path');
var consoler = require('consoler');
var sys = require(path.resolve(__dirname,'../package.json'));
var maker = require('./templates');

exports.fetchLicenses = fetchLicenses;
exports.createReadme = createReadme;
exports.createFile = createFile;
exports.checkPackage = checkPackage;

function fetchLicenses(license) {
if (!license)
return null;
try {
return fs.readFileSync(
__dirname + '/licenses/' + license
);
} catch (e) {
return null;
}
}

function createReadme(filename, callback) {
var dir = process.cwd();
var pkg = require(dir + '/package.json');
var locals = {};

locals.pkg = pkg;
locals.sys = sys;
locals.license = fetchLicenses(pkg.license);
locals.year = new Date().getFullYear();
locals.apis = null;

if (locals.license) locals.license = locals.license.toString();

if (pkg.main) try {
locals.apis = require(path.join(dir, pkg.main));
} catch (err) {
return callback(err);
}

fs.writeFile(
path.join(dir, filename),
maker(filename)(locals),
callback
);
}

function createFile(filename, callback) {
if (filename.indexOf('README') > -1)
return exports.createReadme(filename, callback);

return fs.writeFile(
path.join(process.cwd(), filename),
maker(filename.indexOf('.') === 0 ? filename.substr(1) : filename)(),
callback
);
}

function checkPackage(file) {
var dir = process.cwd();
return fs.existsSync(path.join(dir, file));
}
File renamed without changes.
70 changes: 0 additions & 70 deletions libs/docor.js

This file was deleted.

24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
{
"name": "docor",
"version": "0.1.4",
"logo": "https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/doctor.png",
"description": "a smart and tiny doc-maker using default package.json",
"version": "0.2.0",
"description": "a smart and tiny README maker using default manifest `package.json`.",
"main": "index.js",
"author": "turing",
"author": "turing <[email protected]>",
"license": "MIT",
"bin": {
"docor": "./bin/cli"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": "./bin/cli",
"repository": {
"type": "git",
"url": "https://github.com/turingou/docor.git"
@@ -22,11 +16,13 @@
"keywords": [
"readme",
"pkg",
"package"
"package",
"package.json",
"document",
"docor"
],
"dependencies":{
"optimist": "*",
"swig": "*",
"consoler": "*"
"swig": "~1.4.2",
"consoler": "~0.2.0"
}
}

0 comments on commit 10dbc18

Please sign in to comment.