microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7eaa0c8166e99d61e7ff0c79bbbd3bddc2461ed1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tools/checkCasing.js

42lines · 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 dirpath = path.dirname(i.resolved);
32 try {
33 var entries = fs.readdirSync(dirpath);
34 return entries.indexOf(path.basename(i.resolved)) === -1;
35 } catch (exception) {
36 console.log("Missing folder for import in " + i.path + ": " + dirpath);
37 }
38 }).forEach(function (i) {
39 console.log("Missing file for import in " + i.path + ": " + i.relative);
40 process.exitCode = 1;
41 });
42}
43