Skip to content

Commit

Permalink
Fix files duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
haimkastner committed Sep 9, 2023
1 parent 3cdda8b commit ea6120f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions scripts/fetch-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,27 @@ const SHARED_MODELS_PATH = `${SPEC_FILE_DEST_DIR}/sharedInterfaces.ts`;
async function downloadSourceFile(fileURL, sourceDestination) {
const sharedModelsResponse = await nodeFetch(fileURL);
const sharedModelsResponseBuffer = Buffer.from(await sharedModelsResponse.text(), 'utf-8');
fse.appendFileSync(path.join(sourceDestination), sharedModelsResponseBuffer);
fse.writeFileSync(path.join(sourceDestination), sharedModelsResponseBuffer);
}

(async () => {

// Create generated dir if not yet exists
await fse.promises.mkdir(SPEC_FILE_DEST_DIR, { recursive: true });

console.log(`[fetch-api] Fetching API Spec form server "${API_SERVER_SPEC_BRANCH}" branch...`);

// If local path has been set, use it
if (API_SERVER_SPEC_PATH) {
console.log(`[fetch-api] Coping API Spec from local path "${API_SERVER_SPEC_PATH}"...`);



// And copy spec file
await fse.promises.copyFile(path.join(API_SERVER_SPEC_PATH), path.join(SPEC_FILE_DEST_DIR, SPEC_FILE_NAME));
return;
} else {
await downloadSourceFile(`https://raw.githubusercontent.com/casanet/casanet-server/${API_SERVER_SPEC_BRANCH}/backend/src/generated/swagger.json`, path.join(SPEC_FILE_DEST_DIR, SPEC_FILE_NAME));
}

console.log(`[fetch-api] Fetching API Spec form server "${API_SERVER_SPEC_BRANCH}" branch...`);
// Those are legacy way of sharing TS interfaces, all new interfaces should be part of the OpenAPI spec only
await downloadSourceFile(`https://raw.githubusercontent.com/casanet/casanet-server/${API_SERVER_SPEC_BRANCH}/backend/src/models/remote2localProtocol.ts`, CHANNEL_SPEC_PATH);
await downloadSourceFile(`https://raw.githubusercontent.com/casanet/casanet-server/${API_SERVER_SPEC_BRANCH}/backend/src/models/sharedInterfaces.d.ts`, SHARED_MODELS_PATH);
await downloadSourceFile(`https://raw.githubusercontent.com/casanet/casanet-server/${API_SERVER_SPEC_BRANCH}/backend/src/generated/swagger.json`, path.join(SPEC_FILE_DEST_DIR, SPEC_FILE_NAME));
console.log(`[fetch-api] API Spec fetched successfully`);
})();

0 comments on commit ea6120f

Please sign in to comment.