How to use the @hint/utils-fs.cwd 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 / formatter-excel / src / formatter.ts View on Github external
createSummary(sortedResources, target);

        _.forEach(sortedResources, (resourceName) => {
            processResource(resources[resourceName], resourceName);
        });

        try {
            // We save the file with the friendly target name
            const name = target.replace(/:\/\//g, '-')
                .replace(/:/g, '-')
                .replace(/\./g, '-')
                .replace(/\//g, '-')
                .replace(/-$/, '');

            const fileName = options.output || path.resolve(cwd(), `${name}.xlsx`);

            await workbook.xlsx.writeFile(fileName);
        } catch (e) {
            /* istanbul ignore next */
            { // eslint-disable-line
                logger.error(getMessage('errorSaving', language));

                if (e.message.includes('EBUSY')) {
                    logger.error(getMessage('maybeIsOpened', language));
                }
            }
        }
    }
}
github webhintio / hint / packages / formatter-html / src / formatter.ts View on Github external
},
                    result,
                    scripts,
                    styles: await getStylesContent(stylesList),
                    utils
                });

                await removeLanguageFile();
                // We save the result with the friendly target name
                const name = target.replace(/:\/\//g, '-')
                    .replace(/:/g, '-')
                    .replace(/\./g, '-')
                    .replace(/\//g, '-')
                    .replace(/[?=]/g, '-query-')
                    .replace(/-$/, '');
                const destDir = options.output || path.join(cwd(), 'hint-report');

                const destination = path.join(destDir, `${name}.html`);

                await fs.outputFile(destination, html);

                logger.log(getMessageFormatter('youCanView', language, destination));
            }

            return result;
        } catch (err) {
            logger.error(err);

            throw err;
        }
    }
}
github webhintio / hint / packages / utils / src / packages / load-resource.ts View on Github external
const packageName = `${scope}${unscopedNameParts[0]}`;
    const resourceName = isSource ?
        name : unscopedNameParts[1] || packageName;

    const key = isPackage || isSource ?
        name :
        `${type}-${name}`;

    // When we check the version we ignore if there was a previous version loaded
    if (resources.has(key) && !verifyVersion) {
        return resources.get(key);
    }

    const configPathsToResources = generateConfigPathsToResources(configurations, packageName, type);
    const currentProcessDir = cwd();

    /*
     * We can't use the key for the Official packages neither for the Third party ones because
     * in case that we have a multi-hints packages, the key for the cache has to contain
     * the key for the specific hint, but we need to load the package that contains the hint.
     * i.e.
     * if we want to load the hint `hint-typescript-config/is-valid` the key for the cache
     * has to be `hint-typescript-config/is-valid`.
     * But we need to load the package `hint-typescript-config`.
     */
    let sources: string[];

    if (isSource) {
        sources = [path.resolve(currentProcessDir, name)]; // If the name is direct path to the source we should only check that.
    } else if (isPackage) {
        sources = [packageName].concat(configPathsToResources); // If the name is a full package name we should only check that, but look for it in config paths as well.
github webhintio / hint / packages / utils / src / npm.ts View on Github external
export const installPackages = async (packages: string[]): Promise => {
    /** Whether or not the package should be installed as devDependencies. */
    let isDev = false;
    /** Current working directory. */
    const currentWorkingDir = cwd();
    /** Whether or not the process is running in windows */
    const isWindows = process.platform === 'win32';

    if (packages.length === 0) {
        return Promise.resolve(true);
    }

    const hintLocalPath = path.join(currentWorkingDir, 'node_modules', 'hint', 'package.json');

    // Check if hint is installed locally.
    const global: boolean = !fs.existsSync(hintLocalPath); // eslint-disable-line no-sync

    /** package manager to install the packages. */
    const packageManagerChoice = (!global && await hasYarnLock(currentWorkingDir)) ? 'yarn' : 'npm';

    if (!global) {
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 / create-hintrc / src / create-hintrc.ts View on Github external
message: 'Do you want to use a predefined configuration or create your own based on your installed packages?',
        name: 'configType',
        type: 'list'
    }];

    const initialAnswer: inquirer.Answers = await inquirer.prompt(initialQuestion);

    const result = initialAnswer.configType === 'predefined' ?
        await extendConfig() :
        await customConfig();

    if (!result) {
        return false;
    }

    const filePath: string = path.join(cwd(), '.hintrc');

    await promisify(fs.writeFile)(filePath, JSON.stringify(result.config, null, 4), 'utf8');

    if (Array.isArray(result.packages) && result.packages.length > 0) {
        const isInstalled = getInstalledResources(ResourceType.configuration).includes(getConfigurationName(result.packages[0]));

        if (isInstalled) {
            return true;
        }

        await installPackages(result.packages);
    }

    trackEvent('new-hintrc', result.config);
    await sendPendingData();
github webhintio / hint / packages / create-hint / src / create-hint.ts View on Github external
if (this.official) {
            /**
             * If we are creating an official package it should be under `/packages/`
             * but it is very common to run it from the root of the project so we
             * take into account that scenario and add the folder if needed.
             */
            const root = cwd();

            const packagesPath = root.endsWith('packages') ?
                '' :
                'packages';

            this.destination = join(root, packagesPath, `hint-${this.normalizedName}`);
        } else {
            this.destination = join(cwd(), `hint-${this.normalizedName}`);
        }
    }
}