Skip to content

Optimize NetSuite SDF workflows with this template that automates deploy.xml creation from change logs for targeted deployments. Ensure smooth transitions and collaborative enhancements.

License

Notifications You must be signed in to change notification settings

devnetkc/NetSuite-CustomModules-Template

Repository files navigation

🚀 NetSuite SuiteScript Project Template: Module Testing & CI/CD Integration

🚀 Introduction

Welcome to the NetSuite SuiteScript Project Template - a cutting-edge solution tailored for module testing and CI/CD integration within the NetSuite ecosystem. This project is meticulously aligned with NS 2023.2, ensuring up-to-date compatibility and performance.

Designed to work seamlessly with the NetSuite-Cust-Jest-Stubs-Template, this template stands as a pivotal tool for NetSuite developers. It facilitates the creation, testing, and deployment of custom SuiteScript modules, promoting efficiency and reliability in the development process.

Core Features

  • SuiteScript Module Development: Crafted specifically for SuiteScript, it acts as an essential starting point for scripting, adhering to NetSuite's best practices and standards.
  • Automated Module Testing: Integrating Jest for automated testing, it ensures your SuiteScript modules function flawlessly, enhancing code reliability.
  • Custom Stub Integration: Allows for the integration of custom Jest stubs, simulating NetSuite's API for isolated testing.
  • CI/CD Integration: Comes with pre-configured Azure Pipeline configurations, automating the integration and deployment processes.
  • Documentation Generation: Utilizes JSDoc comments and Markdown for automatic, detailed documentation of SuiteScript modules.

Local aliases for SuiteScript modules are effectively managed using the /SuiteScript/... path, ensuring compatibility with the NetSuite SuiteScript root directory /SuiteScripts/. This feature simplifies the management of scripts and aligns with NetSuite's directory structure.

Targeted Use Cases

  • NetSuite SuiteScript Developers: Ideal for crafting and managing custom scripts within NetSuite.
  • Quality Assurance and Testing: Ensures rigorous testing routines for NetSuite customizations.
  • CI/CD Pipeline Integration: Seamlessly integrates SuiteScript development into CI/CD workflows.
  • Documentation and Maintenance: Automates documentation for easy maintenance and understanding of scripts.

Leverage this template to elevate your SuiteScript development workflow, ensuring robust, well-tested, and efficiently integrated scripts within your NetSuite environment.

🎉 Getting Started

  1. Open ./package.json and customize the project configuration.
  2. Add your ExcludeStubs path aliases to jest.config.js.
  3. Create a local environment variable NPM_TOKEN using your NPM token (variable name can be changed in .npmrc).
  4. Run npm i to install project dependencies.
  5. Run npm run generate-manifests to create deploy.xml and manifest.xml, essential for SuiteCloud tools.
  6. Setup SuiteCloud account details:
    • CLI (update $() variables with your values): npm run setup-server --sourcebranch=$(SOURCEBRANCH) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$(TOKENID) --tokensecret=$(TOKENSECRET)
    • VSCode: Open command pallet (CMD + SHIFT + p on MacOS, CTRL + SHIFT + p on Windows), then select & run SuiteCloud: Set Up Account.

🧐 Notable Files

  • manifest.tpl.xml - Template for SuiteCloud project manifest. (Project Name Change Required)
  • README.hbs - Base template for generating project README.md.
  • npmrc - NPM environment token loader for publishing (variable name NPM_TOKEN can be changed).
  • docsMD.config - Generator for Markdown documentation from JSDoc notations.
  • jsDocsConf.json - Configuration for JSDoc generation. Update base_url from localhost for hosted documentation.
  • New scripts like flattenObjectPath.sh, rmDependents.sh, and web.config.private for improved project management.

🔨 Scripts

Use npm run <script> to execute various project commands:

  • npm run test - Run tests using Jest. (See Running Tests for details.)
  • npm run docs - Generate project documentation from JSDoc notations (configure with docsMD.config & jsDocsConf.json).
  • npm run open-docs - Open documentation in a browser for viewing.
  • npm run generate-manifests - Generate deploy.xml & manifest.xml for SuiteCloud.
  • npm run generate-manifests --headbranch=main --sourcebranch=dev - Generate change-based deploy.xml & manifest.xml.

✅ Running Tests

  • npm run test - Run Jest tests in ./__tests__.
  • npm run test-ci - Run Jest tests in CI mode, creating junit reports.
  • npm run test --watch=watch - Run Jest tests in watch mode.
  • npm run view-coverage - Run tests and open coverage report.

Wallaby.js

Wallaby.js

Repository contributors can use the Wallaby.js OSS License for immediate test results.

👷 CI/CD

Azure yaml pipeline files in .ci/workflows are designed to automate and streamline the CI/CD processes for different deployment scenarios:

  • azure-pipelines-docs.yml: Generates project documentation based on JSDoc comments, commits the changes, and pushes them back to the current PR or branch. This ensures that the documentation is always up-to-date with the codebase.
  • azure-pipelines-build-deploy.yml: Executes Jest tests, generates a change-based deploy.xml, updates manifest dependencies, and uses the SuiteCloud CLI to deploy the project to NetSuite. This pipeline ensures that only tested and verified changes are deployed.
  • azure-pipelines-build-prod.yml: Tailored for production environment deployments. It validates production pull requests and creates a release for the main branch.
  • azure-pipelines-build-sb.yml: Focused on deployments to a Sandbox 1 environment. It facilitates testing and validation in a sandbox before changes are moved to production.
  • azure-pipelines-build-sb2.yml: Similar to azure-pipelines-build-sb.yml but targets a Sandbox 2 environment, providing an additional layer of testing or for separate feature testing.
  • azure-pipelines-select-branch.yml: Assists in determining the source branch for a pull request, ensuring that the correct branch is used for comparisons and deployments in CI/CD processes.
  • azure-pipelines-validate-prod-pr.yml: Validates pull requests against the production branch, ensuring that only approved and compliant changes are merged.

These pipelines collectively support a robust and flexible CI/CD process, enabling automatic testing, documentation updates, and deployment to various environments, ensuring consistency and reliability in software delivery.

📝 Documentation

Comprehensive project documentation is available, detailing setup, configuration, and usage instructions.

Modules

csExampleModule_CS

Your custom NetSuite Client Script module

aModule

This is example custom NetSuite module A. It may or may not be in your SuiteCloud project. Update your jest.config.js to map this module from the stub pkg to your local project if it is available. See project jest.config.js for further examples of this.

/SuiteScripts/Modules/aModule

NetSuite module A export function

Functions

csExampleModule_CS(log, aModule, bModule)

Custom NetSuite Client Script module export function

csExampleModule_CS

Your custom NetSuite Client Script module

Summary: This is example custom NetSuite Client Script module. It may or may not be in your SuiteCloud project. Update your jest.config.js to map this module from the stub pkg to your local project if it is available. See project jest.config.js for further examples of this.
Format:
Napiversion: 2.1
Since: 2022.2
Version: 1.0.0
License: NApiVersion

aModule

This is example custom NetSuite module A. It may or may not be in your SuiteCloud project. Update your jest.config.js to map this module from the stub pkg to your local project if it is available. See project jest.config.js for further examples of this.

Format:
Napiversion: 2.1
Since: 2022.2
Version: 1.0.0
License: NApiVersion

/SuiteScripts/Modules/aModule

NetSuite module A export function

Param Type Description
query Object NS query module
log Object NS log module

/SuiteScripts/Modules/aModule.GetVendorPrefix(vendorId) ⇒ String

Returns preferred vendor prefix from record or blank if no prefix is located

Kind: static method of /SuiteScripts/Modules/aModule

Param Type Description
vendorId String Entity ID of vendor Ex: 4321

/SuiteScripts/Modules/aModule.RunQuery(vendorId) ⇒ String

Returns query result of vendor prefix from vendor record

Kind: static method of /SuiteScripts/Modules/aModule
Returns: String - - Returns vendor prefix string from query result
Access: protected

Param Type Description
vendorId String Vendor entity ID to run query on

Happy Coding! 🥳

About

Optimize NetSuite SDF workflows with this template that automates deploy.xml creation from change logs for targeted deployments. Ensure smooth transitions and collaborative enhancements.

Topics

Resources

License

Stars

Watchers

Forks