Skip to content

Commit 677fd2e

Browse files
committed
Merge pull request #137 from plotly/license-2016
Update license information for 2016
2 parents 4f037ee + 175e927 commit 677fd2e

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Plotly, Inc
3+
Copyright (c) 2016 Plotly, Inc
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ plotly.js charts can also be created and saved online for free at [plot.ly/plot]
104104

105105
## Copyright and license
106106

107-
Code and documentation copyright 2015 Plotly, Inc.
107+
Code and documentation copyright 2016 Plotly, Inc.
108108

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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"browserify": "^12.0.1",
8585
"browserify-transform-tools": "^1.5.0",
8686
"ecstatic": "^1.2.0",
87+
"falafel": "^1.2.0",
8788
"glob": "^6.0.1",
8889
"jasmine-core": "^2.3.4",
8990
"jshint": "^2.8.0",

tasks/header.js

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
var path = require('path');
2+
var fs = require('fs');
3+
14
var prependFile = require('prepend-file');
5+
var falafel = require('falafel');
6+
var glob = require('glob');
27

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

@@ -13,9 +18,60 @@ var pathsDist = [
1318
];
1419

1520
function headerLicense(path) {
16-
prependFile(path, constants.licenseDist, function(err) {
21+
prependFile(path, constants.licenseDist + '\n', function(err) {
1722
if(err) throw err;
1823
});
1924
}
2025

2126
pathsDist.forEach(headerLicense);
27+
28+
29+
// add or update header to src files
30+
31+
// remove leading '/*' and trailing '*/' for comparison with falafel output
32+
var licenseSrc = constants.licenseSrc;
33+
var licenseStr = licenseSrc.substring(2, licenseSrc.length - 2);
34+
35+
36+
glob(path.join(constants.pathToSrc, '**/*.js'), function(err, files) {
37+
files.forEach(function(file) {
38+
fs.readFile(file, 'utf-8', function(err, code) {
39+
40+
// parse through code string while keeping track of comments
41+
var comments = [];
42+
falafel(code, {onComment: comments, locations: true}, function() {});
43+
44+
var header = comments[0];
45+
46+
// if header and license are the same, do nothing
47+
if(isCorrect(header)) return;
48+
49+
// if header and license only differ by date, update header
50+
else if(hasWrongDate(header)) {
51+
var codeLines = code.split('\n');
52+
53+
codeLines.splice(header.loc.start.line-1, header.loc.end.line);
54+
55+
var newCode = licenseSrc + '\n' + codeLines.join('\n');
56+
57+
fs.writeFile(file, newCode, function(err) {
58+
if(err) throw err;
59+
});
60+
}
61+
else {
62+
// otherwise, throw an error
63+
throw new Error(file + ' : has wrong header information.');
64+
}
65+
});
66+
});
67+
});
68+
69+
function isCorrect(header) {
70+
return (header.value === licenseStr);
71+
}
72+
73+
function hasWrongDate(header) {
74+
var regex = /Copyright 20[0-9][0-9]-20[0-9][0-9]/g;
75+
76+
return (header.value.replace(regex, '') === licenseStr.replace(regex, ''));
77+
}

tasks/util/constants.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var pathToTopojsonSrc = path.join(
1212
path.dirname(require.resolve('sane-topojson')), 'dist/'
1313
);
1414

15+
var year = (new Date()).getFullYear();
16+
1517
module.exports = {
1618
pathToRoot: pathToRoot,
1719
pathToSrc: pathToSrc,
@@ -60,10 +62,19 @@ module.exports = {
6062
licenseDist: [
6163
'/**',
6264
'* plotly.js v' + pkg.version,
63-
'* Copyright 2012-2015, Plotly, Inc.',
65+
'* Copyright 2012-' + year + ', Plotly, Inc.',
6466
'* All rights reserved.',
6567
'* Licensed under the MIT license',
66-
'*/',
67-
''
68+
'*/'
69+
].join('\n'),
70+
71+
licenseSrc: [
72+
'/**',
73+
'* Copyright 2012-' + year + ', Plotly, Inc.',
74+
'* All rights reserved.',
75+
'*',
76+
'* This source code is licensed under the MIT license found in the',
77+
'* LICENSE file in the root directory of this source tree.',
78+
'*/'
6879
].join('\n')
6980
};

0 commit comments

Comments
 (0)