diff --git a/package.json b/package.json index c4bf190..71bfc81 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "plg-ghost", "version": "1.0.0", "description": "Host Ghost server in AWS ECS and provision to host static files on AWS S3", - "main": "./dist/run.js", + "main": "./dist/src/run.js", "scripts": { "dev": "ts-node ./src/run.ts", "build": "tsc", @@ -43,12 +43,12 @@ "@cdktf/provider-aws": "8.0.12", "cdktf": "0.11.2", "cdktf-cli": "0.11.2", + "chalk": "4.1.2", "commander": "9.3.0", "constructs": "10.1.37", "psl": "1.9.0", "readline-sync": "1.4.10", - "shelljs": "0.8.5", - "chalk": "4.1.2" + "shelljs": "0.8.5" }, "devDependencies": { "@types/jest": "28.1.1", diff --git a/src/lib/getInput.ts b/src/lib/getInput.ts index 4a8b90b..52fc61e 100644 --- a/src/lib/getInput.ts +++ b/src/lib/getInput.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as readlineSyc from 'readline-sync'; import chalk from 'chalk'; import { Command, Argument } from 'commander'; -import { getRootDomainFromUrl, readJsonFileWithFileName, getCurrentTimestampInSeconds } from '../lib/util'; +import { getRootDomainFromUrl, readJsonFile, getCurrentTimestampInSeconds } from '../lib/util'; import commonConfig from '../config/common.json'; @@ -120,7 +120,8 @@ class GetInput { * @returns {boolean} */ _hasPreviousConfigInFile(): boolean { - const configData = readJsonFileWithFileName(commonConfig.configFile); + const filePath = `${__dirname}/${commonConfig.configFile}`; + const configData = readJsonFile(filePath); let pass = true; for (const key in USER_CONFIGS) { diff --git a/src/lib/util.ts b/src/lib/util.ts index 9e12e10..7b568ee 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -66,13 +66,13 @@ export function getPathSuffixFromUrl(url: string): string { return urlParts.slice(1).join('/'); } -export function readJsonFileWithFileName(fileName: string): any { +export function readJsonFile(filePath: string): any { let fileContent = null; try { - const data = fs.readFileSync(fileName, 'utf-8'); + const data = fs.readFileSync(filePath, 'utf-8'); fileContent = JSON.parse(data); } catch (err) { - console.log(err); + // console.log(err); } finally { fileContent = fileContent || {}; } diff --git a/src/terraform/main.ts b/src/terraform/main.ts index f7cda6c..3acdb4f 100644 --- a/src/terraform/main.ts +++ b/src/terraform/main.ts @@ -1,13 +1,14 @@ import { App } from 'cdktf'; import { BackendStack } from './backend'; import { GhostStack } from './ghost'; -import { readJsonFileWithFileName } from '../lib/util'; +import { readJsonFile } from '../lib/util'; import commonConfig from '../config/common.json'; const app = new App(); -const userInput = readJsonFileWithFileName(commonConfig.configFile); +const filePath = `${__dirname}/${commonConfig.configFile}`; +const userInput = readJsonFile(filePath); new BackendStack(app, commonConfig.backendStackName, { accessKey: userInput.aws.accessKeyId,