├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── bin └── cli ├── dist ├── cli.js ├── cli.js.map ├── docor.js ├── docor.js.map ├── render.js └── render.js.map ├── docor.png ├── example └── package.json ├── lib ├── cli.js ├── docor.js └── render.js ├── package.json └── templates ├── LICENSE ├── README.md ├── README.zh-cn.md ├── gitignore ├── licenses ├── Apache ├── BSD └── MIT └── npmignore /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_* 2 | *.log 3 | logs 4 | 5 | node_modules 6 | bower_componets 7 | 8 | *.sublime* 9 | 10 | psd 11 | thumb 12 | sketch 13 | 14 | example/.* 15 | example/README.md 16 | example/LICENSE 17 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_* 2 | node_modules 3 | *.sublime* 4 | psd 5 | thumb 6 | *.log 7 | example 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 turing 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ![docor](./docor.png) docor ![NPM version](https://img.shields.io/npm/v/docor.svg?style=flat) 2 | 3 | a tiny cli tool to create elegant readme by manifest files, like `package.json`, `bower.json` and `manifest.json` 4 | 5 | ### Installation 6 | ```bash 7 | $ [sudo] npm install docor -g 8 | ``` 9 | 10 | ### Usage 11 | 12 | The very first, Ensure excutes `docor` in directory where contains one manifest file in support manifest files. As a cli tool, Docor will create these files: `README.md` ,`license` `.gitignore` and `.npmignore`. 13 | 14 | ```bash 15 | $ docor 16 | ``` 17 | 18 | #### Supported manifest files 19 | 20 | - `package.json`: NPM manifest. 21 | - `bower.json`: The front-end package manager Bower's manifest. 22 | - `manifest.json`: Chrome App's manifest. 23 | 24 | ### Example 25 | 26 | To run built-in examples: 27 | 28 | ```bash 29 | $ git clone git@github.com:turingou/docor.git 30 | $ cd docor 31 | $ npm install 32 | $ npm run example 33 | ``` 34 | 35 | ### Contributing 36 | - Fork this repo 37 | - Clone your repo 38 | - Install dependencies 39 | - Checkout a feature branch 40 | - Feel free to add your features 41 | - Make sure your features are fully tested 42 | - Open a pull request, and enjoy <3 43 | 44 | ### MIT license 45 | Copyright (c) 2013 turing <o.u.turing@gmail.com> 46 | 47 | Permission is hereby granted, free of charge, to any person obtaining a copy 48 | of this software and associated documentation files (the "Software"), to deal 49 | in the Software without restriction, including without limitation the rights 50 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 51 | copies of the Software, and to permit persons to whom the Software is 52 | furnished to do so, subject to the following conditions: 53 | 54 | The above copyright notice and this permission notice shall be included in 55 | all copies or substantial portions of the Software. 56 | 57 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 58 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 59 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 60 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 61 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 62 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 63 | THE SOFTWARE. 64 | 65 | --- 66 | ![docor](./docor.png) 67 | generated using [docor](https://github.com/turingou/docor.git) @ 0.0.4. brought to you by [turing](https://npmjs.org/~turing) 68 | -------------------------------------------------------------------------------- /bin/cli: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../dist/cli')() 4 | -------------------------------------------------------------------------------- /dist/cli.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { 4 | value: true 5 | }); 6 | 7 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } 8 | 9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 10 | 11 | var _fs = require('fs'); 12 | 13 | var _fs2 = _interopRequireDefault(_fs); 14 | 15 | var _path = require('path'); 16 | 17 | var _path2 = _interopRequireDefault(_path); 18 | 19 | var _consoler = require('consoler'); 20 | 21 | var _consoler2 = _interopRequireDefault(_consoler); 22 | 23 | var _docor = require('./docor'); 24 | 25 | var docor = _interopRequireWildcard(_docor); 26 | 27 | var files = ['README.md', 'LICENSE', '.gitignore', '.npmignore']; 28 | 29 | var checkPackage = function checkPackage(f) { 30 | return _fs2['default'].existsSync(_path2['default'].join(process.cwd(), f)); 31 | }; 32 | 33 | // Add a `;` to prevent compile error. 34 | // It's a bebel's bug ? XD 35 | 36 | exports['default'] = function () { 37 | if (!checkPackage('package.json')) return _consoler2['default'].error('Docor.init(); `package.json` file not found'); 38 | 39 | files.forEach(function (file) { 40 | docor.createFile(file, function (err) { 41 | if (err) return _consoler2['default'].error(err); 42 | 43 | _consoler2['default'].success(file + ' created'); 44 | }); 45 | }); 46 | }; 47 | 48 | module.exports = exports['default']; 49 | //# sourceMappingURL=cli.js.map -------------------------------------------------------------------------------- /dist/cli.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../lib/cli.js"],"names":[],"mappings":";;;;;;;;;;kBAAe,IAAI;;;;oBACF,MAAM;;;;wBACF,UAAU;;;;qBACR,SAAS;;IAApB,KAAK;;AAEjB,IAAM,KAAK,GAAG,CAAC,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,CAAC,CAAA;;AAElE,IAAI,YAAY,GAAG,SAAf,YAAY,CAAI,CAAC,EAAK;AACxB,SAAO,gBAAG,UAAU,CAClB,kBAAK,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAC5B,CAAA;CACF,CAAA;;;;;qBAIc,YAAW;AACxB,MAAI,CAAC,YAAY,CAAC,cAAc,CAAC,EAC/B,OAAO,sBAAS,KAAK,CAAC,6CAA6C,CAAC,CAAA;;AAEtE,OAAK,CAAC,OAAO,CAAC,UAAC,IAAI,EAAK;AACtB,SAAK,CAAC,UAAU,CAAC,IAAI,EAAE,UAAC,GAAG,EAAK;AAC9B,UAAI,GAAG,EACL,OAAO,sBAAS,KAAK,CAAC,GAAG,CAAC,CAAA;;AAE5B,4BAAS,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC,CAAA;KACpC,CAAC,CAAA;GACH,CAAC,CAAA;CACH","file":"lib/cli.js","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport consoler from 'consoler'\nimport * as docor from './docor'\n\nconst files = ['README.md', 'LICENSE', '.gitignore', '.npmignore']\n\nlet checkPackage = (f) => {\n return fs.existsSync(\n path.join(process.cwd(), f)\n )\n}\n\n// Add a `;` to prevent compile error.\n// It's a bebel's bug ? XD\nexport default function() {\n if (!checkPackage('package.json')) \n return consoler.error('Docor.init(); `package.json` file not found')\n\n files.forEach((file) => {\n docor.createFile(file, (err) => {\n if (err) \n return consoler.error(err)\n\n consoler.success(file + ' created')\n })\n })\n}\n"]} -------------------------------------------------------------------------------- /dist/docor.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { 4 | value: true 5 | }); 6 | exports.fetchLicenses = fetchLicenses; 7 | exports.createFile = createFile; 8 | 9 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 10 | 11 | var _fs = require('fs'); 12 | 13 | var _fs2 = _interopRequireDefault(_fs); 14 | 15 | var _path = require('path'); 16 | 17 | var _path2 = _interopRequireDefault(_path); 18 | 19 | var _render = require('./render'); 20 | 21 | var _render2 = _interopRequireDefault(_render); 22 | 23 | var sys = require(_path2['default'].resolve(__dirname, '../package.json')); 24 | var templates = _path2['default'].resolve(__dirname, '../templates'); 25 | 26 | function fetchLicenses(license) { 27 | if (!license) return null; 28 | 29 | license = license.toString().toLowerCase(); 30 | 31 | try { 32 | return _fs2['default'].readFileSync(_path2['default'].join(templates, 'licenses', license)); 33 | } catch (e) { 34 | return null; 35 | } 36 | } 37 | 38 | function createFile(filename, callback) { 39 | var cwd = process.cwd(); 40 | var pkg = require(_path2['default'].join(cwd, 'package.json')); 41 | 42 | var locals = { 43 | pkg: pkg, 44 | sys: sys, 45 | 'year': new Date().getFullYear(), 46 | 'apis': null }; 47 | 48 | if (filename.indexOf('README') > -1 || filename.indexOf('LICENSE') > -1) locals.license = fetchLicenses(pkg.license); 49 | 50 | if (pkg.name) pkg.parsedName = parseName(pkg.name); 51 | 52 | if (locals.license) locals.license = locals.license.toString(); 53 | 54 | if (pkg.main) { 55 | try { 56 | locals.apis = require(_path2['default'].join(cwd, pkg.main)); 57 | } catch (err) {} 58 | } 59 | 60 | return _fs2['default'].writeFile(_path2['default'].join(cwd, filename), _render2['default'](filename.indexOf('.') === 0 ? filename.substr(1) : filename)(locals), callback); 61 | } 62 | 63 | function parseName(str) { 64 | if (str.indexOf('-') === 0) return str; 65 | 66 | var token = str.split('-'); 67 | 68 | if (!token.length) return str; 69 | 70 | for (var i = token.length - 1; i >= 0; i--) { 71 | (function (index) { 72 | if (index === 0) return; 73 | 74 | token[index] = token[index].charAt(0).toUpperCase() + token[index].substr(1); 75 | })(i); 76 | } 77 | 78 | return token.join(''); 79 | } 80 | 81 | // just ignore the error 82 | //# sourceMappingURL=docor.js.map -------------------------------------------------------------------------------- /dist/docor.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../lib/docor.js"],"names":[],"mappings":"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","file":"lib/docor.js","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport render from './render'\n\nconst sys = require(path.resolve(__dirname, '../package.json'));\nconst templates = path.resolve(__dirname, '../templates');\n\nexport function fetchLicenses(license) {\n if (!license)\n return null\n\n license = license.toString().toLowerCase()\n\n try {\n return fs.readFileSync(\n path.join(templates, 'licenses', license)\n )\n } catch (e) {\n return null\n }\n}\n\nexport function createFile(filename, callback) {\n var cwd = process.cwd()\n var pkg = require(path.join(cwd, 'package.json'))\n\n var locals = {\n pkg,\n sys,\n 'year': new Date().getFullYear(),\n 'apis': null,\n }\n\n if (filename.indexOf('README') > -1 || filename.indexOf('LICENSE') > -1)\n locals.license = fetchLicenses(pkg.license)\n\n if (pkg.name)\n pkg.parsedName = parseName(pkg.name)\n\n if (locals.license)\n locals.license = locals.license.toString()\n\n if (pkg.main) {\n try {\n locals.apis = require(path.join(cwd, pkg.main))\n } catch (err) {\n // just ignore the error\n }\n }\n\n return fs.writeFile(\n path.join(cwd, filename),\n render(filename.indexOf('.') === 0 ? filename.substr(1) : filename)(locals),\n callback\n )\n}\n\nfunction parseName(str) {\n if (str.indexOf('-') === 0)\n return str\n\n var token = str.split('-')\n\n if (!token.length)\n return str\n\n for (var i = token.length - 1; i >= 0; i--) {\n ((index) => {\n if (index === 0)\n return\n\n token[index] = token[index].charAt(0).toUpperCase() + token[index].substr(1)\n })(i);\n }\n\n return token.join('')\n}\n"]} -------------------------------------------------------------------------------- /dist/render.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { 4 | value: true 5 | }); 6 | 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } 8 | 9 | var _path = require('path'); 10 | 11 | var _path2 = _interopRequireDefault(_path); 12 | 13 | var _swig = require('swig'); 14 | 15 | var _swig2 = _interopRequireDefault(_swig); 16 | 17 | var templates = _path2['default'].resolve(__dirname, '../templates'); 18 | 19 | exports['default'] = function (filename) { 20 | if (!filename) return; 21 | 22 | return _swig2['default'].compileFile(_path2['default'].join(templates, filename)); 23 | }; 24 | 25 | module.exports = exports['default']; 26 | //# sourceMappingURL=render.js.map -------------------------------------------------------------------------------- /dist/render.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["../lib/render.js"],"names":[],"mappings":";;;;;;;;oBAAiB,MAAM;;;;oBACN,MAAM;;;;AAEvB,IAAM,SAAS,GAAG,kBAAK,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;;qBAE1C,UAAS,QAAQ,EAAE;AAChC,MAAI,CAAC,QAAQ,EACX,OAAM;;AAER,SAAO,kBAAK,WAAW,CACrB,kBAAK,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAC/B,CAAA;CACF","file":"lib/render.js","sourcesContent":["import path from 'path'\nimport swig from 'swig'\n\nconst templates = path.resolve(__dirname, '../templates')\n\nexport default function(filename) {\n if (!filename)\n return\n\n return swig.compileFile(\n path.join(templates, filename)\n )\n}\n"]} -------------------------------------------------------------------------------- /docor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guo-yu/docor/65ff3b0d2f20db03a4a41246de8d11a152bad41a/docor.png -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mime-module-name", 3 | "version": "1.1.1", 4 | "description": "a brief description of this module", 5 | "main": "index.js", 6 | "author": "me ", 7 | "license": "MIT", 8 | "bin": "bin/cli", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/me/mime-module.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/me/mime-module/issues" 15 | }, 16 | "keywords": [ 17 | "readme", 18 | "pkg", 19 | "package", 20 | "package.json", 21 | "document", 22 | "docor" 23 | ], 24 | "dependencies":{ 25 | "swig": "~1.4.2", 26 | "consoler": "~0.2.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/cli.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import path from 'path' 3 | import consoler from 'consoler' 4 | import * as docor from './docor' 5 | 6 | const files = ['README.md', 'LICENSE', '.gitignore', '.npmignore'] 7 | 8 | let checkPackage = (f) => { 9 | return fs.existsSync( 10 | path.join(process.cwd(), f) 11 | ) 12 | } 13 | 14 | // Add a `;` to prevent compile error. 15 | // It's a bebel's bug ? XD 16 | export default function() { 17 | if (!checkPackage('package.json')) 18 | return consoler.error('Docor.init(); `package.json` file not found') 19 | 20 | files.forEach((file) => { 21 | docor.createFile(file, (err) => { 22 | if (err) 23 | return consoler.error(err) 24 | 25 | consoler.success(file + ' created') 26 | }) 27 | }) 28 | } 29 | -------------------------------------------------------------------------------- /lib/docor.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import path from 'path' 3 | import render from './render' 4 | 5 | const sys = require(path.resolve(__dirname, '../package.json')); 6 | const templates = path.resolve(__dirname, '../templates'); 7 | 8 | export function fetchLicenses(license) { 9 | if (!license) 10 | return null 11 | 12 | license = license.toString().toLowerCase() 13 | 14 | try { 15 | return fs.readFileSync( 16 | path.join(templates, 'licenses', license) 17 | ) 18 | } catch (e) { 19 | return null 20 | } 21 | } 22 | 23 | export function createFile(filename, callback) { 24 | var cwd = process.cwd() 25 | var pkg = require(path.join(cwd, 'package.json')) 26 | 27 | var locals = { 28 | pkg, 29 | sys, 30 | 'year': new Date().getFullYear(), 31 | 'apis': null, 32 | } 33 | 34 | if (filename.indexOf('README') > -1 || filename.indexOf('LICENSE') > -1) 35 | locals.license = fetchLicenses(pkg.license) 36 | 37 | if (pkg.name) 38 | pkg.parsedName = parseName(pkg.name) 39 | 40 | if (locals.license) 41 | locals.license = locals.license.toString() 42 | 43 | if (pkg.main) { 44 | try { 45 | locals.apis = require(path.join(cwd, pkg.main)) 46 | } catch (err) { 47 | // just ignore the error 48 | } 49 | } 50 | 51 | return fs.writeFile( 52 | path.join(cwd, filename), 53 | render(filename.indexOf('.') === 0 ? filename.substr(1) : filename)(locals), 54 | callback 55 | ) 56 | } 57 | 58 | function parseName(str) { 59 | if (str.indexOf('-') === 0) 60 | return str 61 | 62 | var token = str.split('-') 63 | 64 | if (!token.length) 65 | return str 66 | 67 | for (var i = token.length - 1; i >= 0; i--) { 68 | ((index) => { 69 | if (index === 0) 70 | return 71 | 72 | token[index] = token[index].charAt(0).toUpperCase() + token[index].substr(1) 73 | })(i); 74 | } 75 | 76 | return token.join('') 77 | } 78 | -------------------------------------------------------------------------------- /lib/render.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import swig from 'swig' 3 | 4 | const templates = path.resolve(__dirname, '../templates') 5 | 6 | export default function(filename) { 7 | if (!filename) 8 | return 9 | 10 | return swig.compileFile( 11 | path.join(templates, filename) 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docor", 3 | "version": "0.3.0", 4 | "description": "a tiny cli tool to create elegant readme by manifest files, like `package.json`, `bower.json` and `manifest.json`", 5 | "main": "dist/docor.js", 6 | "author": "turing ", 7 | "license": "MIT", 8 | "bin": "bin/cli", 9 | "scripts": { 10 | "build": "node_modules/.bin/babel lib --out-dir dist --source-map", 11 | "build": "node_modules/.bin/babel lib --out-dir dist --source-maps --watch", 12 | "example": "cd ./example && ../bin/cli" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/turingou/docor.git" 17 | }, 18 | "bugs": { 19 | "url": "https://github.com/turingou/docor/issues" 20 | }, 21 | "keywords": [ 22 | "readme", 23 | "pkg", 24 | "package", 25 | "package.json", 26 | "document", 27 | "docor" 28 | ], 29 | "dependencies":{ 30 | "swig": "~1.4.2", 31 | "consoler": "~0.2.0" 32 | }, 33 | "devDependencies": { 34 | "babel": "5.1.11" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /templates/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) {{ year }} {% if pkg.author %}{{pkg.author}}{% endif %} 2 | 3 | {% if license %}{{license}}{% endif %} -------------------------------------------------------------------------------- /templates/README.md: -------------------------------------------------------------------------------- 1 | ## {% if pkg.logo %}![{{pkg.name}}]({{pkg.logo}}) {% endif %}{{ pkg.name }} ![NPM version](https://img.shields.io/npm/v/{{ pkg.name }}.svg?style=flat) 2 | 3 | {{ pkg.description }}{% if pkg.author %}{% endif %} 4 | 5 | ### Installation 6 | ```bash 7 | $ npm install {{pkg.name}} 8 | ``` 9 | 10 | ### Example 11 | ```js 12 | var {{pkg.parsedName}} = require('{{pkg.name}}'); 13 | ``` 14 | 15 | ### API 16 | {% if apis %}{% for name,code in apis %} 17 | - {{pkg.name}}.{{name}}(){% endfor %}{% else %}check this file: `{{pkg.main}}`{% endif %} 18 | 19 | ### Contributing 20 | - Fork this Repo first 21 | - Clone your Repo 22 | - Install dependencies by `$ npm install` 23 | - Checkout a feature branch 24 | - Feel free to add your features 25 | - Make sure your features are fully tested 26 | - Publish your local branch, Open a pull request 27 | - Enjoy hacking <3 28 | {% if pkg.license %} 29 | ### {{ pkg.license }} license 30 | Copyright (c) {{ year }} {% if pkg.author %}{{pkg.author}}{% endif %} 31 | 32 | {% if license %}{{license}}{% endif %} 33 | {% endif %} 34 | --- 35 | ![{{sys.name}}]({{sys.logo}}) 36 | built upon love by [{{sys.name}}]({{sys.repository.url}}) v{{sys.version}} 37 | -------------------------------------------------------------------------------- /templates/README.zh-cn.md: -------------------------------------------------------------------------------- 1 | ## {% if pkg.logo %}![logo]({{pkg.logo}}) {% endif %}{{ pkg.name }} ![NPM version](https://img.shields.io/npm/v/{{ pkg.name }}.svg?style=flat) 2 | 3 | {{ pkg.description }}{% if pkg.author %}{% endif %} 4 | 5 | ### 如何安装 6 | ```bash 7 | $ npm install {{pkg.name}} 8 | ``` 9 | 10 | ### 范例代码 11 | ```js 12 | var {{pkg.parsedName}} = require('{{pkg.name}}'); 13 | ``` 14 | 15 | ### API 16 | {% if apis %}{% for name,code in apis %} 17 | - {{pkg.name}}.{{name}}(){% endfor %}{% else %}详细API接口函数请查看文件: `{{pkg.main}}`{% endif %} 18 | 19 | ### 欢迎贡献代码 20 | - 请先 Fork 此项目到自己的代码仓库 21 | - 再 Clone 你的新项目到本地电脑 22 | - 使用 `$ npm install` 安装依赖 23 | - 在本地 Checkout 一个特性分支 24 | - 在特性分支上开发你想要的功能 25 | - 确保功能被完善测试,最好能提供相应的单元测试代码 26 | - Publish 到远程分支,向我提交一个 Pull Request 27 | - 非常感谢 <3 28 | {% if pkg.license %} 29 | ### {{ pkg.license }} license 30 | Copyright (c) {{ year }} {% if pkg.author %}{{pkg.author}}{% endif %} 31 | 32 | {% if license %}{{license}}{% endif %} 33 | {% endif %} 34 | --- 35 | ![{{sys.name}}]({{sys.logo}}) 36 | built upon love by [{{sys.name}}]({{sys.repository.url}}) v{{sys.version}} 37 | -------------------------------------------------------------------------------- /templates/gitignore: -------------------------------------------------------------------------------- 1 | .DS_* 2 | *.log 3 | logs 4 | **/*.backup.* 5 | **/*.back.* 6 | 7 | node_modules 8 | bower_componets 9 | 10 | *.sublime* 11 | 12 | psd 13 | thumb 14 | sketch 15 | -------------------------------------------------------------------------------- /templates/licenses/Apache: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | -------------------------------------------------------------------------------- /templates/licenses/BSD: -------------------------------------------------------------------------------- 1 | All rights reserved. 2 | Redistribution and use in source and binary forms, with or without 3 | modification, are permitted provided that the following conditions are met: 4 | 5 | * Redistributions of source code must retain the above copyright 6 | notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | * Neither the name of the University of California, Berkeley nor the 11 | names of its contributors may be used to endorse or promote products 12 | derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY 15 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY 18 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /templates/licenses/MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. -------------------------------------------------------------------------------- /templates/npmignore: -------------------------------------------------------------------------------- 1 | .DS_* 2 | *.log 3 | logs 4 | **/*.backup.* 5 | **/*.back.* 6 | 7 | node_modules 8 | bower_componets 9 | 10 | *.sublime* 11 | 12 | psd 13 | thumb 14 | sketch 15 | --------------------------------------------------------------------------------