Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | #!/usr/bin/env node
/**
* SCS (Static Content Service) Release Script
*
* Copies versioned CSS files from SLDS1 and SLDS2 dist outputs into the
* slds-scs repo, bumps its package version, updates scs/files.json,
* optionally downloads the latest scs-client from Nexus, and creates a PR.
*
* Migrated from design-system-dist/lib/scs.js to resolve source paths
* locally from within the salesforce-design-system monorepo.
*
* Configuration sources (in priority order):
* 1. CLI arguments (--key=value)
* 2. Environment variables
* 3. .release-config (versions, WI, CODE_DIR)
* 4. .distrc.json (nexusCreds)
* 5. Interactive prompts
*
* Usage:
* yarn workspace @salesforce-ux/design-system scs
* yarn workspace @salesforce-ux/design-system scs -- --wi W-9925295 --case=29996318
* yarn workspace @salesforce-ux/design-system scs:patch
*
* Prerequisites:
* - TMP Auth
* - Cloned ux/slds-scs fork
* - .distrc.json with nexusCreds (or provide via CLI/prompt)
* - .release-config with version info (or provide via CLI/prompt)
*/
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import process from 'node:process';
import fs from 'fs-extra';
import execa from 'execa';
import enquirer from 'enquirer';
const { prompt } = enquirer;
import { FileParser } from './file-parser.js';
import { getTargetBranch } from './scs-utils.js';
import { loadConfig } from './config-loader.js';
import * as autoVersion from './version-utils.js';
// ------------------------------------------------------------------
// Path setup
// ------------------------------------------------------------------
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// packages/design-system (two levels up from scripts/scs/)
const packageRoot = path.resolve(__dirname, '../..');
const rootPath = (...args) => path.resolve(packageRoot, ...args);
// ------------------------------------------------------------------
// Configuration
// ------------------------------------------------------------------
const config = loadConfig(packageRoot);
// Source paths resolved locally within the monorepo
const SLDS1_DIST_PATH = rootPath('dist');
const SLDS2_DIST_PATH = rootPath('../design-system-2/dist');
// Read SLDS1 version from dist package.json
let slds1DistVersion = null;
try {
slds1DistVersion = autoVersion.getVersion(path.join(SLDS1_DIST_PATH, 'package.json'));
console.log(`Found SLDS1 version in dist package.json: ${slds1DistVersion}`);
} catch (err) {
console.log('Could not read SLDS1 version from dist package.json:', err.message);
}
// Read SLDS2 version from design-system-2 package.json
let slds2DistVersion = null;
try {
slds2DistVersion = autoVersion.getVersion(rootPath('../design-system-2/package.json'));
console.log(`Found SLDS2 version in package.json: ${slds2DistVersion}`);
} catch (err) {
console.log('Could not read SLDS2 version from design-system-2 package.json:', err.message);
}
// ------------------------------------------------------------------
// Interactive prompts (fills in anything not provided via config)
// ------------------------------------------------------------------
async function ask() {
return prompt([
config.nexusCreds || {
type: 'input',
name: 'nexusCreds',
message: 'Please provide your Nexus token in user:pass format\n ',
result(creds) {
return creds;
},
},
config.wi || {
type: 'input',
name: 'wi',
message: 'GUS Work Item Number?\n ',
result(wiNumber) {
return wiNumber;
},
},
config.case || {
type: 'input',
name: 'case',
message: 'GUS Change Case Number?\n ',
result(caseNumber) {
return caseNumber;
},
},
config.sldsVersion || {
type: 'input',
name: 'sldsVersion',
message: `SLDS1 Version?\n `,
initial: slds1DistVersion || '',
result(version) {
return version;
},
},
config.slds2Version || {
type: 'input',
name: 'slds2Version',
message: `SLDS2 Version (for slds-plus files)?\n `,
initial: slds2DistVersion || '',
result(version) {
return version;
},
},
config.doPR || {
type: 'toggle',
name: 'doPR',
message: 'Do you want to create the PR?\n ',
enabled: 'Yep',
disabled: 'Nope',
},
config.patch || {
type: 'toggle',
name: 'patch',
message: 'Target master-patch branch instead of master?\n ',
enabled: 'Yes',
disabled: 'No',
},
]).catch(console.error);
}
// ------------------------------------------------------------------
// Main
// ------------------------------------------------------------------
ask().then((answers) => {
const scsRepo = 'slds-scs';
const scsTargetRepoOwner = 'aura';
const scsForkedRepoOwner = 'ux';
const scsTargetRepo = `${scsTargetRepoOwner}/${scsRepo}`;
// Source dir for SLDS1 CSS files (local dist)
const srcDir = () => SLDS1_DIST_PATH;
// Staging directory for intermediate copies
const destDir = () => rootPath('.dist/scs/slds');
// slds-scs repo directory (from config or fallback)
const scsRepoDir = () => config.scsRepoPath;
// Resolve values from config or prompt answers
const nexusCredentials = config.nexusCreds || answers['nexusCreds'];
const workItemId = config.wi || answers['wi'];
const gusChangeCase = config.case || answers['case'];
const sldsVersion = config.sldsVersion || answers['sldsVersion'];
const sldsVersionSemver = autoVersion.toSemver(sldsVersion);
const slds2Version = config.slds2Version || answers['slds2Version'];
const slds2VersionSemver = autoVersion.toSemver(slds2Version);
const isPatch = config.patch || answers['patch'];
console.log('Using SLDS1 version:', sldsVersion, '\u2192', sldsVersionSemver);
console.log('Using SLDS2 version:', slds2Version, '\u2192', slds2VersionSemver);
const targetBranch = getTargetBranch(isPatch);
const prBody = `[GUS](https://gus.my.salesforce.com/apex/ADM_WorkLocator?bugorworknumber=${workItemId})
GUS Case Object:
@gus-change-case: ${gusChangeCase}@`;
// ------------------------------------------------------------------
// CSS file mappings
// SLDS1 files come from the local dist (packages/design-system/dist)
// SLDS2 files come from sibling package (packages/design-system-2/dist)
// ------------------------------------------------------------------
const scsFiles = [
{
src: path.join(srcDir(), 'assets/styles/salesforce-lightning-design-system_touch.css'),
dest: `${destDir()}/`,
filename: `slds-touch-${sldsVersionSemver}.css`,
},
{
src: path.join(srcDir(), 'assets/styles/salesforce-lightning-design-system.css'),
dest: `${destDir()}/`,
filename: `slds-${sldsVersionSemver}.css`,
},
{
src: path.join(srcDir(), 'assets/styles/salesforce-lightning-design-system-legacy.css'),
dest: `${destDir()}/`,
filename: `slds-legacy-${sldsVersionSemver}.css`,
},
{
src: path.join(srcDir(), 'assets/styles/salesforce-lightning-design-system-offline.css'),
dest: `${destDir()}/`,
filename: `slds-offline-${sldsVersionSemver}.css`,
},
{
src: path.join(SLDS2_DIST_PATH, 'css/bundled/slds2.cosmos.css'),
dest: `${destDir()}/`,
filename: `slds-plus-${slds2VersionSemver}.css`,
},
{
src: path.join(SLDS2_DIST_PATH, 'css/bundled/slds2.scoped.cosmos.css'),
dest: `${destDir()}/`,
filename: `scoped-slds-plus-${slds2VersionSemver}.css`,
},
];
// Clear existing SCS files in staging folder
fs.removeSync(rootPath('.dist/scs'));
// Copy the new CSS files to staging
// Since pre-release candidates share the same css file names, they will get replaced automatically.
scsFiles.forEach(({ src, dest, filename }) => {
try {
fs.copySync(src, `${dest}${filename}`);
console.log('copy sync success!\u2026', dest, filename);
} catch (err) {
console.log('copy sync error!\u2026', dest, filename);
console.log(err);
}
});
const gitAdd = (filePath) => {
const command = execa.commandSync(`git add -f ${filePath}`);
console.log(`added ${filePath}`, command);
};
const gitRm = (filePath) => {
const command = execa.commandSync(`git rm ${filePath}`);
console.log(`removed ${filePath}`, command);
};
// ------------------------------------------------------------------
// slds-scs repo operations (output side - unchanged)
// ------------------------------------------------------------------
// Change to scs repo
process.chdir(scsRepoDir());
// Clean up and reset
execa.commandSync('git reset --hard');
execa.commandSync(`git checkout ${targetBranch}`);
execa.commandSync(
`git pull git@git.soma.salesforce.com:aura/slds-scs.git ${targetBranch}`,
);
execa.commandSync(`git push origin ${targetBranch}`);
// Copy staged CSS files to scs repo
try {
fs.copySync(destDir(), path.join(scsRepoDir(), 'slds'));
console.log('copy sync success!\u2026', destDir(), path.join(scsRepoDir(), 'slds'));
} catch (err) {
console.log('copy sync error!\u2026', destDir(), path.join(scsRepoDir(), 'slds'));
console.log(err);
}
// Get scs repo package version from package.json
// Used to map the SLDS version to package for LWR. Version 2.14 is the version before LWR began, or version 0
const lwrMappedVersion =
autoVersion.parse(autoVersion.getVersion(srcDir())).minor - 14;
// Update the slds-scs package version
const packageVersion = autoVersion.getVersion(scsRepoDir());
const newPackageVersion = autoVersion.patch(packageVersion);
// Set scs repo package version in package.json
autoVersion.setVersion(newPackageVersion);
// Add package.json
gitAdd('package.json');
const branchName = `release-${newPackageVersion}-slds-${sldsVersion}-slds-plus-${slds2Version}`;
// Create branch
try {
execa.commandSync(`git show-ref --quiet refs/heads/${branchName}`);
execa.commandSync(`git branch -D ${branchName}`);
console.log(branchName, 'exists\u2026and deleted');
} catch (err) {
console.log(branchName, "doesn't exist");
}
execa.commandSync(`git checkout -b ${branchName}`);
console.log(`checked out ${branchName}`);
gitAdd('slds');
// Edit existing scs/files.json to add the new version and return any rejected versions
const filesJsonString = fs.readFileSync('scs/files.json');
const jsonData = JSON.parse(filesJsonString);
const [updatedFiles, rejectFiles] = FileParser(
sldsVersionSemver,
lwrMappedVersion,
jsonData,
[],
[3, 3, 3],
slds2VersionSemver,
);
fs.writeFileSync('scs/files.json', JSON.stringify(updatedFiles, null, 2));
console.log(
'scs/files.json edited with version',
sldsVersion,
execa.commandSync('cat scs/files.json', { shell: true }).stdout,
);
gitAdd('scs/files.json');
// Remove all rejected files
rejectFiles
.map((f) => f.filePath)
.forEach((filePath) => {
fs.removeSync(filePath);
gitRm(filePath);
});
// ------------------------------------------------------------------
// SCS Client download and git add
// ------------------------------------------------------------------
// Get existing scs-client version
const cmdListScsClientVersion = `ls tnrp/scs* | sed -E "s/..*([[:digit:]]\\.[[:digit:]]\\.[[:digit:]]{1,3})..*/\\1/g"`;
const { stdout: scsClientVersion } = execa.commandSync(
cmdListScsClientVersion,
{ shell: true },
);
console.log('existing scs-client version:', scsClientVersion);
// Check for newer version of scs-client
const cmdLatestScsClientVersion = `curl -L -u '${nexusCredentials}' -X GET "https://nexus-dev.data.sfdc.net/nexus/service/rest/v1/search/assets?sort=version&repository=releases&maven.groupId=com.salesforce.armada&maven.artifactId=scs-client&maven.classifier=&maven.extension=jar&direction=desc" -H "accept: application/json" | jq -r ".items[0]"`;
const { stdout: scsClientLatestVersionStdOut } = execa.commandSync(
cmdLatestScsClientVersion,
{ shell: true },
);
const scsClientLatestVersionData = JSON.parse(scsClientLatestVersionStdOut);
console.log('latest scs-client data:', scsClientLatestVersionData);
const scsClientLatestVersion = scsClientLatestVersionData.maven2.version;
console.log(
'do we have the latest?',
scsClientVersion,
scsClientLatestVersion,
scsClientVersion === scsClientLatestVersion,
);
// Download the latest scs-client version
if (scsClientVersion !== scsClientLatestVersion) {
const cmdDownloadLatestScsClientVersion = `curl -k -o "./tnrp/scs-client-${scsClientLatestVersion}.jar" -u ${nexusCredentials} "${scsClientLatestVersionData.downloadUrl}"`;
const { stderr: scsClientJar } = execa.commandSync(
cmdDownloadLatestScsClientVersion,
{ shell: true },
);
console.log('scs-client jar:', scsClientJar);
gitAdd(`tnrp/scs-client-${scsClientLatestVersion}.jar`);
// Edit tnrp/package file
const cmdUpdatePackage = `sed -i "" -E "s/(scs-client-)[[:digit:]]\\.[[:digit:]]\\.[[:digit:]]{1,3}(\\.jar)/\\1${scsClientLatestVersion}\\2/" tnrp/package`;
execa.commandSync(cmdUpdatePackage, { shell: true });
console.log(
'tnrp/package edited with',
scsClientLatestVersion,
execa.commandSync('cat tnrp/package', { shell: true }).stdout,
);
gitAdd('tnrp');
}
// ------------------------------------------------------------------
// Commit and optionally create PR
// ------------------------------------------------------------------
execa.sync('git', [
'commit',
'-m',
`update SLDS files [${sldsVersion}] in ${newPackageVersion} `,
]);
console.log('committed SLDS files');
if (answers['doPR']) {
// Push (force-with-lease to handle re-runs where the branch was recreated)
try {
const pushBranch = execa.commandSync('git push --force-with-lease origin HEAD', {
shell: true,
});
console.log('branch pushed', pushBranch);
} catch (err) {
console.log(err);
}
// Create PR (may already exist from a prior run)
try {
const cmdCreatePR = `gh pr create -t "@${workItemId} bumped to ${newPackageVersion} with SLDS ${sldsVersion}" -b "${prBody}" -R "git.soma.salesforce.com/${scsTargetRepo}" --head "${scsForkedRepoOwner}:${branchName}" -B ${targetBranch}`;
const createPR = execa.commandSync(cmdCreatePR, { shell: true });
console.log(
'created PR:',
`Release ${newPackageVersion} [SLDS v${sldsVersion}]`,
createPR,
);
} catch (err) {
const existingPrMatch = err.stderr?.match(/https:\/\/\S+\/pull\/\d+/);
if (existingPrMatch) {
console.log('PR already exists:', existingPrMatch[0]);
} else {
console.error('Failed to create PR:', err.shortMessage || err.message);
}
}
}
});
|