Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridha Hassoun committed Mar 13, 2017
2 parents c06f187 + 431a596 commit 8d43628
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,3 @@ typings/

# dotenv environment variables file
.env

# Ignore licenses directory
licenses/
74 changes: 74 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# legit

legit is a command line application that allows you to automagically generate a
LICENSE file for the current working directory that you are in.
LICENSE file for the current working directory that you are in or a license header
for a file where applicable.

### Installation

Expand All @@ -17,16 +18,27 @@ npm install --global @captainsafia/legit
Commands:
list|l List all available licenses
put|p <license> [user] [year] Put a license in this directory
list|l List all available licenses
put|p [options] <license> Put a license in this directory
Options:
-h, --help output usage information
-V, --version output the version number
Usage: put|p [options] <license>
Put a license in this directory
Options:
-h, --help output usage information
-f --file <file> The file to add a header to
-u --user [user] The user/organization who holds the license
-y --year [year] The year the license is in effect
```

![Legit Demo](legit-demo.gif)
![Legit Demo](https://cloud.githubusercontent.com/assets/1857993/23821404/bea5dfc2-05f6-11e7-8525-7f5bd88a7829.gif)

### Currently Supported Licenses
- BSD 2-clause Simplified License (bsd-2-clause)
Expand Down
Binary file removed legit-demo.gif
Binary file not shown.
14 changes: 14 additions & 0 deletions licenses/headers/agpl-3.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (C) <year> <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
13 changes: 13 additions & 0 deletions licenses/headers/apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright {yyyy} {name of copyright owner}

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.
15 changes: 15 additions & 0 deletions licenses/headers/gpl-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Copyright (C) {year} {fullname}

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 changes: 14 additions & 0 deletions licenses/headers/gpl-3.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (C) {year} {fullname}

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
15 changes: 15 additions & 0 deletions licenses/headers/lgpl-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Copyright (C) {year} {fullname}

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@captainsafia/legit",
"version": "2.0.0",
"version": "3.0.0",
"description": "Automatically add a license to a GitHub project",
"main": "index.js",
"bin": {
"legit": "src/index.js"
},
"scripts": {
"postinstall": "mkdir -p licenses && node src/load-licenses.js"
"prepublish": "find licenses -type f -maxdepth 1 -delete",
"postinstall": "node src/load-licenses.js"
},
"keywords": [
"license",
Expand All @@ -18,6 +19,7 @@
"author": "Safia Abdalla <[email protected]>",
"license": "MIT",
"dependencies": {
"@captainsafia/commentator": "^1.1.0",
"commander": "^2.9.0",
"node-fetch": "^1.6.3",
"username": "^2.3.0",
Expand Down
71 changes: 65 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#! /usr/bin/env node

const fs = require('fs');
const path = require('path');
const program = require('commander');
const username = require('username');
const placeholders = require('./placeholders');
const firstCommitDate = require('first-commit-date');
const commentator = require('@captainsafia/commentator');

const licensesPath = __dirname + '/../licenses/';
const licensesPath = path.join(__dirname, '/../licenses/');

function validateLicense(license) {
license = license.toLowerCase();
Expand All @@ -15,7 +17,7 @@ function validateLicense(license) {
}

program
.version('2.0.0')
.version('2.0.0');

program
.command('list').alias('l')
Expand All @@ -28,9 +30,21 @@ program
});

program
.command('put <license> [user] [year]').alias('p')
.command('put <license>').alias('p')
.option('-f --file [file]', 'The file to add a header to')
.option('-u --user [user]', 'The user/organization who holds the license')
.option('-y --year [year]', 'The year the license is in effect')
.description('Put a license in this directory')
.action(function(licenseArg, userArg, yearArg) {
.action(function(licenseArg) {
const fileArg = this.file;
const yearArg = this.year || new Date().getFullYear();
const userArg = this.user || username.sync();

const user = placeholders[licenseArg]['user'];
const year = placeholders[licenseArg]['year'];

const cwd = process.cwd();

if (!validateLicense(licenseArg)) {
return console.log('Please choose one of the licenses under `legit list`!');
}
Expand All @@ -55,11 +69,56 @@ program
const user = placeholders[licenseArg]['user'];
const year = placeholders[licenseArg]['year'];
var result = data.replace(user, userArg).replace(year, yearArg);
if (fileArg) {
const headerFile = path.join(__dirname, '/../licenses/headers/', licenseArg);
const fileExtension = fileArg.split('.').pop();
if (!fs.existsSync(headerFile)) {
return console.log('Header not available for', licenseArg, 'license!');
}
fs.writeFile(cwd + '/LICENSE', result || data, 'utf8', function (error) {

fs.readFile(headerFile, 'utf8', function(error, data) {
if (error) return console.log(error);
var result;

try {
result = commentator.makeBlockComment(
data.replace(user, userArg).replace(year, yearArg), fileExtension);
} catch (error) {
if (error.message.includes('Block comment')) {
try {
result = commentator.makeInlineComment(
data.replace(user, userArg).replace(year, yearArg), fileExtension);
} catch(error) {
if (error.message.includes('Inline comment')) {
return console.log('@captainsafia/commentator doesn\'t support block comments',
'for files with this extension, please open an issue at https://github.com/captainsafia/commentator/issues',
'to add support for this programming language.');
}
}
}
}

const filePath = path.join(cwd, '/', fileArg);

fs.readFile(filePath, 'utf8', function(error, data) {
const newData = result + '\n' + data;
fs.writeFile(filePath, newData, 'utf8', function(error) {
if (error) return console.log(error);
});
});
});
} else {
const licenseFile = licensesPath + licenseArg;
fs.readFile(licenseFile, 'utf8', function (error, data) {
if (error) return console.log(error);
if (placeholders[licenseArg]) {
var result = data.replace(user, userArg).replace(year, yearArg);
}
fs.writeFile(path.join(cwd, '/LICENSE'), result || data, 'utf8', function (error) {
if (error) return console.log(error);
});
});
});
}
});

program.parse(process.argv);
2 changes: 1 addition & 1 deletion src/placeholders.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const placeholders = {
'agpl-3.0': {
user: '<name of author',
user: '<name of author>',
year: '<year>'
},
'apache-2.0': {
Expand Down

0 comments on commit 8d43628

Please sign in to comment.