-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(mock-server): rewrite prepare.sh with javascript
- Loading branch information
Showing
4 changed files
with
61 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// This is a prepare script that is automatically run before "start" command. | ||
// | ||
// It is repsonsible to copy files from sdk-test-data into the proper | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
// The format here is: | ||
// env name -> { api path -> file relative to sdk-test-data } | ||
const envs = { | ||
ufc: { | ||
'api/flag-config/v1/config': 'ufc/flags-v1.json', | ||
}, | ||
obfuscated: { | ||
'api/flag-config/v1/config': 'ufc/flags-v1-obfuscated.json', | ||
}, | ||
bandit: { | ||
'api/flag-config/v1/config': 'ufc/bandit-flags-v1.json', | ||
'api/flag-config/v1/bandits': 'ufc/bandit-models-v1.json', | ||
} | ||
} | ||
|
||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const sdkTestDataPath = path.join(__dirname, '../sdk-test-data/') | ||
const publicPath = path.join(__dirname, './public/') | ||
|
||
try { | ||
await fs.rm(path.join(__dirname, 'public'), {recursive: true}); | ||
} catch { | ||
// ignore if it's not present | ||
} | ||
|
||
for (const [env, links] of Object.entries(envs)) { | ||
for (const [target, source] of Object.entries(links)) { | ||
const sourcePath = path.join(sdkTestDataPath, source); | ||
const targetPath = path.join(publicPath, env, target); | ||
|
||
console.log(sourcePath, '->', targetPath); | ||
|
||
await fs.mkdir(path.dirname(targetPath), { recursive: true }); | ||
console.log('mkdir', path.dirname(targetPath)); | ||
await fs.copyFile(sourcePath, targetPath); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.