|
| 1 | +# 🚀 NetSuite SuiteScript Project Template: Module Testing & CI/CD Integration |
| 2 | + |
| 3 | +## 🚀 Introduction |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +Designed to work seamlessly with the [NetSuite-Cust-Jest-Stubs-Template](https://github.com/devnetkc/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. |
| 8 | + |
| 9 | +### Core Features |
| 10 | + |
| 11 | +- **SuiteScript Module Development:** Crafted specifically for SuiteScript, it acts as an essential starting point for scripting, adhering to NetSuite's best practices and standards. |
| 12 | +- **Automated Module Testing:** Integrating Jest for automated testing, it ensures your SuiteScript modules function flawlessly, enhancing code reliability. |
| 13 | +- **Custom Stub Integration:** Allows for the integration of custom Jest stubs, simulating NetSuite's API for isolated testing. |
| 14 | +- **CI/CD Integration:** Comes with pre-configured Azure Pipeline configurations, automating the integration and deployment processes. |
| 15 | +- **Documentation Generation:** Utilizes JSDoc comments and Markdown for automatic, detailed documentation of SuiteScript modules. |
| 16 | + |
| 17 | +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. |
| 18 | + |
| 19 | +### Targeted Use Cases |
| 20 | + |
| 21 | +- **NetSuite SuiteScript Developers:** Ideal for crafting and managing custom scripts within NetSuite. |
| 22 | +- **Quality Assurance and Testing:** Ensures rigorous testing routines for NetSuite customizations. |
| 23 | +- **CI/CD Pipeline Integration:** Seamlessly integrates SuiteScript development into CI/CD workflows. |
| 24 | +- **Documentation and Maintenance:** Automates documentation for easy maintenance and understanding of scripts. |
| 25 | + |
| 26 | +Leverage this template to elevate your SuiteScript development workflow, ensuring robust, well-tested, and efficiently integrated scripts within your NetSuite environment. |
| 27 | + |
| 28 | +## 🎉 Getting Started |
| 29 | + |
| 30 | +1. Open [`./package.json`](./package.json) and customize the project configuration. |
| 31 | +2. Add your `ExcludeStubs` path aliases to [`jest.config.js`](./jest.config.js). |
| 32 | +3. Create a local environment variable `NPM_TOKEN` using your NPM token (variable name can be changed in [`.npmrc`](./.npmrc)). |
| 33 | +4. Run `npm i` to install project dependencies. |
| 34 | +5. Run `npm run generate-manifests` to create `deploy.xml` and `manifest.xml`, essential for SuiteCloud tools. |
| 35 | +6. Setup SuiteCloud account details: |
| 36 | + - CLI (update `$()` variables with your values): `npm run setup-server --sourcebranch=$(SOURCEBRANCH) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$(TOKENID) --tokensecret=$(TOKENSECRET)` |
| 37 | + - VSCode: Open command pallet (`CMD + SHIFT + p` on MacOS, `CTRL + SHIFT + p` on Windows), then select & run `SuiteCloud: Set Up Account`. |
| 38 | + |
| 39 | +## 🧐 Notable Files |
| 40 | + |
| 41 | +- [`manifest.tpl.xml`](./ci/templates/manifest.tpl.xml) - Template for SuiteCloud project manifest. (Project Name Change Required) |
| 42 | +- [`README.hbs`](./.ci/templates/README.hbs) - Base template for generating project README.md. |
| 43 | +- [`npmrc`](./.npmrc) - NPM environment token loader for publishing (variable name `NPM_TOKEN` can be changed). |
| 44 | +- [`docsMD.config`](./.ci/config/docsMD.config.js) - Generator for Markdown documentation from JSDoc notations. |
| 45 | +- [`jsDocsConf.json`](./.ci/config/jsDocsConf.json) - Configuration for JSDoc generation. Update `base_url` from `localhost` for hosted documentation. |
| 46 | +- New scripts like `flattenObjectPath.sh`, `rmDependents.sh`, and `web.config.private` for improved project management. |
| 47 | + |
| 48 | +## 🔨 Scripts |
| 49 | + |
| 50 | +Use `npm run <script>` to execute various project commands: |
| 51 | + |
| 52 | +- `npm run test` - Run tests using Jest. (See [Running Tests](#-running-tests) for details.) |
| 53 | +- `npm run docs` - Generate project documentation from JSDoc notations (configure with [docsMD.config](./.ci/config/docsMD.config.js) & [jsDocsConf.json](./.ci/config/jsDocsConf.json)). |
| 54 | +- `npm run open-docs` - Open documentation in a browser for viewing. |
| 55 | +- `npm run generate-manifests` - Generate `deploy.xml` & `manifest.xml` for SuiteCloud. |
| 56 | +- `npm run generate-manifests --headbranch=main --sourcebranch=dev` - Generate change-based `deploy.xml` & `manifest.xml`. |
| 57 | + |
| 58 | +### ✅ Running Tests |
| 59 | + |
| 60 | +- `npm run test` - Run Jest tests in `./__tests__`. |
| 61 | +- `npm run test-ci` - Run Jest tests in CI mode, creating junit reports. |
| 62 | +- `npm run test --watch=watch` - Run Jest tests in watch mode. |
| 63 | +- `npm run view-coverage` - Run tests and open coverage report. |
| 64 | + |
| 65 | +#### Wallaby.js |
| 66 | + |
| 67 | +[](https://wallabyjs.com/oss/) |
| 68 | + |
| 69 | +Repository contributors can use the [Wallaby.js OSS License](https://wallabyjs.com/oss/) for immediate test results. |
| 70 | + |
| 71 | +## 👷 CI/CD |
| 72 | + |
| 73 | +Azure yaml pipeline files in [`.ci/workflows`](./.ci/workflows) are designed to automate and streamline the CI/CD processes for different deployment scenarios: |
| 74 | + |
| 75 | +- [`azure-pipelines-docs.yml`](./.ci/workflows/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. |
| 76 | +- [`azure-pipelines-build-deploy.yml`](./.ci/workflows/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. |
| 77 | +- [`azure-pipelines-build-prod.yml`](./.ci/workflows/azure-pipelines-build-prod.yml): Tailored for production environment deployments. It validates production pull requests and creates a release for the main branch. |
| 78 | +- [`azure-pipelines-build-sb.yml`](./.ci/workflows/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. |
| 79 | +- [`azure-pipelines-build-sb2.yml`](./.ci/workflows/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. |
| 80 | +- [`azure-pipelines-select-branch.yml`](./.ci/workflows/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. |
| 81 | +- [`azure-pipelines-validate-prod-pr.yml`](./.ci/workflows/azure-pipelines-validate-prod-pr.yml): Validates pull requests against the production branch, ensuring that only approved and compliant changes are merged. |
| 82 | + |
| 83 | +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. |
| 84 | + |
| 85 | + |
| 86 | +## 📝 Documentation |
| 87 | + |
| 88 | +Comprehensive project documentation is available, detailing setup, configuration, and usage instructions. |
| 89 | + |
| 90 | +## Modules |
| 91 | + |
| 92 | +<dl> |
| 93 | +<dt><a href="#module_csExampleModule_CS">csExampleModule_CS</a></dt> |
| 94 | +<dd><p>Your custom NetSuite Client Script module</p> |
| 95 | +</dd> |
| 96 | +<dt><a href="#module_aModule">aModule</a></dt> |
| 97 | +<dd><p>This is example custom NetSuite module A. It may or may not be in your SuiteCloud project. |
| 98 | +Update your <code>jest.config.js</code> to map this module from the stub pkg to your local project if it is available. |
| 99 | +See project <code>jest.config.js</code> for further examples of this.</p> |
| 100 | +</dd> |
| 101 | +<dt><a href="#module_/SuiteScripts/Modules/aModule">/SuiteScripts/Modules/aModule</a></dt> |
| 102 | +<dd><p>NetSuite module A export function</p> |
| 103 | +</dd> |
| 104 | +</dl> |
| 105 | + |
| 106 | +## Functions |
| 107 | + |
| 108 | +<dl> |
| 109 | +<dt><a href="#exp_module_/SuiteScripts/CS/csExampleModule_CS--csExampleModule_CS">csExampleModule_CS(log, aModule, bModule)</a> ⏏</dt> |
| 110 | +<dd><p>Custom NetSuite Client Script module export function</p> |
| 111 | +</dd> |
| 112 | +</dl> |
| 113 | + |
| 114 | +<a name="module_csExampleModule_CS"></a> |
| 115 | + |
| 116 | +## csExampleModule\_CS |
| 117 | +Your custom NetSuite Client Script module |
| 118 | + |
| 119 | +**Summary**: This is example custom NetSuite Client Script module. It may or may not be in your SuiteCloud project. |
| 120 | +Update your `jest.config.js` to map this module from the stub pkg to your local project if it is available. |
| 121 | +See project `jest.config.js` for further examples of this. |
| 122 | +**Format**: |
| 123 | +**Napiversion**: 2.1 |
| 124 | +**Since**: 2022.2 |
| 125 | +**Version**: 1.0.0 |
| 126 | +**License**: NApiVersion |
| 127 | +<a name="module_aModule"></a> |
| 128 | + |
| 129 | +## aModule |
| 130 | +This is example custom NetSuite module A. It may or may not be in your SuiteCloud project. |
| 131 | +Update your `jest.config.js` to map this module from the stub pkg to your local project if it is available. |
| 132 | +See project `jest.config.js` for further examples of this. |
| 133 | + |
| 134 | +**Format**: |
| 135 | +**Napiversion**: 2.1 |
| 136 | +**Since**: 2022.2 |
| 137 | +**Version**: 1.0.0 |
| 138 | +**License**: NApiVersion |
| 139 | +<a name="module_/SuiteScripts/Modules/aModule"></a> |
| 140 | + |
| 141 | +## /SuiteScripts/Modules/aModule |
| 142 | +NetSuite module A export function |
| 143 | + |
| 144 | + |
| 145 | +| Param | Type | Description | |
| 146 | +| --- | --- | --- | |
| 147 | +| query | <code>Object</code> | NS query module | |
| 148 | +| log | <code>Object</code> | NS log module | |
| 149 | + |
| 150 | + |
| 151 | +* [/SuiteScripts/Modules/aModule](#module_/SuiteScripts/Modules/aModule) |
| 152 | + * [.GetVendorPrefix(vendorId)](#module_/SuiteScripts/Modules/aModule.GetVendorPrefix) ⇒ <code>String</code> |
| 153 | + * [.RunQuery(vendorId)](#module_/SuiteScripts/Modules/aModule.RunQuery) ⇒ <code>String</code> |
| 154 | + |
| 155 | +<a name="module_/SuiteScripts/Modules/aModule.GetVendorPrefix"></a> |
| 156 | + |
| 157 | +### /SuiteScripts/Modules/aModule.GetVendorPrefix(vendorId) ⇒ <code>String</code> |
| 158 | +Returns preferred vendor prefix from record or blank if no prefix is located |
| 159 | + |
| 160 | +**Kind**: static method of [<code>/SuiteScripts/Modules/aModule</code>](#module_/SuiteScripts/Modules/aModule) |
| 161 | + |
| 162 | +| Param | Type | Description | |
| 163 | +| --- | --- | --- | |
| 164 | +| vendorId | <code>String</code> | Entity ID of vendor Ex: `4321` | |
| 165 | + |
| 166 | +<a name="module_/SuiteScripts/Modules/aModule.RunQuery"></a> |
| 167 | + |
| 168 | +### /SuiteScripts/Modules/aModule.RunQuery(vendorId) ⇒ <code>String</code> |
| 169 | +Returns query result of vendor prefix from vendor record |
| 170 | + |
| 171 | +**Kind**: static method of [<code>/SuiteScripts/Modules/aModule</code>](#module_/SuiteScripts/Modules/aModule) |
| 172 | +**Returns**: <code>String</code> - - Returns vendor prefix string from query result |
| 173 | +**Access**: protected |
| 174 | + |
| 175 | +| Param | Type | Description | |
| 176 | +| --- | --- | --- | |
| 177 | +| vendorId | <code>String</code> | Vendor entity ID to run query on | |
| 178 | + |
| 179 | + |
| 180 | +Happy Coding! 🥳 |
0 commit comments