@salesforce/webapp-template-app-react-template-b2e-experimental 1.83.0 → 1.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AGENT.md +2 -0
- package/dist/CHANGELOG.md +11 -0
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/package.json +4 -4
- package/dist/force-app/main/default/webapplications/appreacttemplateb2e/webapplication.json +1 -1
- package/dist/package.json +3 -2
- package/dist/scripts/prepare-import-unique-fields.js +108 -0
- package/dist/scripts/setup-cli.mjs +282 -0
- package/package.json +1 -1
package/dist/AGENT.md
CHANGED
|
@@ -26,6 +26,8 @@ Used for SFDX metadata (LWC, Aura, etc.). Scripts here are for the base SFDX tem
|
|
|
26
26
|
| `npm run prettier` | Format supported metadata files |
|
|
27
27
|
| `npm run prettier:verify` | Check Prettier |
|
|
28
28
|
|
|
29
|
+
**One-command setup:** From project root run `node scripts/setup-cli.mjs --target-org <alias>` to run login (if needed), deploy, optional permset/data import, GraphQL schema/codegen, web app build, and optionally the dev server. Use `node scripts/setup-cli.mjs --help` for options (e.g. `--skip-login`, `--skip-data`, `--webapp-name`).
|
|
30
|
+
|
|
29
31
|
Root **does not** run the React app. The root `npm run build` is a no-op for the base SFDX project.
|
|
30
32
|
|
|
31
33
|
### 2. React web app (where you do most work)
|
package/dist/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.84.0](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.83.0...v1.84.0) (2026-03-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **template:** add setup-cli and prepare-import-unique-fields scripts ([#240](https://github.com/salesforce-experience-platform-emu/webapps/issues/240)) ([5cad14c](https://github.com/salesforce-experience-platform-emu/webapps/commit/5cad14c9be8176b2faf2429fe8e8a56383aac1ae))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [1.83.0](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.82.0...v1.83.0) (2026-03-09)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"graphql:schema": "node scripts/get-graphql-schema.mjs"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@salesforce/agentforce-conversation-client": "^1.
|
|
19
|
-
"@salesforce/sdk-data": "^1.
|
|
20
|
-
"@salesforce/webapp-experimental": "^1.
|
|
18
|
+
"@salesforce/agentforce-conversation-client": "^1.84.0",
|
|
19
|
+
"@salesforce/sdk-data": "^1.84.0",
|
|
20
|
+
"@salesforce/webapp-experimental": "^1.84.0",
|
|
21
21
|
"@tailwindcss/vite": "^4.1.17",
|
|
22
22
|
"@tanstack/react-form": "^1.28.4",
|
|
23
23
|
"class-variance-authority": "^0.7.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@graphql-eslint/eslint-plugin": "^4.1.0",
|
|
42
42
|
"@graphql-tools/utils": "^11.0.0",
|
|
43
43
|
"@playwright/test": "^1.49.0",
|
|
44
|
-
"@salesforce/vite-plugin-webapp-experimental": "^1.
|
|
44
|
+
"@salesforce/vite-plugin-webapp-experimental": "^1.84.0",
|
|
45
45
|
"@testing-library/jest-dom": "^6.6.3",
|
|
46
46
|
"@testing-library/react": "^16.1.0",
|
|
47
47
|
"@testing-library/user-event": "^14.5.2",
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/webapp-template-base-sfdx-project-experimental",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.84.0",
|
|
4
4
|
"description": "Base SFDX project template",
|
|
5
5
|
"private": true,
|
|
6
6
|
"files": [
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"test:unit:coverage": "sfdx-lwc-jest --coverage",
|
|
19
19
|
"prettier": "prettier --write \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"",
|
|
20
20
|
"prettier:verify": "prettier --check \"**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"",
|
|
21
|
-
"precommit": "lint-staged"
|
|
21
|
+
"precommit": "lint-staged",
|
|
22
|
+
"setup": "node scripts/setup-cli.mjs"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@lwc/eslint-plugin-lwc": "^2.0.0",
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Updates unique fields in data JSON files so "sf data import tree" can be run
|
|
4
|
+
* repeatedly (e.g. after org already has data). Run before data import.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* node scripts/prepare-import-unique-fields.js
|
|
8
|
+
* node scripts/prepare-import-unique-fields.js --data-dir /path/to/force-app/main/default/data
|
|
9
|
+
*
|
|
10
|
+
* Expects data dir to contain (optional) JSON files:
|
|
11
|
+
* Contact.json (Email with unique domain per run, LastName, FirstName, Phone — standard Contact)
|
|
12
|
+
* Agent__c.json (License_Number__c — unique per record)
|
|
13
|
+
* Property_Management_Company__c.json (Company_Code__c, max 10 chars)
|
|
14
|
+
* Property_Owner__c.json (Email__c)
|
|
15
|
+
* Missing files are skipped. Customize this script for your app's objects/fields.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
|
|
21
|
+
// When run from project root: scripts/prepare-import-unique-fields.js → data dir under force-app
|
|
22
|
+
const DEFAULT_DATA_DIR = path.resolve(__dirname, '..', 'force-app/main/default/data');
|
|
23
|
+
|
|
24
|
+
function parseArgs() {
|
|
25
|
+
const args = process.argv.slice(2);
|
|
26
|
+
let dataDir = DEFAULT_DATA_DIR;
|
|
27
|
+
for (let i = 0; i < args.length; i++) {
|
|
28
|
+
if (args[i] === '--data-dir' && args[i + 1]) {
|
|
29
|
+
dataDir = path.resolve(args[++i]);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return dataDir;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const dataDir = parseArgs();
|
|
37
|
+
const runId = Date.now();
|
|
38
|
+
const runSuffix2 = String(runId % 100).padStart(2, '0'); // 00-99 for Company_Code__c (10-char limit)
|
|
39
|
+
|
|
40
|
+
// Contact: Email (unique domain + local), LastName, FirstName, Phone — avoid duplicate rules
|
|
41
|
+
const contactPath = path.join(dataDir, 'Contact.json');
|
|
42
|
+
if (fs.existsSync(contactPath)) {
|
|
43
|
+
let contact = JSON.parse(fs.readFileSync(contactPath, 'utf8'));
|
|
44
|
+
if (contact.records) {
|
|
45
|
+
contact.records.forEach((r, i) => {
|
|
46
|
+
if (r.Email && r.Email.includes('@')) {
|
|
47
|
+
const parts = r.Email.replace(/\+[0-9]+@/, '@').split('@');
|
|
48
|
+
const local = (parts[0] || 'user') + '+' + runId;
|
|
49
|
+
const domain = 'run' + runId + '.example.com';
|
|
50
|
+
r.Email = local + '@' + domain;
|
|
51
|
+
}
|
|
52
|
+
if (r.LastName)
|
|
53
|
+
r.LastName = String(r.LastName).replace(/-[0-9]+$/, '') + '-' + runId;
|
|
54
|
+
if (r.FirstName)
|
|
55
|
+
r.FirstName = String(r.FirstName).replace(/-[0-9]+$/, '') + '-' + (i + 1);
|
|
56
|
+
if (r.Phone)
|
|
57
|
+
r.Phone = String(r.Phone).replace(/\d{2}$/, runSuffix2);
|
|
58
|
+
});
|
|
59
|
+
fs.writeFileSync(contactPath, JSON.stringify(contact, null, 2));
|
|
60
|
+
console.log('Updated Contact.json (Email, LastName, FirstName, Phone)');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Agent__c: License_Number__c — unique per record (field is often unique in org)
|
|
65
|
+
const agentPath = path.join(dataDir, 'Agent__c.json');
|
|
66
|
+
if (fs.existsSync(agentPath)) {
|
|
67
|
+
let agent = JSON.parse(fs.readFileSync(agentPath, 'utf8'));
|
|
68
|
+
if (agent.records) {
|
|
69
|
+
agent.records.forEach((r, i) => {
|
|
70
|
+
if (r.License_Number__c) {
|
|
71
|
+
const base = r.License_Number__c.replace(/-[0-9]+(-[0-9]+)?$/, '');
|
|
72
|
+
r.License_Number__c = base + '-' + runId + '-' + (i + 1);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
fs.writeFileSync(agentPath, JSON.stringify(agent, null, 2));
|
|
76
|
+
console.log('Updated Agent__c.json (License_Number__c)');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Property_Management_Company__c: Company_Code__c — max 10 chars, use 8-char base + 2-digit suffix
|
|
81
|
+
const companyPath = path.join(dataDir, 'Property_Management_Company__c.json');
|
|
82
|
+
if (fs.existsSync(companyPath)) {
|
|
83
|
+
let company = JSON.parse(fs.readFileSync(companyPath, 'utf8'));
|
|
84
|
+
if (company.records) {
|
|
85
|
+
company.records.forEach((r) => {
|
|
86
|
+
if (r.Company_Code__c)
|
|
87
|
+
r.Company_Code__c = r.Company_Code__c.slice(0, 8) + runSuffix2;
|
|
88
|
+
});
|
|
89
|
+
fs.writeFileSync(companyPath, JSON.stringify(company, null, 2));
|
|
90
|
+
console.log('Updated Property_Management_Company__c.json (Company_Code__c)');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Property_Owner__c: Email__c — add +runId before @
|
|
95
|
+
const ownerPath = path.join(dataDir, 'Property_Owner__c.json');
|
|
96
|
+
if (fs.existsSync(ownerPath)) {
|
|
97
|
+
let owner = JSON.parse(fs.readFileSync(ownerPath, 'utf8'));
|
|
98
|
+
if (owner.records) {
|
|
99
|
+
owner.records.forEach((r) => {
|
|
100
|
+
if (r.Email__c && r.Email__c.includes('@'))
|
|
101
|
+
r.Email__c = r.Email__c.replace(/\+[0-9]+@/, '@').replace('@', '+' + runId + '@');
|
|
102
|
+
});
|
|
103
|
+
fs.writeFileSync(ownerPath, JSON.stringify(owner, null, 2));
|
|
104
|
+
console.log('Updated Property_Owner__c.json (Email__c)');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log('Unique fields updated: runId=%s companySuffix=%s', runId, runSuffix2);
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* One-command setup: login, deploy, optional permset/data, GraphQL schema/codegen, web app build.
|
|
4
|
+
* Use this script to make setup easier for each app generated from this template.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* node scripts/setup-cli.mjs --target-org <alias> # run all steps
|
|
8
|
+
* node scripts/setup-cli.mjs --target-org afv5 --skip-login
|
|
9
|
+
* node scripts/setup-cli.mjs --target-org afv5 --skip-data --skip-webapp-build
|
|
10
|
+
* node scripts/setup-cli.mjs --target-org myorg --webapp-name my-app
|
|
11
|
+
*
|
|
12
|
+
* Steps (in order):
|
|
13
|
+
* 1. login — sf org login web only if org not already connected (skip with --skip-login)
|
|
14
|
+
* 2. deploy — sf project deploy start --target-org <alias>
|
|
15
|
+
* 3. permset — sf org assign permset (skip with --skip-permset; name via --permset-name)
|
|
16
|
+
* 4. data — prepare unique fields + sf data import tree (skipped if no data dir/plan)
|
|
17
|
+
* 5. graphql — (in webapp) npm run graphql:schema then npm run graphql:codegen
|
|
18
|
+
* 6. webapp — (in webapp) npm install && npm run build
|
|
19
|
+
* 7. dev — (in webapp) npm run dev — launch dev server (skip with --skip-dev)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { spawnSync } from 'node:child_process';
|
|
23
|
+
import { resolve, dirname } from 'node:path';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
import { readdirSync, existsSync } from 'node:fs';
|
|
26
|
+
|
|
27
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
28
|
+
const ROOT = resolve(__dirname, '..');
|
|
29
|
+
const WEBAPPLICATIONS_DIR = resolve(ROOT, 'force-app/main/default/webapplications');
|
|
30
|
+
const DATA_DIR = resolve(ROOT, 'force-app/main/default/data');
|
|
31
|
+
const DATA_PLAN = resolve(ROOT, 'force-app/main/default/data/data-plan.json');
|
|
32
|
+
|
|
33
|
+
function parseArgs() {
|
|
34
|
+
const args = process.argv.slice(2);
|
|
35
|
+
let targetOrg = null;
|
|
36
|
+
let webappName = null;
|
|
37
|
+
let permsetName = 'Property_Management_Access';
|
|
38
|
+
const flags = {
|
|
39
|
+
skipLogin: false,
|
|
40
|
+
skipDeploy: false,
|
|
41
|
+
skipPermset: false,
|
|
42
|
+
skipData: false,
|
|
43
|
+
skipGraphql: false,
|
|
44
|
+
skipWebappBuild: false,
|
|
45
|
+
skipDev: false,
|
|
46
|
+
};
|
|
47
|
+
for (let i = 0; i < args.length; i++) {
|
|
48
|
+
if (args[i] === '--target-org' && args[i + 1]) {
|
|
49
|
+
targetOrg = args[++i];
|
|
50
|
+
} else if (args[i] === '--webapp-name' && args[i + 1]) {
|
|
51
|
+
webappName = args[++i];
|
|
52
|
+
} else if (args[i] === '--permset-name' && args[i + 1]) {
|
|
53
|
+
permsetName = args[++i];
|
|
54
|
+
} else if (args[i] === '--skip-login') flags.skipLogin = true;
|
|
55
|
+
else if (args[i] === '--skip-deploy') flags.skipDeploy = true;
|
|
56
|
+
else if (args[i] === '--skip-permset') flags.skipPermset = true;
|
|
57
|
+
else if (args[i] === '--skip-data') flags.skipData = true;
|
|
58
|
+
else if (args[i] === '--skip-graphql') flags.skipGraphql = true;
|
|
59
|
+
else if (args[i] === '--skip-webapp-build') flags.skipWebappBuild = true;
|
|
60
|
+
else if (args[i] === '--skip-dev') flags.skipDev = true;
|
|
61
|
+
else if (args[i] === '--help' || args[i] === '-h') {
|
|
62
|
+
console.log(`
|
|
63
|
+
Setup CLI — one-command setup for apps in this project
|
|
64
|
+
|
|
65
|
+
Usage:
|
|
66
|
+
node scripts/setup-cli.mjs --target-org <alias> [options]
|
|
67
|
+
|
|
68
|
+
Required:
|
|
69
|
+
--target-org <alias> Target Salesforce org alias (e.g. myorg)
|
|
70
|
+
|
|
71
|
+
Options:
|
|
72
|
+
--webapp-name <name> Web app folder name under webapplications/ (default: auto-detect)
|
|
73
|
+
--permset-name <name> Permission set to assign (default: Property_Management_Access)
|
|
74
|
+
--skip-login Skip login step (login is auto-skipped if org is already connected)
|
|
75
|
+
--skip-deploy Do not deploy metadata
|
|
76
|
+
--skip-permset Do not assign permission set
|
|
77
|
+
--skip-data Do not prepare data or run data import
|
|
78
|
+
--skip-graphql Do not fetch schema or run GraphQL codegen
|
|
79
|
+
--skip-webapp-build Do not npm install / build the web application
|
|
80
|
+
--skip-dev Do not launch the dev server at the end
|
|
81
|
+
-h, --help Show this help
|
|
82
|
+
`);
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!targetOrg) {
|
|
87
|
+
console.error('Error: --target-org <alias> is required.');
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
return { targetOrg, webappName, permsetName, ...flags };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function discoverWebappDir(webappName) {
|
|
94
|
+
if (webappName) {
|
|
95
|
+
const dir = resolve(WEBAPPLICATIONS_DIR, webappName);
|
|
96
|
+
if (!existsSync(dir)) {
|
|
97
|
+
console.error(`Error: Web app directory not found: ${dir}`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
return dir;
|
|
101
|
+
}
|
|
102
|
+
if (!existsSync(WEBAPPLICATIONS_DIR)) {
|
|
103
|
+
console.error(`Error: webapplications directory not found: ${WEBAPPLICATIONS_DIR}`);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
const entries = readdirSync(WEBAPPLICATIONS_DIR, { withFileTypes: true });
|
|
107
|
+
const dirs = entries.filter((e) => e.isDirectory() && !e.name.startsWith('.'));
|
|
108
|
+
if (dirs.length === 0) {
|
|
109
|
+
console.error(`Error: No web app folder found under ${WEBAPPLICATIONS_DIR}`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
if (dirs.length > 1) {
|
|
113
|
+
console.log(`Multiple web apps found; using first: ${dirs[0].name}`);
|
|
114
|
+
}
|
|
115
|
+
return resolve(WEBAPPLICATIONS_DIR, dirs[0].name);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function isOrgConnected(targetOrg) {
|
|
119
|
+
const result = spawnSync('sf', ['org', 'display', '--target-org', targetOrg, '--json'], {
|
|
120
|
+
cwd: ROOT,
|
|
121
|
+
stdio: 'pipe',
|
|
122
|
+
shell: true,
|
|
123
|
+
});
|
|
124
|
+
return result.status === 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function run(name, cmd, args, opts = {}) {
|
|
128
|
+
const { cwd = ROOT, optional = false } = opts;
|
|
129
|
+
console.log('\n---', name, '---');
|
|
130
|
+
const result = spawnSync(cmd, args, {
|
|
131
|
+
cwd,
|
|
132
|
+
stdio: 'inherit',
|
|
133
|
+
shell: true,
|
|
134
|
+
...(opts.timeout && { timeout: opts.timeout }),
|
|
135
|
+
});
|
|
136
|
+
if (result.status !== 0 && !optional) {
|
|
137
|
+
console.error(`\nSetup failed at step: ${name}`);
|
|
138
|
+
process.exit(result.status ?? 1);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function main() {
|
|
144
|
+
const {
|
|
145
|
+
targetOrg,
|
|
146
|
+
webappName,
|
|
147
|
+
permsetName,
|
|
148
|
+
skipLogin,
|
|
149
|
+
skipDeploy,
|
|
150
|
+
skipPermset,
|
|
151
|
+
skipData,
|
|
152
|
+
skipGraphql,
|
|
153
|
+
skipWebappBuild,
|
|
154
|
+
skipDev,
|
|
155
|
+
} = parseArgs();
|
|
156
|
+
|
|
157
|
+
const webappDir = discoverWebappDir(webappName);
|
|
158
|
+
const hasDataPlan = existsSync(DATA_PLAN) && existsSync(DATA_DIR);
|
|
159
|
+
const doData = !skipData && hasDataPlan;
|
|
160
|
+
|
|
161
|
+
console.log('Setup — target org:', targetOrg, '| web app:', webappDir);
|
|
162
|
+
console.log(
|
|
163
|
+
'Steps: login=%s deploy=%s permset=%s data=%s graphql=%s webapp=%s dev=%s',
|
|
164
|
+
!skipLogin,
|
|
165
|
+
!skipDeploy,
|
|
166
|
+
!skipPermset,
|
|
167
|
+
doData,
|
|
168
|
+
!skipGraphql,
|
|
169
|
+
!skipWebappBuild,
|
|
170
|
+
!skipDev
|
|
171
|
+
);
|
|
172
|
+
if (skipData && hasDataPlan) {
|
|
173
|
+
console.log('(Data dir present; use without --skip-data to run data import.)');
|
|
174
|
+
} else if (!hasDataPlan && !skipData) {
|
|
175
|
+
console.log('(No data plan found; skipping data step.)');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!skipLogin) {
|
|
179
|
+
if (isOrgConnected(targetOrg)) {
|
|
180
|
+
console.log('\n--- Login ---');
|
|
181
|
+
console.log(`Org ${targetOrg} is already authenticated; skipping browser login.`);
|
|
182
|
+
} else {
|
|
183
|
+
run('Login (browser)', 'sf', ['org', 'login', 'web', '--alias', targetOrg], { optional: true });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!skipDeploy) {
|
|
188
|
+
run('Deploy metadata', 'sf', ['project', 'deploy', 'start', '--target-org', targetOrg], {
|
|
189
|
+
timeout: 180000,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!skipPermset && permsetName) {
|
|
194
|
+
console.log('\n--- Assign permission set ---');
|
|
195
|
+
const permsetResult = spawnSync(
|
|
196
|
+
'sf',
|
|
197
|
+
['org', 'assign', 'permset', '--name', permsetName, '--target-org', targetOrg],
|
|
198
|
+
{
|
|
199
|
+
cwd: ROOT,
|
|
200
|
+
stdio: 'pipe',
|
|
201
|
+
shell: true,
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
if (permsetResult.status === 0) {
|
|
205
|
+
console.log('Permission set assigned.');
|
|
206
|
+
} else {
|
|
207
|
+
const out =
|
|
208
|
+
(permsetResult.stderr?.toString() || '') + (permsetResult.stdout?.toString() || '');
|
|
209
|
+
if (out.includes('Duplicate') && out.includes('PermissionSet')) {
|
|
210
|
+
console.log('Permission set already assigned; skipping.');
|
|
211
|
+
} else if (out.includes('not found') && out.includes('target org')) {
|
|
212
|
+
console.log(`Permission set "${permsetName}" not in org; skipping.`);
|
|
213
|
+
} else {
|
|
214
|
+
process.stdout.write(permsetResult.stdout?.toString() || '');
|
|
215
|
+
process.stderr.write(permsetResult.stderr?.toString() || '');
|
|
216
|
+
console.error('\nSetup failed at step: Assign permission set');
|
|
217
|
+
process.exit(permsetResult.status ?? 1);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (doData) {
|
|
223
|
+
// Prepare data for uniqueness (run before import so repeat imports don't conflict)
|
|
224
|
+
const prepareScript = resolve(__dirname, 'prepare-import-unique-fields.js');
|
|
225
|
+
run('Prepare data (unique fields)', 'node', [prepareScript, '--data-dir', DATA_DIR], {
|
|
226
|
+
cwd: ROOT,
|
|
227
|
+
});
|
|
228
|
+
// Data import tree: if only DUPLICATES_DETECTED (org duplicate rules), warn and continue
|
|
229
|
+
console.log('\n--- Data import tree ---');
|
|
230
|
+
const importResult = spawnSync(
|
|
231
|
+
'sf',
|
|
232
|
+
['data', 'import', 'tree', '--plan', DATA_PLAN, '--target-org', targetOrg, '--json'],
|
|
233
|
+
{ cwd: ROOT, stdio: 'pipe', shell: true, timeout: 120000 }
|
|
234
|
+
);
|
|
235
|
+
const out = (importResult.stdout?.toString() || '') + (importResult.stderr?.toString() || '');
|
|
236
|
+
if (importResult.status !== 0) {
|
|
237
|
+
let onlyDuplicates = false;
|
|
238
|
+
try {
|
|
239
|
+
const j = JSON.parse(out);
|
|
240
|
+
const errors = Array.isArray(j?.data) ? j.data : [];
|
|
241
|
+
onlyDuplicates =
|
|
242
|
+
errors.length > 0 &&
|
|
243
|
+
errors.every((e) => e.StatusCode === 'DUPLICATES_DETECTED' || e.statusCode === 'DUPLICATES_DETECTED');
|
|
244
|
+
} catch (_) {
|
|
245
|
+
onlyDuplicates = out.includes('DUPLICATES_DETECTED') && /Use one of these records\?/.test(out);
|
|
246
|
+
}
|
|
247
|
+
if (onlyDuplicates) {
|
|
248
|
+
console.warn(
|
|
249
|
+
'Data import hit org duplicate rules (e.g. Contact). Skipping import; rest of setup continues.'
|
|
250
|
+
);
|
|
251
|
+
} else {
|
|
252
|
+
process.stdout.write(importResult.stdout?.toString() || '');
|
|
253
|
+
process.stderr.write(importResult.stderr?.toString() || '');
|
|
254
|
+
console.error('\nSetup failed at step: Data import tree');
|
|
255
|
+
process.exit(importResult.status ?? 1);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (!skipGraphql || !skipWebappBuild) {
|
|
261
|
+
run('Web app npm install', 'npm', ['install'], { cwd: webappDir });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (!skipGraphql) {
|
|
265
|
+
run('Set default org for schema', 'sf', ['config', 'set', 'target-org', targetOrg, '--global']);
|
|
266
|
+
run('GraphQL schema (introspect)', 'npm', ['run', 'graphql:schema'], { cwd: webappDir });
|
|
267
|
+
run('GraphQL codegen', 'npm', ['run', 'graphql:codegen'], { cwd: webappDir });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (!skipWebappBuild) {
|
|
271
|
+
run('Web app build', 'npm', ['run', 'build'], { cwd: webappDir });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
console.log('\n--- Setup complete ---');
|
|
275
|
+
|
|
276
|
+
if (!skipDev) {
|
|
277
|
+
console.log('\n--- Launching dev server (Ctrl+C to stop) ---\n');
|
|
278
|
+
run('Dev server', 'npm', ['run', 'dev'], { cwd: webappDir });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
main();
|