Skip to content

Commit

Permalink
Fix build scripts to support new schemes source
Browse files Browse the repository at this point in the history
  • Loading branch information
golf1052 committed Aug 2, 2022
1 parent ae3e9c2 commit ded7df2
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 127 deletions.
7 changes: 3 additions & 4 deletions src/scripts/build-themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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));
});
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/finish-themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export function mainWithDir(workingDirectory: string): void {
});
}

main();
// main();
206 changes: 95 additions & 111 deletions src/scripts/generate-light-schemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -293,4 +277,4 @@ function findMatchingSchemeNames(scheme: string, schemes: string[]): string[] {
return matching;
}

main();
// main();
18 changes: 7 additions & 11 deletions src/scripts/list-themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit ded7df2

Please sign in to comment.