Skip to content

Commit

Permalink
(#412) Add Support for CCM
Browse files Browse the repository at this point in the history
This modifies and adds support to choco-theme to
allow generation of JS and CSS on CCM. This also
brings in a handful of accessibility updates that
all Chocolatey websites will benefit from.
  • Loading branch information
st3phhays committed Aug 27, 2024
1 parent 673802c commit 043ba97
Show file tree
Hide file tree
Showing 145 changed files with 123,756 additions and 128,408 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module.exports = {
browser: true,
es2021: true
},
ignorePatterns: ['js/src/lib', 'node_modules', 'wwwroot/js/*.min.js', 'input/assets/js/*.min.js', 'Scripts/*.min.js'],
ignorePatterns: ['js/src/lib', 'node_modules', 'wwwroot/js/**/*.min.js', 'input/assets/js/*.min.js', 'Scripts/*.min.js'],
globals: {
Prism: 'readonly'
Prism: 'readonly',
bootstrap: 'readonly'
},
extends: 'standard',
parserOptions: {
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"combinators",
"corepack",
"cssnano",
"datatable",
"datatables",
"Disqus",
"DOCSEARCH",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chocolatey choco-theme 0.7.4
# Chocolatey choco-theme 0.8.0

**NOTE: This project is used on Chocolatey websites and is being released for the benefit of the community. While we endeavour to help and fix issues, it will be limited to GitHub issues, discussions and pull requests when we are able to.**

Expand Down
35 changes: 0 additions & 35 deletions build/build-portal.ts

This file was deleted.

75 changes: 75 additions & 0 deletions build/build-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env ts-node

/*!
* Script to build additional assets for portal.
* Copyright 2020-2024 Chocolatey Software
* Licensed under Apache License (https://github.com/chocolatey/choco-theme/blob/main/LICENSE)
*/

import * as esbuild from 'esbuild';
import * as fs from 'fs/promises';
import { purgeCss } from './functions/purge-css';
import { repository } from './functions/determine-repository';
import { repositoryConfig } from './data/repository-config';

const init = async () => {
console.log('🚀 Compiling and minifying repository JS...');

if (repository.name === repositoryConfig.ccm.name) {
await fs.rm(`${repository.js}dist`, { force: true, recursive: true });
}

let esbuildOptions: esbuild.BuildOptions = {
entryPoints: [''],
target: 'es2015',
bundle: true,
outdir: '',
minify: true,
outExtension: { '.js': '.min.js' }
}

switch (repository.name) {
case repositoryConfig.ccm.name:
esbuildOptions = {
...esbuildOptions,
external: ['popper.js'],
banner: {
js: `
if (typeof window !== 'undefined') {
window.require = function(module) {
if (module === 'popper.js') return window.Popper;
throw new Error('Cannot find module ' + module);
};
}
`,
},
entryPoints: [
`${repository.js}src/views/**/*.js`,
`${repository.js}src/account.js`
],
outdir: `${repository.js}dist/`
};
break;
case repositoryConfig.portal.name:
esbuildOptions = {
...esbuildOptions,
entryPoints: [`${repository.js}src/*.js`],
outdir: repository.js
};
break;
}

await esbuild.build({
...esbuildOptions
}).then(async () => {
console.log('✅ Repository JS compiled and minified');

// PurgeCSS
await purgeCss({
source: `${repository.css}${repository.name}.min.css`,
repository: repository
});
});
};

init();
153 changes: 108 additions & 45 deletions build/choco-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,12 @@
*/

import * as fs from 'fs/promises';
import * as process from 'process';
import { repository } from './functions/determine-repository';
import { repositoryConfig } from './data/repository-config';
import { purgeCss } from './functions/purge-css';
import { updateContent } from './functions/update-content';

// Process args
const params: Record<string, string> = {};
process.argv.slice(2).forEach(val => {
const [key, value] = val.split('=');

if (key.startsWith('--')) {
params[key.slice(2)] = value;
}
});

// Determine repository information
let repository = repositoryConfig.default;
if (params.repository && repositoryConfig[params.repository]) {
repository = repositoryConfig[params.repository];
console.log('Using repository information:', repository);
}
console.log('Using repository information:', repository);

// Determine source CSS name
let sourceCss: string;
Expand Down Expand Up @@ -69,34 +54,46 @@ const init = async () => {
try {
const containsValidation = repository.name === repositoryConfig.portal.name || repository.name === repositoryConfig.community.name;

// Define arrays for parallel tasks
// Define array for parallel tasks
const parallelTasksInitial = [
{
task: 'theme-toggle.min.js',
source: `${repositoryConfig.theme.js}theme-toggle.min.js`,
destination: `${repository.js}theme-toggle.min.js`,
isFolder: false
},
{
task: `${repository.name}.min.js`,
source: `${repositoryConfig.theme.js}${repository.name}.min.js`,
destination: `${repository.js}${repository.name}.min.js`,
isFolder: false
},
{
task: 'Partials',
source: `${repositoryConfig.theme.partials}${repository.language}/`,
destination: repository.partials
},
{
task: `${repository.name}.min.css`,
source: `${repositoryConfig.theme.css}${sourceCss}.min.css`,
destination: `${repository.css}${repository.name}.min.css`,
isFolder: false
},
{
task: 'PT Sans',
source: repositoryConfig.theme.ptSans,
destination: repository.ptSans,
isFolder: true
}
];

// Conditional tasks
// Not CCM scripts
if (repository.name !== repositoryConfig.ccm.name) {
parallelTasksInitial.push(
{
task: 'theme-toggle.min.js',
source: `${repositoryConfig.theme.js}theme-toggle.min.js`,
destination: `${repository.js}theme-toggle.min.js`,
isFolder: false
},
{
task: `${repository.name}.min.js`,
source: `${repositoryConfig.theme.js}${repository.name}.min.js`,
destination: `${repository.js}${repository.name}.min.js`,
isFolder: false
},
{
task: 'Partials',
source: `${repositoryConfig.theme.partials}${repository.language}/`,
destination: repository.partials,
isFolder: true
}
);
}

// Community only scripts
if (repository.name === repositoryConfig.community.name) {
parallelTasksInitial.push(
Expand Down Expand Up @@ -145,13 +142,62 @@ const init = async () => {
);
}

// bootstrap-duallistbox css
if (repository.name === repositoryConfig.ccm.name) {
parallelTasksInitial.push(
{
task: 'bootstrap-duallistbox.min.css',
source: `${repositoryConfig.theme.css}bootstrap-duallistbox.min.css`,
destination: `${repository.css}bootstrap-duallistbox.min.css`,
isFolder: false
}
);
}

// jstree css
if (repository.name === repositoryConfig.ccm.name) {
parallelTasksInitial.push(
{
task: 'jstree.min.css',
source: `${repositoryConfig.theme.css}jstree.min.css`,
destination: `${repository.css}jstree.min.css`,
isFolder: false
}
);
}

// vendors css
if (repository.name === repositoryConfig.ccm.name) {
parallelTasksInitial.push(
{
task: 'vendors.min.css',
source: `${repositoryConfig.theme.css}vendors.min.css`,
destination: `${repository.css}vendors.min.css`,
isFolder: false
}
);
}

// tempus-dominus css
if (repository.name === repositoryConfig.ccm.name) {
parallelTasksInitial.push(
{
task: 'tempus-dominus.min.css',
source: `${repositoryConfig.theme.css}tempus-dominus.min.css`,
destination: `${repository.css}tempus-dominus.min.css`,
isFolder: false
}
);
}

// Playwright
if (repository.playwright) {
parallelTasksInitial.push(
{
task: 'Playwright tests - general',
source: `${repositoryConfig.theme.playwright}tests/general/`,
destination: `${repository.playwright}general/`
destination: `${repository.playwright}general/`,
isFolder: true
}
);

Expand All @@ -160,7 +206,8 @@ const init = async () => {
{
task: 'Playwright tests - pricing calculator',
source: `${repositoryConfig.theme.playwright}tests/pricing-calculator/`,
destination: `${repository.playwright}pricing-calculator/`
destination: `${repository.playwright}pricing-calculator/`,
isFolder: true
}
);
}
Expand All @@ -172,7 +219,8 @@ const init = async () => {
{
task: 'Favicons',
source: repositoryConfig.theme.favicons,
destination: repository.favicons
destination: repository.favicons,
isFolder: true
}
);
}
Expand All @@ -183,24 +231,26 @@ const init = async () => {
{
task: 'Font Awesome',
source: repositoryConfig.theme.fontAwesome,
destination: repository.fontAwesome
destination: repository.fontAwesome,
isFolder: true
}
);
}

// Images
if (repository.name !== repositoryConfig.zendesk.name) {
if (repository.name !== repositoryConfig.zendesk.name && repository.name !== repositoryConfig.ccm.name) {
parallelTasksInitial.push(
{
task: 'Images',
source: repositoryConfig.theme.images,
destination: repository.images
destination: repository.images,
isFolder: true
}
);
}

// ESLint and tsconfig - needed if repository contains it's own assets along with choco-theme
if (repository.name === repositoryConfig.portal.name) {
if (repository.name === repositoryConfig.portal.name || repository.name === repositoryConfig.ccm.name) {
parallelTasksInitial.push(
{
task: '.eslintrc.js',
Expand Down Expand Up @@ -248,7 +298,7 @@ const init = async () => {

// Change CSS content
// Font Awesome
if (repository.name === repositoryConfig.portal.name || repository.language === 'astro') {
if (repository.name === repositoryConfig.portal.name || repository.name === repositoryConfig.ccm.name || repository.language === 'astro') {
console.log('🚀 Updating Font Awesome font path...');
await updateContent({
destination: repository.css,
Expand Down Expand Up @@ -287,8 +337,21 @@ const init = async () => {
console.log('✅ Image paths for headers updated');
}

if (repository.name === repositoryConfig.ccm.name) {
console.log('🚀 Updating jstree image paths...');
await updateContent({
destination: repository.css,
targetFile: 'jstree.min.css',
targetFileDestination: repository.css,
targetFileContentToReplace: 'url(32px.png)',
replaceWithContent: 'var(--jstree-image-checkbox-path)',
replacementContentIsFile: false
});
console.log('✅ jstree image paths updated');
}

// PurgeCSS
if (repository.name !== repositoryConfig.portal.name) {
if (repository.name !== repositoryConfig.portal.name && repository.name !== repositoryConfig.ccm.name) {
await purgeCss({
source: `${repository.css}${repository.name}.min.css`,
repository: repository
Expand Down
Loading

0 comments on commit 043ba97

Please sign in to comment.