-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
99 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ | |
"lint-staged": { | ||
"*.{ts,js}": "eslint --fix" | ||
} | ||
} | ||
} |
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,18 @@ | ||
import { environmentVariableControllerGet, environmentVariableControllerUpdateAll } from "../../api/v1/application"; | ||
import { AppSchema } from "../../schema/app"; | ||
import { EnvironmentSchema } from "../../schema/environment"; | ||
import { getEmoji } from "../../util/print"; | ||
|
||
export async function pull(): Promise<void> { | ||
const appSchema = AppSchema.read() | ||
const env = await environmentVariableControllerGet(appSchema.appid) | ||
EnvironmentSchema.write(env) | ||
console.log(`${getEmoji('✅')} env pulled`) | ||
} | ||
|
||
export async function push(): Promise<void> { | ||
const appSchema = AppSchema.read() | ||
const env = EnvironmentSchema.read() | ||
await environmentVariableControllerUpdateAll(appSchema.appid, env) | ||
console.log(`${getEmoji('✅')} env pushed`) | ||
} |
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,28 @@ | ||
import { Command, program } from 'commander' | ||
import { checkApplication } from '../../common/hook' | ||
import { pull, push } from '../../action/environment' | ||
|
||
export function command(): Command { | ||
const cmd = program | ||
.command('environment') | ||
.alias('env') | ||
.hook('preAction', () => { | ||
checkApplication() | ||
}) | ||
|
||
cmd | ||
.command('pull') | ||
.description('push environment variables') | ||
.action(() => { | ||
pull() | ||
}) | ||
|
||
cmd | ||
.command('push') | ||
.description('pull environment variables') | ||
.action(() => { | ||
push() | ||
}) | ||
|
||
return cmd | ||
} |
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 @@ | ||
import * as path from 'node:path' | ||
import * as fs from 'node:fs' | ||
import { getAppPath } from '../util/sys' | ||
import { ENVIRONMENT_SCHEMA_NAME } from '../common/constant' | ||
import * as dotenv from 'dotenv' | ||
import { exist } from '../util/file' | ||
|
||
|
||
export class EnvironmentSchema { | ||
|
||
variables: EnvironmentVariable[] | ||
|
||
|
||
static read(): EnvironmentVariable[] { | ||
const configPath = path.join(getAppPath(), ENVIRONMENT_SCHEMA_NAME) | ||
if (!exist(configPath)) { | ||
return null | ||
} | ||
const dataStr = fs.readFileSync(configPath, 'utf-8') | ||
const data = dotenv.parse(dataStr) | ||
const env: EnvironmentVariable[] = [] | ||
for (const key in data) { | ||
env.push({ | ||
name: key, | ||
value: data[key] | ||
}) | ||
} | ||
return env | ||
} | ||
|
||
static write(env: EnvironmentVariable[]): void { | ||
const configPath = path.join(getAppPath(), ENVIRONMENT_SCHEMA_NAME) | ||
let dataStr = '' | ||
for (const item of env) { | ||
dataStr += `${item.name}=${item.value}\n` | ||
} | ||
fs.writeFileSync(configPath, dataStr) | ||
} | ||
|
||
} | ||
|
||
export interface EnvironmentVariable { | ||
name: string | ||
value: string | ||
} |