How to use the @hint/utils-fs.readFile 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 / hint-performance-budget / src / connections.ts View on Github external
const getConnections = (): NetworkConfig[] => {
    const configContent = readFile(`${__dirname}/connections.ini`);

    const configsText = configContent
        .replace(/#.*?\n/g, '') // remove comments
        .replace(/\r\n/g, '\n') // remove \r in case the file has a Windows EOL
        .split(`\n\n`);

    const configs = configsText.map(parseConnection);

    return configs;
};
github webhintio / hint / packages / connector-jsdom / src / before-parse.ts View on Github external
return (window: DOMWindow) => {
        const mutationObserverPolyfill = readFile(require.resolve('mutationobserver-shim'));
        const customElementsPolyfill = readFile(path.join(__dirname, 'polyfills', 'custom-elements.min.js'));

        const mutationScript: vm.Script = new vm.Script(mutationObserverPolyfill);
        const customElementsScript: vm.Script = new vm.Script(customElementsPolyfill);

        mutationScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
        customElementsScript.runInContext(jsdomutils.implForWrapper(window.document)._global);

        window.document.domain = new URL(finalHref).host;

        /* istanbul ignore next */
        window.matchMedia = () => {
            return { addListener() { } } as any;
        };

        Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientWidth', { value: 1024 });
github webhintio / hint / packages / utils / src / packages / is-official.ts View on Github external
export const isOfficial = async (): Promise => {
    try {
        const pkg = JSON.parse(await readFile(join(findPackageRoot(process.cwd()), 'package.json')));

        return pkg.name === '@hint/monorepo';
    } catch (e) {
        // No `package.json` was found, so it's not official
        return false;
    }
};
github webhintio / hint / packages / hint / src / lib / utils / resource-loader.ts View on Github external
const ids: string[] = resourcesFiles.reduce((list: string[], resourceFile: string) => {
        const resource = requirePackage(path.dirname(resourceFile));
        const packageName = JSON.parse(readFile(resourceFile)).name;
        const resourceName = packageName.substr(packageName.lastIndexOf('/') + 1).replace(`${type}-`, '');

        /* istanbul ignore else */
        if (!hasMultipleResources(resource, type)) {
            list.push(resourceName);
        } else {
            const hints = Object.entries(resource);

            if (hints.length === 1 && resource[resourceName]) {
                list.push(resourceName);
            } else {
                for (const [key] of hints) {
                    list.push(`${resourceName}/${key}`);
                }
            }
        }
github webhintio / hint / packages / connector-jsdom / src / before-parse.ts View on Github external
return (window: DOMWindow) => {
        const mutationObserverPolyfill = readFile(require.resolve('mutationobserver-shim'));
        const customElementsPolyfill = readFile(path.join(__dirname, 'polyfills', 'custom-elements.min.js'));

        const mutationScript: vm.Script = new vm.Script(mutationObserverPolyfill);
        const customElementsScript: vm.Script = new vm.Script(customElementsPolyfill);

        mutationScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
        customElementsScript.runInContext(jsdomutils.implForWrapper(window.document)._global);

        window.document.domain = new URL(finalHref).host;

        /* istanbul ignore next */
        window.matchMedia = () => {
            return { addListener() { } } as any;
        };

        Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientWidth', { value: 1024 });
        Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientHeight', { value: 768 });
github webhintio / hint / packages / create-hint / src / create-hint.ts View on Github external
this.destination = join(cwd(), `hint-${this.normalizedName}`);
        }
    }
}

/*
 * ------------------------------------------------------------------------------
 * Constants and Private functions.
 * ------------------------------------------------------------------------------
 */

const mkdirpAsync = promisify(mkdirp) as (dir: string) => Promise;
/** Name of the package to use as a template. */
const TEMPLATE_PATH = './templates';
const SHARED_TEMPLATE_PATH = './shared-templates';
const partialEventCode = readFile(join(__dirname, 'templates', 'partial-event-code.hbs'));

Handlebars.registerPartial('event-code', partialEventCode);
Handlebars.registerHelper('toCamelCase', toCamelCase);

/** List hint categories. */
const categories: any[] = [];

for (const [, value] of Object.entries(Category)) {
    if (value !== 'other') {
        categories.push({ name: value });
    }
}

/** List of scopes */
const scopes: any[] = [];