-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#27 Added support for not adding projects to dever_config.json when k…
…eywords conflict with pre-defined keys
- Loading branch information
Showing
5 changed files
with
160 additions
and
119 deletions.
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
This file was deleted.
Oops, something went wrong.
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,118 @@ | ||
const config_handler = require('./handleConfigFile'); | ||
|
||
module.exports = new class { | ||
/** | ||
* Gets only one component specifically looking through component keywords found in dever.json | ||
* @param keyword | ||
* @returns Config | ||
*/ | ||
get(keyword) { | ||
let config = this.#getProjects(); | ||
if (config == null) { | ||
return null; | ||
} | ||
|
||
let components = []; | ||
|
||
config.components.forEach(x => { | ||
if (x == null) { | ||
return; | ||
} | ||
|
||
if (x.keywords.includes(keyword)) { | ||
components.push(x); | ||
} | ||
}) | ||
|
||
if (components.length > 1) { | ||
console.error('Components are not allowed to share keywords. Please fix this.'); | ||
return null; | ||
} | ||
|
||
if (components.length === 0) { | ||
return null; | ||
} | ||
|
||
return components[0]; | ||
} | ||
|
||
/** | ||
* Gets all projects from dever_config.json | ||
* @returns {Config[] | null} | ||
*/ | ||
getAll() { | ||
const config = this.#getProjects(); | ||
if (config == null) { | ||
return null; | ||
} | ||
|
||
const components = []; | ||
|
||
config.components.forEach(x => { | ||
if (x == null) { | ||
return; | ||
} | ||
|
||
components.push(x); | ||
}); | ||
|
||
return components; | ||
} | ||
|
||
/** | ||
* Removes all projects from dever_config.json | ||
* @return void | ||
*/ | ||
clear() { | ||
const config = config_handler.get(); | ||
|
||
config.components = []; | ||
|
||
config_handler.write(config); | ||
} | ||
|
||
/** | ||
* Adds project to dever_config.json | ||
* @param file string | ||
*/ | ||
add(file) { | ||
const config = config_handler.get(); | ||
|
||
config.components.push(file); | ||
|
||
config_handler.write(config); | ||
} | ||
|
||
/** | ||
* Removes project from dever_config.json | ||
* @param file {string} | ||
*/ | ||
remove(file) { | ||
const config = config_handler.get(); | ||
|
||
const index = config.components.indexOf(file); | ||
if (index === -1) { | ||
return; | ||
} | ||
|
||
config.components.splice(index, 1); | ||
|
||
config_handler.write(config); | ||
} | ||
|
||
/** | ||
* Gets all components and their dever.json configuration | ||
* @returns LocalConfig | ||
*/ | ||
#getProjects() { | ||
const config = config_handler.get(); | ||
if (config.components == null || config.components.length === 0) { | ||
console.error("No components found. Please run 'dever init'"); | ||
return null; | ||
} | ||
|
||
return { | ||
components: config.components.map(x => config_handler.getComponentConfig(x)) | ||
} | ||
} | ||
} |
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