浏览代码

Added the script.

Piotrek Koszuliński 8 年之前
父节点
当前提交
82bdb7042d
共有 2 个文件被更改,包括 66 次插入7 次删除
  1. 4 7
      package.json
  2. 62 0
      scripts/bump-year.js

+ 4 - 7
package.json

@@ -51,13 +51,15 @@
     "@ckeditor/ckeditor5-dev-tests": "^10.0.0",
     "@ckeditor/ckeditor5-dev-webpack-plugin": "^3.0.4",
     "babel-minify-webpack-plugin": "^0.2.0",
-    "extract-text-webpack-plugin": "^3.0.2",
     "eslint": "^4.8.0",
     "eslint-config-ckeditor5": "^1.0.7",
+    "extract-text-webpack-plugin": "^3.0.2",
+    "glob": "^7.1.2",
     "husky": "^0.14.3",
-    "lint-staged": "^4.2.3",
     "lerna": "^2.2.0",
+    "lint-staged": "^4.2.3",
     "mgit2": "^0.7.2",
+    "minimatch": "^3.0.4",
     "postcss-loader": "^2.0.10",
     "raw-loader": "^0.5.1",
     "style-loader": "^0.19.1",
@@ -80,21 +82,16 @@
   "scripts": {
     "lint": "eslint --quiet '**/*.js'",
     "precommit": "lint-staged",
-
     "test": "node --max_old_space_size=4096 node_modules/@ckeditor/ckeditor5-dev-tests/bin/test.js",
     "test:manual": "node --max_old_space_size=4096 node_modules/@ckeditor/ckeditor5-dev-tests/bin/test-manual.js",
-
     "docs": "node ./scripts/docs/build-docs.js",
     "docs:api": "node ./scripts/docs/build-api-docs.js",
     "docs:build-and-publish": "node ./scripts/docs/build-and-publish.js",
-
     "translations:collect": "ckeditor5-dev-env-translations collect",
     "translations:download": "ckeditor5-dev-env-translations download",
     "translations:upload": "ckeditor5-dev-env-translations upload",
-
     "changelog": "node ./scripts/release/changelog.js",
     "release:dependencies": "node ./scripts/release/release-dependencies.js",
-
     "switch-to-dev-dev": "sh ./scripts/switch-to-dev-dev.sh"
   },
   "lint-staged": {

+ 62 - 0
scripts/bump-year.js

@@ -0,0 +1,62 @@
+#!/usr/bin/env node
+
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* eslint-env node */
+
+/*
+
+Usage:
+mgit exec 'node ../../scripts/bump-year.js'
+node scripts/bump-year.js
+
+Full command to update the entire project:
+git pull && mgit update && mgit exec 'node ../../scripts/bump-year.js' && node scripts/bump-year.js
+
+And after reviewing the changes:
+mgit exec 'git commit -m "Internal: Bumped up the year. [skip ci]" && git push' &&
+git commit -m "Internal: Bumped up the year." && git push
+
+*/
+
+const glob = require( 'glob' );
+const minimatch = require( 'minimatch' );
+const fs = require( 'fs' );
+
+glob( '!(node_modules|build|coverage|packages)/**/*', ( err, fileNames ) => {
+	const filteredFileNames = fileNames.filter( fileName => {
+		// Filter out stuff from ckeditor5-utils/src/lib.
+		if ( minimatch( fileName, '**/src/lib/**' ) ) {
+			return false;
+		}
+
+		if ( fs.statSync( fileName ).isDirectory() ) {
+			return false;
+		}
+
+		return true;
+	} );
+
+	filteredFileNames.forEach( fileName => {
+		fs.readFile( fileName, ( err, data ) => {
+			data = data.toString();
+
+			const year = new Date().getFullYear();
+			const regexp = /Copyright \(c\) 2003-\d{4}/;
+			const updatedData = data.replace( regexp, 'Copyright (c) 2003-' + year );
+
+			if ( data == updatedData ) {
+				// License headers are only required in JS files.
+				// Also, the file might have already been updated.
+				if ( fileName.endsWith( '.js' ) && !data.match( regexp ) ) {
+					console.warn( `The file "${ fileName }" misses a license header.` );
+				}
+			} else {
+				fs.writeFile( fileName, updatedData );
+			}
+		} );
+	} );
+} );