diff --git a/generators/app/index.js b/generators/app/index.js index 45bef57..60a6d83 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -5,6 +5,16 @@ var yosay = require('yosay'); // var extend = require('deep-extend'); var changeCase = require('change-case'); +var licenses = [ + { name: 'Apache 2.0', value: 'Apache-2.0' }, + { name: 'MIT', value: 'MIT' }, + { name: 'Unlicense', value: 'unlicense' }, + { name: 'FreeBSD', value: 'BSD-2-Clause-FreeBSD' }, + { name: 'NewBSD', value: 'BSD-3-Clause' }, + { name: 'Internet Systems Consortium (ISC)', value: 'ISC' }, + { name: 'No License (Copyrighted)', value: 'nolicense' } +]; + module.exports = yeoman.generators.Base.extend({ prompting: { greeting() { @@ -61,17 +71,48 @@ module.exports = yeoman.generators.Base.extend({ this.username = props.username; done(); }); + }, + license() { + var done = this.async(); + + this.prompt({ + type: 'list', + name: 'license', + message: 'Which license do you want to use?', + default: 'MIT', + choices: licenses + }, (props) => { + this.license = props.license; + done(); + }); + }, + nameOnLicense() { + var done = this.async(); + + this.prompt({ + type: 'input', + name: 'name', + message: 'Name to use on the license?', + default: this.username + }, (props) => { + this.nameOnLicense = props.name; + done(); + }); } }, writing: { copyFiles() { this.fs.copy( - this.templatePath('**/*'), + this.templatePath('test/*'), + this.destinationPath('test') + ); + this.fs.copy( + this.templatePath('*'), this.destinationPath() ); this.fs.copy( - this.templatePath('**/.*'), + this.templatePath('.*'), this.destinationPath() ); }, @@ -118,10 +159,18 @@ module.exports = yeoman.generators.Base.extend({ // }); // this.fs.writeJSON(this.destinationPath('package.json'), pkg); }, - updateLICENSE() { - var lic = this.fs.read(this.destinationPath('LICENSE')); - lic = lic.replace('{username}', this.username); - this.fs.write(this.destinationPath('LICENSE'), lic); + createLICENSE() { + var filename = `licenses/${this.license}.txt`; + var author = this.nameOnLicense.trim(); + + this.fs.copyTpl( + this.templatePath(filename), + this.destinationPath('LICENSE'), + { + year: (new Date()).getFullYear(), + author: author + } + ); } }, install: { diff --git a/generators/app/templates/licenses/Apache-2.0.txt b/generators/app/templates/licenses/Apache-2.0.txt new file mode 100644 index 0000000..cd421c5 --- /dev/null +++ b/generators/app/templates/licenses/Apache-2.0.txt @@ -0,0 +1,13 @@ +Copyright <%- year %> <%- author %> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/generators/app/templates/licenses/BSD-2-Clause-FreeBSD.txt b/generators/app/templates/licenses/BSD-2-Clause-FreeBSD.txt new file mode 100644 index 0000000..991089a --- /dev/null +++ b/generators/app/templates/licenses/BSD-2-Clause-FreeBSD.txt @@ -0,0 +1,26 @@ +Copyright (c) <%- year %>, <%- author %> +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. diff --git a/generators/app/templates/licenses/BSD-3-Clause.txt b/generators/app/templates/licenses/BSD-3-Clause.txt new file mode 100644 index 0000000..c89e023 --- /dev/null +++ b/generators/app/templates/licenses/BSD-3-Clause.txt @@ -0,0 +1,24 @@ +Copyright (c) <%- year %>, <%- author %> +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/generators/app/templates/licenses/ISC.txt b/generators/app/templates/licenses/ISC.txt new file mode 100644 index 0000000..677bb87 --- /dev/null +++ b/generators/app/templates/licenses/ISC.txt @@ -0,0 +1,15 @@ +Copyright (c) <%- year %> <%- author %> + +Permission to use, copy, modify, and/or distribute this software for +any purpose with or without fee is hereby granted, provided that the +above copyright notice and this permission notice appear in all +copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/generators/app/templates/LICENSE b/generators/app/templates/licenses/MIT.txt similarity index 96% rename from generators/app/templates/LICENSE rename to generators/app/templates/licenses/MIT.txt index df96af5..f219e75 100644 --- a/generators/app/templates/LICENSE +++ b/generators/app/templates/licenses/MIT.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 {username} +Copyright (c) <%- year %> <%- author %> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/generators/app/templates/licenses/nolicense.txt b/generators/app/templates/licenses/nolicense.txt new file mode 100644 index 0000000..cbe1ea2 --- /dev/null +++ b/generators/app/templates/licenses/nolicense.txt @@ -0,0 +1 @@ +Copyright (c) <%- year %> <%- author %> diff --git a/generators/app/templates/licenses/unlicense.txt b/generators/app/templates/licenses/unlicense.txt new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/generators/app/templates/licenses/unlicense.txt @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to