Forráskód Böngészése

chore: Fix line encoding of script

Michael Bromley 6 éve
szülő
commit
d952968086
1 módosított fájl, 55 hozzáadás és 1 törlés
  1. 55 1
      scripts/check-imports.ts

+ 55 - 1
scripts/check-imports.ts

@@ -1 +1,55 @@
-/* tslint:disable:no-console */
import fs from 'fs';
import path from 'path';
// tslint:disable-next-line:no-var-requires
const find = require('find');

/**
 * An array of regular expressions defining illegal import patterns to be checked in the
 * source files of the monorepo packages. This prevents bad imports (which work locally
 * and go undetected) from getting into published releases of Vendure.
 */
const illegalImportPatters: RegExp[] = [
    /@vendure\/common\/src/,
];

findInFiles(illegalImportPatters, path.join(__dirname, '../packages'), /\.ts$/);

function findInFiles(patterns: RegExp[], directory: string, fileFilter: RegExp) {
    find.file(fileFilter, directory, async (files: string[]) => {
        const matches = await getMatchedFiles(patterns, files);
        if (matches.length) {
            console.error(`Found illegal imports in the following files:`);
            console.error(matches.join('\n'));
            process.exitCode = 1;
        } else {
            console.log('Imports check ok!');
        }
    });
}

async function getMatchedFiles(patterns: RegExp[], files: string[]) {
    const matchedFiles = [];
    for (let i = files.length - 1; i >= 0; i--) {
        const content = await readFile(files[i]);
        for (const pattern of patterns) {
            if (pattern.test(content)) {
                matchedFiles.push(files[i]);
                continue;
            }
        }
    }
    return matchedFiles;
}

function readFile(filePath: string): Promise<string> {
    return new Promise((resolve, reject) => {
        fs.readFile(filePath, 'utf-8', (err, data) => {
            if (err) {
                reject(err);
            } else {
                resolve(data);
            }
        });
    });
}
+/* tslint:disable:no-console */
+import fs from 'fs';
+import path from 'path';
+// tslint:disable-next-line:no-var-requires
+const find = require('find');
+
+/**
+ * An array of regular expressions defining illegal import patterns to be checked in the
+ * source files of the monorepo packages. This prevents bad imports (which work locally
+ * and go undetected) from getting into published releases of Vendure.
+ */
+const illegalImportPatters: RegExp[] = [
+    /@vendure\/common\/src/,
+];
+
+findInFiles(illegalImportPatters, path.join(__dirname, '../packages'), /\.ts$/);
+
+function findInFiles(patterns: RegExp[], directory: string, fileFilter: RegExp) {
+    find.file(fileFilter, directory, async (files: string[]) => {
+        const matches = await getMatchedFiles(patterns, files);
+        if (matches.length) {
+            console.error(`Found illegal imports in the following files:`);
+            console.error(matches.join('\n'));
+            process.exitCode = 1;
+        } else {
+            console.log('Imports check ok!');
+        }
+    });
+}
+
+async function getMatchedFiles(patterns: RegExp[], files: string[]) {
+    const matchedFiles = [];
+    for (let i = files.length - 1; i >= 0; i--) {
+        const content = await readFile(files[i]);
+        for (const pattern of patterns) {
+            if (pattern.test(content)) {
+                matchedFiles.push(files[i]);
+                continue;
+            }
+        }
+    }
+    return matchedFiles;
+}
+
+function readFile(filePath: string): Promise<string> {
+    return new Promise((resolve, reject) => {
+        fs.readFile(filePath, 'utf-8', (err, data) => {
+            if (err) {
+                reject(err);
+            } else {
+                resolve(data);
+            }
+        });
+    });
+}