maiass 5.9.7 → 5.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/version-manager.js +119 -21
- package/package.json +1 -1
package/lib/version-manager.js
CHANGED
|
@@ -516,21 +516,96 @@ function updateWordPressVersions(newVersion, projectPath = process.cwd()) {
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
/**
|
|
519
|
-
*
|
|
519
|
+
* Extract version from a file using type and line-start pattern (matches bashmaiass behavior)
|
|
520
|
+
* @param {string} content - File content
|
|
521
|
+
* @param {string} type - File type: 'json', 'txt', 'text', 'php', 'pattern'
|
|
522
|
+
* @param {string} lineStart - Line start pattern for txt type
|
|
523
|
+
* @returns {string|null} Extracted version or null
|
|
524
|
+
*/
|
|
525
|
+
function extractVersionByType(content, type, lineStart) {
|
|
526
|
+
if (type === 'json') {
|
|
527
|
+
return VERSION_FILE_TYPES.json.extract(content);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (type === 'txt' || type === 'text') {
|
|
531
|
+
if (lineStart) {
|
|
532
|
+
for (const line of content.split('\n')) {
|
|
533
|
+
if (line.trim().startsWith(lineStart)) {
|
|
534
|
+
const match = line.match(/(\d+\.\d+\.\d+)/);
|
|
535
|
+
if (match) return match[1];
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
return VERSION_FILE_TYPES.text.extract(content);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (type === 'php' || type === 'pattern') {
|
|
544
|
+
return VERSION_FILE_TYPES.php.extract(content);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Unknown type - try generic version extraction
|
|
548
|
+
const match = content.match(/(\d+\.\d+\.\d+)/);
|
|
549
|
+
return match ? match[1] : null;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Detect version files in the current directory.
|
|
554
|
+
* Checks MAIASS_VERSION_PRIMARY_FILE env var first (from .env.maiass),
|
|
555
|
+
* then falls back to scanning common version file patterns.
|
|
520
556
|
* @param {string} projectPath - Path to project directory
|
|
521
557
|
* @returns {Array} Array of detected version files
|
|
522
558
|
*/
|
|
523
559
|
export function detectVersionFiles(projectPath = process.cwd()) {
|
|
524
560
|
const versionFiles = [];
|
|
525
561
|
|
|
526
|
-
//
|
|
562
|
+
// Check for custom primary version file from .env.maiass first
|
|
563
|
+
const primaryFile = process.env.MAIASS_VERSION_PRIMARY_FILE;
|
|
564
|
+
const primaryType = process.env.MAIASS_VERSION_PRIMARY_TYPE || 'txt';
|
|
565
|
+
const primaryLineStart = process.env.MAIASS_VERSION_PRIMARY_LINE_START || '';
|
|
566
|
+
|
|
567
|
+
if (primaryFile) {
|
|
568
|
+
logger.debug(`Custom primary version file configured: ${primaryFile} (type: ${primaryType})`);
|
|
569
|
+
const filePath = path.isAbsolute(primaryFile)
|
|
570
|
+
? primaryFile
|
|
571
|
+
: path.join(projectPath, primaryFile);
|
|
572
|
+
|
|
573
|
+
if (fs.existsSync(filePath)) {
|
|
574
|
+
try {
|
|
575
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
576
|
+
const version = extractVersionByType(content, primaryType, primaryLineStart);
|
|
577
|
+
|
|
578
|
+
if (version) {
|
|
579
|
+
logger.debug(`Found version ${version} in custom primary file: ${primaryFile}`);
|
|
580
|
+
versionFiles.push({
|
|
581
|
+
path: filePath,
|
|
582
|
+
filename: path.basename(filePath),
|
|
583
|
+
type: primaryType,
|
|
584
|
+
currentVersion: version,
|
|
585
|
+
content,
|
|
586
|
+
isPrimary: true,
|
|
587
|
+
lineStart: primaryLineStart
|
|
588
|
+
});
|
|
589
|
+
return versionFiles;
|
|
590
|
+
} else {
|
|
591
|
+
logger.warning(SYMBOLS.WARNING, `Could not extract version from custom primary file: ${primaryFile}`);
|
|
592
|
+
}
|
|
593
|
+
} catch (error) {
|
|
594
|
+
logger.error(SYMBOLS.CROSS, `Error reading custom primary version file ${primaryFile}: ${error.message}`);
|
|
595
|
+
}
|
|
596
|
+
} else {
|
|
597
|
+
logger.warning(SYMBOLS.WARNING, `Custom primary version file not found: ${filePath}`);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Fallback: scan common version file patterns in project root
|
|
527
602
|
const filesToCheck = [
|
|
528
603
|
'package.json',
|
|
529
604
|
'composer.json',
|
|
530
605
|
'VERSION',
|
|
531
606
|
'version.txt',
|
|
532
|
-
'style.css',
|
|
533
|
-
'plugin.php',
|
|
607
|
+
'style.css',
|
|
608
|
+
'plugin.php',
|
|
534
609
|
'functions.php'
|
|
535
610
|
];
|
|
536
611
|
|
|
@@ -542,7 +617,6 @@ export function detectVersionFiles(projectPath = process.cwd()) {
|
|
|
542
617
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
543
618
|
const ext = path.extname(filename);
|
|
544
619
|
|
|
545
|
-
// Determine file type and check if it contains version info
|
|
546
620
|
for (const [typeName, typeConfig] of Object.entries(VERSION_FILE_TYPES)) {
|
|
547
621
|
if (typeConfig.extensions.includes(ext) || typeConfig.extensions.includes('')) {
|
|
548
622
|
if (typeConfig.detect(content, filename)) {
|
|
@@ -555,13 +629,12 @@ export function detectVersionFiles(projectPath = process.cwd()) {
|
|
|
555
629
|
currentVersion: version,
|
|
556
630
|
content
|
|
557
631
|
});
|
|
558
|
-
break;
|
|
632
|
+
break;
|
|
559
633
|
}
|
|
560
634
|
}
|
|
561
635
|
}
|
|
562
636
|
}
|
|
563
637
|
} catch (error) {
|
|
564
|
-
// Skip files that can't be read
|
|
565
638
|
continue;
|
|
566
639
|
}
|
|
567
640
|
}
|
|
@@ -603,18 +676,24 @@ export async function getCurrentVersion(projectPath = process.cwd()) {
|
|
|
603
676
|
let primaryVersion = null;
|
|
604
677
|
let primarySource = null;
|
|
605
678
|
|
|
606
|
-
// Prioritize
|
|
607
|
-
const
|
|
608
|
-
if (
|
|
609
|
-
primaryVersion =
|
|
610
|
-
primarySource =
|
|
611
|
-
} else
|
|
612
|
-
//
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
679
|
+
// Prioritize custom primary file from .env.maiass if present
|
|
680
|
+
const customPrimary = versionFiles.find(f => f.isPrimary);
|
|
681
|
+
if (customPrimary) {
|
|
682
|
+
primaryVersion = customPrimary.currentVersion;
|
|
683
|
+
primarySource = process.env.MAIASS_VERSION_PRIMARY_FILE || customPrimary.filename;
|
|
684
|
+
} else {
|
|
685
|
+
// Fallback: prioritize package.json
|
|
686
|
+
const packageJson = versionFiles.find(f => f.filename === 'package.json');
|
|
687
|
+
if (packageJson) {
|
|
688
|
+
primaryVersion = packageJson.currentVersion;
|
|
689
|
+
primarySource = 'package.json';
|
|
690
|
+
} else if (versionFiles.length > 0) {
|
|
691
|
+
primaryVersion = versionFiles[0].currentVersion;
|
|
692
|
+
primarySource = versionFiles[0].filename;
|
|
693
|
+
} else if (tagVersion) {
|
|
694
|
+
primaryVersion = tagVersion;
|
|
695
|
+
primarySource = 'git tags';
|
|
696
|
+
}
|
|
618
697
|
}
|
|
619
698
|
|
|
620
699
|
return {
|
|
@@ -765,8 +844,27 @@ export async function updateVersionFiles(newVersion, versionFiles, dryRun = fals
|
|
|
765
844
|
// Update primary version files
|
|
766
845
|
for (const file of versionFiles) {
|
|
767
846
|
try {
|
|
768
|
-
|
|
769
|
-
|
|
847
|
+
let updatedContent = null;
|
|
848
|
+
|
|
849
|
+
// Custom primary file with lineStart pattern needs special handling
|
|
850
|
+
if (file.isPrimary && file.lineStart && (file.type === 'txt' || file.type === 'text')) {
|
|
851
|
+
const lines = file.content.split('\n');
|
|
852
|
+
for (let i = 0; i < lines.length; i++) {
|
|
853
|
+
if (lines[i].trim().startsWith(file.lineStart)) {
|
|
854
|
+
lines[i] = lines[i].replace(/\d+\.\d+\.\d+/, newVersion);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
updatedContent = lines.join('\n');
|
|
858
|
+
} else {
|
|
859
|
+
// Map env types to VERSION_FILE_TYPES keys
|
|
860
|
+
const typeKey = (file.type === 'txt' || file.type === 'text') ? 'text'
|
|
861
|
+
: (file.type === 'pattern') ? 'php'
|
|
862
|
+
: file.type;
|
|
863
|
+
const typeConfig = VERSION_FILE_TYPES[typeKey];
|
|
864
|
+
if (typeConfig) {
|
|
865
|
+
updatedContent = typeConfig.update(file.content, newVersion);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
770
868
|
|
|
771
869
|
if (!updatedContent) {
|
|
772
870
|
results.failed.push({
|