LICENSE 中文文档教程
license
轻松为您的项目生成许可证!
Table of Contents
What is this?
您是否曾经开始过一个新项目,并且需要为其添加新许可证,但是 不知道确切的措辞(因为谁会)? 你必须 搜索所需的许可证,复制其文本,将其粘贴到新文件中,然后 然后检查是否有您需要的诸如版权信息之类的信息 更新。
License 是一个超级易于使用的 CLI 工具,用于简化 LICENSE 文件 创作过程。 受诸如以下工具的启发,具有超级简单但功能强大的 CLI 现在,为您的新项目设置许可证 从未如此简单!
Usage
首先,通过您选择的包管理器全局安装许可证。
$ yarn global add license
# or
$ npm i -g license
然后只需运行 license
即可生成许可证。
$ license [license]
如果您没有指定要生成的许可证,它将从您的配置中选择, 或显示交互式提示供您搜索。
如果您不想安装许可证而只想运行一次,可以使用 npx
$ npx license [license]
# Or using Yarn 2.x
$ yarn dlx license [license]
Examples
todo
Advanced Usage
默认情况下,许可证将尝试猜测您的姓名、电子邮件、当前项目和 在其生成的许可证中使用的当前年份。 您可以在 虽然有很多方法。
Name
默认情况下,许可证将尝试从您的 Git 配置中获取您的名称, (git config --global user.name
)。 如果失败,它将回退到使用 USER
环境变量,通常是您在 shell 中的用户名。
您可以通过两种方式覆盖它:
- Overriding it as a one time thing by providing a
--name
option while runninglicense
(also alised to-n
). - 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 tolicense
, unless the--name
option above is used, in which case that will take precedence.
默认情况下,许可证将尝试从您的 Git 配置获取您的电子邮件,只需 就像它对你的名字所做的那样,(git config --global user.email
),但它确实 没有任何后备可使用,因此建议您使用两者中的任何一个 覆盖下面的方法。
- Overriding it as a one time thing by providing an
--email
option while runninglicense
(also aliased to-e
). - 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 tolicense
, unless the--email
option above is used, in which case that will take precedence.
Year
默认情况下,许可证将使用当前年份(根据您的系统时间)来 填写,但是您可以使用 --year
选项设置自定义年份 许可证
。
它全年支持多种格式:
- a plain year -
2009
- a year range -
2005-2009
- a list of years -
2004, 2006, 2007
- also supports ranges in it -2004, 2005-2009, 2011
Project
默认情况下,许可证将使用其制作许可证文件的目录 项目的名称,但是如果目录名称与 项目名称或其他名称,您可以使用 --projectName
覆盖该名称 许可
选项。
如果您想更改生成许可证的目录,而不需要 需要cd
进入它,您可以提供--project
选项(别名为-p
) 而是使用目录路径,它将在那里生成许可证。 它还会将项目名称集更改为目录的名称,除非您 指定上面的 --projectName
选项。
Default License
如果您希望能够运行 license
而不必指定相同的 每次都使用许可证 - 假设您只想在任何地方使用 MIT 许可证,因为 那是你的首选。 您可以设置默认生成的许可证 license config --license
,它将继续将其用于所有 以后的调用无需每次都指定 MIT 作为许可证。
当然,您可以通过指定许可证来推翻此决定 通过正常使用调用license
,这只是更改默认的空 从搜索提示到自动填写许可证的行为。
API Usage
您还可以通过简单的API来使用license
的核心功能,
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',
// ...
// ]
结合起来,您可以提供强大的许可证搜索体验,而无需 需要您的用户准确记住他们想要的内容的名称。
API Docs
getLicense(license[, replacements]) => string
获取给定许可证的正文,可以选择填写任何占位符 具有给定值的值,例如作者或日期。
许可证(字符串)
要获取/填写的许可证名称。必须完全匹配,包括 大写。
replacements (object)
一个简单的 key: value
对象,用于填充给定的任何当前占位符 许可证文本,其中 key
用作占位符的名称,value
为 什么取代占位符。
findLicense(search[, osiOnly = true]) => string[]
给定一个字符串,获取可能匹配的许可证标识符的列表 - 可能 用户输入。 如果输入完全匹配(无大写),它将返回 仅此而已,以便更轻松地确定用户是否获得了搜索 正确的。
搜索(字符串)
用于在所有标识符中搜索匹配项的字符串。
osiOnly(布尔值)
确定是否仅在文件中显示 OSI 批准的许可证。 结果。 默认为true
。
License
该存储库及其内部的代码已根据 MIT 许可证获得许可。 读 许可证了解更多信息。
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:
- Overriding it as a one time thing by providing a
--name
option while runninglicense
(also alised to-n
). - 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 tolicense
, unless the--name
option above is used, in which case that will take precedence.
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.
- Overriding it as a one time thing by providing an
--email
option while runninglicense
(also aliased to-e
). - 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 tolicense
, 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:
- a plain year -
2009
- a year range -
2005-2009
- 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.