Skip to content

Update license information for 2016 #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Plotly, Inc
Copyright (c) 2016 Plotly, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ plotly.js charts can also be created and saved online for free at [plot.ly/plot]

## Copyright and license

Code and documentation copyright 2015 Plotly, Inc.
Code and documentation copyright 2016 Plotly, Inc.

Code released under the [MIT license](https://github.com/plotly/plotly.js/blob/master/LICENSE).

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"browserify": "^12.0.1",
"browserify-transform-tools": "^1.5.0",
"ecstatic": "^1.2.0",
"falafel": "^1.2.0",
"glob": "^6.0.1",
"jasmine-core": "^2.3.4",
"jshint": "^2.8.0",
Expand Down
58 changes: 57 additions & 1 deletion tasks/header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
var path = require('path');
var fs = require('fs');

var prependFile = require('prepend-file');
var falafel = require('falafel');
var glob = require('glob');

var constants = require('./util/constants');

Expand All @@ -13,9 +18,60 @@ var pathsDist = [
];

function headerLicense(path) {
prependFile(path, constants.licenseDist, function(err) {
prependFile(path, constants.licenseDist + '\n', function(err) {
if(err) throw err;
});
}

pathsDist.forEach(headerLicense);


// add or update header to src files

// remove leading '/*' and trailing '*/' for comparison with falafel output
var licenseSrc = constants.licenseSrc;
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);


glob(path.join(constants.pathToSrc, '**/*.js'), function(err, files) {
files.forEach(function(file) {
fs.readFile(file, 'utf-8', function(err, code) {

// parse through code string while keeping track of comments
var comments = [];
falafel(code, {onComment: comments, locations: true}, function() {});

var header = comments[0];

// if header and license are the same, do nothing
if(isCorrect(header)) return;

// if header and license only differ by date, update header
else if(hasWrongDate(header)) {
var codeLines = code.split('\n');

codeLines.splice(header.loc.start.line-1, header.loc.end.line);

var newCode = licenseSrc + '\n' + codeLines.join('\n');

fs.writeFile(file, newCode, function(err) {
if(err) throw err;
});
}
else {
// otherwise, throw an error
throw new Error(file + ' : has wrong header information.');
}
});
});
});

function isCorrect(header) {
return (header.value === licenseStr);
}

function hasWrongDate(header) {
var regex = /Copyright 20[0-9][0-9]-20[0-9][0-9]/g;

return (header.value.replace(regex, '') === licenseStr.replace(regex, ''));
}
17 changes: 14 additions & 3 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var pathToTopojsonSrc = path.join(
path.dirname(require.resolve('sane-topojson')), 'dist/'
);

var year = (new Date()).getFullYear();

module.exports = {
pathToRoot: pathToRoot,
pathToSrc: pathToSrc,
Expand Down Expand Up @@ -60,10 +62,19 @@ module.exports = {
licenseDist: [
'/**',
'* plotly.js v' + pkg.version,
'* Copyright 2012-2015, Plotly, Inc.',
'* Copyright 2012-' + year + ', Plotly, Inc.',
'* All rights reserved.',
'* Licensed under the MIT license',
'*/',
''
'*/'
].join('\n'),

licenseSrc: [
'/**',
'* Copyright 2012-' + year + ', Plotly, Inc.',
'* All rights reserved.',
'*',
'* This source code is licensed under the MIT license found in the',
'* LICENSE file in the root directory of this source tree.',
'*/'
].join('\n')
};