@putout/operator-match-files
🐊Putout operator adds ability to match files to plugins
Last updated 2 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/operator-match-files 
SYNC missed versions from official npm registry.

@putout/operator-match-files NPM version

????Putout operator adds ability to match files to plugins.

Install

npm i putout @putout/operator-match-files

API

If you want to create ????Putout plugin that will match files according to your needs just:

const {operator} = require('putout');
const {matchFiles} = operator;
const updateTSConfig = require('../update-tsconfig');

module.exports = matchFiles({
    'tsconfig.json': updateTSConfig,
});

This will help in case when update-tsconfig is disabled by default:

const updateTSConfig = require('./update-tsconfig');

module.exports.rules = {
    'update-tsconfig': ['off', updateTSConfig],
};

And you want to help users avoid updating .putout.json config with:

{
    "match": {
        "tsconfig.json": {
            "nextjs/update-tsconfig": "on"
        }
    },
    "plugins": ["nextjs"]
}

If you want to pass options use:

{
    "match": {
        "tsconfig.json": {
            "nextjs/update-tsconfig": ["on", {
                "ignore": []
            }]
        }
    },
    "plugins": ["nextjs"]
}

Instead of this, redlint can be used, it will generate .filesystem.json which can be processed by ????Putout.

Rename

If you want to save with other name use ->:

const {operator} = require('putout');
const {matchFiles} = operator;
const updateTSConfig = require('../update-tsconfig');

module.exports = matchFiles({
    'tsconfig.json -> hello.json': updateTSConfig,
});

Matcher

You can even use file matchers:

{
    "rules": {
        "filesystem/convert-json-to-js": ["on", {
            "filename": "package.json"
        }]
    }
}

Matchers: __filename = __name.__ext

module.exports = matchFiles({
    '__name.json -> __name.js': updateTSConfig,
});

exclude

If you want to exclude some files, use:

const {operator} = require('putout');
const {matchFiles} = operator;
const updateTSConfig = require('../update-tsconfig');

module.exports = matchFiles({
    files: {
        '__name.ts -> __name.js': updateTSConfig,
    },
    exclude: ['*.d.ts'],
});

Options

You can also pass options:

module.exports = matchFiles({
    '.eslintrc.json -> eslint.config.js': {
        rules: {
            'eslint/declare': ['on', {
                type: 'esm',
            }],
        },
        plugins: [
            ['eslint/convert-rc-to-flat', rcToFlat],
            ['eslint/declare', declare],
        ],
    },
});

Printer Options

You can also pass printer options:

module.exports = matchFiles({
    '.eslintrc.json -> eslint.config.js': {
        printer: ['putout', {
            format: {
                indent: '  ',
            },
        }],
        rules: {
            'eslint/declare': ['on', {
                type: 'esm',
            }],
        },
        plugins: [
            ['eslint/convert-rc-to-flat', rcToFlat],
            ['eslint/declare', declare],
        ],
    },
});

filename

You can pass default filename, so when no options provided it will be used.

const {operator} = require('putout');
const {matchFiles} = operator;
const updateTSConfig = require('../update-tsconfig');

module.exports = matchFiles({
    filename: '*.d.ts',
    files: {
        '__name.ts -> __name.js': updateTSConfig,
    },
});

License

MIT

Current Tags

  • 12.0.0                                ...           latest (2 months ago)

43 Versions

  • 12.0.0                                ...           2 months ago
  • 11.1.1                                ...           2 months ago
  • 11.1.0                                ...           3 months ago
  • 11.0.1                                ...           3 months ago
  • 11.0.0                                ...           3 months ago
  • 10.1.0                                ...           3 months ago
  • 10.0.1                                ...           4 months ago
  • 10.0.0                                ...           4 months ago
  • 9.0.1                                ...           10 months ago
  • 9.0.0                                ...           10 months ago
  • 8.0.0                                ...           a year ago
  • 7.0.2                                ...           a year ago
  • 7.0.1                                ...           a year ago
  • 7.0.0                                ...           a year ago
  • 6.0.1                                ...           a year ago
  • 6.0.0                                ...           a year ago
  • 5.3.0                                ...           a year ago
  • 5.2.0                                ...           a year ago
  • 5.1.0                                ...           a year ago
  • 5.0.0                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.5.0                                ...           2 years ago
  • 3.4.0                                ...           2 years ago
  • 3.3.0                                ...           2 years ago
  • 3.2.2                                ...           2 years ago
  • 3.2.1                                ...           2 years ago
  • 3.2.0                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.4.1                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 7
Last Day 0
Last Week 8
Last Month 1
Dev Dependencies (11)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |