Skip to content

Commit 8258926

Browse files
authored
Fix creating android model files that have path embedded in it (#711)
1 parent 3c8dbde commit 8258926

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.changeset/plenty-rules-sparkle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/model-generator': patch
3+
---
4+
5+
Fix creating android model files that have path embedded in it

packages/model-generator/src/appsync_graphql_generation_result.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ void describe('AppsyncGraphqlDocumentGenerationResult', () => {
99
const writeMock = mock.method(fs, 'writeFile');
1010
mock.method(fs, 'mkdir').mock.mockImplementation(async () => null);
1111
writeMock.mock.mockImplementation(async () => null);
12-
const files = {
12+
const filePathWithDir = path.join('a-third', 'fake-file', '.type');
13+
const files: Record<string, string> = {
1314
'fake-file': 'my \n fake file \n contents',
1415
'a-second-fake-file': 'ooo you tried to trick me',
1516
};
17+
files[filePathWithDir] = 'another trick, deal with it';
1618

1719
const result = new AppsyncGraphqlGenerationResult(files);
1820
const directory = './fake-dir';
@@ -21,10 +23,10 @@ void describe('AppsyncGraphqlDocumentGenerationResult', () => {
2123

2224
Object.entries(files).forEach(([fileName, content]) => {
2325
const resolvedName = path.resolve(path.join(directory, fileName));
24-
const call = writeMock.mock.calls.find(
26+
const writeCall = writeMock.mock.calls.find(
2527
({ arguments: [f] }) => resolvedName === f
2628
);
27-
assert.deepEqual(call?.arguments, [resolvedName, content]);
29+
assert.deepEqual(writeCall?.arguments, [resolvedName, content]);
2830
});
2931
});
3032
});

packages/model-generator/src/appsync_graphql_generation_result.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export class AppsyncGraphqlGenerationResult implements GenerationResult {
1919
filePath: string,
2020
contents: string
2121
) => {
22-
await fs.mkdir(basePath, { recursive: true });
23-
await fs.writeFile(path.resolve(path.join(basePath, filePath)), contents);
22+
const absFilePath = path.resolve(path.join(basePath, filePath));
23+
await fs.mkdir(path.dirname(absFilePath), { recursive: true });
24+
await fs.writeFile(absFilePath, contents);
2425
};
2526

2627
writeToDirectory = async (directoryPath: string) => {

0 commit comments

Comments
 (0)