Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Allow script configuration for a specific OS environment/type #484

Closed
estruyf opened this issue Dec 13, 2022 · 3 comments
Closed

Comments

@estruyf
Copy link
Owner

estruyf commented Dec 13, 2022

Currently, the scripts are defined for all OS types. Meaning if you create a bash script, and you would use it for Windows and macOS, it might fail.

A better solution would be the ability to specify scripts per OS type so that you can define a PowerShell script for Windows and a bash script for macOS.

The current script configuration

{
  "$schema": "https://frontmatter.codes/config/custom.scripts.schema.json",
  "title": "Create image folder",
  "id": "create-image-folder",
  "script": "./.frontmatter/config/custom/scripts/create-image-folder.sh",
  "command": "bash"
}

Proposed change:

{
  "$schema": "https://frontmatter.codes/config/custom.scripts.schema.json",
  "title": "Create image folder",
  "id": "create-image-folder",
  "script": "./.frontmatter/config/custom/scripts/create-image-folder.sh",
  "command": "bash",
  "environments": [
    {
      "type": "windows"
      "script": "./.frontmatter/config/custom/scripts/create-image-folder.ps1",
      "command": "powershell"
    }   
  ]
}

By adding the environments property with options for windows, macos, and linux, it would allow you to override the default script for a specific environment.

@estruyf estruyf added the enhancement New feature or request label Dec 13, 2022
@michaeltlombardi
Copy link

It might be worth being able to define a fallback or graceful error message, while we're thinking about cross-platform concerns. For example, both PowerShell and Python are available on Linux, macOS, and Windows, but not on all three by default.

I definitely like this though, extremely useful!

@estruyf
Copy link
Owner Author

estruyf commented Dec 14, 2022

@michaeltlombardi cross-platform is indeed difficult to know what is available on the user's device.

The fallback would be tricky. For instance, if the above PowerShell fails, the fallback could be Bash, but it might fail again. Although, it would already be better to check the two options than count on one. I will check if there is an easy way to validate if the command is available.

estruyf added a commit that referenced this issue Dec 14, 2022
estruyf added a commit that referenced this issue Dec 14, 2022
@michaeltlombardi
Copy link

The easiest way might be to rummage in the PATH (or call which on not-windows, unless there's a helpful javascript function for looking up executables) and skip trying if there's no matching binary (checking for <name>\.\w+ on windows, since it could be a cmd or exe or whatever).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants