facelessuser / SerializedDataConverter

Convert between serialized data formats (plist | json | yaml)
Other
26 stars 4 forks source link

Convert on save feature help #15

Closed WebDevLuke closed 4 years ago

WebDevLuke commented 5 years ago

Hey, so I'm trying to configure this so when I save a YAML file, it auto converts to JSON and vice versa. I've added the below options to the plugin's user settings file, but nothing is happening on save. Is their something I'm missing? Maybe a step that I haven't completed to get this working?

I'm on Sublime 3.2.1.

Thanks.

{
    "convert_on_save": [
        {"ext": "tmLanguage.JSON", "command": "json_to_yaml"},
        {"ext": "tmPreferences.JSON", "command": "json_to_yaml"},
        {"ext": "tmTheme.JSON", "command": "json_to_yaml"},
        {"ext": "tmLanguage.YAML", "command": "yaml_to_json"},
        {"ext": "tmPreferences.YAML", "command": "yaml_to_json"},
        {"ext": "tmTheme.YAML", "command": "yaml_to_json"}
    ]
}
facelessuser commented 5 years ago

I actually don't use this feature like I used to. I mainly use the on demand conversion these days. I was looking at the documentation, and apparently I don't make this very clear.

I want to say you also have to define the extension mapping so it knows what to convert the extension to as well:

    "plist_json_conversion_ext": [
        {"plist": "tmLanguage", "json": "tmLanguage.JSON"},
        {"plist": "tmPreferences", "json": "tmPreferences.JSON"},
        {"plist": "tmTheme", "json": "tmTheme.JSON"}
    ],

    "plist_yaml_conversion_ext": [
        {"plist": "tmLanguage", "yaml": "tmLanguage.YAML"},
        {"plist": "tmPreferences", "yaml": "tmPreferences.YAML"},
        {"plist": "tmTheme", "yaml": "tmTheme.YAML"}
    ],

I think when you do that and then add the extension you want to convert on save, it should work.

facelessuser commented 5 years ago

@WebDevLuke, I am assuming this answered your question?

WebDevLuke commented 5 years ago

Hey, sorry no it didn't have an effect. Are you able to get the functionality working your end?

facelessuser commented 5 years ago

Yeah, it is working for me. Here is the related settings I am using. It is the same settings I've had for years, I'm just not editing XXX.JSON files much anymore.

I guess in short you need two things. Apparently, an extension mapping is not one of them as it is optional. If you don't provide an extension mapping, it will just strip the trailing extension and apply a default. So the two things are:

  1. Enable the save feature: "enable_save_to_file_commands": true,. (I assume you are missing this one)
  2. And have the convert on save mapping.
    // Enable creation of new file based on extension map containing the coverted data
    // If the current file to convert does not exist on disk, the converted file will default
    // To being shown in a view buffer only, and will not be automatcially saved to disk.
    "enable_save_to_file_commands": true,

    // When saving converted data to a file, or when opening
    // conversion in new buffer use these extension maps for file name.
    // Extensions will be evaluated in the order listed below.
    // If the file does not match any of the extensions, the current
    // extension will be replaced with either "plist", "json", or "yaml" accordingly.
    "plist_json_conversion_ext": [
        {"plist": "tmLanguage", "json": "tmLanguage.JSON"},
        {"plist": "tmPreferences", "json": "tmPreferences.JSON"},
        {"plist": "tmTheme", "json": "tmTheme.JSON"}
    ],

    "plist_yaml_conversion_ext": [
        {"plist": "tmLanguage", "yaml": "tmLanguage.YAML"},
        {"plist": "tmPreferences", "yaml": "tmPreferences.YAML"},
        {"plist": "tmTheme", "yaml": "tmTheme.YAML"}
    ],

    "json_yaml_conversion_ext": [
        // Nothing to see here; move along
        // Add your rules here
        //{"json": "some extension", "yaml": "some extension"}
    ],

    // Extensions to auto convert from json to plist on save
    // Extensions are case insensitive
    // available commands are:
    //    -json_to_plist
    //    -plist_to_json
    //    -yaml_to_plist
    //    -plist_to_yaml
    //    -json_to_yaml
    //    -yaml_to_json
    "convert_on_save": [
        // Enable or add what you would like
        {"ext": "tmLanguage.JSON", "command": "json_to_plist"},
        {"ext": "tmPreferences.JSON", "command": "json_to_plist"},
        {"ext": "tmTheme.JSON", "command": "json_to_plist"},
        {"ext": "tmLanguage.YAML", "command": "yaml_to_plist"},
        {"ext": "tmPreferences.YAML", "command": "yaml_to_plist"},
        {"ext": "tmTheme.YAML", "command": "yaml_to_plist"}
    ],

If you are having issues still, check the console for errors and post them here. I've confirmed the feature works locally for me still. I probably need to link people to the setting enable_save_to_file_commands from convert_on_save as a reminder.

facelessuser commented 4 years ago

Closing as the issue was not reproducible.