Skip to content

Commit e85a395

Browse files
authored
fix: update the update2 script for TS strict compile (#954)
1 parent 11218d7 commit e85a395

File tree

2 files changed

+68
-60
lines changed

2 files changed

+68
-60
lines changed

scripts/update-registry/update2.ts

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { CoverageObject, CoverageObjectType } from '../../src/registry/types';
88
import { getMissingTypes } from '../../test/utils/getMissingTypes';
99
import { getCurrentApiVersion, getCoverage } from '../../src/registry/coverage';
1010

11-
const registry = JSON.parse(
12-
fs.readFileSync('./src/registry/metadataRegistry.json', 'utf8')
13-
) as unknown as MetadataRegistry;
14-
1511
export let metadataCoverage: CoverageObject;
1612

1713
interface DescribeResult {
@@ -24,6 +20,67 @@ interface DescribeResult {
2420
childXmlNames: string[];
2521
}
2622

23+
const registry = JSON.parse(
24+
fs.readFileSync('./src/registry/metadataRegistry.json', 'utf8')
25+
) as unknown as MetadataRegistry;
26+
27+
const updateProjectScratchDef = (missingTypes: [string, CoverageObjectType][]) => {
28+
const scratchDefSummary = deepmerge.all(
29+
[{}].concat(missingTypes.map(([key, missingType]) => missingType.orgShapes.developer))
30+
) as {
31+
features: string[];
32+
};
33+
34+
scratchDefSummary.features = [...new Set(scratchDefSummary.features)];
35+
const jsonData = JSON.stringify({ edition: 'developer', ...scratchDefSummary });
36+
fs.writeFileSync('./registryBuilder/config/project-scratch-def.json', jsonData);
37+
if (scratchDefSummary.features.length > 0) {
38+
console.log(`Creating org with features ${scratchDefSummary.features.join(',')}`);
39+
}
40+
};
41+
42+
const getMissingTypesAsDescribeResult = (missingTypes: [string, CoverageObjectType][]): DescribeResult[] => {
43+
const describeResult = shelljs.exec('sfdx force:mdapi:describemetadata -u registryBuilder --json', { silent: true });
44+
const metadataObjectsByName = new Map<string, DescribeResult>();
45+
(JSON.parse(describeResult.stdout).result.metadataObjects as DescribeResult[]).map((describeObj) => {
46+
metadataObjectsByName.set(describeObj.xmlName, describeObj);
47+
});
48+
// get the missingTypes from the describe
49+
return missingTypes.map(([key]) => metadataObjectsByName.get(key)).filter((t): t is DescribeResult => !!t); // <-- satisfies TS compiler
50+
};
51+
52+
/**
53+
* Simple type implementation. Not handling children.
54+
*/
55+
const registryUpdate = (missingTypesAsDescribeResult: DescribeResult[]) => {
56+
missingTypesAsDescribeResult.map((missingTypeDescribe) => {
57+
if (missingTypeDescribe.childXmlNames?.length || missingTypeDescribe.folderContentType) {
58+
console.log(`Skipping ${missingTypeDescribe.xmlName} because it is a folder or has children`);
59+
return;
60+
}
61+
const { xmlName: name, suffix, metaFile, directoryName, inFolder } = missingTypeDescribe;
62+
let typeId = missingTypeDescribe.xmlName.toLowerCase();
63+
64+
const generatedType = {
65+
id: typeId,
66+
name,
67+
suffix,
68+
directoryName,
69+
inFolder,
70+
strictDirectoryName: false,
71+
};
72+
registry.types[typeId] = {
73+
...generatedType,
74+
...(metaFile ? { strategies: { adapter: 'matchingContentFile' } } : {}),
75+
};
76+
if (registry.suffixes) {
77+
registry.suffixes[suffix] = typeId;
78+
}
79+
});
80+
const jsonData = JSON.stringify(registry, null, 2);
81+
fs.writeFileSync('./src/registry/metadataRegistry.json', jsonData);
82+
};
83+
2784
// get the coverage report
2885
(async () => {
2986
const currentApiVersion = await getCurrentApiVersion();
@@ -70,6 +127,7 @@ Example: \`sfdx config:set defaultdevhubusername=<devhub-username> --global\`
70127
const missingTypesAsDescribeResult = getMissingTypesAsDescribeResult(missingTypes);
71128
console.log(missingTypesAsDescribeResult);
72129
registryUpdate(missingTypesAsDescribeResult);
130+
73131
// update the registry
74132

75133
// destroy the scratch org and the project
@@ -78,58 +136,3 @@ Example: \`sfdx config:set defaultdevhubusername=<devhub-username> --global\`
78136
}
79137
shelljs.rm('-rf', 'registryBuilder');
80138
})();
81-
82-
/**
83-
* Simple type implementation. Not handling children.
84-
*/
85-
const registryUpdate = (missingTypesAsDescribeResult: DescribeResult[]) => {
86-
missingTypesAsDescribeResult.map((missingTypeDescribe) => {
87-
if (missingTypeDescribe.childXmlNames?.length || missingTypeDescribe.folderContentType) {
88-
console.log(`Skipping ${missingTypeDescribe.xmlName} because it is a folder or has children`);
89-
return;
90-
}
91-
const { xmlName: name, suffix, metaFile, directoryName, inFolder } = missingTypeDescribe;
92-
let typeId = missingTypeDescribe.xmlName.toLowerCase();
93-
94-
const generatedType = {
95-
id: typeId,
96-
name,
97-
suffix,
98-
directoryName,
99-
inFolder,
100-
strictDirectoryName: false,
101-
};
102-
registry.types[typeId] = {
103-
...generatedType,
104-
...(metaFile ? { strategies: { adapter: 'matchingContentFile' } } : {}),
105-
};
106-
registry.suffixes[suffix] = typeId;
107-
});
108-
const jsonData = JSON.stringify(registry, null, 2);
109-
fs.writeFileSync('./src/registry/metadataRegistry.json', jsonData);
110-
};
111-
112-
const getMissingTypesAsDescribeResult = (missingTypes: [string, CoverageObjectType][]): DescribeResult[] => {
113-
const describeResult = shelljs.exec('sfdx force:mdapi:describemetadata -u registryBuilder --json', { silent: true });
114-
const metadataObjectsByName = new Map<string, DescribeResult>();
115-
(JSON.parse(describeResult.stdout).result.metadataObjects as DescribeResult[]).map((describeObj) => {
116-
metadataObjectsByName.set(describeObj.xmlName, describeObj);
117-
});
118-
// get the missingTypes from the describe
119-
return missingTypes.map(([key]) => metadataObjectsByName.get(key)).filter(Boolean);
120-
};
121-
122-
const updateProjectScratchDef = (missingTypes: [string, CoverageObjectType][]) => {
123-
const scratchDefSummary = deepmerge.all(
124-
[{}].concat(missingTypes.map(([key, missingType]) => missingType.orgShapes.developer))
125-
) as {
126-
features: string[];
127-
};
128-
129-
scratchDefSummary.features = [...new Set(scratchDefSummary.features)];
130-
const jsonData = JSON.stringify({ edition: 'developer', ...scratchDefSummary });
131-
fs.writeFileSync('./registryBuilder/config/project-scratch-def.json', jsonData);
132-
if (scratchDefSummary.features.length > 0) {
133-
console.log(`Creating org with features ${scratchDefSummary.features.join(',')}`);
134-
}
135-
};

tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
"baseUrl": ".",
1212
"paths": { "@salesforce/kit": ["node_modules/@salesforce/kit"] }
1313
},
14-
"include": ["./src/**/*.ts", "./src/registry/metadataRegistry.json", "./src/registry/stdValueSetRegistry.json"],
14+
"include": [
15+
"./src/**/*.ts",
16+
"./scripts/update-registry/*.ts",
17+
"./src/registry/metadataRegistry.json",
18+
"./src/registry/stdValueSetRegistry.json"
19+
],
1520
"exclude": ["node_modules", "lib", "examples"]
1621
}

0 commit comments

Comments
 (0)