dry-react
Version:
Initialiseur de structure React Native typée et modulaire
48 lines (39 loc) • 1.44 kB
JavaScript
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
function installPackages() {
const root = path.resolve(__dirname, '..');
const packagePath = path.join(root, 'package.json');
const packagesToAdd = [
'@react-native-async-storage/async-storage',
'@react-navigation/native',
'@react-navigation/native-stack',
'@react-navigation/stack',
'axios',
'react-native-gesture-handler',
'react-native-remix-icon',
'react-native-screens',
'react-native-svg',
'@reduxjs/toolkit',
'react-redux'
];
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
if (!pkg.dependencies) pkg.dependencies = {};
let added = [];
for (const pkgName of packagesToAdd) {
if (!pkg.dependencies[pkgName]) {
pkg.dependencies[pkgName] = 'latest';
added.push(pkgName);
}
}
if (added.length > 0) {
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2));
console.log(`📦 Packages ajoutés à package.json :\n - ${added.join('\n - ')}`);
} else {
console.log(`📦 Tous les packages sont déjà présents dans package.json.`);
}
console.log(`\n📥 Installation avec npm install --force...\n`);
// execSync('npm install --force', { stdio: 'inherit' });
console.log(`\n✅ Installation terminée avec succès.`);
}
module.exports = installPackages;