arnoudkooi / sn-scriptsync

Use sn-scriptsync in combination with SN Utils to be able to code in VS Code, including all benefits of a full fledged code editor
https://marketplace.visualstudio.com/items?itemName=arnoudkooicom.sn-scriptsync
Other
43 stars 28 forks source link

_map.json only works as a one way solution #85

Closed Blenderpics closed 1 year ago

Blenderpics commented 1 year ago

Renaming of files and folders (inlcuding the coresponding entry in _map.json) works for the VS-Code -> SN sync, but not vice versa.
A new file/folder will be created with the "generated" name.

It would be nice if this would work both ways. That way you can customize file names and get rid of the autogenerated suffixes in case of file name conflicts. (files with identical names.)

arnoudkooi commented 1 year ago

Not exactly sure what you envision...

Are you on 3.0.3? This version adds a suffix when a double filename is detected

Blenderpics commented 1 year ago

Yes, i am on v3.03.
The suffix is what i am trying to get rid of, for better readability.

My usecase is as follows:
Let's say i have to business rules for two different tables.
The business rules have the same name "Some Business Rule".

SN-Script-Sync will create one file named "SomeBusinessRule.script.js" and one "SomeBusinessRule12EF.script.js".
I want to customize the names of these files, so i can better differentiate between the two.

One should be called "SomeTable_SomeBusinessRule.script.js" and the other one should be called "SomeOtherTable_SomeBusinessRule.script.js".

Renaming the files, and renaming the according entries in _map.json works partially. You are able to make changes within both files and sync them to SN.
However, if you click "sync" WITHIN servicenow a new file will be created following the default naming schema. ("SomeBusinessRule.script.js").

SN-Script-Sync could check if there is an entry with the same sys_id in _map.json before the file on disk gets created.
If there already is an entry in _map.json, the file name of that entry could be used.
That way one could customize the file names, and sn-script-sync should also be more tolerant in case the default naming schema is changed in the future.

Blenderpics commented 1 year ago

To further elaborate:
I am working in a team with multiple developers, so often need to "resync" a file, since another developer changed it.
With the current implementation, each time i would "resync" my manually changed filename will be ignored and a new file following the default naming schema will be created.

arnoudkooi commented 1 year ago

Ok, I understand the use-case. This would require a filesystem watcher and other logic. This is a problem you had in the old version as well I assume?

At this point, I want to focus on stabilizing the 3.x version and do some code restructuring, before considering new features. (Been rather intense to get this change to happen, so I hope in essence you like the update!)

josh-blub01 commented 1 year ago

Co-worker here. No we hadn't had this issue pre version 3 as the file names had the unique sys_id attached to the end of their filename: script^name-of-business-rule^0ce18d33db70e112c14h94d3f3561984.js

arnoudkooi commented 1 year ago

Any direct problems at this point with the changes I made? The duplicate issue should be resolved..

Blenderpics commented 1 year ago

No the changes of >3.0 itself are fine :)
I created a pull request to implement a possible solution for this issue. See https://github.com/arnoudkooi/sn-scriptsync/pull/88

arnoudkooi commented 1 year ago

Need to consider... Does this handle the resync scenario? (It's hard to read the PR because it removes spaces.)

My idea is to add an option to add a name convention per table, like table-operation-whatever_column in other to keep it consistent/automated.

Blenderpics commented 1 year ago

Yes, as soon as there is an entry in _map.json, the filename of that entry will be used instead of the generated one.

I think your proposal and mine are not mutually exclusive solutions and would work quite well together. Even with custom naming rules for each table, filename conflicts will happen, in which case my solution would enable the user to specify a custom name.

Gonna get rid of the whitespace changes after my lunch, so the diff is more readable

Blenderpics commented 1 year ago

Done.