Refactor the Utopian API - Increase Maintainability
This refactoring a step in the right direction as the code is currently messy. The codebase has been migrated to Typescript (no strict typing yet). This allows for future maintenance and refactoring to be much easier on any developer planning to contribute. This is in preparation for the registration API that will be implemented soon.
All compiled files get outputted into the dist
folder. No more finding which directory the script belongs in since there is now a consistent output with compiled JS files.
During the port, a few bugs have been fixed as a result of Typescript's type checking. Thus already increasing Typescript's value and necessity for future development.
Bugs as a result of type errors
These bug fixes were a necessary change in order to ensure that the compilation of all the typescript files were successful.
utopian-bot.js
The variable i
and posts
was undefined in the current scope. The correct variable references are index
and scoredPosts
.
Change from
if (i + 1 === posts.length) {
conn.close();
process.exit(0);
}
Change to
if (index + 1 === scoredPosts.length) {
conn.close();
process.exit(0);
}
updater-posts.js
next(e)
is usually an express call. However, this script does not use express, removing the invocation fixes this issue.
Change from
.catch(e => {
console.log(`ERROR UPDATING POST ${e}\n`);
next(e)
})
Change to
.catch(e => {
console.log(`ERROR UPDATING POST ${e}\n`);
})
Other changes
Since babel is no longer in use, the copy and babel gulp tasks have been removed. Instead, it has been replaced with a ts compilation task that will compile the entire app.
What needs to be done
As a result of the refactor and new typescript compiler, some changes will need to be made on the server. The change is small but necessary. Whenever changes get pulled in npm run build
will need to be executed to update the app (runs a compilation). Afterwards all future script runs won't require any compilation.
It used to be setup to require a babel compilation on every run and then run it live. This change will make start up a bit faster.
This is in preparation of the new registration API that was announced not to long ago. The future work that will go into it will be based off of this refactor to ease maintenance and future development.
Links
Commit: https://github.com/samrg472/api.utopian.io/commit/e36a2761b4cca237fe03798c4d83a2a412a46693
Pull request: https://github.com/utopian-io/api.utopian.io/pull/36
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
[utopian-moderator]
Congratulations @samrg472! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of posts published
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Hey @samrg472 I am @utopian-io. I have just upvoted you at 5% Power!
Achievements
Suggestions
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Vote for my Witness. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Great information
This is some excellent info :)
delete
Congratulations @samrg472! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the number of upvotes
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Congratulations @samrg472! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Award for the total payout received
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Sam is very wise when it comes to coding, much more than he gives himself credit for. I am sure this contribution will help immensely.
This is sure to help out a great deal, wonderful job!