SuiteCloud Project Files in SuiteCloud CLI for Node.js

Your project configuration is stored in the suitecloud.config.js file in your project folder.

Suitecloud.config.js File

This file is created when you run suitecloud project:create -i and defines the default folder for your project. By default, the structure of the file looks like this:

            module.exports = {
         defaultProjectFolder: "src",
         commands: {}
}; 

          

You can use this file to add customizations to SuiteCloud CLI for Node.js commands. You can add code to inject logic such as defining different folders for specific commands, setting command flags, or adding unit tests.

Note:

Use the same command names used by SuiteCloud CLI for Node.js. To make sure you use the right names, see SuiteCloud CLI for Node.js Commands Reference.

Suitecloud.config.js File Entry Points

To trigger command customizations, you can use these entry points on different commands:

  • beforeExecuting: The code runs before the command runs.

  • onCompleted: The code runs after the command finishes successfully (without errors).

  • onError: The code runs if an error is thrown.

Suitecloud.config.js Customizations

The suitecloud.config.js file lets you do the following customizations:

  • Set command options so you don't have to pass their value every time you run the command. To call a command option, enter options.argument.[optionName], then, set the value you want as default.

    For example, if you want to apply content protection every time you deploy a SuiteApp, add this code:

                      commands: {
          "project:deploy": {
            beforeExecuting: options => {
           options.arguments.applycontentprotection = true;
          return options;
        },
      },
    }; 
    
                    
    Note:

    Use the same option names as SuiteCloud CLI for Node.js. To make sure you use the right names, see SuiteCloud CLI for Node.js Commands Reference and check the Option table in the commands section you want to customize. You can also see the possible values of the options.

  • Add messages to any of the three entry points. These messages show up along with SuiteCloud CLI for Node.js logs. To display a custom message, create a function on an entry point and log it to the console.

    For example, if you want to show a message in your console every time you import files, add this code:

                      commands: {
            "file:import": {
                beforeExecuting: myMessage => {
                    console.log("We're importing SuiteScript files...");
                },
            },
    }; 
    
                    
  • Set a project folder different from the default one.

    For example, if you want to run all your commands from the src folder, but deploy from the dist folder, add this code:

                      module.exports = {
        defaultProjectFolder: 'src',
        commands: {
            "project:deploy": {
                projectFolder: 'dist',
            },
        },
    }; 
    
                    
    Note:

    The folder you set needs to be inside of the project folder.

  • You can add your own code to run unit tests, for example. You can add it to any of the three entry points.

Suitecloud.config.js File Example

Here's an example of a customized suitecloud.config.js file.

              module.exports = {
    defaultProjectFolder: 'src',
    commands: {
        "project:deploy": {
            projectFolder: 'dist',
            beforeExecuting: async options => {
                options.arguments.validate = true;
                // You can run some build processes or unit tests here.
                // You should return the options object or a Promise that returns the options object on resolve.
                return options;
            },
            onCompleted: output => {
                console.log("Eureka! The deployment was a success.");
            },
            onError: error => {
                console.log("Houston, we've had a problem here. The deployment failed.");
            },
        },
        "project:validate": {
            projectFolder: 'dist',
        },
        "project:adddependencies": {
            projectFolder: 'dist',
        },
    },
}; 

            

In this example, these customizations have been set:

  • project:deploy command

    • The command is run from the dist folder instead of the default src folder.

    • Before the command runs, the project gets validated locally.

    • When the command finishes without errors, you'll see this message in the console: Eureka! The deployment was a success.

    • If there's an error, you'll see this message in the console: Houston, we've had a problem here. The deployment failed.

  • project:validate command: This command runs from the dist folder, instead of the default src folder.

  • project:adddependencies command: This command runs from the dist folder, instead of the default src folder.

Related Topics

General Notices