Socket
Socket
Sign inDemoInstall

clean-rn

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

90

index.js
#! /usr/bin/env node
const shell = require('shelljs')
const { path } = require('app-root-path')
const fs = require("fs")
const {existsSync, rmSync, readFileSync} = require('fs')
const {homedir} = require('os')
const {join} = require('path')
const {execSync:exec} = require('child_process')
const appRoot = process.cwd()
function error(message) {
console.log('\x1b[31m%s\x1b[0m', message);
}
function hasReactNativeDependency() {
try {
const packageJson = JSON.parse(readFileSync(join(appRoot, 'package.json'), 'utf8'));
const dependencies = packageJson.dependencies || {};
const devDependencies = packageJson.devDependencies || {};
const hasReactNativeDependency = dependencies['react-native'] || devDependencies['react-native'];
return hasReactNativeDependency;
} catch (err) {
error(
'Could not parse package.json. make sure your terminal is at the root of your React Native project',
);
return false;
}
}
if (!hasReactNativeDependency()) {
error('This is not a React Native project');
process.exit(1);
}
function rm(path) {
try {
fs.rmSync(path, { recursive: true, force: true })
rmSync(path, { recursive: true, force: true })
} catch (e) {
console.warn(`Failed to delete ${path}, continuing..`)
error(`Failed to delete ${path}, continuing..`)
}
}
console.log(`clean-rn: Cleaning React Native caches for ${path}..`)
console.log(`clean-rn: Cleaning React Native caches for ${appRoot}..`)
// npm
rm(`${path}/node_modules`)
rm(join(appRoot, 'node_modules'))
rm(`${path}/yarn.lock`)
shell.exec("yarn cache clean")
if(existsSync(join(appRoot, 'package-lock.json'))) {
exec('npm cache clean --force')
rm(join(appRoot, 'package-lock.json'))
} else if(existsSync(join(appRoot, 'yarn.lock'))) {
exec('yarn cache clean')
rm(join(appRoot, 'yarn.lock'))
} else if(existsSync(join(appRoot, 'pnpm-lock.yaml'))) {
exec('pnpm store prune')
rm(join(appRoot, 'pnpm-lock.yaml'))
}
rm(`${path}/package-lock.json`)
shell.exec("npm cache clean --force")
// android
rm(`${path}/android/.gradle`)
rm(`${path}/android/.idea`)
rm(`${path}/android/.cxx`)
rm(`${path}/android/build`)
rm(`${path}/android/app/build`)
rm(`${path}/android/app/.cxx`)
rm(`$HOME/.gradle/caches`)
shell.exec("./android/gradlew cleanBuildCache")
const androidPaths=[
'.gradle',
'.idea',
'.cxx',
'build',
'build',
join('app', 'build'),
join('app', '.cxx'),
]
androidPaths.forEach((p) => rm(join(appRoot, 'android', p)))
exec(join(appRoot, 'android', 'gradlew --stop')) // stop gradle daemon
rm(join(homedir(), '.gradle', 'caches'))
exec(join(appRoot, 'android', 'gradlew clean'))
// ios
rm(`${path}/ios/build`)
rm(`${path}/ios/Pods`)
rm(`${path}/ios/DerivedData`)
console.log("Cleaned everything! Run:\n - yarn/npm i\n - cd ios && pod repo update && pod update\n..to reinstall everything!")
const iosPaths=[
'build',
'Pods',
'Podfile.lock',
'DerivedData',
]
iosPaths.forEach((p) => rm(join(appRoot, 'ios', p)))
console.log('Cleaned everything! Run:\n - yarn/npm i\n - cd ios && pod repo update && pod update\n..to reinstall everything!')
{
"name": "clean-rn",
"version": "1.0.2",
"version": "1.0.3",
"description": "Clean all React Native caches in your project.",

@@ -33,7 +33,3 @@ "main": "index.js",

},
"homepage": "https://github.com/mrousavy/clean-rn#readme",
"dependencies": {
"app-root-path": "^3.1.0",
"shelljs": "^0.8.5"
}
"homepage": "https://github.com/mrousavy/clean-rn#readme"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc