How to use the @hint/utils-fs.isFile function in @hint/utils-fs

To help you get started, we’ve selected a few @hint/utils-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webhintio / hint / packages / utils / src / chromium-finder.ts View on Github external
for (const folder of desktopInstallationFolders) {
        const executable = findChromeExecutable(folder, executables);

        if (executable) {
            return executable;
        }
    }

    // 2. Look for executables by using the which command
    for (const executable of executables) {
        try {
            const chromePath =
                execFileSync('which', [executable], { stdio: 'pipe' }).toString()
                    .split(newLineRegex)[0];

            if (chromePath && isFile(chromePath)) {
                return chromePath;
            }
        } catch (e) {
            // Not installed.
        }
    }

    return '';
};
github webhintio / hint / packages / hint / src / lib / config.ts View on Github external
public static getFilenameForDirectory = (directory: string): string | null => {

        for (let i = 0, len = CONFIG_FILES.length; i < len; i++) {
            const filename: string = path.join(directory, CONFIG_FILES[i]);

            if (isFile(filename)) {
                return filename;
            }
        }

        const homedir = os.homedir();

        // If we reach this point we've tested in the original directory and homedir
        if (directory === homedir) {
            return null;
        }

        return Configuration.getFilenameForDirectory(homedir);
    };
}
github webhintio / hint / packages / utils / src / chromium-finder.ts View on Github external
/* istanbul ignore if */
    if (!suffixes) {
        throw new Error(ERRORS.NotSupportedBrowser`${browser}`);
    }

    const prefixes = [
        getVariable('LOCALAPPDATA'),
        getVariable('PROGRAMFILES'),
        getVariable('PROGRAMFILES(X86)')
    ].filter(Boolean);

    for (const suffix of suffixes) {
        for (const prefix of prefixes) {
            const browserPath = path.join(prefix!, suffix);

            if (isFile(browserPath)) {
                return browserPath;
            }
        }
    }

    return '';
};
github webhintio / hint / packages / connector-local / src / connector.ts View on Github external
return new Promise(async (resolve, reject) => {
            const isF = isFile(targetString);
            /* istanbul ignore next */
            const target = isF ? targetString : '.';
            const ignored = await this.getGitIgnore();

            this.watcher = chokidar.watch(target, {
                /* istanbul ignore next */
                cwd: !isF ? targetString : undefined,
                ignored: ignored.concat(['.git/']),
                ignoreInitial: true,
                /*
                 * If you are using vscode and create and remove a folder
                 * from the editor, an EPERM error is thrown.
                 * This option avoid that error.
                 */
                ignorePermissionErrors: true
            });
github webhintio / hint / packages / utils / src / chromium-finder.ts View on Github external
* See https://github.com/GoogleChrome/chrome-launcher/issues/46 for more context.
             */
            try {
                execPaths = execSync(`grep -ER "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);
            } catch (e) {
                execPaths = execSync(`grep -Er "${chromeExecRegex}" ${folder} | awk -F '=' '{print $2}'`);
            }

            execPaths = execPaths.toString()
                .split(newLineRegex)
                .map((execPath: string) => {
                    return execPath.replace(argumentsRegex, '$1');
                });

            for (const execPath of execPaths) {
                if (isFile(execPath)) {
                    return execPath;
                }
            }
        }
    }

    return '';
};
github webhintio / hint / packages / utils / src / chromium-finder.ts View on Github external
.split(newLineRegex);

    /**
     * Because `suffixes` are already prioritized, we iterate them first to make
     * sure that priorization is respected
     */
    for (const suffix of suffixes) {
        for (const inst of lines) {

            const execPath = path.join(inst.trim(), suffix);

            /**
             * An example of valid path for Chrome would be:
             * `/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`
             */
            if (isFile(execPath)) {
                return execPath;
            }
        }
    }

    return '';
};
github webhintio / hint / packages / hint / src / lib / analyzer.ts View on Github external
public static getUserConfig(filePath?: string): UserConfig | null {
        const isDirectory = !isFile(filePath);
        const configPath = isDirectory ? Configuration.getFilenameForDirectory(filePath || cwd()) : filePath;

        if (!configPath) {
            return null;
        }

        try {
            const resolvedPath = path.resolve(isDirectory ? (filePath || cwd()) : cwd(), configPath);

            return Configuration.loadConfigFile(resolvedPath);
        } catch {
            return null;
        }
    }
github webhintio / hint / packages / utils / src / chromium-finder.ts View on Github external
const resolveChromiumPath = () => {
    const chromiumPaths = [
        getVariable('WEBHINT_CHROMIUM_PATH'),
        getVariable('CHROME_PATH')
    ];

    while (chromiumPaths.length > 0) {
        const browserPath = chromiumPaths.shift()!;

        if (isFile(browserPath)) {
            return browserPath;
        }
    }

    return '';
};