|
1 | 1 | // @ts-check
|
2 |
| -const path = require("path"); |
| 2 | +const { basename, join, relative } = require("path"); |
3 | 3 | const { emptyDirSync } = require("fs-extra");
|
4 |
| -const { copyFileSync, readdirSync, lstatSync } = require("fs"); |
| 4 | +const { copyFileSync } = require("fs"); |
5 | 5 | const { spawnProcess } = require("../utils/spawn-process");
|
6 | 6 | const { CODE_GEN_ROOT, CODE_GEN_SDK_ROOT, TEMP_CODE_GEN_INPUT_DIR } = require("./code-gen-dir");
|
7 |
| -const Glob = require("glob"); |
| 7 | +const { getModelFilepaths } = require("./get-model-filepaths"); |
8 | 8 |
|
9 |
| -const generateClients = async (models) => { |
10 |
| - let designatedModels = false; |
11 |
| - if (typeof models === "string") { |
12 |
| - //`models` is a folder path |
13 |
| - designatedModels = true; |
| 9 | +const generateClients = async (models, batchSize) => { |
| 10 | + const filepaths = getModelFilepaths(models); |
| 11 | + const options = [ |
| 12 | + ":sdk-codegen:clean", |
| 13 | + ":sdk-codegen:build", |
| 14 | + `-PmodelsDirProp=${relative(CODE_GEN_SDK_ROOT, TEMP_CODE_GEN_INPUT_DIR)}`, |
| 15 | + ]; |
| 16 | + |
| 17 | + while (filepaths.length > 0) { |
14 | 18 | emptyDirSync(TEMP_CODE_GEN_INPUT_DIR);
|
15 |
| - console.log(`preparing models from ${models}...`); |
16 |
| - for (const modelFileName of readdirSync(models)) { |
17 |
| - const modelPath = path.join(models, modelFileName); |
18 |
| - if (!lstatSync(modelPath).isFile()) continue; |
19 |
| - console.log(`copying model ${modelFileName}...`); |
20 |
| - copyFileSync(modelPath, path.join(TEMP_CODE_GEN_INPUT_DIR, modelFileName)); |
| 19 | + const filepathsToCopy = filepaths.splice(0, batchSize); |
| 20 | + for (const filepath of filepathsToCopy) { |
| 21 | + const filename = basename(filepath); |
| 22 | + copyFileSync(filepath, join(TEMP_CODE_GEN_INPUT_DIR, filename)); |
21 | 23 | }
|
22 |
| - } else if (Array.isArray(models)) { |
23 |
| - //`models` is a list of globs |
24 |
| - designatedModels = true; |
25 |
| - emptyDirSync(TEMP_CODE_GEN_INPUT_DIR); |
26 |
| - models.forEach((pattern) => { |
27 |
| - const files = Glob.sync(pattern, { |
28 |
| - realpath: true, |
29 |
| - absolute: true, |
30 |
| - }); |
31 |
| - files.forEach((file) => { |
32 |
| - if (!lstatSync(file).isFile()) return; |
33 |
| - const name = path.basename(file); |
34 |
| - console.log(`copying model ${name}...`); |
35 |
| - copyFileSync(file, path.join(TEMP_CODE_GEN_INPUT_DIR, name)); |
36 |
| - }); |
37 |
| - }); |
38 |
| - } else { |
39 |
| - console.log("no model supplied, generating all AWS clients"); |
40 |
| - } |
41 |
| - const options = [":sdk-codegen:clean", ":sdk-codegen:build"]; |
42 |
| - if (designatedModels) { |
43 |
| - options.push(`-PmodelsDirProp=${path.relative(CODE_GEN_SDK_ROOT, TEMP_CODE_GEN_INPUT_DIR)}`); |
| 24 | + await spawnProcess("./gradlew", options, { cwd: CODE_GEN_ROOT }); |
44 | 25 | }
|
45 |
| - |
46 |
| - await spawnProcess("./gradlew", options, { |
47 |
| - cwd: CODE_GEN_ROOT, |
48 |
| - }); |
49 | 26 | };
|
50 | 27 |
|
51 | 28 | const generateProtocolTests = async () => {
|
|
0 commit comments