From 4d3c97797d2faa14f03c85970cc2c61ec58b028d Mon Sep 17 00:00:00 2001 From: etpinard Date: Mon, 21 Dec 2015 15:55:29 -0500 Subject: [PATCH 1/4] mv trailing '\n' out of constants into header script --- tasks/header.js | 2 +- tasks/util/constants.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tasks/header.js b/tasks/header.js index 14792f21f8e..83aa94083fc 100644 --- a/tasks/header.js +++ b/tasks/header.js @@ -13,7 +13,7 @@ var pathsDist = [ ]; function headerLicense(path) { - prependFile(path, constants.licenseDist, function(err) { + prependFile(path, constants.licenseDist + '\n', function(err) { if(err) throw err; }); } diff --git a/tasks/util/constants.js b/tasks/util/constants.js index 4079f753cc2..087593bea0f 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -61,7 +61,6 @@ module.exports = { '* Copyright 2012-2015, Plotly, Inc.', '* All rights reserved.', '* Licensed under the MIT license', - '*/', - '' + '*/' ].join('\n') }; From 473250a7dddcf5947a791ccd9ced70500e14bad9 Mon Sep 17 00:00:00 2001 From: etpinard Date: Mon, 21 Dec 2015 15:56:44 -0500 Subject: [PATCH 2/4] find date year using `new Date` for licenses --- tasks/util/constants.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasks/util/constants.js b/tasks/util/constants.js index 087593bea0f..ef66d6fc218 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -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, @@ -58,7 +60,7 @@ 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', '*/' From 2f8b00c130fc08a525d5ee16e9a760ea2fef5b94 Mon Sep 17 00:00:00 2001 From: etpinard Date: Mon, 21 Dec 2015 15:57:56 -0500 Subject: [PATCH 3/4] add src license update script: - add header info in constants - check src file header with falafel and glob - if header and license differ only by a date, update the header! --- package.json | 2 ++ tasks/header.js | 56 +++++++++++++++++++++++++++++++++++++++++ tasks/util/constants.js | 10 ++++++++ 3 files changed, 68 insertions(+) diff --git a/package.json b/package.json index fe8a718f172..9b4d302fe93 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,8 @@ "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", "karma": "^0.13.15", diff --git a/tasks/header.js b/tasks/header.js index 83aa94083fc..baf7dbdfdf9 100644 --- a/tasks/header.js +++ b/tasks/header.js @@ -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'); @@ -19,3 +24,54 @@ function headerLicense(path) { } 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, '')); +} diff --git a/tasks/util/constants.js b/tasks/util/constants.js index ef66d6fc218..f17c39e7e32 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -64,5 +64,15 @@ module.exports = { '* 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') }; From ddbaf7b6bcd3542a00df468b65c03ce8ca211884 Mon Sep 17 00:00:00 2001 From: etpinard Date: Mon, 21 Dec 2015 15:59:57 -0500 Subject: [PATCH 4/4] update 2015 -> 2016 in LICENSE & README --- LICENSE | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 88e36b21d9f..ae3a855cb18 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 8c28d7693b9..da6c7a43b04 100644 --- a/README.md +++ b/README.md @@ -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).