Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/tools/kolibri-cli/src/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MODIFIED_FILES,
POST_MESSAGES,
setRemoveMode,
hasKolibriTags,
} from './shares/reuse';
import { REMOVE_MODE, RemoveMode } from './types';

Expand Down Expand Up @@ -91,6 +92,13 @@ Target version of @public-ui/*: ${options.overwriteTargetVersion}
Source folder to migrate: ${baseDir}
`);

Comment thread
deleonio marked this conversation as resolved.
if (!fs.existsSync(baseDir)) {
throw logAndCreateError(`The specified source folder "${baseDir}" does not exist or is inaccessible. Please check the path and try again.`);
}
if (!hasKolibriTags(baseDir)) {
console.log(chalk.yellow(`No KoliBri components (web or React) found under "${baseDir}". Check the path or your task configuration.`));
Comment thread
deleonio marked this conversation as resolved.
}

if (!options.ignoreGreaterVersion && semver.lt(options.overwriteTargetVersion, options.overwriteCurrentVersion)) {
throw logAndCreateError(
'Your current version of @public-ui/components is greater than the version of @public-ui/kolibri-cli. Please update @public-ui/kolibri-cli or force the migration with --ignore-greater-version.',
Expand Down Expand Up @@ -203,6 +211,10 @@ Modified files: ${MODIFIED_FILES.size}`);
console.log(`- ${file}`);
});

if (MODIFIED_FILES.size === 0) {
console.log(chalk.yellow(`No files were modified. Verify the folder "${baseDir}" or check your .kolibri.config.json tasks.`));
}

if (MODIFIED_FILES.size > 0 && options.format) {
console.log(`
We try to format the modified files with prettier...`);
Expand Down
25 changes: 24 additions & 1 deletion packages/tools/kolibri-cli/src/migrate/shares/reuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from 'chalk';
import fs from 'fs';
import path from 'path';

import { FileExtension, PackageJson } from '../../types';
import { FileExtension, PackageJson, MARKUP_EXTENSIONS, WEB_TAG_REGEX, REACT_TAG_REGEX } from '../../types';
import { RemoveMode } from '../types';

/**
Expand Down Expand Up @@ -61,6 +61,29 @@ export function filterFilesByExt(dir: string, ext: FileExtension | FileExtension
return files;
}

/**
* Checks if the specified directory contains any files with KoliBri tags.
* @param {string} dir The directory to search in
* @returns {boolean} True if at least one file contains KoliBri component tags (web or React)
*/
export function hasKolibriTags(dir: string): boolean {
const regexes = [WEB_TAG_REGEX, REACT_TAG_REGEX];
const files = filterFilesByExt(dir, MARKUP_EXTENSIONS);

for (const file of files) {
try {
const content = fs.readFileSync(file, 'utf8');
if (regexes.some((regex) => regex.test(content))) {
Comment thread
deleonio marked this conversation as resolved.
Outdated
return true;
}
} catch (err) {
console.error(`Error reading file ${file}:`, err);
Comment thread
deleonio marked this conversation as resolved.
Outdated
}
}

return false;
}

/**
* This function is used to get the version of the package.json as string.
* @param {string} offsetPath The offset path to the package.json
Expand Down
3 changes: 3 additions & 0 deletions packages/tools/kolibri-cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const COMPONENT_FILE_EXTENSIONS: FileExtension[] = ['jsx', 'tsx', 'vue'];
export const CUSTOM_ELEMENT_FILE_EXTENSIONS: FileExtension[] = ['html', 'xhtml', 'jsx', 'tsx', 'vue'];
export const MARKUP_EXTENSIONS: FileExtension[] = COMPONENT_FILE_EXTENSIONS.concat(CUSTOM_ELEMENT_FILE_EXTENSIONS);

export const WEB_TAG_REGEX = /\b<kol-[a-z-]+/i;
Comment thread
deleonio marked this conversation as resolved.
Comment thread
deleonio marked this conversation as resolved.
export const REACT_TAG_REGEX = /\b<Kol[A-Z][A-Za-z]*/;
Comment thread
deleonio marked this conversation as resolved.

export type PackageJson = {
name: string;
version: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/tools/visual-tests/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { readFile } from 'fs/promises';
import * as fs from 'fs';
import portfinder from 'portfinder';
import * as process from 'process';
import os from 'node:os';

const tempDir = process.env.RUNNER_TEMP || process.env.TMPDIR; // TODO: Check on Windows
const tempDir = process.env.RUNNER_TEMP || process.env.TMPDIR || os.tmpdir(); // TODO: Check on Windows

if (!process.env.THEME_MODULE) {
throw new Error('Environment variable THEME_MODULE not specified.');
Expand Down
Loading