Skip to content

feat: make client changelog preservable #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/importexport/2010-06-01/service-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"endpointPrefix":"importexport",
"globalEndpoint":"importexport.amazonaws.com",
"serviceFullName":"AWS Import/Export",
"serviceId":"ImportExport",
"signatureVersion":"v2",
"xmlNamespace":"http://importexport.amazonaws.com/doc/2010-06-01/",
"protocol":"query"
Expand Down
30 changes: 30 additions & 0 deletions packages/package-generator/src/ModuleGenerator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ModuleGenerator} from "./ModuleGenerator";
import * as fs from 'fs';

describe('ModuleGenerator', () => {
describe('expected files', () => {
Expand Down Expand Up @@ -148,4 +149,33 @@ ${description}`
}
);
});

describe('CHANGELOG.md', () => {
it('should inherit previous change log if exists', () => {
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => '###changelog###');
const name = 'name';
const generator = new ModuleGenerator({name});
let generated = false;
for (const [filename, contents] of generator) {
if (filename === 'CHANGELOG.md') {
generated = true;
expect(contents).toBe('###changelog###');
}
}
expect(generated).toBe(true);
});

it('should not add changelog if no changelog exists previously', () => {
jest.spyOn(fs, 'readFileSync').mockImplementationOnce(() => {throw new Error('ENOENT')});
const name = 'name';
const generator = new ModuleGenerator({name});
let generated = false;
for (const [filename, contents] of generator) {
if (filename === 'CHANGELOG.md') {
generated = true;
}
}
expect(generated).toBe(false);
})
});
});
17 changes: 17 additions & 0 deletions packages/package-generator/src/ModuleGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
DEFAULT_TSCONFIG,
JsonDocument,
} from './constants';
import { join, dirname } from 'path';
import { readFileSync } from 'fs';

export interface CustomModuleInit {
name: string;
Expand Down Expand Up @@ -36,6 +38,8 @@ export class ModuleGenerator {
yield ['LICENSE', APACHE_2_LICENSE];
yield ['tsconfig.json', JSON.stringify(this.tsconfig(), null, 4)];
yield ['tsconfig.test.json', JSON.stringify(this.testTsconfig(), null, 4)];
const changelog = this.changelog();
if (changelog) yield ['CHANGELOG.md', changelog];
}

protected gitignore(): string {
Expand Down Expand Up @@ -90,4 +94,17 @@ ${this.description || ''}
protected tsconfig(): {[key: string]: any} {
return DEFAULT_TSCONFIG;
}

protected changelog(): string | undefined {
const previousChangelog = join(
dirname(dirname(__dirname)),
this.name.replace(/^@aws-sdk\//, ''),
'CHANGELOG.md'
);
try {
return readFileSync(previousChangelog).toString();
} catch(e) {
return undefined;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ImportModelsCommand: yargs.CommandModule = {
console.log(`Generating ${services.size} SDK packages...`);

for (const [identifier, {model, smoke}] of services) {
for (const runtime of ['node', 'browser', 'universal']) {
for (const runtime of ['node', 'browser']) {
console.log(`Generating ${runtime} ${clientModuleIdentifier(model.metadata)} SDK`);
ImportClientPackageCommand.handler({ model, runtime, smoke });
}
Expand Down