forcedotcom/sf-skills / plugins/builder/consumer-goods/skills/consumer-goods-accruals-datakit-deploy
consumer-goods-accruals-datakit-deploy
VerifiedUse this skill to deploy the TPM Liability Accruals data kit end to end to a Salesforce org. Invoke when a customer or teammate wants to install the accrual engine, verify the Data Cloud connection, deploy the Data Kit components, and schedule the export and accrual calculation chain. Trigger phrases include: 'deploy the accrual data kit', 'set up liability accruals', 'install TPM accruals', 'headless accruals setup', 'configure the Data Cloud export connector', 'schedule the accrual chain'. Do NOT use for creating a Data Space alone (use platform-dataspace-access-configure), for generic Salesforce metadata deployment (use platform-metadata-deploy), for querying org data only (use platform-soql-query), or when setting up the data kit for the Trade Promotion Effectiveness (TPE) feature (use consumer-goods-tpe-datakit-deploy instead).
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 18.9 KB |
| scripts/setup.jsexecutable | script | 10.9 KB |
| scripts/steps/00-check-prerequisites.js | script | 1.9 KB |
| scripts/steps/01-download-static-resource.js | script | 3.5 KB |
| scripts/steps/02-replace-org-id.js | script | 1.6 KB |
| scripts/steps/03-deploy-metadata.js | script | 1.1 KB |
| scripts/steps/04-deploy-engine.js | script | 6.7 KB |
| scripts/steps/05-deploy-tpm-accruals.js | script | 8.9 KB |
| scripts/steps/06-create-dataspace.js | script | 2.0 KB |
| scripts/steps/07-deploy-accruals-reports.js | script | 8.5 KB |
| scripts/steps/08-deploy-ui.js | script | 8.1 KB |
| scripts/steps/09-completion.js | script | 2.5 KB |
| scripts/steps/utils.js | script | 15.8 KB |
scripts/steps/07-deploy-accruals-reports.js
View on GitHubconst { execFileSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const { exec, execDeployJson, getSfBin } = require('./utils');
const OBJECT_SOURCE_TARGET_MAPS_DIR = 'objectSourceTargetMaps';
/**
* Step 7: Deploy Accruals Reports with Data Space replacements.
*
* The Accruals Reports payload contains references between objects (DLOs/DLMs)
* and ObjectSourceTargetMap definitions. The maps reference fields that only
* exist after the other folders (objects, wave, ...) are deployed, so we must
* deploy them in two passes: first everything except objectSourceTargetMaps,
* then objectSourceTargetMaps on its own.
*
* @param {string} orgAlias - The Salesforce org alias
* @param {string} setupDir - The setup directory path
* @param {boolean} skipDataSpace - Whether to skip data space configuration
* @param {string} configuredDataSpaceName - The data space name from config
* @param {string} configuredDataSpacePrefix - The data space prefix from config
* @param {string} namespace - Org namespace prefix (e.g. "cgcloud_dev__"), or '' for unmanaged orgs
* @param {boolean} dryRun - If true, skip deployment but keep temp files
*/
async function deployAccrualsReports(
orgAlias,
setupDir,
skipDataSpace,
configuredDataSpaceName,
configuredDataSpacePrefix,
namespace = '',
dryRun = false
) {
console.log('\n=== Step 7: Deploying Accruals Reports ===');
// Use "default" and empty prefix if skipping data space, otherwise use configured values
const dataSpaceName = skipDataSpace ? 'default' : configuredDataSpaceName;
const dataSpacePrefix = skipDataSpace ? '' : configuredDataSpacePrefix;
console.log(`Data Space Name: ${dataSpaceName}`);
console.log(`Data Space Prefix: ${dataSpacePrefix || '(empty)'}`);
console.log(`Org Namespace: ${namespace || '(none)'}`);
const sourceDir = path.join(setupDir, 'CGCloudAddons', 'TPM', 'Accruals', 'Accruals Reports');
const tempDir = path.join(setupDir, 'temp-accruals-reports');
if (fs.existsSync(tempDir)) {
console.log('Cleaning up existing temp directory...');
fs.rmSync(tempDir, { recursive: true });
}
console.log('Copying Accruals Reports to temp directory...');
copyDirectory(sourceDir, tempDir);
console.log('Replacing Data Space placeholders and namespace in file names and contents...');
replaceDataSpacePlaceholders(tempDir, dataSpaceName, dataSpacePrefix, namespace);
const deployPath = path.join(tempDir, 'force-app');
const defaultDir = path.join(deployPath, 'main', 'default');
const objectSourceTargetMapsPath = path.join(defaultDir, OBJECT_SOURCE_TARGET_MAPS_DIR);
const hasMaps = fs.existsSync(objectSourceTargetMapsPath);
if (dryRun) {
console.log('[DRY RUN] Skipping deployment - files prepared at:');
console.log(` ${tempDir}`);
if (hasMaps) {
console.log(`[DRY RUN] objectSourceTargetMaps would deploy in a second pass from:`);
console.log(` ${objectSourceTargetMapsPath}`);
}
console.log('[DRY RUN] Temp directory preserved for inspection');
console.log('[OK] Step 7 completed (dry run)\n');
return;
}
// Pass 1: Deploy everything except objectSourceTargetMaps. The maps depend on
// fields that only exist once the DLM objects are in place, so we briefly
// move the maps folder out of the deploy tree, deploy the rest, then deploy
// the maps on their own.
let stagedMapsPath = null;
if (hasMaps) {
stagedMapsPath = path.join(tempDir, '__staged-objectSourceTargetMaps');
if (fs.existsSync(stagedMapsPath)) {
fs.rmSync(stagedMapsPath, { recursive: true });
}
console.log('Setting aside objectSourceTargetMaps for the second deployment pass...');
fs.renameSync(objectSourceTargetMapsPath, stagedMapsPath);
}
try {
console.log('Deploying Accruals Reports metadata (pass 1: objects, wave, ...)...');
execDeployJson(['project', 'deploy', 'start', '--source-dir', 'force-app', '--target-org', orgAlias], { cwd: tempDir });
if (stagedMapsPath) {
console.log('Restoring objectSourceTargetMaps for the second deployment pass...');
fs.renameSync(stagedMapsPath, objectSourceTargetMapsPath);
stagedMapsPath = null;
console.log('Deploying Accruals Reports metadata (pass 2: objectSourceTargetMaps)...');
execDeployJson(['project', 'deploy', 'start', '--source-dir', path.relative(tempDir, objectSourceTargetMapsPath).replace(/\\/g, '/'), '--target-org', orgAlias], { cwd: tempDir });
}
} finally {
// If pass 1 failed before we restored the staged maps, put them back so
// dry-run inspection still shows the full tree.
if (stagedMapsPath && fs.existsSync(stagedMapsPath) && !fs.existsSync(objectSourceTargetMapsPath)) {
fs.renameSync(stagedMapsPath, objectSourceTargetMapsPath);
}
}
console.log('Cleaning up temp directory...');
fs.rmSync(tempDir, { recursive: true });
console.log('[OK] Accruals Reports deployed successfully\n');
}
/**
* Recursively copy a directory
*/
function copyDirectory(src, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDirectory(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
/**
* Replace placeholders in a name (file or directory)
* Handles double underscore pattern to avoid DS2__ becoming DS2___
*/
function replaceNamePlaceholders(name, dataSpaceName, dataSpacePrefix, namespace) {
let newName = name;
if (dataSpacePrefix === '') {
newName = newName.replace(/_DATASPACE_PREFIX__/g, '');
} else {
newName = newName.replace(/_DATASPACE_PREFIX__/g, dataSpacePrefix);
}
newName = newName
.replace(/_DATASPACE_PREFIX_/g, dataSpacePrefix)
.replace(/_DATASPACE_NAME_/g, dataSpaceName)
.replace(/_ORG_NS_/g, namespace || '');
return newName;
}
/**
* Replace Data Space placeholders in both file names and file contents
*/
function replaceDataSpacePlaceholders(dir, dataSpaceName, dataSpacePrefix, namespace) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const oldPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
replaceDataSpacePlaceholders(oldPath, dataSpaceName, dataSpacePrefix, namespace);
if (entry.name.includes('_DATASPACE_PREFIX_') || entry.name.includes('_DATASPACE_NAME_') || entry.name.includes('_ORG_NS_')) {
const newName = replaceNamePlaceholders(entry.name, dataSpaceName, dataSpacePrefix, namespace);
const newPath = path.join(dir, newName);
fs.renameSync(oldPath, newPath);
}
} else {
replaceInFile(oldPath, dataSpaceName, dataSpacePrefix, namespace);
if (entry.name.includes('_DATASPACE_PREFIX_') || entry.name.includes('_DATASPACE_NAME_') || entry.name.includes('_ORG_NS_')) {
const newName = replaceNamePlaceholders(entry.name, dataSpaceName, dataSpacePrefix, namespace);
const newPath = path.join(dir, newName);
fs.renameSync(oldPath, newPath);
}
}
}
}
/**
* Replace placeholders in file contents
*/
function replaceInFile(filePath, dataSpaceName, dataSpacePrefix, namespace) {
try {
let content = fs.readFileSync(filePath, 'utf8');
if (content.includes('_DATASPACE_PREFIX_') || content.includes('_DATASPACE_NAME_') || content.includes('_ORG_NS_')) {
if (dataSpacePrefix === '') {
// If dataspace prefix is empty, remove double underscore pattern entirely
content = content.replace(/_DATASPACE_PREFIX__/g, '');
} else {
// Replace double underscore pattern first to avoid double underscores in output
// _DATASPACE_PREFIX__ with DS2_ results in DS2_ (not DS2__)
content = content.replace(/_DATASPACE_PREFIX__/g, dataSpacePrefix);
}
content = content
.replace(/_DATASPACE_PREFIX_/g, dataSpacePrefix)
.replace(/_DATASPACE_NAME_/g, dataSpaceName)
.replace(/_ORG_NS_/g, namespace || '');
fs.writeFileSync(filePath, content, 'utf8');
}
} catch (error) {
if (error.code === 'EISDIR') {
// Directory entry — skip silently, expected when walking mixed trees
return;
}
// Unexpected I/O failure (missing file, permission error, write error)
throw new Error(`Failed to process template file ${filePath}: ${error.message}`, { cause: error });
}
}
module.exports = deployAccrualsReports;
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |