Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function diffResource(oldValue?: types.Resource, newValue?: types.Resource): types.ResourceDifference {
const resourceType = {
oldType: oldValue && oldValue.Type,
newType: newValue && newValue.Type
};
let propertyDiffs: { [key: string]: types.PropertyDifference } = {};
let otherDiffs: { [key: string]: types.Difference } = {};
if (resourceType.oldType !== undefined && resourceType.oldType === resourceType.newType) {
// Only makes sense to inspect deeper if the types stayed the same
const typeSpec = cfnspec.filteredSpecification(resourceType.oldType);
const impl = typeSpec.ResourceTypes[resourceType.oldType];
propertyDiffs = diffKeyedEntities(oldValue!.Properties,
newValue!.Properties,
(oldVal, newVal, key) => _diffProperty(oldVal, newVal, key, impl));
otherDiffs = diffKeyedEntities(oldValue, newValue, _diffOther);
delete otherDiffs.Properties;
}
return new types.ResourceDifference(oldValue, newValue, {
resourceType, propertyDiffs, otherDiffs,
});
function _diffProperty(oldV: any, newV: any, key: string, resourceSpec?: cfnspec.schema.ResourceType) {
let changeImpact = types.ResourceImpact.NO_CHANGE;
export default async function(scopes: string | string[], outPath: string): Promise {
if (outPath !== '.') { await fs.mkdirp(outPath); }
if (typeof scopes === 'string') { scopes = [scopes]; }
for (const scope of scopes) {
const spec = cfnSpec.filteredSpecification(s => s.startsWith(`${scope}::`));
if (Object.keys(spec.ResourceTypes).length === 0) {
throw new Error(`No resource was found for scope ${scope}`);
}
const name = packageName(scope);
const affix = computeAffix(scope, scopes);
const generator = new CodeGenerator(name, spec, affix);
generator.emitCode();
await generator.save(outPath);
const augs = new AugmentationGenerator(name, spec, affix);
if (augs.emitCode()) {
await augs.save(outPath);
}
}
}