microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tools/checkCopyright.js

79lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3"use strict";
4/// <reference path="../../node_modules/vscode/typings/node.d.ts" />
5/// <reference path="../../src/typings/q/q.d.ts" />
6var FindFiles = require("node-find-files");
7var fs = require("fs");
8var Q = require("q");
9var path_module = require("path");
10var CopyrightVerifier = (function () {
11 function CopyrightVerifier() {
12 this.foundMissing = false;
13 }
14 CopyrightVerifier.prototype.findIn = function (path) {
15 var defer = Q.defer();
16 var foundFiles = [];
17 var finder = new FindFiles({
18 rootFolder: path,
19 filterFunction: function (path, stat) {
20 // match only filename
21 return path.match(CopyrightVerifier.SOURCE_CODE_FILE_PATTERN) && !path.match(CopyrightVerifier.EXCLUDED_FILE_PATTERN);
22 }
23 });
24 finder.on("match", function (filePath, fileStats) {
25 var contents = fs.readFileSync(filePath).toString().replace(/\r\n/g, "\n");
26 if (contents.indexOf(CopyrightVerifier.UTB_BYTE_ORDER_MARKER) === 0) {
27 contents = contents.substr(1);
28 }
29 if (!(contents.indexOf(CopyrightVerifier.COPYRIGHT_NOTICE) === 0)) {
30 foundFiles.push(filePath);
31 }
32 });
33 finder.on("complete", function () {
34 return defer.resolve(foundFiles);
35 });
36 finder.on("patherror", function (err, strPath) {
37 defer.reject("Error for Path " + strPath + " " + err + "\nStackTrace: " + err.stack);
38 });
39 finder.on("error", function (err) {
40 defer.reject("Global Error " + err);
41 });
42 finder.startSearch();
43 return defer.promise;
44 };
45 CopyrightVerifier.prototype.findInAll = function (paths) {
46 var _this = this;
47 return Q.all(paths.map(function (path) { return _this.findIn(path_module.resolve(path)); })).then(function (invalids) {
48 return [].concat.apply([], invalids);
49 });
50 };
51 CopyrightVerifier.prototype.verify = function () {
52 var paths = [];
53 for (var _i = 0; _i < arguments.length; _i++) {
54 paths[_i - 0] = arguments[_i];
55 }
56 return this.findInAll(paths).done(function (filePaths) {
57 if (filePaths.length !== 0) {
58 process.stderr.write("Found files which don't match the expected copyright notice:\n");
59 filePaths.forEach(function (filePath) { return process.stderr.write("\t" + filePath + "\n"); });
60 process.exit(1);
61 }
62 else {
63 process.exit(0);
64 }
65 }, function (reason) {
66 process.stderr.write("Uknown error while trying to check files copyright: " + reason);
67 process.exit(1);
68 });
69 };
70 CopyrightVerifier.UTB_BYTE_ORDER_MARKER = "\ufeff";
71 CopyrightVerifier.SOURCE_CODE_FILE_PATTERN = /.*\.(ts|js)$/;
72 CopyrightVerifier.EXCLUDED_FILE_PATTERN = /.*\.d\.ts/;
73 CopyrightVerifier.COPYRIGHT_NOTICE = "// Copyright (c) Microsoft Corporation. All rights reserved.\n" +
74 "// Licensed under the MIT license. See LICENSE file in the project root for details.\n";
75 return CopyrightVerifier;
76}());
77new CopyrightVerifier().verify("../src", "../tools");
78
79//# sourceMappingURL=checkCopyright.js.map
80