breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
3.01k stars 78 forks source link

[feat] Better Typescript support / documentation #133

Closed danwetherald closed 2 years ago

danwetherald commented 2 years ago

The docs / examples on Typescript are very poor and hard to understand, would be nice if the examples were not half baked and had a full example on setup.

  ...(CRON_MODE === 'ts'
      ? {
            path: typescript_worker,
            worker: {
                workerData: {
                    __filename: path.join(paths.jobs, `${jobPath}.ts`)
                }
            }
        }
      : {
            path: path.join(paths.jobs, `${jobPath}.js`)
        })

This is in particular makes no sense, what is paths, where is jobPath coming from, are you actually writing this ternary for every job?

nikosgpet commented 2 years ago

Just came up with this issue myself. Better typescript support would be greatly appreciated indeed.

danwetherald commented 2 years ago

I have found that its "working" without doing any of the documented path hacks.

shadowgate15 commented 2 years ago

I do plan on building a typescript plugin for bree that will allow you to run .ts files, as well as, improving the declaration file and moving it to be shipped with the package.

shadowgate15 commented 2 years ago

the path hacks are primarily for use when compiling with something that changes the file system structure.

shadowgate15 commented 2 years ago

Please see @breejs/ts-worker! Send feature requests and bug fixes there! I will work on getting type declarations in package soon.