Skip to content

Commit

Permalink
Support YML file argument (#36)
Browse files Browse the repository at this point in the history
* Support YML file argument

* Use themeFilePath for finding theme directory config file path
  • Loading branch information
comonadd authored Sep 15, 2021
1 parent 4c7d80d commit 9f95045
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ function createConfigFile() {
});
}

function updateTheme(data, theme, ymlPath, preview = false) {
const themePath = themeFilePath(theme);
function updateThemeWithFile(data, themePath, ymlPath, preview = false) {
const themeFile = fs.readFileSync(themePath, 'utf8');

const doc = YAML.parseDocument(data);
Expand Down Expand Up @@ -82,14 +81,31 @@ function updateTheme(data, theme, ymlPath, preview = false) {
.writeFile(ymlPath, newContent, 'utf8')
.then(() => {
if (!preview) {
console.log(`The theme ${theme} has been applied successfully!`);
const namePairs = colors
? colors.value.items.filter((i) => i.key.value === 'name')
: [];
const themeName = namePairs.length !== 0 ? namePairs[0].value : null;
if (themeName !== null) {
console.log(
`The theme "${themeName}" has been applied successfully!`
);
} else {
console.log(`The theme has been applied successfully!`);
}
}
})
.catch((err) => {
if (err) throw err;
});
}

function updateTheme(data, theme, ymlPath, preview = false) {
const isSpecificFile =
fs.existsSync(theme) && !fs.lstatSync(theme).isDirectory();
const themePath = isSpecificFile ? theme : themeFilePath(theme);
return updateThemeWithFile(data, themePath, ymlPath, preview);
}

function applyTheme(theme, preview = false) {
// alacritty.yml path
const ymlPath = getAlacrittyConfig();
Expand Down

0 comments on commit 9f95045

Please sign in to comment.