jurassiscripts / velociraptor

The npm-style script runner for Deno

Home Page:https://velociraptor.run

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Javascript Support

Lonniebiz opened this issue · comments

Instead of JSON and YAML, I'd prefer to use a JavaScript module. For example, instead of this JSON:

{
  "scripts": {
    "start": "deno run --allow-net server.ts",
    "test": "deno test --allow-net server_test.ts"
  }
}

or this YAML:

# scripts.yaml
scripts:
  start: deno run --allow-net server.ts
  test: deno test --allow-net server_test.ts

I prefer this:

let options = {};
options.scripts = {};
options.scripts.start = "deno run --allow-net server.ts";
options.scripts.test = "deno test --allow-net server_test.ts";
export options;

Granted, my preference is more verbose. However, nothing is more flexible. You could do anything you wanted (programmatically) within this file and Velociraptor should only care about the object that gets exported at the end.

@Lonniebiz Created a PR. Waiting for it to be merged.

Thanks @Lonniebiz for the proposal and @divy-work for the PR!

I wouldn't mind adding this functionality (I initially considered it), but let me just share some considerations about it:

  • these config files are effectively Deno scripts and therefore could need some permissions that vr may not have. This essentially would require all permissions to be granted to vr at install time. Probably not a big deal (also the install command would be much shorter), but I was trying to avoid it if possible...
  • .js configuration files are commonly used, but since Deno's main language is TS wouldn't it be more appropriate to use .ts files? (or at most both of them?)
  • Every time .ts config files are compiled you would get a bunch of Deno logs which interfere with the output of launched scripts (don't know if it's possible to add the -q flag to an installed script though).

What do you think?

@umbopepato : You can support TS, as well, if you like, but since ES6 (where ES Modules and Classes were added to the spec), I personally consider TypeScirpt an antiquated unneeded technology. I'm personally completely against these fake static types that ultimately compile to javascript (which really doesn't have static types, or need them). I feel like everyone has become brainwashed by static type propaganda promoted by a Billion dollar company trying to become the go to place for coding. I know, shocking, huh? I'm sorry to hold back. Here's what I really think.

these config files are effectively Deno scripts and therefore could need some permissions that vr may not have. This essentially would require all permissions to be granted to vr at install time. Probably not a big deal (also the install command would be much shorter), but I was trying to avoid it if possible...

That is true and inevitable. To avoid perm errors the install command must give all perms (which seems fair).

.js configuration files are commonly used, but since Deno's main language is TS wouldn't it be more appropriate to use .ts files? (or at most both of them?)

Yup. I've just added that to the PR.

Every time .ts config files are compiled you would get a bunch of Deno logs which interfere with the output of launched scripts (don't know if it's possible to add the -q flag to an installed script though).

Maybe it is better to let the user know that the config scripts are compiled at runtime so they should expect compile logs from Deno. Though it won't actually interrupt other logs as it is the compiled before any of the configs is processed.

Overall, I think this would be a good feature to introduce as it provides a more dynamic way to make config files.

@Lonniebiz I'm not against you. Keeping whole of Deno community in mind...TS support is necessary

@umbopepato This can be closed now.

For the moment code assistance in .ts configuration files is obtained by manually applying the ScriptsConfiguration type but this will (hopefully) be handled automatically by the editor extensions.

Just to be clear. This will allow me to accomplish the configuration in a .js file correct? The updated documentation only shows typescript. @divy-work

This will allow me to accomplish the configuration in a .js file correct?

@Lonniebiz no, we're supporting only .ts for the reasons discussed above but you can still write JS in TS files since they're sub/supersets of one another. Also, when this is implemented you will get code assistante for the configuration object without needing to manually add types.