forked from hazza/dspace-angular
33 lines
739 B
TypeScript
33 lines
739 B
TypeScript
import * as fs from 'fs';
|
|
import * as yaml from 'js-yaml';
|
|
import { join } from 'path';
|
|
|
|
const args = process.argv.slice(2);
|
|
|
|
if (args[0] === undefined) {
|
|
console.log(`Usage:\n\tyarn env:yaml [relative path to environment.ts file] (optional relative path to write yaml file)\n`);
|
|
process.exit(0);
|
|
}
|
|
|
|
const envFullPath = join(process.cwd(), args[0]);
|
|
|
|
if (!fs.existsSync(envFullPath)) {
|
|
console.error(`Error:\n${envFullPath} does not exist\n`);
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
const env = require(envFullPath);
|
|
|
|
const config = yaml.dump(env);
|
|
if (args[1]) {
|
|
const ymlFullPath = join(process.cwd(), args[1]);
|
|
fs.writeFileSync(ymlFullPath, config);
|
|
} else {
|
|
console.log(config);
|
|
}
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
|