magically-sdk
Version:
Official SDK for Magically - Build mobile apps with AI
125 lines (112 loc) • 3.66 kB
JavaScript
const fs = require('fs');
const path = require('path');
// Get the current version from package.json
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const newVersion = packageJson.version;
console.log(`✨ Syncing magically-sdk version to ${newVersion}...`);
// Files to update with their specific patterns
const filesToUpdate = [
// TypeScript/JavaScript files with object notation
{
path: '../../src/types/editor.ts',
patterns: [
{
regex: /"magically-sdk":\s*{\s*version:\s*"[^"]+"\s*}/g,
replacement: `"magically-sdk": {version: "${newVersion}"}`
}
]
},
{
path: '../../src/stores/SnackStore.ts',
patterns: [
{
regex: /'magically-sdk':\s*{\s*version:\s*'[^']+'\s*}/g,
replacement: `'magically-sdk': {version: '${newVersion}'}`
}
]
},
// Package.json files
{
path: '../../magically-expo/package.json',
patterns: [
{
regex: /"magically-sdk":\s*"\^?~?[^"]+"/g,
replacement: `"magically-sdk": "^${newVersion}"`
}
]
},
{
path: '../cloudflare-compiler/package.json',
patterns: [
{
regex: /"magically-sdk":\s*"\^?~?[^"]+"/g,
replacement: `"magically-sdk": "^${newVersion}"`
}
]
},
{
path: '../typescript-validator/package.json',
patterns: [
{
regex: /"magically-sdk":\s*"\^?~?[^"]+"/g,
replacement: `"magically-sdk": "${newVersion}"`
}
]
}
];
let updatedCount = 0;
let errorCount = 0;
filesToUpdate.forEach(({ path: relativePath, patterns }) => {
const filePath = path.join(__dirname, relativePath);
try {
if (fs.existsSync(filePath)) {
let content = fs.readFileSync(filePath, 'utf8');
let updated = false;
patterns.forEach(({ regex, replacement }) => {
const matches = content.match(regex);
if (matches) {
content = content.replace(regex, replacement);
updated = true;
}
});
if (updated) {
fs.writeFileSync(filePath, content, 'utf8');
console.log(`✅ Updated ${relativePath}`);
updatedCount++;
} else {
console.log(`⏭️ No changes needed in ${relativePath}`);
}
} else {
console.log(`⚠️ File not found: ${relativePath}`);
}
} catch (error) {
console.error(`❌ Error updating ${relativePath}:`, error.message);
errorCount++;
}
});
console.log(`\n📦 magically-sdk v${newVersion} sync complete!`);
console.log(` Updated: ${updatedCount} files`);
if (errorCount > 0) {
console.log(` Errors: ${errorCount} files`);
process.exit(1);
}
// Trigger Snackager bundling
console.log(`\n🚀 Triggering Snackager bundling for v${newVersion}...`);
const { exec } = require('child_process');
const snackagerUrl = `https://snackager.eascdn.net/bundle/magically-sdk@${newVersion}?version_snackager=true&sdkVersion=53.0.0&platforms=ios,android,web&bypassCache=true`;
exec(`curl -s -o /dev/null -w "%{http_code}" "${snackagerUrl}"`, (error, stdout, stderr) => {
if (error) {
console.error(`❌ Failed to trigger Snackager bundling:`, error.message);
process.exit(1);
}
const statusCode = stdout.trim();
if (statusCode === '200' || statusCode === '202') {
console.log(`✅ Snackager bundling triggered successfully (HTTP ${statusCode})`);
console.log(` Bundle URL: ${snackagerUrl}`);
} else {
console.log(`⚠️ Snackager returned HTTP ${statusCode}`);
console.log(` You may need to manually check: ${snackagerUrl}`);
}
});