@akson/cortex-shopify-translations
Version:
Unified Shopify translations management client with product extraction, translation sync, and CLI tools
73 lines (60 loc) ⢠2.53 kB
JavaScript
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log(chalk.blue('\nš§ Cortex Shopify Translations - Setup\n'));
// Create necessary directories
const dirs = [
'translations/data',
'translations/config',
'translations/scripts'
];
for (const dir of dirs) {
const dirPath = path.join(__dirname, dir);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
console.log(chalk.green(`ā Created ${dir}`));
} else {
console.log(chalk.yellow(`ā ${dir} already exists`));
}
}
// Copy brand template if brand.json doesn't exist
const brandTemplatePath = path.join(__dirname, 'translations/config/brand.template.json');
const brandConfigPath = path.join(__dirname, 'translations/config/brand.json');
if (!fs.existsSync(brandConfigPath) && fs.existsSync(brandTemplatePath)) {
fs.copyFileSync(brandTemplatePath, brandConfigPath);
console.log(chalk.green('ā Created brand.json from template'));
console.log(chalk.cyan(' ā Please edit translations/config/brand.json with your brand information'));
} else if (fs.existsSync(brandConfigPath)) {
console.log(chalk.yellow('ā brand.json already exists'));
}
// Create .env file if it doesn't exist
const envPath = path.join(__dirname, '.env');
if (!fs.existsSync(envPath)) {
const envContent = `# Shopify Store Configuration
SHOPIFY_STORE_DOMAIN=your-store.myshopify.com
SHOPIFY_ACCESS_TOKEN=your-access-token
# Language Configuration
SUPPORTED_LANGUAGES=fr,de,it,en
PRIMARY_LANGUAGE=en
# OpenAI Configuration (for AI translations)
OPENAI_API_KEY=your-openai-api-key
# Optional: Resource limits
MAX_RESOURCES_PER_TYPE=100
`;
fs.writeFileSync(envPath, envContent);
console.log(chalk.green('ā Created .env file'));
console.log(chalk.cyan(' ā Please edit .env with your Shopify and OpenAI credentials'));
} else {
console.log(chalk.yellow('ā .env file already exists'));
}
console.log(chalk.blue('\n⨠Setup complete!\n'));
console.log('Next steps:');
console.log('1. Edit .env with your Shopify store credentials');
console.log('2. Edit translations/config/brand.json with your brand information');
console.log('3. Run "npm run extract" to fetch translations from Shopify');
console.log('4. Run "npm run extract:product" to extract product translations');
console.log('\nFor more help, run "npm run extract:help"\n');