Skip to content

Commit

Permalink
feat: add extra ignored file paths and update crowdin copy script
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasgil-arranz committed Jul 31, 2024
1 parent a4a1a32 commit b72dcc4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 35 deletions.
91 changes: 58 additions & 33 deletions copyIgnoredFiles.mjs
Original file line number Diff line number Diff line change
@@ -1,56 +1,81 @@
import fs from 'fs';
import path from 'path';
import glob from 'glob';

// Define the list of language codes
const languages = ['es'];

// Define the ignored files path (as per crowdin.yml configuration)
const ignoredPaths = ['/docs/data/horizon/api-reference/resources/**/*', '/docs/data/horizon/api-reference/errors/**/*'];
const ignoredPaths = [
'/docs/data/horizon/api-reference/resources/**/*',
'/docs/data/horizon/api-reference/errors/**/*',
'/docs/**/*.api.mdx',
'/docs/**/*.json',
'/platforms/anchor-platform/api-reference/resources/**/*',
'/platforms/**/*.api.mdx',
'/platforms/**/*.json'
];

// Function to copy files recursively
function copyFilesRecursively(src, dest) {
if (!fs.existsSync(src)) {
console.log(`Source directory ${src} does not exist.`);
return;
}

fs.mkdirSync(dest, { recursive: true });
const entries = fs.readdirSync(src, { withFileTypes: true });
/**
* Logs a message to the console with a timestamp.
* @param {string} message - The message to log.
*/
function logMessage(message) {
console.log(`[${new Date().toISOString()}] ${message}`);
}

for (let entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
/**
* Copies a file or directory from source to destination.
* @param {string} src - The source path.
* @param {string} dest - The destination path.
*/
function copyFileOrDirectory(src, dest) {
const destDir = path.dirname(dest);
fs.mkdirSync(destDir, { recursive: true });

if (entry.isDirectory()) {
copyFilesRecursively(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
const stat = fs.statSync(src);
if (stat.isDirectory()) {
fs.cpSync(src, dest, { recursive: true });
logMessage(`Successfully copied directory ${src} to ${dest}`);
} else {
fs.copyFileSync(src, dest);
logMessage(`Successfully copied file ${src} to ${dest}`);
}
}

// Function to copy ignored files for each language
/**
* Copies ignored files for each language based on the patterns.
*/
function copyIgnoredFilesForLanguages() {
ignoredPaths.forEach(ignoredPath => {
// Strip the leading and trailing slashes and wildcard for the source path
const srcPath = ignoredPath.replace('/**/*', '').replace(/^\//, '');

languages.forEach(languageCode => {
const destPath = ignoredPath
.replace('/docs', `i18n/${languageCode}/docusaurus-plugin-content-docs/current`)
.replace('/**/*', '')
.replace(/^\//, '');

copyFilesRecursively(srcPath, destPath);
console.log(`Copied ignored files from ${srcPath} to ${destPath}`);
ignoredPaths.forEach(ignoredPattern => {
// Strip the leading slash for the source path
const srcPattern = ignoredPattern.replace(/^\//, '');

glob(srcPattern, (err, files) => {
if (err) {
logMessage(`Error processing pattern ${srcPattern}: ${err.message}`);
return;
}

files.forEach(srcPath => {
languages.forEach(languageCode => {
const destPath = srcPath
.replace(/^docs/, `i18n/${languageCode}/docusaurus-plugin-content-docs/current`)
.replace(/^platforms/, `i18n/${languageCode}/docusaurus-plugin-content-docs-platforms/current`);

copyFileOrDirectory(srcPath, destPath);
});
});
});
});
}

// Main function to execute the workflow
/**
* Main function to execute the workflow.
*/
function main() {
copyIgnoredFilesForLanguages();
console.log('Ignored files copied for all specified languages.');
logMessage('Ignored files copied for all specified languages.');
}

// Execute the main function
Expand Down
4 changes: 2 additions & 2 deletions crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ files:
translation: /i18n/%two_letters_code%/**/%original_file_name%
- source: /docs/**/*
translation: /i18n/%two_letters_code%/docusaurus-plugin-content-docs/current/**/%original_file_name%
ignore : ['/docs/data/horizon/api-reference/resources/**/*', '/docs/data/horizon/api-reference/errors/**/*']
ignore : ['/docs/data/horizon/api-reference/resources/**/*', '/docs/data/horizon/api-reference/errors/**/*', '/docs/**/*.api.mdx', '/docs/**/*.json']
- source: /platforms/**/*
translation: /i18n/%two_letters_code%/docusaurus-plugin-content-docs-platforms/current/**/%original_file_name%
ignore : ['/platforms/anchor-platform/api-reference/resources/**/*']
ignore : ['/platforms/anchor-platform/api-reference/resources/**/*', '/platforms/**/*.api.mdx', '/platforms/**/*.json']

0 comments on commit b72dcc4

Please sign in to comment.