From ded7df23f18c78a6392a3e5654cbfa53b44aba88 Mon Sep 17 00:00:00 2001 From: Sanders Lauture Date: Tue, 2 Aug 2022 00:07:46 -0700 Subject: [PATCH] Fix build scripts to support new schemes source --- src/scripts/build-themes.ts | 7 +- src/scripts/finish-themes.ts | 2 +- src/scripts/generate-light-schemes.ts | 206 ++++++++++++-------------- src/scripts/list-themes.ts | 18 +-- 4 files changed, 106 insertions(+), 127 deletions(-) diff --git a/src/scripts/build-themes.ts b/src/scripts/build-themes.ts index b3c617f..99f30d5 100644 --- a/src/scripts/build-themes.ts +++ b/src/scripts/build-themes.ts @@ -36,8 +36,6 @@ function main(): void { // Copy user updated template to builder template directory copy(updatedTemplateFile, path.join(dir, 'sources/templates/vscode/templates/default.mustache')) .then(() => { - - // Generate light schemes generate_light_schemes.mainWithDir(schemesDir); @@ -48,9 +46,10 @@ function main(): void { catch (e) { printE(e); } - - // Empty the themes dir + // Make sure themes dir exists + fs.mkdirSync(themesDir); + // Empty the themes dir fs.readdirSync(themesDir).forEach(file => { fs.unlinkSync(path.join(themesDir, file)); }); diff --git a/src/scripts/finish-themes.ts b/src/scripts/finish-themes.ts index 62efbd0..ad9b993 100644 --- a/src/scripts/finish-themes.ts +++ b/src/scripts/finish-themes.ts @@ -22,4 +22,4 @@ export function mainWithDir(workingDirectory: string): void { }); } -main(); +// main(); diff --git a/src/scripts/generate-light-schemes.ts b/src/scripts/generate-light-schemes.ts index 7bc4daf..acd5dc0 100644 --- a/src/scripts/generate-light-schemes.ts +++ b/src/scripts/generate-light-schemes.ts @@ -30,128 +30,112 @@ export function mainWithDir(workingDirectory: string): void { let dir = fs.readdirSync(path.resolve(workingDirectory)); // then filter out everything that isn't a folder - let schemesDirs = dir.filter(d => { - return d.indexOf('.') == -1; + let schemes = dir.filter(f => { + return f.endsWith('yaml'); }); - schemesDirs.forEach(schemeDir => { - console.log(`Current folder: ${schemeDir}`); - // then for each scheme folder read the directory - let files = fs.readdirSync(path.resolve(workingDirectory, schemeDir)); - - // filter out anything that isn't a .yaml file - let schemes = files.filter(f => { - return f.endsWith('.yaml'); - }); - - // now pair the light and dark themes up, ignore anything that seems like a weird file - // weird files are files where base00 and base07 are either both dark or both light - let pairings: SchemePairing[] = []; - let other: string[] = []; - let schemesCopy = schemes.slice(); - for (let i = 0; i < schemesCopy.length; i++) { - const scheme: string = schemesCopy[i]; - let pathToSchemeFolder = path.resolve(workingDirectory, schemeDir); - let isDark = isSchemeDark(scheme, pathToSchemeFolder); - let matchingSchemes = findMatchingSchemeNames(scheme, schemesCopy); - if (isDark.isWeird) { - if (isDark.isDark) { - console.log(`Scheme is dark on both ends: ${scheme}`); - } - else { - console.log(`Scheme is light on both ends: ${scheme}`); - } - other.push(scheme); - schemesCopy.splice(schemesCopy.indexOf(scheme), 1); - i--; - continue; + // now pair the light and dark themes up, ignore anything that seems like a weird file + // weird files are files where base00 and base07 are either both dark or both light + let pairings: SchemePairing[] = []; + let other: string[] = []; + let schemesCopy = schemes.slice(); + for (let i = 0; i < schemesCopy.length; i++) { + const scheme: string = schemesCopy[i]; + let pathToSchemeFolder = path.resolve(workingDirectory); + let isDark = isSchemeDark(scheme, pathToSchemeFolder); + let matchingSchemes = findMatchingSchemeNames(scheme, schemesCopy); + if (isDark.isWeird) { + if (isDark.isDark) { + console.log(`Scheme is dark on both ends: ${scheme}`); + } else { + console.log(`Scheme is light on both ends: ${scheme}`); } - if (matchingSchemes.length == 0) { - // couldn't find any matching schemes so we probably need to create the other version - if (isDark.isDark) { - pairings.push({ - dark: scheme, - light: null - }); - } - else { - pairings.push({ - dark: null, - light: scheme - }); - } - schemesCopy.splice(schemesCopy.indexOf(scheme), 1); + other.push(scheme); + schemesCopy.splice(schemesCopy.indexOf(scheme), 1); + i--; + continue; + } + if (matchingSchemes.length == 0) { + // couldn't find any matching schemes so we probably need to create the other version + if (isDark.isDark) { + pairings.push({ + dark: scheme, + light: null + }); + } else { + pairings.push({ + dark: null, + light: scheme + }); } - else if (matchingSchemes.length == 1) { - // found a matching - let matchingScheme = matchingSchemes[0]; - let matchingIsDark = isSchemeDark(matchingScheme, pathToSchemeFolder); - if (isDark.isDark == matchingIsDark.isDark) { - // the file we matched to is the same theme type! - console.log(`WARNING: Matching may be incorrect! ${scheme} -> ${matchingScheme}`); - } - if (isDark.isDark) { - pairings.push({ - dark: scheme, - light: matchingScheme - }); - } - else { - pairings.push({ - dark: matchingScheme, - light: scheme - }); - } - schemesCopy.splice(schemesCopy.indexOf(scheme), 1); - schemesCopy.splice(schemesCopy.indexOf(matchingScheme), 1); + schemesCopy.splice(schemesCopy.indexOf(scheme), 1); + } else if (matchingSchemes.length == 1) { + // found a matching + let matchingScheme = matchingSchemes[0]; + let matchingIsDark = isSchemeDark(matchingScheme, pathToSchemeFolder); + if (isDark.isDark == matchingIsDark.isDark) { + // the file we matched to is the same theme type! + console.log(`WARNING: Matching may be incorrect! ${scheme} -> ${matchingScheme}`); } - else if (matchingSchemes.length > 1) { - // if we match on more than one just ignore everything - console.log(`WARNING: Found more than one matching scheme, just pushing to other.`); - console.log(scheme); - matchingSchemes.forEach(s => { - console.log(s); - schemesCopy.splice(schemesCopy.indexOf(s), 1); + if (isDark.isDark) { + pairings.push({ + dark: scheme, + light: matchingScheme + }); + } else { + pairings.push({ + dark: matchingScheme, + light: scheme }); - schemesCopy.splice(schemesCopy.indexOf(scheme), 1); } - // we set i to -1 here because we want to go back to the beginning of the array because we could have - // removed items in any position of the array, we are always removing items from the array so we can't - // infinite loop - i = -1; + schemesCopy.splice(schemesCopy.indexOf(scheme), 1); + schemesCopy.splice(schemesCopy.indexOf(matchingScheme), 1); + } else if (matchingSchemes.length > 1) { + // if we match on more than one just ignore everything + console.log(`WARNING: Found more than one matching scheme, just pushing to other.`); + console.log(scheme); + matchingSchemes.forEach(s => { + console.log(s); + schemesCopy.splice(schemesCopy.indexOf(s), 1); + }); + schemesCopy.splice(schemesCopy.indexOf(scheme), 1); } + // we set i to -1 here because we want to go back to the beginning of the array because we could have + // removed items in any position of the array, we are always removing items from the array so we can't + // infinite loop + i = -1; + } - console.log('Pairings:'); - pairings.forEach(p => { - console.log(`(${p.dark}, ${p.light})`); - }); - console.log('Other:'); - other.forEach(p => { console.log(p); }) + console.log('Pairings:'); + pairings.forEach(p => { + console.log(`(${p.dark}, ${p.light})`); + }); + console.log('Other:'); + other.forEach(p => { console.log(p); }) - // now for each pairing - pairings.forEach(pairing => { - let pathToSchemeFolder = path.resolve(workingDirectory, schemeDir); - if (pairing.dark == null) { - // create dark version from light version - console.log(`Creating dark version from light version: ${pairing.light}`); - pairing.dark = reverseAndPolishScheme(pairing.light as string, pathToSchemeFolder, true, VersionToCreate.Dark, true); - } - if (pairing.light == null) { - // create light version from dark version - console.log(`Creating light version from dark version: ${pairing.dark}`); - pairing.light = reverseAndPolishScheme(pairing.dark, pathToSchemeFolder, true, VersionToCreate.Light, true); - } - // and also make sure schemes are polished - polishScheme(pairing.light, pathToSchemeFolder, VersionToCreate.Light); - polishScheme(pairing.dark, pathToSchemeFolder, VersionToCreate.Dark); - }); + // now for each pairing + pairings.forEach(pairing => { + let pathToSchemeFolder = path.resolve(workingDirectory); + if (pairing.dark == null) { + // create dark version from light version + console.log(`Creating dark version from light version: ${pairing.light}`); + pairing.dark = reverseAndPolishScheme(pairing.light as string, pathToSchemeFolder, true, VersionToCreate.Dark, true); + } + if (pairing.light == null) { + // create light version from dark version + console.log(`Creating light version from dark version: ${pairing.dark}`); + pairing.light = reverseAndPolishScheme(pairing.dark, pathToSchemeFolder, true, VersionToCreate.Light, true); + } + // and also make sure schemes are polished + polishScheme(pairing.light, pathToSchemeFolder, VersionToCreate.Light); + polishScheme(pairing.dark, pathToSchemeFolder, VersionToCreate.Dark); + }); - filesToDelete.forEach(file => { - console.log(`Deleting ${file}`); - fs.unlinkSync(file); - }); - filesToDelete = []; + filesToDelete.forEach(file => { + console.log(`Deleting ${file}`); + fs.unlinkSync(file); }); + filesToDelete = []; } function reverseAndPolishScheme(schemeFile: string, @@ -293,4 +277,4 @@ function findMatchingSchemeNames(scheme: string, schemes: string[]): string[] { return matching; } -main(); +// main(); diff --git a/src/scripts/list-themes.ts b/src/scripts/list-themes.ts index a5bd42d..e8c6b9c 100644 --- a/src/scripts/list-themes.ts +++ b/src/scripts/list-themes.ts @@ -10,23 +10,19 @@ export function main(): void { export function mainWithDir(workingDirectory: string): void { let resolvedWorkingDirectory = path.resolve(workingDirectory); let dir = fs.readdirSync(resolvedWorkingDirectory); - let schemesDirs = dir.filter(d => { - return d.indexOf('.') == -1; + let schemes = dir.filter(f => { + return f.endsWith('yaml'); }); let themesList: string = ''; themesList += '# Available Themes\n\n'; - schemesDirs.forEach(schemeDir => { - let files = fs.readdirSync(path.resolve(workingDirectory, schemeDir)); - let schemes = files.filter(f => { return f.endsWith('.yaml'); }); - schemes.forEach(scheme => { - let loadedScheme: any = yaml.load(fs.readFileSync(path.join(resolvedWorkingDirectory, schemeDir, scheme), 'utf8')); - console.log(loadedScheme.scheme); - themesList += (`${loadedScheme.scheme} \n`); - }); + schemes.forEach(scheme => { + let loadedScheme: any = yaml.load(fs.readFileSync(path.join(resolvedWorkingDirectory, scheme), 'utf8')); + console.log(loadedScheme.scheme); + themesList += (`${loadedScheme.scheme} \n`); }); fs.writeFileSync(path.join(resolvedWorkingDirectory, 'themes.md'), themesList); } -main(); +// main();