microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
db80cd4e10b83524bc77c15018effab72cbabeb8

Branches

Tags

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

Clone

HTTPS

Download ZIP

tools/checkCasing.js

37lines · modecode

1var fs = require("fs");
2var path = require("path");
3var os = require("os");
4var child_process = require("child_process");
5
6// Recursively find all instances of 'import [...] from "[...]";'
7if (os.platform() === "win32") {
8 child_process.exec("findstr /sir /C:\"import.*from\" *.ts", parseOutput);
9} else {
10 child_process.exec("grep -Ri 'import.*from' .", parseOutput);
11}
12
13function parseOutput(err, out, stderr) {
14 // Extract out the filename containing the match,
15 // and the relative path of the file it is searching for
16 var regex = /(\s|^)([^\n:]*):.*from ["'](\.[^"']*)["'];/g;
17 var imports = [];
18 out.replace(regex, function (all, _, file, from) {
19 imports.push({ path: file, relative: from });
20 });
21 checkImports(imports);
22}
23
24function checkImports(imports) {
25 // Check to see if the import references a source file
26 // with an exact match of a name, and complain otherwise
27 imports.map(function (i) {
28 i.resolved = path.resolve(path.dirname(i.path), i.relative + ".ts");
29 return i;
30 }).filter(function (i) {
31 var entries = fs.readdirSync(path.dirname(i.resolved));
32 return entries.indexOf(path.basename(i.resolved)) === -1;
33 }).forEach(function (i) {
34 console.log("Missing file for import in " + i.path + ": " + i.relative);
35 process.exitCode = 1;
36 });
37}
38