Skip to content

Commit

Permalink
chore: add code to copy models
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 12, 2020
1 parent bc6076e commit b3ddb3f
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion scripts/copy-models/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// @ts-check
const yargs = require("yargs");

const { promises: fsPromises } = require("fs");
const { join } = require("path");

const { models } = yargs
.alias("m", "models")
.string("m")
Expand All @@ -9,5 +12,50 @@ const { models } = yargs
.help().argv;

(async () => {
console.log(models);
const files = await fsPromises.readdir(models.toString(), {
withFileTypes: true,
});

const smithyModelsFiles = files
.filter((file) => file.isDirectory())
.map((dir) => join(models.toString(), dir.name, `smithy/model.json`));

for (const smithyModelsFile of smithyModelsFiles) {
try {
// Test if file exists.
await fsPromises.stat(smithyModelsFile);
// File exists, copy it.
try {
const fileContent = (await fsPromises.readFile(smithyModelsFile))
.toString()
// Fix for issue SMITHY-95
.replace('"smithy.api#authDefinition": {},', "");

const sdkIdRE = /"sdkId": "([^"]*)"/;
const sdkId = fileContent.match(sdkIdRE)[1].toLowerCase().replace(/\s/g, "-");

const versionRE = /"version": "([^"]*)"/;
const version = fileContent.match(versionRE)[1];

// Copy file.
const outputFile = join(
__dirname,
"..",
"..",
"codegen",
"sdk-codegen",
"aws-models",
`${sdkId}.${version}.json`
);
await fsPromises.writeFile(outputFile, fileContent);
} catch (e) {
// Copy failed, log.
console.log(smithyModelsFile);
console.log(e.message);
}
} catch (e) {
// File doesn't exist, ignore.
console.log(e.message);
}
}
})();

0 comments on commit b3ddb3f

Please sign in to comment.