Giter Club home page Giter Club logo

license's Introduction

license

Easily generate licenses for your projects!

Table of Contents

What is this?

Have you ever started a new project, and needed to add a new license to it but don't know the exact wording off by heart (because who would)? You have to search for the license you want, copy its text, paste it into a new file, and then check to see if there's anything like copyright information that you need to update.

License is a super easy to use CLI tool for streamlining the LICENSE file creation process. With a super simple but powerful CLI inspired by tools such as now, setting up a license for your new project has never been easier!

Usage

First, globally install license through your package manager of choice.

$ yarn global add license
# or
$ npm i -g license

And then simply run license to generate a license.

$ license [license]

If you don't specify a license to generate, it'll either pick from your config, or show an interactive prompt for you to search through.

If you don't want to install license and just want to run it once, you can use npx

$ npx license [license]
# Or using Yarn 2.x
$ yarn dlx license [license]

Examples

todo

Advanced Usage

By default, license will try to guess your name, email, the current project, and the current year to use in the license it generates. You can override these in a number of ways though.

Name

By default, license will try to get your name from your Git configuration, (git config --global user.name). If it fails to, it will fallback to using the USER environment variable, often your username in a shell.

You can override this in two ways:

  1. Overriding it as a one time thing by providing a --name option while running license (also alised to -n).
  2. Overriding it permanently by using license config --name <name>, which will add it to the global config, and will be used for any future calls to license, unless the --name option above is used, in which case that will take precedence.

Email

By default, license will try to get your email from your Git configuration, just like it does with your name, (git config --global user.email), however it does not have any fallback to use, so it's recommended you use either of the two override methods below.

  1. Overriding it as a one time thing by providing an --email option while running license (also aliased to -e).
  2. Overriding it permanently by using license config --email <email>, which will add it to the global config, and will be used for any future calls to license, unless the --email option above is used, in which case that will take precedence.

Year

By default, license will use the current year (according to your system time) to fill in, however you can set a custom year using the --year option to license.

It supports a couple formats for the year:

  1. a plain year - 2009
  2. a year range - 2005-2009
  3. a list of years - 2004, 2006, 2007 - also supports ranges in it - 2004, 2005-2009, 2011

Project

By default, license will use the directory it's making the license file in as the name of the project, however in case the directory's name doesn't match the project name or whatever, you can override the name using the --projectName option to license.

If you want to change the directory the license gets generated in, without needing to cd into it, you can supply the --project option (aliased to -p) with a path to the directory instead, and it'll generate the license there. It'll also change the project name set to that of the directory, unless you specify the --projectName option above.

Default License

If you wish to be able to run license without having to specify the same license everytime - say you just want to use the MIT License everywhere because that's your go-to. You can set what license gets generated by default with license config --license <license>, and it will procede to use that for all future calls without you need to specify MIT as the license every single time.

You can of course override this decision by specifying a license to when you call license via the normal usage, this just changes the default empty behaviour from the search prompt to auto filling a license.

API Usage

You can also use the core functionality of license through a simple API

Getting a license you know

import { getLicense } from "license";

// Get license template text
console.log(getLicense("MIT"));

// Fill out some info
console.log(getLicense("MIT", { author: "Ovyerus", year: "2020" }));

Getting a list of licenses that match a search term

import { findLicense } from "license";

console.log(findLicense("mi"));
// [ 'MIT', 'MirOS', 'Multics', 'MPL-2.0-no-copyleft-exception' ]

console.log(findLicense("mit"));
// [ 'MIT' ] (exact match)

// Showing more licenses than just OSI-approved
console.log(findLicense("mi", false));
// [
//   'CDLA-Permissive-1.0',
//   'MIT',
//   'MIT-0',
//   'MIT-CMU',
//   'MIT-advertising',
//   'MIT-enna',
//   'MIT-feh',
//   'MITNFA',
//   'MirOS',
//   ...
// ]

Combined, you can provide a powerful searching experience for a license without needing your users to exactly remember the name of what they want.

API Docs

getLicense(license[, replacements]) => string

Get the body text of a given license, optionally filling in any placeholder values with given values, such as author or date.

license (string)

The name of the license to get/fill in. Must be an exact match including capitalisation.

replacements (object)

A plain key: value object used to populate given any present placeholders in the license text, where key is used as the placeholder's name, and value is what replaces the placeholder.

findLicense(search[, osiOnly = true]) => string[]

Get a list of possible matching license identifiers, given a string - possibly user input. If the input is an exact matchs (sans capitalisation), it'll return only that as a result, to make it easier to determine if the user got the search right.

search (string)

The string to search through all the identifiers for a match.

osiOnly (boolean)

Determines whether or not to only show only OSI-approved licenses in the results. Defaults to true.

License

This repository and the code inside it is licensed under the MIT License. Read LICENSE for more information.

license's People

Contributors

buschtoens avatar dependabot[bot] avatar erunion avatar ovyerus avatar yurickh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

license's Issues

license [license] does not work with npx

Running the follow code still triggers the interactive CLI:

npx license [license]

With the example of mit:

npx license mit

I think this changed in the most recent release since it stopped working for me about 9 months ago.

Also, thank you for this module. It's a core part of my workflow <3

`getLicense` replacements don't work on Apache-2.0

๐Ÿ‘‹ We're using this library for some code generation tooling we've got and noticed that the yyyy template value in the Apache-2.0 license isn't getting swapped out:

const license = getLicense('Apache-2.0', {
  year: 2023,
  author:  'Company Name',
});
Copyright [yyyy] Company Name

Looking at the source for getLicense it seems like it doesn't support templates that are structured as [templatekey]:

modified = modified.replace(new RegExp(`<${key}>`, "g"), value);

Can't install license version 1.0.0 and up

When trying to install or use license via npx I get the following error message

npm i license
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /Users/pnash/projects/project-name/node_modules/license/dist/cli/index.js
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/Users/pnash/projects/project-name/node_modules/license/dist/cli/index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/pnash/.npm/_logs/2020-03-24T03_59_10_214Z-debug.log

Version 0.0.3 still works. Was the project released without building the files to dist? Or are the dist files not being included in the package?

Thanks

use git username and email for getLicense by default

Currently,

import getLicense from "license";
getLicense("MIT")

Will generate a license with empty username and emailname. Why not insert username and email from git by default? That is, if user name is foo and email is [email protected], getLicense("MIT") will be like getLicense("MIT", { author: "foo", year: "2020" }).

Refactor

  • Monorepo with CLI & licenses list packages.
  • Find new CLI library to use (probably oclif)
  • Put together license data from scratch instead of relying on Sindre's list.
  • Make betterer

Checking license of other package/repository

There's several other packages available that allow trying to find the license of a particular npm package or git repository. It might be cool to integrate something similar into license to help make it an all-in-one experience.

Usage could look something like license check [@scope/]package for checking an npm package, and license check user/repo for checking a GitHub repository. Ideally would also want to support any other Git provider without needing to be locked into just GitHub, via just a url I presume.
(Note to self: research to see if we can get info about a remote repo through Git without needing to locally clone it, would probably help with performance in this respect)

Idea

Also add a flag to try and check the compatibility of a package's license with another license, would be useful for companies or individuals who need to ensure that dependencies are compatible with a specific license - e.g. GPL.

Would probably be named something along the lines of --check-compatibility or --compatibility-with, e.g. license check MIT --compatibility-with GPL (and add a shorthand of course, -c).


Also expose it as through the API like with getLicense so users don't need to install an extra package.

License ISC wrongly applied

STEPS TO REPRODUCE:

npm install ISC

CURRENT BEHAVIOUR:

The produced license has the copyright set the Internet Software Consortium

DESIRED BEHAVIOUR:

The produced license has the copyright set to the author of the project

SUMMARY:

The ISC license is indeed created by the Internet Software Consortium but the license generated should have the permission from the author of the new piece of software, not the ISC.

You may follow this official template:

https://opensource.org/licenses/ISC

(you may find date and owner placeholders for be replaced by the projects author and date)

NOTE: no need to replace the "AUTHOR" text on the license if the copyright is correctly set to the author as mentioned

Thank you very much for the license package is really cool and usefull.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.