forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopyrights.js
76 lines (68 loc) · 2.87 KB
/
copyrights.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var es = require('event-stream');
var fs = require('fs');
var path = require('path');
var copyright = [
'/*---------------------------------------------------------------------------------------------',
' * Copyright (c) Microsoft Corporation. All rights reserved.',
' * Licensed under the MIT License. See License.txt in the project root for license information.',
' *--------------------------------------------------------------------------------------------*/'
].join('\n');
var ignoreList = [
'/src/vs/languages/typescript/common/lib/lib.d.ts',
'/src/vs/languages/typescript/common/lib/lib.es6.d.ts',
'/src/vs/languages/typescript/common/lib/typescriptServices.d.ts',
'/src/vs/workbench/parts/emmet/node/emmet.d.ts',
'/src/vs/editor/standalone-languages/swift.ts',
'/src/vs/workbench/browser/media/octicons/octicons.css',
'/src/vs/base/test/node/encoding/fixtures/some_utf16be.css',
'/src/vs/base/test/node/encoding/fixtures/some_utf16le.css',
'/src/vs/workbench/services/search/test/node/fixtures/site.css',
'/src/vs/workbench/services/search/test/node/fixtures/some_utf16be.css',
'/src/vs/workbench/services/search/test/node/fixtures/some_utf16le.css',
'/src/vs/workbench/services/files/test/node/fixtures/service/some_utf16le.css',
'/extensions/lib.core.d.ts',
'/extensions/node.d.ts',
'/extensions/csharp-o/src/typings/applicationinsights.d.ts',
'/extensions/typescript/out/lib/lib.core.d.ts',
'/extensions/typescript/out/lib/lib.core.es6.d.ts',
'/extensions/typescript/out/lib/lib.d.ts',
'/extensions/typescript/out/lib/lib.dom.d.ts',
'/extensions/typescript/out/lib/lib.es6.d.ts',
'/extensions/typescript/out/lib/lib.scriptHost.d.ts',
'/extensions/typescript/out/lib/lib.webworker.d.ts',
'/extensions/typescript/src/lib/lib.core.d.ts',
'/extensions/typescript/src/lib/lib.core.es6.d.ts',
'/extensions/typescript/src/lib/lib.d.ts',
'/extensions/typescript/src/lib/lib.dom.d.ts',
'/extensions/typescript/src/lib/lib.es6.d.ts',
'/extensions/typescript/src/lib/lib.scriptHost.d.ts',
'/extensions/typescript/src/lib/lib.webworker.d.ts',
'/extensions/csharp-o/src/typings/semver/semver.d.ts'
];
function ignore(filePath) {
filePath = path.posix.normalize(filePath);
return ignoreList.some(function(p) {
return filePath.indexOf(p) !== -1;
});
}
exports.copyrights = function () {
return es.mapSync(function (file) {
if (file.contents) {
var contents = file.contents.toString('utf8');
if (contents.indexOf(copyright) !== 0 && !ignore(file.path)) {
throw new Error('File ' + file.path + ' does not contain copyright statement.');
}
}
});
};
exports.insertCopyrights = function() {
return es.mapSync(function (file) {
if (file.contents) {
var contents = file.contents.toString('utf8');
if (contents.indexOf(copyright) !== 0 && !ignore(file.path)) {
contents = copyright + '\n\n' + contents;
fs.writeFileSync(file.path, contents, 'utf8');
}
}
});
}