Skip to content

Commit

Permalink
chore: Standards and general maintenance (#33)
Browse files Browse the repository at this point in the history
* Update general scaffolding

* Upgrade devDependencies

* Add standard scripts
  • Loading branch information
spautz authored Oct 25, 2020
1 parent 3e399b4 commit f6182ee
Show file tree
Hide file tree
Showing 9 changed files with 776 additions and 562 deletions.
2 changes: 2 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
network-timeout 30000
save-prefix ""
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ to discuss your idea and make sure it is inline with the project goals.
git checkout -b my-topic-branch
```

4. To test your local dev version of `limited-cache` in other projects, I recommend [Yalc](https://github.com/whitecolor/yalc).
4. To test your local dev version of `limited-cache` in other projects, [Yalc](https://github.com/whitecolor/yalc)
is an excellent tool.

5. After you have made your changes, submit a pull request. Issues and pull requests are monitored, and you should receive a reply.

Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
},
"author": {
"name": "Steven Pautz",
"url": "https://stevenpautz.com/"
"url": "http://stevenpautz.com/"
},
"files": [
"dist/",
"src/",
"CHANGELOG.md",
"LICENSE",
"README.md"
"*.md"
],
"source": "src/index.ts",
"main": "dist/index.js",
Expand All @@ -54,31 +53,31 @@
"ci": "yon run clean && yon run dev:readonly && yon run test:report",
"____ INDIVIDUAL COMMANDS ___________________________________________": "",
"build": "tsdx build",
"build:clean": "rimraf dist/",
"build:clean": "rimraf ./dist",
"build:verify": "node ./scripts/verify-build.js",
"build:watch": "tsdx watch",
"format": "prettier --write \"**/*.*\"",
"format:verify": "prettier --list-different \"**/*.*\"",
"lint": "tsdx lint . --max-warnings 0",
"release:changelog": "standard-version --skip.commit --skip.tag --release-as ",
"release:tag": "standard-version --commit-all --sign --skip.changelog --release-as ",
"test:clean": "rimraf coverage/",
"test:clean": "rimraf ./coverage",
"test:nowatch": "tsdx test --coverage",
"test:report": "tsdx test --coverage && coveralls < coverage/lcov.info",
"test:report": "tsdx test --coverage && coveralls < ./coverage/lcov.info",
"test:watch": "tsdx test --coverage --watch",
"types": "tsc --noEmit --p tsconfig.json"
},
"dependencies": {},
"devDependencies": {
"@types/jest": "26.0.14",
"@types/node": "14.11.2",
"@types/jest": "26.0.15",
"@types/node": "14.14.2",
"coveralls": "3.1.0",
"husky": "4.3.0",
"lint-staged": "10.4.0",
"lint-staged": "10.4.2",
"rimraf": "3.0.2",
"standard-version": "9.0.0",
"tsdx": "0.14.0",
"tslib": "2.0.1",
"tsdx": "0.14.1",
"tslib": "2.0.3",
"typescript": "3.9.7",
"yarn-or-npm": "3.0.1"
},
Expand Down
22 changes: 22 additions & 0 deletions scripts/build-everything.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# Fail if anything in here fails
set -e

# This script runs from the project root
cd "$(dirname "$0")/.."

source scripts/helpers.sh

###################################################################################################
# Setup

run_command "./scripts/check-environment.sh"
run_command "yarn install"

###################################################################################################
# Run all read-write scripts and read-only scripts. This is overkill and duplicates some work, but
# also helps catch intermittent errors. Suitable for running before lunch or teatime.

run_command "yarn all"
run_command "yarn all:readonly"
35 changes: 35 additions & 0 deletions scripts/check-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Fail if anything in here fails
set -e

# This script runs from the project root
cd "$(dirname "$0")/.."

source scripts/helpers.sh

###################################################################################################
# Check versions of Node, Yarn, and any other tools required

# If "engines" is set in package.json, validate against its values
HAS_ENGINES=$(get_json_value package.json "engines")
if [ $HAS_ENGINES ]; then
run_npm_command check-node-version --package --print
fi

# If a "node" value is not set in package.json's "engines", validate against .nvmrc
HAS_ENGINES_NODE=$(get_json_value package.json "node")
if [ ! $HAS_ENGINES ] || [ ! $HAS_ENGINES_NODE ]; then
NODE_ACTUAL=$(echo $(node --version) | tr -d '[v:space:]')
NODE_DESIRED=$(cat .nvmrc)

echo "Node version: $NODE_ACTUAL"
if [ $NODE_DESIRED ] && [ $NODE_ACTUAL != $NODE_DESIRED ]; then
echo "Node version desired: $NODE_DESIRED"
exit 1
fi
fi

###################################################################################################

echo "All environment checks passed!"
49 changes: 49 additions & 0 deletions scripts/clean-everything.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# Fail if anything in here fails
set -e

# This script runs from the project root
cd "$(dirname "$0")/.."

source scripts/helpers.sh

###################################################################################################
# Halt running processes and local servers

if command_exists killall; then
run_command killall node
fi

if command_exists xcrun; then
run_command xcrun simctl shutdown all
fi

##################################################################################################
# Clear caches

run_npm_command jest --clearCache --config={}

run_command npm cache clean --force
run_command yarn cache clean

if command_exists watchman; then
run_command watchman watch-del-all
fi

run_command "rm -rf
$TMPDIR/react-*
"

##################################################################################################
# Remove generated files

run_command "rm -rf
.yarn
coverage/
dist/
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
"
20 changes: 20 additions & 0 deletions scripts/full-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Fail if anything in here fails
set -e

# This script runs from the project root
cd "$(dirname "$0")/.."

source scripts/helpers.sh

###################################################################################################
# Setup: Node should already have been set up in the environment init

run_command "./scripts/check-environment.sh"
run_command "yarn install --frozen-lockfile"

###################################################################################################
# Run whatever the script in package.json wants to run

run_command "yarn ci"
41 changes: 41 additions & 0 deletions scripts/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# These are helpful functions for the other bash scripts in this directory.
# Note that this is not a runnable script itself.

command_exists() {
# This check is based on https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then
command -v "$1" > /dev/null 2>&1
}

get_json_value() {
local FILE=$1
local PROPERTY=$2

echo $(cat $FILE \
| grep "\"$PROPERTY\":" \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]'
)
}

# This simply echoes and then runs a command. It's just an alternative to turning on echo (set -x)
run_command() {
local FULL_COMMAND=$*

echo "$FULL_COMMAND"
$FULL_COMMAND
}

# Given a command like `run_npm_command("jest" "--version")`, this will look for a directly-runnable command
# (i.e., "jest" if you have jest-cli installed) but also fall back to using npx to run the desired command if you don't.
run_npm_command() {
local EXEC=$1
local FULL_COMMAND=$*

if command_exists "$EXEC"; then
run_command $FULL_COMMAND
else
run_command npx $FULL_COMMAND
fi
}
Loading

0 comments on commit f6182ee

Please sign in to comment.