Skip to content

Commit

Permalink
feat: add android clean project
Browse files Browse the repository at this point in the history
  • Loading branch information
wilau2 committed Dec 4, 2019
1 parent 614e49e commit 3b1f21b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ Or add it as a script to your `package.json`

This is a combination of the commands suggested in the React Native documentation plus others.

| State Type | Command | In `clean-project-auto`? | Optional? | Default? | Option Flag |
| -------------------- | ----------------------------- | ------------------------ | ---------- | -------- | ---------------------- |
| React-native cache | `rm -rf $TMPDIR/react-*` | Yes | No | true | |
| Metro bundler cache | `rm -rf $TMPDIR/metro-*` | Yes | No | true | |
| Watchman cache | `watchman watch-del-all` | Yes | No | true | |
| NPM modules | `rm -rf node_modules` | Yes | Yes | true | --keep-node_modules |
| Yarn cache | `yarn cache clean` | Yes | Yes | true | --keep-node-modules |
| Yarn packages | `yarn install` | No | Yes | true | --keep-node-modules |
| NPM cache | `npm cache verify` | Yes | Yes | true | --keep-node-modules |
| NPM Install | `npm ci` | Yes | Yes | true | --keep-node-modules |
| iOS build folder | `rm -rf ios/build` | Yes | Yes | false | --remove-iOS-build |
| iOS pods folder | `rm -rf ios/pods` | Yes | Yes | false | --remove-iOS-pods |
| Android build folder | `rm -rf android/build` | Yes | Yes | false | --remove-android-build |
| Brew package | `brew update && brew upgrade` | No | Yes | true | --keep-brew |
| Pod packages | `pod update` | No | Yes | true | --keep-pods |
| State Type | Command | In `clean-project-auto`? | Optional? | Default? | Option Flag |
| --------------------- | -------------------------------- | ------------------------ | ---------- | -------- | ---------------------- |
| React-native cache | `rm -rf $TMPDIR/react-*` | Yes | No | true | |
| Metro bundler cache | `rm -rf $TMPDIR/metro-*` | Yes | No | true | |
| Watchman cache | `watchman watch-del-all` | Yes | No | true | |
| NPM modules | `rm -rf node_modules` | Yes | Yes | true | --keep-node_modules |
| Yarn cache | `yarn cache clean` | Yes | Yes | true | --keep-node-modules |
| Yarn packages | `yarn install` | No | Yes | true | --keep-node-modules |
| NPM cache | `npm cache verify` | Yes | Yes | true | --keep-node-modules |
| NPM Install | `npm ci` | Yes | Yes | true | --keep-node-modules |
| iOS build folder | `rm -rf ios/build` | Yes | Yes | false | --remove-iOS-build |
| iOS pods folder | `rm -rf ios/pods` | Yes | Yes | false | --remove-iOS-pods |
| Android build folder | `rm -rf android/build` | Yes | Yes | false | --remove-android-build |
| Android clean project | `(cd android && ./gradlew clean)`| Yes | Yes | false | --clean-android-project|
| Brew package | `brew update && brew upgrade` | No | Yes | true | --keep-brew |
| Pod packages | `pod update` | No | Yes | true | --keep-pods |

Example: `./node_modules/.bin/react-native-clean-project --remove-iOS-build`

Expand Down
4 changes: 4 additions & 0 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ options
.then(options.askiOSPods)
.then(options.askUpdatePods)
.then(options.askAndroid)
.then(options.askAndroidCleanProject)
.then(options.askNodeModules)
.then(options.askBrew)
.then(() => {
Expand All @@ -21,6 +22,9 @@ options
if (options.getWipeAndroidBuild()) {
executeTask(tasks.wipeAndroidBuildFolder);
}
if (options.getCleanAndroidProject()) {
executeTask(tasks.cleanAndroidProject);
}
executeTask(tasks.watchmanCacheClear);
executeTask(tasks.wipeTempCaches);
if (options.getUpdateBrew()) {
Expand Down
18 changes: 18 additions & 0 deletions source/internals/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ const rlInterface = createInterface({
// Possible arguments: --remove-iOS-build --remove-android-build --keep-node-modules
const args = process.argv.slice(2);
// Defaults

let cleanAndroidProject = false;
let wipeiOSBuild = false;
let wipeiOSPods = false;
let wipeAndroidBuild = false;
let wipeNodeModules = true;
let updateBrew = true;
let updatePods = true;

const getCleanAndroidProject = () => {
return cleanAndroidProject;
}
const getWipeiOSBuild = () => {
return wipeiOSBuild;
};
Expand Down Expand Up @@ -75,6 +80,17 @@ const askiOSPods = () =>
});
});

const askAndroidCleanProject = () =>
new Promise(resolve => {
if (args.includes('--clean-android-project')) {
cleanAndroidProject = true;
return resolve();
}
return askQuestion('Clean Android project? (Y/n) ', answer => {
cleanAndroidProject = checkAnswer(answer, askAndroidCleanProject, resolve);
});
});

const askAndroid = () =>
new Promise(resolve => {
if (args.includes('--remove-android-build')) {
Expand Down Expand Up @@ -120,6 +136,7 @@ const askUpdatePods = () =>
});

module.exports = {
getCleanAndroidProject,
getWipeiOSBuild,
getWipeiOSPods,
getWipeAndroidBuild,
Expand All @@ -130,6 +147,7 @@ module.exports = {
askiOSPods,
askUpdatePods,
askAndroid,
askAndroidCleanProject,
askNodeModules,
askBrew,
rlInterface
Expand Down
5 changes: 5 additions & 0 deletions source/internals/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const tasks = {
command: 'rm',
args: ['-rf', 'android/build']
},
cleanAndroidProject: {
name: 'clean android project',
command: '(cd android && ./gradlew clean)',
args: []
},
watchmanCacheClear: {
name: 'watchman cache clear (if watchman is installed)',
command: 'watchman watch-del-all || true',
Expand Down

0 comments on commit 3b1f21b

Please sign in to comment.