core-maugli 1.2.61 → 1.2.63
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/package.json +1 -1
- package/scripts/check-version-old.js +346 -0
- package/scripts/check-version.js +41 -114
package/package.json
CHANGED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
|
|
11
|
+
// Colors for console output
|
|
12
|
+
const colors = {
|
|
13
|
+
red: '\x1b[31m',
|
|
14
|
+
green: '\x1b[32m',
|
|
15
|
+
yellow: '\x1b[33m',
|
|
16
|
+
blue: '\x1b[34m',
|
|
17
|
+
magenta: '\x1b[35m',
|
|
18
|
+
cyan: '\x1b[36m',
|
|
19
|
+
white: '\x1b[37m',
|
|
20
|
+
reset: '\x1b[0m',
|
|
21
|
+
bold: '\x1b[1m'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function colorize(text, color) {
|
|
25
|
+
return `${colors[color]}${text}${colors.reset}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Handle CLI arguments and environment variables first
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
if (args.includes('--skip-check') ||
|
|
31
|
+
process.env.SKIP_VERSION_CHECK === 'true' ||
|
|
32
|
+
process.env.DISABLE_AUTO_UPDATE === 'true') {
|
|
33
|
+
console.log(colorize('⏭️ Version check skipped', 'yellow'));
|
|
34
|
+
process.exit(0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function getMaugliConfig() {
|
|
38
|
+
try {
|
|
39
|
+
const configPath = path.join(process.cwd(), 'src/config/maugli.config.ts');
|
|
40
|
+
if (!fs.existsSync(configPath)) {
|
|
41
|
+
console.log(colorize('⚠️ maugli.config.ts not found at src/config/maugli.config.ts', 'yellow'));
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Простое чтение конфига через регулярные выражения
|
|
46
|
+
const configContent = fs.readFileSync(configPath, 'utf8');
|
|
47
|
+
console.log(colorize('🔍 Reading maugli.config.ts...', 'cyan'));
|
|
48
|
+
|
|
49
|
+
// Убираем комментарии и лишние пробелы для более точного парсинга
|
|
50
|
+
const cleanContent = configContent
|
|
51
|
+
.replace(/\/\*[\s\S]*?\*\//g, '') // убираем /* */ комментарии
|
|
52
|
+
.replace(/\/\/.*$/gm, '') // убираем // комментарии
|
|
53
|
+
.replace(/\s+/g, ' '); // заменяем множественные пробелы на одинарные
|
|
54
|
+
|
|
55
|
+
// Ищем forceUpdate разными способами
|
|
56
|
+
let forceUpdate = false;
|
|
57
|
+
|
|
58
|
+
// Способ 1: В секции automation
|
|
59
|
+
const automationMatch = cleanContent.match(/automation\s*:\s*\{([^}]*)\}/);
|
|
60
|
+
if (automationMatch) {
|
|
61
|
+
const automationSection = automationMatch[1];
|
|
62
|
+
const forceUpdateMatch = automationSection.match(/forceUpdate\s*:\s*(true|false)/);
|
|
63
|
+
if (forceUpdateMatch) {
|
|
64
|
+
forceUpdate = forceUpdateMatch[1] === 'true';
|
|
65
|
+
console.log(colorize(`📋 Found in automation section - forceUpdate: ${forceUpdate}`, 'cyan'));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Способ 2: Прямой поиск forceUpdate в файле (fallback)
|
|
70
|
+
if (!automationMatch) {
|
|
71
|
+
const directMatch = cleanContent.match(/forceUpdate\s*:\s*(true|false)/);
|
|
72
|
+
if (directMatch) {
|
|
73
|
+
forceUpdate = directMatch[1] === 'true';
|
|
74
|
+
console.log(colorize(`📋 Found direct forceUpdate - value: ${forceUpdate}`, 'cyan'));
|
|
75
|
+
} else {
|
|
76
|
+
console.log(colorize('⚠️ No forceUpdate setting found in config', 'yellow'));
|
|
77
|
+
console.log(colorize('� Make sure your config has: automation: { forceUpdate: true }', 'cyan'));
|
|
78
|
+
|
|
79
|
+
// Показываем часть конфига для диагностики
|
|
80
|
+
const configSnippet = configContent.slice(0, 200).replace(/\n/g, '\\n');
|
|
81
|
+
console.log(colorize(`🔍 Config preview: ${configSnippet}...`, 'gray'));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
automation: {
|
|
87
|
+
forceUpdate: forceUpdate
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.warn(colorize('⚠️ Could not read maugli.config.ts: ' + error.message, 'yellow'));
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function getCurrentVersion() {
|
|
97
|
+
try {
|
|
98
|
+
const packagePath = path.join(process.cwd(), 'package.json');
|
|
99
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
|
100
|
+
return packageJson.dependencies?.['core-maugli'] || packageJson.version;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.warn(colorize('⚠️ Could not read package.json', 'yellow'));
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function getLatestVersion() {
|
|
108
|
+
try {
|
|
109
|
+
const result = execSync('npm view core-maugli version', { encoding: 'utf8' });
|
|
110
|
+
return result.trim();
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.warn(colorize('⚠️ Could not fetch latest version from npm', 'yellow'));
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function isCriticalUpdate(current, latest) {
|
|
118
|
+
// Определяем критические обновления (major version или серьезные security fixes)
|
|
119
|
+
const currentParts = current.replace(/^[\^~]/, '').split('.').map(Number);
|
|
120
|
+
const latestParts = latest.split('.').map(Number);
|
|
121
|
+
|
|
122
|
+
// Разница в major версии - критическое обновление
|
|
123
|
+
if (latestParts[0] > currentParts[0]) return true;
|
|
124
|
+
|
|
125
|
+
// Разница в minor версии больше 2 - критическое
|
|
126
|
+
if (latestParts[1] - currentParts[1] > 2) return true;
|
|
127
|
+
|
|
128
|
+
// Разница в patch версии больше 10 - критическое
|
|
129
|
+
if (latestParts[1] === currentParts[1] && latestParts[2] - currentParts[2] > 10) return true;
|
|
130
|
+
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function compareVersions(current, latest) {
|
|
135
|
+
if (!current || !latest) return false;
|
|
136
|
+
|
|
137
|
+
// Remove ^ or ~ from version if present
|
|
138
|
+
current = current.replace(/^[\^~]/, '');
|
|
139
|
+
|
|
140
|
+
const currentParts = current.split('.').map(Number);
|
|
141
|
+
const latestParts = latest.split('.').map(Number);
|
|
142
|
+
|
|
143
|
+
for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
|
|
144
|
+
const currentPart = currentParts[i] || 0;
|
|
145
|
+
const latestPart = latestParts[i] || 0;
|
|
146
|
+
|
|
147
|
+
if (latestPart > currentPart) return true;
|
|
148
|
+
if (latestPart < currentPart) return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function getUpdateContent(version) {
|
|
155
|
+
try {
|
|
156
|
+
// Try to get changelog or release notes
|
|
157
|
+
const result = execSync(`npm view core-maugli@${version} description`, { encoding: 'utf8' });
|
|
158
|
+
return result.trim();
|
|
159
|
+
} catch (error) {
|
|
160
|
+
return "New version available with improvements and bug fixes.";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function promptUpdate() {
|
|
165
|
+
return new Promise((resolve) => {
|
|
166
|
+
// Check for CI/CD environments
|
|
167
|
+
const isCI = process.env.CI === 'true' ||
|
|
168
|
+
process.env.NETLIFY === 'true' ||
|
|
169
|
+
process.env.VERCEL === '1' ||
|
|
170
|
+
process.env.GITHUB_ACTIONS === 'true' ||
|
|
171
|
+
process.env.BUILD_ID || // Netlify
|
|
172
|
+
process.env.VERCEL_ENV || // Vercel
|
|
173
|
+
!process.stdin.isTTY; // Non-interactive terminal
|
|
174
|
+
|
|
175
|
+
if (isCI) {
|
|
176
|
+
console.log(colorize('\n🤖 CI/CD environment detected. Auto-updating...', 'cyan'));
|
|
177
|
+
resolve(true);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Simple input handling that works across all environments
|
|
182
|
+
process.stdin.resume();
|
|
183
|
+
process.stdin.setEncoding('utf8');
|
|
184
|
+
|
|
185
|
+
const handleInput = (data) => {
|
|
186
|
+
const input = data.toString().trim().toLowerCase();
|
|
187
|
+
process.stdin.pause();
|
|
188
|
+
process.stdin.removeListener('data', handleInput);
|
|
189
|
+
|
|
190
|
+
if (input === 'y' || input === 'yes' || input === '') {
|
|
191
|
+
resolve(true);
|
|
192
|
+
} else if (input === 'n' || input === 'no') {
|
|
193
|
+
resolve(false);
|
|
194
|
+
} else {
|
|
195
|
+
console.log(colorize('\nPlease enter Y for yes or N for no:', 'yellow'));
|
|
196
|
+
process.stdout.write(colorize('🔄 Would you like to update now? (Y/n): ', 'bold'));
|
|
197
|
+
process.stdin.resume();
|
|
198
|
+
process.stdin.once('data', handleInput);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
process.stdin.once('data', handleInput);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function performUpdate() {
|
|
207
|
+
console.log(colorize('\n🔄 Updating core-maugli...', 'blue'));
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
// Check if update script exists
|
|
211
|
+
const updateScriptPath = path.join(process.cwd(), 'scripts', 'update-all-blogs.js');
|
|
212
|
+
if (fs.existsSync(updateScriptPath)) {
|
|
213
|
+
console.log(colorize('📦 Running update script...', 'cyan'));
|
|
214
|
+
execSync(`node ${updateScriptPath} ${process.cwd()}`, { stdio: 'inherit' });
|
|
215
|
+
} else {
|
|
216
|
+
// Fallback to simple npm update
|
|
217
|
+
console.log(colorize('📦 Running npm update...', 'cyan'));
|
|
218
|
+
execSync('npm update core-maugli', { stdio: 'inherit' });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
console.log(colorize('✅ Update completed successfully!', 'green'));
|
|
222
|
+
return true;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error(colorize('❌ Update failed:', 'red'), error.message);
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function main() {
|
|
230
|
+
console.log(colorize('\n🔍 Checking for core-maugli updates...', 'cyan'));
|
|
231
|
+
|
|
232
|
+
const currentVersion = await getCurrentVersion();
|
|
233
|
+
const latestVersion = await getLatestVersion();
|
|
234
|
+
const maugliConfig = await getMaugliConfig();
|
|
235
|
+
|
|
236
|
+
if (!currentVersion || !latestVersion) {
|
|
237
|
+
console.log(colorize('⚠️ Could not check version. Continuing with build...', 'yellow'));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
console.log(colorize(`📦 Current version: ${currentVersion}`, 'white'));
|
|
242
|
+
console.log(colorize(`📦 Latest version: ${latestVersion}`, 'white'));
|
|
243
|
+
|
|
244
|
+
if (!compareVersions(currentVersion, latestVersion)) {
|
|
245
|
+
console.log(colorize('✅ You are using the latest version!', 'green'));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// New version available
|
|
250
|
+
console.log(colorize('\n🎉 A new version of core-maugli is available!', 'magenta'));
|
|
251
|
+
console.log(colorize('═'.repeat(60), 'magenta'));
|
|
252
|
+
|
|
253
|
+
const updateContent = await getUpdateContent(latestVersion);
|
|
254
|
+
console.log(colorize(`\n📋 What's new in v${latestVersion}:`, 'bold'));
|
|
255
|
+
console.log(colorize(updateContent, 'white'));
|
|
256
|
+
|
|
257
|
+
console.log(colorize('\n🚀 New features include:', 'bold'));
|
|
258
|
+
console.log(colorize('• Enhanced image optimization pipeline', 'green'));
|
|
259
|
+
console.log(colorize('• Improved build performance', 'green'));
|
|
260
|
+
console.log(colorize('• Better asset management', 'green'));
|
|
261
|
+
console.log(colorize('• Centralized update system', 'green'));
|
|
262
|
+
console.log(colorize('• Bug fixes and stability improvements', 'green'));
|
|
263
|
+
|
|
264
|
+
console.log(colorize('\n💡 Benefits of updating:', 'bold'));
|
|
265
|
+
console.log(colorize('• Faster build times with flatten-images optimization', 'cyan'));
|
|
266
|
+
console.log(colorize('• Better Netlify compatibility', 'cyan'));
|
|
267
|
+
console.log(colorize('• Enhanced security and bug fixes', 'cyan'));
|
|
268
|
+
console.log(colorize('• Access to latest features and improvements', 'cyan'));
|
|
269
|
+
|
|
270
|
+
console.log(colorize('\n═'.repeat(60), 'magenta'));
|
|
271
|
+
|
|
272
|
+
// Проверяем, является ли обновление критическим
|
|
273
|
+
const isCritical = isCriticalUpdate(currentVersion, latestVersion);
|
|
274
|
+
|
|
275
|
+
if (isCritical) {
|
|
276
|
+
console.log(colorize(`\n🚨 CRITICAL UPDATE REQUIRED!`, 'red'));
|
|
277
|
+
console.log(colorize(`Your version (${currentVersion}) is significantly outdated.`, 'red'));
|
|
278
|
+
console.log(colorize('This update contains important security fixes and breaking changes.', 'red'));
|
|
279
|
+
console.log(colorize('Building with outdated version may cause errors.', 'red'));
|
|
280
|
+
} else {
|
|
281
|
+
console.log(colorize(`\n⚠️ Your current version (${currentVersion}) is outdated.`, 'yellow'));
|
|
282
|
+
console.log(colorize('To ensure optimal performance and security, updating is recommended.', 'yellow'));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Check for CI/CD environments and forceUpdate setting
|
|
286
|
+
const isCI = process.env.CI === 'true' ||
|
|
287
|
+
process.env.NETLIFY === 'true' ||
|
|
288
|
+
process.env.VERCEL === '1' ||
|
|
289
|
+
process.env.GITHUB_ACTIONS === 'true' ||
|
|
290
|
+
process.env.BUILD_ID || // Netlify
|
|
291
|
+
process.env.VERCEL_ENV || // Vercel
|
|
292
|
+
!process.stdin.isTTY; // Non-interactive terminal
|
|
293
|
+
|
|
294
|
+
// Check forceUpdate setting from maugli.config.ts
|
|
295
|
+
const forceUpdate = maugliConfig?.automation?.forceUpdate || false;
|
|
296
|
+
|
|
297
|
+
console.log(colorize(`\n🔧 Configuration check:`, 'cyan'));
|
|
298
|
+
console.log(colorize(` • maugli.config.ts found: ${maugliConfig ? 'Yes' : 'No'}`, 'white'));
|
|
299
|
+
console.log(colorize(` • forceUpdate setting: ${forceUpdate}`, 'white'));
|
|
300
|
+
console.log(colorize(` • CI/CD detected: ${isCI}`, 'white'));
|
|
301
|
+
|
|
302
|
+
// Если конфиг не найден, предложим создать его
|
|
303
|
+
if (!maugliConfig) {
|
|
304
|
+
console.log(colorize('\n💡 To enable automatic updates, create src/config/maugli.config.ts with:', 'cyan'));
|
|
305
|
+
console.log(colorize(' automation: { forceUpdate: true }', 'white'));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (isCI) {
|
|
309
|
+
console.log(colorize('\n🤖 CI/CD environment detected. Updating automatically...', 'cyan'));
|
|
310
|
+
const success = await performUpdate();
|
|
311
|
+
if (!success) {
|
|
312
|
+
console.log(colorize('\n❌ Auto-update failed in CI/CD environment. Build cancelled.', 'red'));
|
|
313
|
+
process.exit(1);
|
|
314
|
+
}
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (forceUpdate) {
|
|
319
|
+
console.log(colorize('\n🤖 Force update enabled in config. Updating automatically...', 'cyan'));
|
|
320
|
+
const success = await performUpdate();
|
|
321
|
+
if (!success) {
|
|
322
|
+
console.log(colorize('\n❌ Auto-update failed. Continuing with build...', 'yellow'));
|
|
323
|
+
}
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// If forceUpdate is false, show update notification without prompts
|
|
328
|
+
console.log(colorize('\n💡 To update core-maugli, run:', 'cyan'));
|
|
329
|
+
console.log(colorize(' npm run update', 'white'));
|
|
330
|
+
console.log(colorize(' # или', 'gray'));
|
|
331
|
+
console.log(colorize(' npm update core-maugli', 'white'));
|
|
332
|
+
|
|
333
|
+
if (isCritical) {
|
|
334
|
+
console.log(colorize('\n🚨 WARNING: This is a critical update!', 'red'));
|
|
335
|
+
console.log(colorize('Building with this version may cause errors.', 'red'));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
console.log(colorize('\n✅ Proceeding with build...\n', 'green'));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
main().catch(error => {
|
|
343
|
+
console.error(colorize('❌ Version check failed:', 'red'), error.message);
|
|
344
|
+
console.log(colorize('⚠️ Continuing with build...', 'yellow'));
|
|
345
|
+
process.exit(0);
|
|
346
|
+
});
|
package/scripts/check-version.js
CHANGED
|
@@ -38,20 +38,51 @@ async function getMaugliConfig() {
|
|
|
38
38
|
try {
|
|
39
39
|
const configPath = path.join(process.cwd(), 'src/config/maugli.config.ts');
|
|
40
40
|
if (!fs.existsSync(configPath)) {
|
|
41
|
+
console.log(colorize('⚠️ maugli.config.ts not found at src/config/maugli.config.ts', 'yellow'));
|
|
41
42
|
return null;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
// Простое чтение конфига через регулярные выражения
|
|
45
45
|
const configContent = fs.readFileSync(configPath, 'utf8');
|
|
46
|
-
|
|
46
|
+
console.log(colorize('🔍 Reading maugli.config.ts...', 'cyan'));
|
|
47
|
+
|
|
48
|
+
// Простой и надежный поиск forceUpdate
|
|
49
|
+
let forceUpdate = false;
|
|
50
|
+
|
|
51
|
+
// Ищем все строки с forceUpdate
|
|
52
|
+
const lines = configContent.split('\n');
|
|
53
|
+
const forceUpdateLines = lines.filter(line => line.includes('forceUpdate'));
|
|
54
|
+
|
|
55
|
+
console.log(colorize(`🔍 Found ${forceUpdateLines.length} lines with forceUpdate:`, 'cyan'));
|
|
56
|
+
|
|
57
|
+
for (const line of forceUpdateLines) {
|
|
58
|
+
console.log(colorize(` ${line.trim()}`, 'gray'));
|
|
59
|
+
|
|
60
|
+
// Проверяем разные форматы
|
|
61
|
+
if (line.includes('forceUpdate') && line.includes('true')) {
|
|
62
|
+
// Проверяем что это не комментарий
|
|
63
|
+
const trimmedLine = line.trim();
|
|
64
|
+
if (!trimmedLine.startsWith('//') && !trimmedLine.startsWith('*')) {
|
|
65
|
+
forceUpdate = true;
|
|
66
|
+
console.log(colorize(`✅ Found forceUpdate: true in line: ${trimmedLine}`, 'green'));
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!forceUpdate && forceUpdateLines.length > 0) {
|
|
73
|
+
console.log(colorize('⚠️ forceUpdate found but not set to true', 'yellow'));
|
|
74
|
+
} else if (!forceUpdate) {
|
|
75
|
+
console.log(colorize('⚠️ No forceUpdate setting found in config', 'yellow'));
|
|
76
|
+
console.log(colorize('💡 Make sure your config has: automation: { forceUpdate: true }', 'cyan'));
|
|
77
|
+
}
|
|
47
78
|
|
|
48
79
|
return {
|
|
49
80
|
automation: {
|
|
50
|
-
forceUpdate:
|
|
81
|
+
forceUpdate: forceUpdate
|
|
51
82
|
}
|
|
52
83
|
};
|
|
53
84
|
} catch (error) {
|
|
54
|
-
console.warn(colorize('⚠️ Could not read maugli.config.ts', 'yellow'));
|
|
85
|
+
console.warn(colorize('⚠️ Could not read maugli.config.ts: ' + error.message, 'yellow'));
|
|
55
86
|
return null;
|
|
56
87
|
}
|
|
57
88
|
}
|
|
@@ -77,23 +108,6 @@ async function getLatestVersion() {
|
|
|
77
108
|
}
|
|
78
109
|
}
|
|
79
110
|
|
|
80
|
-
function isCriticalUpdate(current, latest) {
|
|
81
|
-
// Определяем критические обновления (major version или серьезные security fixes)
|
|
82
|
-
const currentParts = current.replace(/^[\^~]/, '').split('.').map(Number);
|
|
83
|
-
const latestParts = latest.split('.').map(Number);
|
|
84
|
-
|
|
85
|
-
// Разница в major версии - критическое обновление
|
|
86
|
-
if (latestParts[0] > currentParts[0]) return true;
|
|
87
|
-
|
|
88
|
-
// Разница в minor версии больше 2 - критическое
|
|
89
|
-
if (latestParts[1] - currentParts[1] > 2) return true;
|
|
90
|
-
|
|
91
|
-
// Разница в patch версии больше 10 - критическое
|
|
92
|
-
if (latestParts[1] === currentParts[1] && latestParts[2] - currentParts[2] > 10) return true;
|
|
93
|
-
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
111
|
function compareVersions(current, latest) {
|
|
98
112
|
if (!current || !latest) return false;
|
|
99
113
|
|
|
@@ -114,58 +128,6 @@ function compareVersions(current, latest) {
|
|
|
114
128
|
return false;
|
|
115
129
|
}
|
|
116
130
|
|
|
117
|
-
async function getUpdateContent(version) {
|
|
118
|
-
try {
|
|
119
|
-
// Try to get changelog or release notes
|
|
120
|
-
const result = execSync(`npm view core-maugli@${version} description`, { encoding: 'utf8' });
|
|
121
|
-
return result.trim();
|
|
122
|
-
} catch (error) {
|
|
123
|
-
return "New version available with improvements and bug fixes.";
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function promptUpdate() {
|
|
128
|
-
return new Promise((resolve) => {
|
|
129
|
-
// Check for CI/CD environments
|
|
130
|
-
const isCI = process.env.CI === 'true' ||
|
|
131
|
-
process.env.NETLIFY === 'true' ||
|
|
132
|
-
process.env.VERCEL === '1' ||
|
|
133
|
-
process.env.GITHUB_ACTIONS === 'true' ||
|
|
134
|
-
process.env.BUILD_ID || // Netlify
|
|
135
|
-
process.env.VERCEL_ENV || // Vercel
|
|
136
|
-
!process.stdin.isTTY; // Non-interactive terminal
|
|
137
|
-
|
|
138
|
-
if (isCI) {
|
|
139
|
-
console.log(colorize('\n🤖 CI/CD environment detected. Auto-updating...', 'cyan'));
|
|
140
|
-
resolve(true);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Simple input handling that works across all environments
|
|
145
|
-
process.stdin.resume();
|
|
146
|
-
process.stdin.setEncoding('utf8');
|
|
147
|
-
|
|
148
|
-
const handleInput = (data) => {
|
|
149
|
-
const input = data.toString().trim().toLowerCase();
|
|
150
|
-
process.stdin.pause();
|
|
151
|
-
process.stdin.removeListener('data', handleInput);
|
|
152
|
-
|
|
153
|
-
if (input === 'y' || input === 'yes' || input === '') {
|
|
154
|
-
resolve(true);
|
|
155
|
-
} else if (input === 'n' || input === 'no') {
|
|
156
|
-
resolve(false);
|
|
157
|
-
} else {
|
|
158
|
-
console.log(colorize('\nPlease enter Y for yes or N for no:', 'yellow'));
|
|
159
|
-
process.stdout.write(colorize('🔄 Would you like to update now? (Y/n): ', 'bold'));
|
|
160
|
-
process.stdin.resume();
|
|
161
|
-
process.stdin.once('data', handleInput);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
process.stdin.once('data', handleInput);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
131
|
async function performUpdate() {
|
|
170
132
|
console.log(colorize('\n🔄 Updating core-maugli...', 'blue'));
|
|
171
133
|
|
|
@@ -211,39 +173,6 @@ async function main() {
|
|
|
211
173
|
|
|
212
174
|
// New version available
|
|
213
175
|
console.log(colorize('\n🎉 A new version of core-maugli is available!', 'magenta'));
|
|
214
|
-
console.log(colorize('═'.repeat(60), 'magenta'));
|
|
215
|
-
|
|
216
|
-
const updateContent = await getUpdateContent(latestVersion);
|
|
217
|
-
console.log(colorize(`\n📋 What's new in v${latestVersion}:`, 'bold'));
|
|
218
|
-
console.log(colorize(updateContent, 'white'));
|
|
219
|
-
|
|
220
|
-
console.log(colorize('\n🚀 New features include:', 'bold'));
|
|
221
|
-
console.log(colorize('• Enhanced image optimization pipeline', 'green'));
|
|
222
|
-
console.log(colorize('• Improved build performance', 'green'));
|
|
223
|
-
console.log(colorize('• Better asset management', 'green'));
|
|
224
|
-
console.log(colorize('• Centralized update system', 'green'));
|
|
225
|
-
console.log(colorize('• Bug fixes and stability improvements', 'green'));
|
|
226
|
-
|
|
227
|
-
console.log(colorize('\n💡 Benefits of updating:', 'bold'));
|
|
228
|
-
console.log(colorize('• Faster build times with flatten-images optimization', 'cyan'));
|
|
229
|
-
console.log(colorize('• Better Netlify compatibility', 'cyan'));
|
|
230
|
-
console.log(colorize('• Enhanced security and bug fixes', 'cyan'));
|
|
231
|
-
console.log(colorize('• Access to latest features and improvements', 'cyan'));
|
|
232
|
-
|
|
233
|
-
console.log(colorize('\n═'.repeat(60), 'magenta'));
|
|
234
|
-
|
|
235
|
-
// Проверяем, является ли обновление критическим
|
|
236
|
-
const isCritical = isCriticalUpdate(currentVersion, latestVersion);
|
|
237
|
-
|
|
238
|
-
if (isCritical) {
|
|
239
|
-
console.log(colorize(`\n🚨 CRITICAL UPDATE REQUIRED!`, 'red'));
|
|
240
|
-
console.log(colorize(`Your version (${currentVersion}) is significantly outdated.`, 'red'));
|
|
241
|
-
console.log(colorize('This update contains important security fixes and breaking changes.', 'red'));
|
|
242
|
-
console.log(colorize('Building with outdated version may cause errors.', 'red'));
|
|
243
|
-
} else {
|
|
244
|
-
console.log(colorize(`\n⚠️ Your current version (${currentVersion}) is outdated.`, 'yellow'));
|
|
245
|
-
console.log(colorize('To ensure optimal performance and security, updating is recommended.', 'yellow'));
|
|
246
|
-
}
|
|
247
176
|
|
|
248
177
|
// Check for CI/CD environments and forceUpdate setting
|
|
249
178
|
const isCI = process.env.CI === 'true' ||
|
|
@@ -254,9 +183,13 @@ async function main() {
|
|
|
254
183
|
process.env.VERCEL_ENV || // Vercel
|
|
255
184
|
!process.stdin.isTTY; // Non-interactive terminal
|
|
256
185
|
|
|
257
|
-
// Check forceUpdate setting from maugli.config.ts
|
|
258
186
|
const forceUpdate = maugliConfig?.automation?.forceUpdate || false;
|
|
259
187
|
|
|
188
|
+
console.log(colorize(`\n🔧 Configuration check:`, 'cyan'));
|
|
189
|
+
console.log(colorize(` • maugli.config.ts found: ${maugliConfig ? 'Yes' : 'No'}`, 'white'));
|
|
190
|
+
console.log(colorize(` • forceUpdate setting: ${forceUpdate}`, 'white'));
|
|
191
|
+
console.log(colorize(` • CI/CD detected: ${isCI}`, 'white'));
|
|
192
|
+
|
|
260
193
|
if (isCI) {
|
|
261
194
|
console.log(colorize('\n🤖 CI/CD environment detected. Updating automatically...', 'cyan'));
|
|
262
195
|
const success = await performUpdate();
|
|
@@ -279,15 +212,9 @@ async function main() {
|
|
|
279
212
|
// If forceUpdate is false, show update notification without prompts
|
|
280
213
|
console.log(colorize('\n💡 To update core-maugli, run:', 'cyan'));
|
|
281
214
|
console.log(colorize(' npm run update', 'white'));
|
|
282
|
-
console.log(colorize(' #
|
|
215
|
+
console.log(colorize(' # or', 'gray'));
|
|
283
216
|
console.log(colorize(' npm update core-maugli', 'white'));
|
|
284
217
|
|
|
285
|
-
if (isCritical) {
|
|
286
|
-
console.log(colorize('\n🚨 WARNING: This is a critical update!', 'red'));
|
|
287
|
-
console.log(colorize('Building with this version may cause errors.', 'red'));
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
218
|
console.log(colorize('\n✅ Proceeding with build...\n', 'green'));
|
|
292
219
|
}
|
|
293
220
|
|