sfcc-env-switcher
v1.0.1
Published
CLI tool to switch Salesforce Commerce Cloud (SFCC/Demandware) environment files for the Prophet VS Code plugin
Maintainers
Readme
sfcc-env-switcher
An interactive CLI tool for switching Salesforce Commerce Cloud (SFCC / Demandware) environment connection files. Designed to work seamlessly with the Prophet Debugger VS Code extension.
Why
Prophet reads its connection settings from a dw.json file in your repository root. When you work across multiple SFCC instances (e.g. dev-us, dev-jp, production-us), you'd normally edit dw.json by hand every time you switch. This tool replaces that with an interactive menu — select an environment, and dw.json is updated instantly. The previously active environment's changes are backed up automatically before switching.
Prerequisites
- Node.js >= 14.0.0
- Prophet Debugger VS Code extension (or any tool that reads
dw.json)
Recommended Folder Structure
Keep the switcher in a separate folder next to your SFCC repository:
parent/
├── your-sfcc-repo/ ← SFCC project (contains dw.json)
└── env-switcher/ ← switcher lives here
├── Config/
│ └── default.json
├── EnvFiles/
│ ├── dev-us.json
│ ├── dev-jp.json
│ └── production-us.json
├── package.json
└── node_modules/Installation
1. Create the switcher folder
mkdir env-switcher
cd env-switcher2. Install the package
npm install sfcc-env-switcher3. Scaffold the config structure
npx sfcc-env-switcher initThis copies the template Config/ and EnvFiles/ directories into your current folder. If they already exist, you will be prompted before anything is overwritten.
4. Edit the config files
Open Config/default.json and point it at your repository:
{
"repo": "../your-sfcc-repo",
"target": "dw.json",
"envFiles": "./EnvFiles"
}| Field | Description |
|------------|-------------------------------------------------------------------------|
| repo | Relative path from the config file to your SFCC repository root |
| target | Path to the dw.json file inside the repo (relative to repo) |
| envFiles | Path to the folder containing your environment files (relative to CWD) |
5. Edit the environment files
Inside EnvFiles/, each .json file represents one environment. The filename becomes the name shown in the menu. Fill in the real values for each instance:
{
"cartridgesPath": "app_storefront_base:modules:",
"version": "version1",
"hostname": "dev-us-short.demandware.net",
"username": "[email protected]",
"password": "your_bm_password"
}These files use the same format as Prophet's dw.json. The easiest starting point is to copy your current working dw.json and adjust per environment.
Usage
Run from the env-switcher folder:
npx sfcc-env-switcherOr add a start script to the local package.json and use npm start:
{
"scripts": {
"start": "sfcc-env-switcher"
}
}You will see an interactive menu listing all configured environments, with the currently active one marked:
? Select Environment
> dev-us (active)
dev-jp
production-us
ExitSelect an environment and press Enter. The tool will:
- Back up the current
dw.jsoncontents into the previously active environment file - Copy the selected environment file into
dw.json
Prophet will pick up the new connection automatically (you may need to restart the uploader).
How Active Environment is Detected
The tool compares the hostname field in dw.json against each environment file. The environment whose hostname matches is marked as active.
License
MIT
