What is the best practice for custom scripts?

Hi,

I have created a custom script (javascript) for Support Issue which calls a server side Python script. I am planning a deployment strategy for these few pieces of my code. My question:

  1. What is the best way to version control my code
  2. What is the best deployment strategy for a setup like this ?

Any comments or suggestion from people who have deployed frappe sites in the wild very much welcomed.

@The_Lowkster, the best way is using a app!

The deployinment is covered by this!
By default we use git and github to source code version control.

What about the custom script that I added to one of the doctype in erpnext ?

@The_Lowkster, when do you mean custom script I only understood about Setup > Customize > Custom Script that is coded in JS, this you can manage as fixtures, in your app.

If are you talking about Python code it can be defined using hooks! Check the app development tutorial! https://frappe.github.io/frappe/user/

Yeah that is what I did. So you mean by adding fixtures, I can somehow save the contents of the custom script and use that during deployment ?

@The_Lowkster, exactly!

To store your custom script from the db to an app, you need run bench export-fixtures, it will create some files in your app, to the custom script!

An alternative way is:

You can add a folder under your_app/fixtures/custom_script, and in this folder add your custom scripts as:

Sales Order.js
Sales Invoice.js
Quotation.js

etc

5 Likes

Thank you!

@max_morais_dmm taking this issue I have doubts …
when developing my custom app I have created custom fields, scripts and for me to have those on my client side I need to export-fixtures correct?
If i export the json file will be created … and not the custom_script folder (need to create manually) and for me to have the eg. sales_order.js need to copy the text from the custom_script (IE) to this created file correct ?

What is happening with me is that I have created the custom_script folder and when I do export-fixtures I still need to copy the changed script to the file … and when installing on the client and doing the migrate errors like doctype sales_order does not exist !!!

If you are doing export-fixtures (and you have defined custom scripts as a fixture in you hooks.py file) then you do not need to make a custom script folder or a .js file. The system will create a .json file with all the information from your custom scripts. When you install or update the app on your other installation the .json file will rebuild your custom script and you will see it again in Setup–>Custom Scripts exactly like you had it.
Making a custom scripts folder and .js file is just another option for storing custom scripts in your app.

thanks for the tips.