0.0.12 • Published 2 years ago

@luoxiu/watch v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Watch

Do something exciting on file changes!

ci npm license

Install

$ npm install -g @luoxiu/watch

$ yarn add -g @luoxiu/watch

$ pnpm add -g @luoxiu/watch

Usage

In your working directory, create a file named watch.config.js:

$ cd ./wd && touch watch.config.js

and execute:

$ watch

watch.config.js

The following example will format your swift code as it changes:

// watch.config.js
module.exports = {
    watchers: [ 
        {
            paths: ["Source/**/*.swift", "Tests/**/*.swift"],
            options: {
                ignored: ["*.generated.swift"],
            },
            callbacks: [
                {
                    events: ["change"],
                    callback: async (path) => {
                        await $`swiftformat ${path}`
                    }
                }
            ]
        }
    ]
}

// or
module.exports = async () => {
    return {
        // ...
    }
}

watch uses chokidar to watch file changes, so you can watch add | change | unlink(remove) | etc events on file | dir | glob | etc.

Please refer to chokidar#api to learn more about paths, options, events and callbacks.

watch uses zx to execute callbacks, so you can write expressive scripts like:

{
    events: ["changes"],
    callback: async (path) => {
        const resp = await fetch('https://wttr.in')
        const text = await fs.readFile(path)

        console.log(chalk.blue('Hello world!'))

        cd('/a-path')
        await $`pwd` // outputs /tmp
    }
}

Please refer to zx#documentation to learn more about zx.

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago