Skip to content

Commit

Permalink
Merge pull request #84 from pmadruga/wipe-fix-debug
Browse files Browse the repository at this point in the history
Making tasks truly asynchronous
  • Loading branch information
pmadruga committed Jan 15, 2022
2 parents 22c226f + f2b3b92 commit a0d28ac
Show file tree
Hide file tree
Showing 14 changed files with 2,193 additions and 7,843 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"jest": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["prettier"],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
.yarn-error.log
coverage
example
.vscode
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.DS_Store
npm-debug.log
.yarn-error.log
coverage
example
.vscode
.travis.yml
.github
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"trailingComma": "none"
}
6,048 changes: 2,022 additions & 4,026 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "react-native-clean-project",
"version": "3.6.7",
"version": "4.0.0",
"engines": {
"node": ">=8.9.0"
"node": ">=10.0.0"
},
"description": "Automating the cleaning of a React Native Project",
"main": "./source/index.js",
Expand All @@ -29,12 +29,12 @@
},
"homepage": "https://github.com/pmadruga/react-native-clean-project#readme",
"devDependencies": {
"eslint": "5.2.0",
"eslint-config-prettier": "4.3.0",
"eslint-plugin-node": "9.0.1",
"eslint-plugin-prettier": "3.1.0",
"jest": "24.8.0",
"prettier": "1.17.1"
"eslint": "8.1.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.0.0",
"jest": "27.3.1",
"prettier": "2.4.1"
},
"rnpm": {
"plugin": "./source/plugin.js"
Expand Down
122 changes: 57 additions & 65 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,60 @@ const options = require('./internals/options');
const { executeTask } = require('./internals/executor');
const { tasks } = require('./internals/tasks');

options
.askiOS()
.then(options.askiOSPods)
.then(options.askSystemiOSPodsCache)
.then(options.askUseriOSPodsCache)
.then(options.askUpdatePods)
.then(options.askAndroid)
.then(options.askAndroidCleanProject)
.then(options.askNodeModules)
.then(options.askBrew)
.then(() => {
options.rlInterface.close();
if (options.getWipeiOSBuild()) {
executeTask(tasks.wipeiOSBuildFolder);
}
if (options.getWipeiOSPods()) {
executeTask(tasks.wipeiOSPodsFolder);
}
if (options.getWipeSystemiOSPodsCache()) {
executeTask(tasks.wipeSystemiOSPodsCache);
}
if (options.getWipeUseriOSPodsCache()) {
executeTask(tasks.wipeUseriOSPodsCache);
}
if (options.getWipeAndroidBuild()) {
executeTask(tasks.wipeAndroidBuildFolder);
}
executeTask(tasks.watchmanCacheClear);
executeTask(tasks.wipeTempCaches);
if (options.getUpdateBrew()) {
executeTask(tasks.brewUpdate)
.then(code => {
if (code === 0) {
executeTask(tasks.brewUpgrade);
}
})
.catch(() => {
console.log(
"❌ Skipping task 'brew upgrade' because there was an error with 'brew update'"
);
});
}
let prepareNodeModulesTask = Promise.resolve(true);
if (options.getWipeNodeModules()) {
prepareNodeModulesTask = executeTask(tasks.wipeNodeModules)
.then(() => executeTask(tasks.yarnCacheClean))
.then(() => executeTask(tasks.npmCacheVerify))
.then(() => executeTask(tasks.npmInstall))
.then(() => executeTask(tasks.yarnInstall))
.catch(() => {
console.log(
'❌ Examine output - error in either yarn cache clean, yarn install, or pod update'
);
});
}
prepareNodeModulesTask
.then(() => {
if (options.getCleanAndroidProject()) {
executeTask(tasks.cleanAndroidProject);
}
if (options.getUpdatePods()) {
executeTask(tasks.updatePods);
}
});
});
async function main() {
await options.askiOS();
await options.askiOSPods();
await options.askSystemiOSPodsCache();
await options.askUseriOSPodsCache();
await options.askUpdatePods();
await options.askAndroid();
await options.askAndroidCleanProject();
await options.askNodeModules();
await options.askBrew();

options.rlInterface.close();

await executeTask(tasks.watchmanCacheClear);
await executeTask(tasks.wipeTempCaches);

if (options.getWipeiOSBuild()) {
await executeTask(tasks.wipeiOSBuildFolder);
}

if (options.getWipeiOSPods()) {
await executeTask(tasks.wipeiOSPodsFolder);
}

if (options.getWipeSystemiOSPodsCache()) {
await executeTask(tasks.wipeSystemiOSPodsCache);
}

if (options.getUpdatePods()) {
await executeTask(tasks.updatePods);
}

if (options.getWipeUseriOSPodsCache()) {
await executeTask(tasks.wipeUseriOSPodsCache);
}
if (options.getWipeAndroidBuild()) {
await executeTask(tasks.wipeAndroidBuildFolder);
}

if (options.getUpdateBrew()) {
await executeTask(tasks.brewUpdate);
await executeTask(tasks.brewUpgrade);
}

if (options.getWipeNodeModules()) {
await executeTask(tasks.wipeNodeModules);
await executeTask(tasks.yarnCacheClean);
await executeTask(tasks.npmInstall);
await executeTask(tasks.yarnInstall);
}

if (options.getCleanAndroidProject()) {
await executeTask(tasks.cleanAndroidProject);
}
}

main();
66 changes: 37 additions & 29 deletions source/internals/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,44 @@ function elapsedTime(startTime) {
return `${millisecondCount}ms`;
}

function executeTask(task) {
return new Promise((resolve, reject) => {
const startTime = process.hrtime();
const spawnedTask = spawn(task.command, task.args, { shell: true });

spawnedTask.stderr.on('data', data => {
console.log(`Error running '${task.name}': ${data}`);
});

spawnedTask.on('error', error => {
console.log(
`❌ Command '${task.name}' failed with error: ${error.message}`
);
reject();
});

spawnedTask.on('exit', code => {
if (code !== 0) {
console.log(`❌ Command '${task.name}' failed with code: ${code}`);
reject();
} else {
console.log(
`✅ ${task.name} task has finished running in ${elapsedTime(
startTime
)}.`
);
resolve(code);
}
});
async function executeTask(task) {
// return new Promise((resolve, reject) => {
const startTime = process.hrtime();
const spawnedTask = await spawn(task.command, task.args, { shell: true });

// These are just warnings and will be disabled for now.
// spawnedTask.stderr.on('data', data => {
// console.log(`Error running '${task.name}': ${data}`);
// });

let data = '';
console.log(`\nℹ️ STARTED: "${task.name}"`);
for await (const chunk of spawnedTask.stdout) {
data += chunk;
}

let error = '';
for await (const chunk of spawnedTask.stderr) {
// console.error('stderr chunk: ' + chunk);
error += chunk;
}

const exitCode = await new Promise((resolve /*reject*/) => {
spawnedTask.on('close', resolve);
});

if (exitCode) {
throw new Error(
`\n\nTask "${task.name}" \nError: ${error}. \nExit code: ${exitCode}\n\n`
);
}

console.log(
`✅ FINISHED: "${task.name}" task has finished running in ${elapsedTime(
startTime
)}.`
);
return data;
}

module.exports = {
Expand Down
Loading

0 comments on commit a0d28ac

Please sign in to comment.