Skip to content

Commit

Permalink
Fix CLI errors when the ew-config file path not found (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleli-akamai committed Apr 13, 2023
1 parent 234398b commit 0cbc4c4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"commands": [
{
"name": "edgeworkers",
"version": "1.7.2",
"version": "1.7.3",
"aliases": ["ew", "edgeworkers"],
"description": "Manage Akamai EdgeWorkers code bundles."
},
{
"name": "edgekv",
"version": "1.7.2",
"version": "1.7.3",
"aliases": ["ekv", "edgekv"],
"description": "Manage Akamai EdgeKV database."
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akamai-edgeworkers-cli",
"version": "1.7.2",
"version": "1.7.3",
"description": "A tool that makes it easier to manage Akamai EdgeWorkers code bundles and EdgeKV databases. Call the EdgeWorkers and EdgeKV API from the command line.",
"repository": "https://github.com/akamai/cli-edgeworkers",
"scripts": {
Expand Down
14 changes: 11 additions & 3 deletions src/utils/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,32 @@ export const Operations = {
export class Config {
path: string;
section: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config: any;

constructor(path: string, section: string) {
this.path = untildify(path);
this.section = section;

// create a config file if it doesn't exist
if (!fs.existsSync(this.path)) {
fs.writeFileSync(this.path, '');
try {
if (!fs.existsSync(this.path)) {
fs.writeFileSync(this.path, '');
}
this.config = ini.parse(fs.readFileSync(this.path, 'utf8'));
} catch (e) {
// When fail to write or read the config file, treat it as an empty config file
console.error(`File path not found: ${this.path}`);
this.config = {};
}
this.config = ini.parse(fs.readFileSync(this.path, 'utf8'));

// initialize the section if not exist
if (!(this.section in this.config)) {
this.config[this.section] = {};
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
save(context: any=null) {
try {
if (context) {
Expand Down

0 comments on commit 0cbc4c4

Please sign in to comment.