Skip to content

Commit 7bc40aa

Browse files
authored
feat: make client changelog preservable (#198)
When generating any model, the changelog within to model shouldn't be reset. This change will preserve the CHANGELOG.md when regenerating the package.
1 parent f2aa325 commit 7bc40aa

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

models/importexport/2010-06-01/service-2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"endpointPrefix":"importexport",
77
"globalEndpoint":"importexport.amazonaws.com",
88
"serviceFullName":"AWS Import/Export",
9+
"serviceId":"ImportExport",
910
"signatureVersion":"v2",
1011
"xmlNamespace":"http://importexport.amazonaws.com/doc/2010-06-01/",
1112
"protocol":"query"

packages/package-generator/src/ModuleGenerator.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {ModuleGenerator} from "./ModuleGenerator";
2+
import * as fs from 'fs';
23

34
describe('ModuleGenerator', () => {
45
describe('expected files', () => {
@@ -148,4 +149,33 @@ ${description}`
148149
}
149150
);
150151
});
152+
153+
describe('CHANGELOG.md', () => {
154+
it('should inherit previous change log if exists', () => {
155+
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => '###changelog###');
156+
const name = 'name';
157+
const generator = new ModuleGenerator({name});
158+
let generated = false;
159+
for (const [filename, contents] of generator) {
160+
if (filename === 'CHANGELOG.md') {
161+
generated = true;
162+
expect(contents).toBe('###changelog###');
163+
}
164+
}
165+
expect(generated).toBe(true);
166+
});
167+
168+
it('should not add changelog if no changelog exists previously', () => {
169+
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => {throw new Error('ENOENT')});
170+
const name = 'name';
171+
const generator = new ModuleGenerator({name});
172+
let generated = false;
173+
for (const [filename, contents] of generator) {
174+
if (filename === 'CHANGELOG.md') {
175+
generated = true;
176+
}
177+
}
178+
expect(generated).toBe(false);
179+
})
180+
});
151181
});

packages/package-generator/src/ModuleGenerator.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
DEFAULT_TSCONFIG,
77
JsonDocument,
88
} from './constants';
9+
import { join, dirname } from 'path';
10+
import { readFileSync } from 'fs';
911

1012
export interface CustomModuleInit {
1113
name: string;
@@ -36,6 +38,8 @@ export class ModuleGenerator {
3638
yield ['LICENSE', APACHE_2_LICENSE];
3739
yield ['tsconfig.json', JSON.stringify(this.tsconfig(), null, 4)];
3840
yield ['tsconfig.test.json', JSON.stringify(this.testTsconfig(), null, 4)];
41+
const changelog = this.changelog();
42+
if (changelog) yield ['CHANGELOG.md', changelog];
3943
}
4044

4145
protected gitignore(): string {
@@ -90,4 +94,17 @@ ${this.description || ''}
9094
protected tsconfig(): {[key: string]: any} {
9195
return DEFAULT_TSCONFIG;
9296
}
97+
98+
protected changelog(): string | undefined {
99+
const previousChangelog = join(
100+
dirname(dirname(__dirname)),
101+
this.name.replace(/^@aws-sdk\//, ''),
102+
'CHANGELOG.md'
103+
);
104+
try {
105+
return readFileSync(previousChangelog).toString();
106+
} catch(e) {
107+
return undefined;
108+
}
109+
}
93110
}

packages/package-generator/src/commands/ImportModelsCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const ImportModelsCommand: yargs.CommandModule = {
5353
console.log(`Generating ${services.size} SDK packages...`);
5454

5555
for (const [identifier, {model, smoke}] of services) {
56-
for (const runtime of ['node', 'browser', 'universal']) {
56+
for (const runtime of ['node', 'browser']) {
5757
console.log(`Generating ${runtime} ${clientModuleIdentifier(model.metadata)} SDK`);
5858
ImportClientPackageCommand.handler({ model, runtime, smoke });
5959
}

0 commit comments

Comments
 (0)