Skip to content

Add uphold-scripts project#2

Merged
Americas merged 1 commit intomasterfrom
feature/add-uphold-scripts
Jul 31, 2018
Merged

Add uphold-scripts project#2
Americas merged 1 commit intomasterfrom
feature/add-uphold-scripts

Conversation

@rplopes
Copy link
Copy Markdown
Contributor

@rplopes rplopes commented Jul 13, 2018

Set of scripts and dev dependencies to help with common tasks on Uphold projects.

Available Scripts:

  • changelog - generate changelog file for a given version
  • lint - run eslint to lint JS files
  • release - cut a new release for a new version
  • test - run the test suite with jest pre-configured
  • version - tag a new version and generate its changelog

@rplopes rplopes self-assigned this Jul 13, 2018
@rplopes rplopes force-pushed the feature/add-uphold-scripts branch from 9e8fdbc to 0a515d2 Compare July 13, 2018 17:00
Comment thread bin/uphold-scripts Outdated

set -e

case "$1" in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about adding a release script?

  release)
    npm version $2 -m "Release %s"
    ;;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread bin/uphold-scripts Outdated

case "$1" in
changelog)
./node_modules/.bin/github-changelog-generator --future-release=v$2 > CHANGELOG.md
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ./node_modules/.bin/?

Comment thread package.json
"author": "Ricardo Lopes",
"license": "MIT",
"precommit.silent": true,
"dependencies": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should they be fixed to a specific version? To ensure the same versions in all our projects.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the rule is to fix specific versions on applications and to allow updates on packages. Then, any application using a package can fix the dependencies it needs.

I don't think there's any problem with project foo having resolved jest to 23.4.0 and project bar having resolved it to 23.4.1, since they both can fix a specific version if needed and they both share a common dependency that shares maintenance work anyway.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough for me.

@rplopes rplopes force-pushed the feature/add-uphold-scripts branch from 0a515d2 to 961f0df Compare July 16, 2018 11:14
Comment thread package.json Outdated
"name": "uphold-scripts",
"version": "0.0.1",
"description": "Set of scripts and dev dependencies to help with common tasks on Uphold projects",
"bin": "./bin/uphold-scripts",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about separating each command into its own file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It started with separate files, but there were problems with loading them (they don't get added to node_modules/.bin, as the main one does). Since each of them is a one liner, didn't want to spend too much time trying to get a loader that worked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will eventually run into this problem, I can foresee bigger and more complex scripts popping up, and this setup won't be practical.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, tested separating and the scripts were added to node_modules/.bin just fine..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. Did you test from a different project, like the huobi-client example linked in the description?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is how I tested it. Required it from the huobi-client and I set up the scripts, and tested running each script.

Copy link
Copy Markdown
Contributor Author

@rplopes rplopes Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new commit that separates into different files. Got the same issue as before:

$ git df
diff --git i/yarn.lock w/yarn.lock
index 2124b3e..da63491 100644
--- i/yarn.lock
+++ w/yarn.lock
@@ -3685,7 +3685,7 @@ unset-value@^1.0.0:

 "uphold-scripts@git+ssh://git@github.com/uphold/uphold-scripts#feature/add-uphold-scripts":
   version "0.0.1"
-  resolved "git+ssh://git@github.com/uphold/uphold-scripts#6da4033bfc0bf409e56ac22c5ef2cf41f7f44c05"
+  resolved "git+ssh://git@github.com/uphold/uphold-scripts#83b4d40f9fdf4369d033432858809afe9d6ef0b3"
   dependencies:
     "@uphold/github-changelog-generator" "^0.7.0"
     eslint "^5.1.0"

$ yarn lint
yarn run v1.7.0
$ uphold-scripts lint
sh: /Users/ricardo/Projects/uphold/huobi-client/node_modules/.bin/uphold-scripts-help: No such file or directory
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

$ ls -la node_modules/.bin/ | grep uphold-scripts
lrwxr-xr-x    1 ricardo  staff     36 Jul 16 15:44 uphold-scripts -> ../uphold-scripts/bin/uphold-scripts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"bin": {
  "us-lint": "./bin/uphold-scripts-lint"
  ...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of having to expose n+1 bins like that. But if it's the best option we've got...

@rplopes rplopes force-pushed the feature/add-uphold-scripts branch from 961f0df to 6da4033 Compare July 16, 2018 11:16
Comment thread configs/jest-preset.json
@@ -0,0 +1,8 @@
{
"collectCoverage": true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add clearMocks too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required I think, restoreMocks does all the needed work.

Comment thread configs/jest-preset.json
"src/**/*.js"
],
"restoreMocks": true,
"testEnvironment": "node"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add things like:

"modulePaths": ["<rootDir>"]

and

"testRegex": "test/.*\\.test.js$"

Or are these too opinionated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our test suites seem to run fine without them, so at least for now I don't think we really need them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module path allows us to refer to a file as 'src/foobar' instead of '../../../src/foobar'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that sounds like a useful addition. Test regex seems to be the opposite (limiting possibilities), so maybe we can use the former and leave out the latter.

@rplopes rplopes force-pushed the feature/add-uphold-scripts branch 2 times, most recently from a6ea8ef to b8c2f69 Compare July 16, 2018 14:21
Comment thread bin/uphold-scripts-help Outdated
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

echo 'uphold-scripts [command] [options]';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use cat with heredoc?

cat <<EOF
uphold-scripts [command] [options]

Commands:
  changelog [version]  Generate changelog file
  help                 Display this help section
  lint                 Lint JS files
  release              Cut a new release
  test                 Run the test suite
  version              Tag a new version
EOF

@rplopes rplopes force-pushed the feature/add-uphold-scripts branch 2 times, most recently from 15a074f to d6733c6 Compare July 16, 2018 15:07
Comment thread package.json Outdated
"version": "0.0.1",
"description": "Set of scripts and dev dependencies to help with common tasks on Uphold projects",
"bin": {
"uphold-scripts": "./bin/uphold-scripts",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the help bin are a bit too much.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I agree. I'd much prefer having a uphold-scripts bin with specific commands than n different bins to memorise individually. Also, when requiring a uphold-scripts package, makes sense to then call uphold-scripts command instead of uphold-scripts-command IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not assuming the purpose of this repo was to memorize commands. I thought they would be added automatically in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about this, and I believe it really is better to have these scripts under one executable instead of many.

This way, we could also provide many developer utility commands without polluting the package.json, like uphold-scripts prs to open the github PRs page for that project, for instance.

That being said, WDYT about this alternative strategy:

  • keeping all scripts in separate files, for maintainability
  • having a build step on release that builds a final bin with all scripts included (similar to what webpack would do, for instance)
  • exporting that automatically-generated bin only, that projects and developers could call without having to load different bins at runtime

@rplopes rplopes force-pushed the feature/add-uphold-scripts branch 4 times, most recently from ce25733 to 88f6c01 Compare July 16, 2018 15:48
@rplopes rplopes force-pushed the feature/add-uphold-scripts branch from 9616584 to ce56e3c Compare July 31, 2018 11:35
Comment thread src/index.js Outdated
program
.command('changelog [version]', 'Generate changelog file')
.command('lint', 'Lint JS files')
.command('release', 'Cut a new release')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release [version]

@rplopes rplopes force-pushed the feature/add-uphold-scripts branch from ce56e3c to e4b65d0 Compare July 31, 2018 13:29
@rplopes rplopes force-pushed the feature/add-uphold-scripts branch from e4b65d0 to ee3b670 Compare July 31, 2018 13:31
@rplopes rplopes changed the title Add @uphold/scripts project Add uphold-scripts project Jul 31, 2018
@Americas Americas merged commit e24f598 into master Jul 31, 2018
@Americas Americas deleted the feature/add-uphold-scripts branch July 31, 2018 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants