Skip to content

Commit

Permalink
WIP Astro
Browse files Browse the repository at this point in the history
  • Loading branch information
st3phhays committed May 14, 2024
1 parent 630dbbc commit d71633c
Show file tree
Hide file tree
Showing 53 changed files with 1,481 additions and 432 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"astro",
"atcb",
"blockquotes",
"bluesky",
Expand Down Expand Up @@ -41,6 +42,7 @@
"socialmedia",
"splide",
"splidejs",
"Statiq",
"stylelint",
"stylelintcache",
"svgstyles",
Expand Down
24 changes: 24 additions & 0 deletions build/build-partials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ const updateLanguageAttributes = async ({
});
}

// if (newExt === '.astro') {
// // Add partial front matter
// await updateContent({
// destination: destination,
// targetFile: file,
// targetFileDestination: destination,
// targetFileContentToReplace: null,
// replaceWithContent: file,
// replacementContentIsFile: true,
// replacementTemplate: `---\npartial: ${newFileName}\n---\n{0}`
// });
// }

await fs.rename(path.join(destination, file), path.join(destination, `${newFileName}${newExt}`));
}
}
Expand All @@ -58,6 +71,7 @@ const init = async () => {
const destinationTemp = './dist/partials/temp';
const destinationCshtml = './dist/partials/cshtml';
const destinationHbs = './dist/partials/hbs';
const destinationAstro = './dist/partials/astro';

await fs.cp('./partials/', destinationTemp, { recursive: true });

Expand All @@ -73,6 +87,7 @@ const init = async () => {

await fs.cp(destinationTemp, destinationCshtml, { recursive: true });
await fs.cp(destinationTemp, destinationHbs, { recursive: true });
await fs.cp(destinationTemp, destinationAstro, { recursive: true });
await fs.rm(destinationTemp, { recursive: true });

// hbs files
Expand All @@ -87,6 +102,7 @@ const init = async () => {

// Delete TopAlertBanner.html
await fs.rm(path.join(destinationHbs, 'TopAlertBanner.html'));
await fs.rm(path.join(destinationAstro, 'TopAlertBanner.html'));

// cshtml files
await updateContent({
Expand All @@ -102,10 +118,12 @@ const init = async () => {
// Delete AlertText.html
await fs.rm(path.join(destinationHbs, 'AlertText.html'));
await fs.rm(path.join(destinationCshtml, 'AlertText.html'));
await fs.rm(path.join(destinationAstro, 'AlertText.html'));

// Update file extensions and casing of names
const filesHbs = await fs.readdir(destinationHbs);
const filesCshtml = await fs.readdir(destinationCshtml);
const filesAstro = await fs.readdir(destinationAstro);

await updateLanguageAttributes({
files: filesHbs,
Expand All @@ -119,6 +137,12 @@ const init = async () => {
newExt: '.cshtml'
});

await updateLanguageAttributes({
files: filesAstro,
destination: destinationAstro,
newExt: '.astro'
});

console.log('✅ Partials built');
} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion build/choco-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const init = async () => {

// Change CSS content
// Font Awesome
if (repository.name === repositoryConfig.portal.name) {
if (repository.name === repositoryConfig.portal.name || repository.language === 'astro') {
console.log('🚀 Updating Font Awesome font path...');
await updateContent({
destination: repository.css,
Expand Down
30 changes: 20 additions & 10 deletions build/data/preview-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export interface FolderMapping {
folder: string;
protocol?: string;
port?: null | number;
isStatic: boolean;
isStatiq: boolean;
isAstro: boolean;
root?: string
};
}
Expand All @@ -20,48 +21,57 @@ export const folderMapping: FolderMapping = {
'--blog': {
folder: 'blog',
port: 5082,
isStatic: true
isStatiq: true,
isAstro: false
},
'--boxstarter': {
folder: 'boxstarter.org',
port: 5083,
isStatic: true
isStatiq: true,
isAstro: false
},
'--community': {
folder: 'community.chocolatey.org',
port: 55881,
isStatic: false,
isStatiq: false,
isAstro: false,
root: '/chocolatey/Website'
},
'--design': {
folder: 'choco-design-system',
port: 5085,
isStatic: true
isStatiq: true,
isAstro: false
},
'--docs': {
folder: 'docs',
port: 5086,
isStatic: true
isStatiq: false,
isAstro: true
},
'--fest': {
folder: 'chocolateyfest',
port: 5084,
isStatic: true
isStatiq: true,
isAstro: false
},
'--org': {
folder: 'chocolatey.org',
port: 5081,
isStatic: true
isStatiq: true,
isAstro: false
},
'--portal': {
folder: 'licensing-services',
protocol: 'https',
port: 44362,
isStatic: false,
isStatiq: false,
isAstro: false,
root: '/source/LicensingServices'
},
'--zendesk': {
folder: 'copenhagen_theme',
isStatic: false
isStatiq: false,
isAstro: false
}
};
30 changes: 29 additions & 1 deletion build/data/repository-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,35 @@ export const defaultRepositoryConfig = {
/^fa-(check|triangle-exclamation|info|xmark)/,
/^text-bg-(info|warning|danger|success)/,
/^data-bs-popper/
]
},
root: './'
};

export const astroRepositoryConfig = {
css: 'public/styles/',
js: 'public/scripts/',
favicons: 'public/',
fontAwesome: 'public/fonts/fontawesome-free/',
images: 'public/images/global-shared/',
partials: 'src/components/global/',
language: 'astro',
purgeCss: {
content: [
'src/**/*.astro',
'src/**/*.html',
'src/**/*.txt',
'src/**/*.md',
'src/**/*.js',
'src/**/*.ts',
'public/**/*.js'
],
safelist: [
'::-webkit-scrollbar',
'::-webkit-scrollbar-thumb',
/^fa-(check|triangle-exclamation|info|xmark)/,
/^text-bg-(info|warning|danger|success)/,
/^data-bs-popper/
]
},
root: './'
Expand Down Expand Up @@ -77,7 +105,7 @@ export const repositoryConfig: Record<string, RepositoryConfig> = {
name: 'design'
},
docs: {
...defaultRepositoryConfig,
...astroRepositoryConfig,
name: 'docs'
},
fest: {
Expand Down
151 changes: 90 additions & 61 deletions build/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,76 +60,105 @@ const init = async () => {
await Promise.all(foldersToRun.map(async (option, index) => {
const folderConfig = folderMapping[option];
const folderName = folderConfig.folder;
const folderIsAstro = folderConfig.isAstro;
const folderPath = path.join(__dirname, '../../', folderName);
const port = folderConfig.port;

// Determine platform specific information
let command;
let previewScript;

if (isWindows) {
previewScript = 'preview.ps1';
command = `powershell.exe -File ./${previewScript} ${port}`;
if (folderIsAstro) {
const childProcessTwo = spawn('yarn dev', [], {
shell: true,
cwd: folderPath
});

childProcessTwo.stdout.on('data', data => {
const output = data.toString().trim();

if (output.includes(`http://localhost:${port}`)) {
// Stop loading animation for this script
clearInterval(loadingIntervals[index]);
process.stdout.write('\r✅ ');
console.log(`Preview for ${folderName} is running on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}. Changes will be automatically reloaded. Keep this terminal open.`);
console.log(`🤖 Listening on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}...`);
}
});

// Handle exit event
childProcessTwo.on('exit', code => {
if (code !== 0) {
clearInterval(loadingIntervals[index]);
process.stdout.write('\r⛔ ');
console.error(`Astro in ${folderPath} exited with code ${code}`);
}
});
} else {
previewScript = 'preview.sh';
command = `./${previewScript} ${port}`;
}

const scriptPath = path.join(folderPath, previewScript);

// Check if preview script exists
try {
await fs.access(scriptPath);
} catch (error) {
clearInterval(loadingIntervals[index]);
process.stdout.write('\r🟨 ');
console.log(`${folderName} does not contain a ${previewScript} file. Skipping...`);
return; // Skip to the next folder
}

const childProcessTwo = spawn(command, [], {
shell: true, // Needed for Windows to execute .sh files
cwd: folderPath // Specify the working directory for the child process
// stdio: 'pipe', // Default value - Works on Mac, but on Windows. On Windows, the .preview.ps1 file gives the error `Error: The handle is invalid.` and closes the running port that was just opened by the script
});

let scriptStarted = false;

childProcessTwo.stdout.on('data', data => {
const output = data.toString().trim();

if (output.includes(`[INFO] Preview server listening at http://localhost:${port}`)) {
// Stop loading animation for this script
clearInterval(loadingIntervals[index]);
process.stdout.write('\r✅ ');
console.log(`Preview for ${folderName} is running on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}`);
console.log(`🤖 Listening on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}...`);
}

if (output.includes('Error: The handle is invalid.')) {
console.log('⛔ Error: The handle is invalid.');
}

if (output.includes('files have changed, re-executing')) {
console.log(`🚀 Rebuilding ${folderName}...`);
scriptStarted = true;
// Determine platform specific information
let command;
let previewScript;

if (isWindows) {
previewScript = 'preview.ps1';
command = `powershell.exe -File ./${previewScript} ${port}`;
} else {
previewScript = 'preview.sh';
command = `./${previewScript} ${port}`;
}

// Check if the output contains the completion message
if (scriptStarted && output.includes('[INFO] ========== Completed')) {
console.log(`✅ ${folderName} rebuilt`);
console.log(`🤖 Listening on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}...`);
}
});
const scriptPath = path.join(folderPath, previewScript);

// Handle exit event
childProcessTwo.on('exit', code => {
if (code !== 0) {
// Check if preview script exists
try {
await fs.access(scriptPath);
} catch (error) {
clearInterval(loadingIntervals[index]);
process.stdout.write('\r⛔ ');
console.error(`Preview script in ${folderPath} exited with code ${code}`);
process.stdout.write('\r🟨 ');
console.log(`${folderName} does not contain a ${previewScript} file. Skipping...`);
return; // Skip to the next folder
}
});

const childProcessTwo = spawn(command, [], {
shell: true, // Needed for Windows to execute .sh files
cwd: folderPath // Specify the working directory for the child process
// stdio: 'pipe', // Default value - Works on Mac, but on Windows. On Windows, the .preview.ps1 file gives the error `Error: The handle is invalid.` and closes the running port that was just opened by the script
});

let scriptStarted = false;

childProcessTwo.stdout.on('data', data => {
const output = data.toString().trim();

if (output.includes(`[INFO] Preview server listening at http://localhost:${port}`)) {
// Stop loading animation for this script
clearInterval(loadingIntervals[index]);
process.stdout.write('\r✅ ');
console.log(`Preview for ${folderName} is running on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}`);
console.log(`🤖 Listening on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}...`);
}

if (output.includes('Error: The handle is invalid.')) {
console.log('⛔ Error: The handle is invalid.');
}

if (output.includes('files have changed, re-executing')) {
console.log(`🚀 Rebuilding ${folderName}...`);
scriptStarted = true;
}

// Check if the output contains the completion message
if (scriptStarted && output.includes('[INFO] ========== Completed')) {
console.log(`✅ ${folderName} rebuilt`);
console.log(`🤖 Listening on ${consoleColors.green}http://localhost:${port}${consoleColors.revert}...`);
}
});

// Handle exit event
childProcessTwo.on('exit', code => {
if (code !== 0) {
clearInterval(loadingIntervals[index]);
process.stdout.write('\r⛔ ');
console.error(`Preview script in ${folderPath} exited with code ${code}`);
}
});
}
}));
} catch (error) {
console.error(`⛔ Error: ${error}`);
Expand Down
Loading

0 comments on commit d71633c

Please sign in to comment.