Skip to content

Commit

Permalink
add support for Apache-2.0 license
Browse files Browse the repository at this point in the history
  • Loading branch information
rmg committed May 13, 2016
1 parent 6eb9135 commit 03de9a9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/slt.ejs
Expand Up @@ -5,7 +5,7 @@ Commands:
cla Create or verify contribution guidelines
license [F] Set package licensing to standard form F
Form is auto-detected by default, it can be set explicitly to one of:
--mit, --dual-mit, --artistic, --dual-artistic, or --strongloop
--mit, --apache, --artistic
copyright [F..]
Insert/update copyright headers in JS source files. Uses git for
copyright years and package.json for license reference.
Expand Down
17 changes: 17 additions & 0 deletions lib/APACHE.tpl
@@ -0,0 +1,17 @@
Copyright (c) <%= owner %> <%= years %>. All Rights Reserved.
Node module: <%= name %>

--------
Copyright <%= years %> <%= 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.
2 changes: 1 addition & 1 deletion lib/cla.js
Expand Up @@ -26,7 +26,7 @@ function ensureCLA(project, log) {
var pkgRoot = project.rootPath;
var templatePath = process.env.SLT_CONTRIBUTING;
var claTpl = _.template(templatePath ? fs.readFileSync(templatePath, 'utf8')
: (/MIT|Artistic/.test(project.license()) ? DCO : NO_CONTRIBUTIONS));
: (/MIT|Artistic|Apache/.test(project.license()) ? DCO : NO_CONTRIBUTIONS));
var existingPath = path.resolve(pkgRoot, 'CONTRIBUTING.md');
var suggestionPath = path.resolve(pkgRoot, 'CONTRIBUTING.md.suggested');

Expand Down
7 changes: 7 additions & 0 deletions lib/copyright.js
Expand Up @@ -100,6 +100,13 @@ function copyHeader(path, pkg) {

function expandLicense(pkg) {
var name = _.result(pkg, 'license', pkg);
if (/^apache/i.test(name)) {
return {
template: LICENSED,
license: 'Apache License 2.0',
ref: 'at https://opensource.org/licenses/Apache-2.0',
};
}
if (/^artistic/i.test(name)) {
return {
template: LICENSED,
Expand Down
21 changes: 21 additions & 0 deletions lib/license.js
Expand Up @@ -22,6 +22,7 @@ if (process.env.SLT_LICENSE) {
CUSTOM = fs.readFileSync(process.env.SLT_LICENSE);
}
var MIT = fs.readFileSync(require.resolve('./MIT.tpl'));
var APACHE = fs.readFileSync(require.resolve('./APACHE.tpl'));
var ARTISTIC = fs.readFileSync(require.resolve('./ARTISTIC.tpl'));

exports.cli = fixCli;
Expand Down Expand Up @@ -56,6 +57,13 @@ function fixCli(pkgPath) {
var license = file.data.license;

switch (setLicense) {
case 'apache-2.0':
case 'apache-2':
case 'apache':
file.data.license = 'Apache-2.0';
license = writeApacheLicense(file.data);
return save();

case 'artistic':
case 'dual-artistic': // deprecated
file.data.license = 'Artistic-2.0';
Expand Down Expand Up @@ -103,6 +111,14 @@ function fixCli(pkgPath) {

// License string
switch (license) {
case 'Apache-2.0':
case 'Apache-2':
case 'Apache':
case 'apache':
file.data.license = 'Apache-2.0';
license = writeApacheLicense(file.data);
return save();

case '(Artistic-2.0 OR LicenseRef-LICENSE.md)': // OBSOLETE
case 'Artistic-2.0 OR LicenseRef-LICENSE.md': // OBSOLETE
case 'Artistic-2.0 OR LicenseRef-LICENSE': // OBSOLETE
Expand Down Expand Up @@ -163,6 +179,11 @@ function writeArtisticLicense(pkg) {
return 'Artistic-2.0';
}

function writeApacheLicense(pkg) {
writeTemplatedLicense('LICENSE', 'LICENSE.md', APACHE, pkg);
return 'Apache-2.0';
}

function writeTemplatedLicense(newName, oldName, text, pkg) {
assert(newName);
assert(oldName);
Expand Down
9 changes: 9 additions & 0 deletions test/test-copyright.js
Expand Up @@ -50,10 +50,19 @@ test('copyright headers', function(t) {
t.match(header, /at https:.+Artistic-2.0$/);
});
});
t.test('Apache license', function(t) {
var artistic = mockPackage({license: _.constant('Apache')});
return copyright.header(__filename, artistic).then(function(header) {
testCopyrightStatement(t, header);
t.match(header, 'Apache License 2.0');
t.match(header, /at https:.+Apache-2.0$/);
});
});
t.test('Commercial license', function(t) {
var custom = mockPackage({license: _.constant('custom')});
return copyright.header(__filename, custom).then(function(header) {
testCopyrightStatement(t, header);
t.notMatch(header, 'Apache');
t.notMatch(header, 'Artistic');
t.notMatch(header, 'MIT');
t.match(header, 'US Government Users Restricted Rights');
Expand Down

0 comments on commit 03de9a9

Please sign in to comment.