-
Notifications
You must be signed in to change notification settings - Fork 86
/
inject-env.ts
executable file
·32 lines (27 loc) · 1.03 KB
/
inject-env.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ts-node-script
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
import { replaceInFile } from 'replace-in-file';
import path from 'path';
/**
* Environment variables to be interpolated into the built files. Interpolations
* occur where `%VARIABLE_NAME%` is found.
*
* (FYI: it's best to encapsulate the interpolation as a string, i.e.: `"%VARIABLE_NAME%"`).
*/
const environment = {
WEB_VERSION: require(path.resolve(__dirname, '../packages/magic-sdk/package.json')).version,
REACT_NATIVE_VERSION: require(path.resolve(__dirname, '../packages/@magic-sdk/react-native/package.json')).version,
};
const files = process.argv.slice(2).map((f) => path.resolve(__dirname, '..', f, 'dist/**/*'));
Object.keys(environment).forEach(async (envVar) => {
if (environment[envVar]) {
await replaceInFile({
files,
from: `%${envVar}%`,
to: environment[envVar],
allowEmptyPaths: true,
}).catch(console.error);
}
});