Skip to content

Commit

Permalink
♻️ Standardize scripts (#346)
Browse files Browse the repository at this point in the history
This PR cleans up and standardizes utility and npm scripts across the repo.

- remove the `data-pipeline` directory in server
- remove the data-pipeline rollup config
- generalize the bin rollup config so it builds any ts script
- add runtime reading of ts script names so the bin script can build all of them if individual ones aren't specified
- standardize names of npm scripts. all scripts like `test` run all the tests, and if needed follow the pattern `test:unit` (for example) if there are more targeted tests to run (also applies to builds, etc)
- add server e2e to travis
- spend 5 gd hours troubleshooting why the server was failing in travis
- simplify lint scripts (prettier step was removed since eslint/eslint prettier plugins should serve the same purpose)
- this apparently exposed some type problems; fix those
  • Loading branch information
rhinodavid authored May 8, 2020
1 parent 55257d2 commit dbc2091
Show file tree
Hide file tree
Showing 32 changed files with 1,594 additions and 1,617 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = {
},
project: "./tsconfig.json",
},
// ignorePatterns: ["packages/upswyng-server/cypress/**/*"],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ config.ts
# server e2e test
.mongodbpid
.mongodburi
.redispid
.redisuri
packages/upswyng-server/cypress/screenshots/**/*(failed).png

# misc
Expand Down
27 changes: 18 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
language: node_js
node_js:
- "12"
# if using Ubuntu 16 need this library for cypress
# https://github.com/cypress-io/cypress-documentation/pull/1647
addons:
apt:
packages:
- libgconf-2-4
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.22.1
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.22.4
- export PATH="$HOME/.yarn/bin:$PATH"
cache:
yarn: true
node_js:
- "12"
directories:
# we also need to cache folder with Cypress binary
- ~/.cache
script:
- yarn install
- mv packages/upswyng-native/config.example.ts packages/upswyng-native/config.ts
- yarn run build-local-packages
- yarn run ci-lint
- yarn run test
- yarn workspace @upswyng/upswyng-server server-build
- yarn workspace @upswyng/upswyng-server worker-build
- yarn workspace @upswyng/upswyng-server rollup --config data-pipeline.rollup.config.js
- yarn build-local-packages
- yarn workspace @upswyng/upswyng-server build:bin
- yarn run lint:ci
- yarn test:ci
- yarn workspace @upswyng/upswyng-server build:server
- yarn workspace @upswyng/upswyng-server build:worker
- CI=false yarn workspace @upswyng/upswyng-web build
79 changes: 40 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
{
"name": "upswyng",
"version": "0.1.0",
"private": true,
"license": "MIT",
"scripts": {
"build-local-packages": "yarn workspace @upswyng/upswyng-types run build && yarn workspace @upswyng/upswyng-core run build",
"build-server": "yarn run build-local-packages && yarn workspace @upswyng/upswyng-server run build",
"build-web": "yarn run build-local-packages && yarn workspace @upswyng/upswyng-web run build",
"ci-lint": "prettier --check --loglevel error '{{.github,.vscode}/**/*,packages/*/src/**/*}.{js,jsx,ts,tsx,json,css,scss,svelte,md}' && tsc --noEmit && eslint 'packages/upswyng-*/src/**/*.{js,jsx,ts,tsx}' --quiet",
"clean": "node clean.js",
"heroku-postbuild": "yarn workspace @upswyng/upswyng-core build && yarn workspace @upswyng/upswyng-server run build",
"lint": "prettier --write --loglevel warn '{{.github,.vscode}/**/*,packages/*/src/**/*}.{js,jsx,ts,tsx,json,css,scss,svelte,md}' && tsc --noEmit && eslint 'packages/upswyng-*/src/**/*.{js,jsx,ts,tsx}' --fix",
"test": "CI=true SKIP_PREFLIGHT_CHECK=true concurrently --kill-others-on-fail \"yarn workspace @upswyng/upswyng-core run test\" \"yarn workspace @upswyng/upswyng-server run test\" && yarn workspace @upswyng/upswyng-web run test"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"packages/*/src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"yarn lint",
"git add"
]
},
"devDependencies": {
"@pyoner/svelte-types": "^3.4.4-2",
"@testing-library/react-hooks": "^1.0.4",
Expand All @@ -55,7 +30,7 @@
"@types/simple-oauth2": "^2.2.1",
"@typescript-eslint/eslint-plugin": "^2.6.0",
"@typescript-eslint/parser": "^2.6.0",
"concurrently": "^5.0.0",
"concurrently": "^5.2.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-prettier": "^3.1.1",
Expand All @@ -73,26 +48,52 @@
"ts-jest": "^24.2.0",
"typescript": "^3.7.3"
},
"workspaces": [
"packages/*"
],
"dependencies": {
"concurrently": "^5.0.0"
"engines": {
"node": "12.x.x",
"yarn": "^1.22.1"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"importSort": {
".js, .jsx, .es6, .es": {
"options": {},
"parser": "babylon",
"style": "eslint",
"options": {}
"style": "eslint"
},
".ts, .tsx": {
"options": {},
"parser": "typescript",
"style": "eslint",
"options": {}
"style": "eslint"
}
},
"engines": {
"node": "12.x.x",
"yarn": "^1.22.1"
}
"license": "MIT",
"lint-staged": {
"packages/*/src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"yarn lint",
"git add"
]
},
"name": "upswyng",
"private": true,
"scripts": {
"build-local-packages": "yarn build:local-packages",
"build-server": "yarn build:server",
"build-web": "yarn build:web",
"build:local-packages": "yarn workspace @upswyng/upswyng-types build && yarn workspace @upswyng/upswyng-core build",
"build:server": "yarn build-local-packages && yarn workspace @upswyng/upswyng-server build",
"build:web": "yarn build-local-packages && yarn workspace @upswyng/upswyng-web build",
"clean": "node clean.js",
"heroku-postbuild": "yarn workspace @upswyng/upswyng-core build && yarn workspace @upswyng/upswyng-server build",
"lint": "tsc --noEmit && eslint 'packages/upswyng-*/src/**/*.{js,jsx,ts,tsx}' --fix",
"lint:ci": "tsc --noEmit && eslint 'packages/upswyng-*/src/**/*.{js,jsx,ts,tsx}' --quiet",
"test": "concurrently -n core,server,web -c yellow,blue,cyan \"yarn workspace @upswyng/upswyng-core test\" \"yarn workspace @upswyng/upswyng-server test\" \"yarn workspace @upswyng/upswyng-web test\"",
"test:ci": "yarn test --kill-others-on-fail"
},
"version": "0.1.0",
"workspaces": [
"packages/*"
]
}
2 changes: 1 addition & 1 deletion packages/upswyng-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"rrule": "^2.6.2"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-json": "^4.0.1",
"@rollup/plugin-node-resolve": "^6.0.0",
"@types/moment-timezone": "^0.5.12",
Expand Down
4 changes: 2 additions & 2 deletions packages/upswyng-server/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://github.com/heroku/heroku-buildpack-multi-procfile
web: yarn workspace @upswyng/upswyng-server run server-start
worker: yarn workspace @upswyng/upswyng-server run worker-start
web: yarn workspace @upswyng/upswyng-server run start:server
worker: yarn workspace @upswyng/upswyng-server run start:worker
14 changes: 12 additions & 2 deletions packages/upswyng-server/bin.rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createEnv, readConfigFile } from "@pyoner/svelte-ts-preprocess";

import commonjs from "@rollup/plugin-commonjs";
import fs from "fs";
import json from "@rollup/plugin-json";
import pkg from "./package.json";
import replace from "@rollup/plugin-replace";
import resolve from "@rollup/plugin-node-resolve";
import shebang from "rollup-plugin-add-shebang";
import typescript from "rollup-plugin-typescript2";
Expand All @@ -29,7 +29,17 @@ const tsOpts = {
tsconfig: "./tsconfig.build.json",
};

const targets = ["checkAlerts"];
const targets = process.env.TARGETS
? process.env.TARGETS.split(",")
: fs
.readdirSync("./src/bin")
.filter(x => /^.+\.ts/.test(x))
.map(f => {
// remove extension
return f.slice(0, -3);
});

// IDEA(@rhinodavid): suppress the output from rollup and just print out the file name as they succeed

export default targets.map(target => ({
input: `./src/bin/${target}.ts`,
Expand Down
5 changes: 2 additions & 3 deletions packages/upswyng-server/cypress/start_memory_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ child.stdout.on("data", chunk => {
/^CONNECTION_STRING=(?<connectionString>mongodb:\/\/.+\?)$/
);
if (!match) {
console.error(`Invalid connection string: ${uri}`);
process.exit(1);
return;
}
const { connectionString } = match.groups;
fs.writeFileSync(`${__dirname}/.mongodburi`, connectionString);
Expand All @@ -35,7 +34,7 @@ child.stdout.on("data", chunk => {
console.info(`🎉 Started in-memory mongo db`);
console.info(`PID:\t\t${pid}`);
console.info(`Connection URI:\t${connectionString}`);

// got data, maybe look at it to verify that it started up ok
child.unref(); // let the process close normally
process.exit(0);
Expand Down
41 changes: 41 additions & 0 deletions packages/upswyng-server/cypress/start_memory_redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node

/**
* Sets up a redis instance for testing
*
* Writes two files to its directory:
* .redispid contains the PID of the child process which should be killed once the test is complete.
* .redisuri contains the connection string/uri of the instance
*/

/* eslint-disable */
const fs = require("fs");
const { spawn } = require("child_process");
const child = spawn("node", [`${__dirname}/start_memory_redis_impl.js`], {
detached: true, // don't SIGHUP when the parent proc exits
stdio: ["ignore", "pipe", "pipe"],
});

child.stderr.pipe(process.stderr);
child.stdout.on("data", chunk => {
const pid = String(child.pid).trim();
const uri = String(chunk).trim();
const match = uri.match(
/^CONNECTION_STRING=(?<connectionString>redis:\/\/.+:[0-9]{4,})$/
);
if (!match) {
console.error(`Invalid connection string: ${uri}`);
process.exit(1);
}
const { connectionString } = match.groups;
fs.writeFileSync(`${__dirname}/.redisuri`, connectionString);
fs.writeFileSync(`${__dirname}/.redispid`, pid);

console.info(`🎉 Started in-memory redis`);
console.info(`PID:\t\t${pid}`);
console.info(`Connection URI:\t${connectionString}`);

// got data, maybe look at it to verify that it started up ok
child.unref(); // let the process close normally
process.exit(0);
});
17 changes: 17 additions & 0 deletions packages/upswyng-server/cypress/start_memory_redis_impl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

/**
* Starts an in-memory redis instance.
* Logs CONNECTION_STRING=<connection string> once started
*/

/* eslint-disable */
const tmpRedis = require("tmp-redis");
const getPort = require("get-port");

getPort({ port: 6379 }).then(p => {
tmpRedis(p, (e, _shutdown) =>{
if (e) throw e;
console.info(`CONNECTION_STRING=redis://localhost:${p}`);
});
});
39 changes: 0 additions & 39 deletions packages/upswyng-server/data-pipeline.rollup.config.js

This file was deleted.

Loading

0 comments on commit dbc2091

Please sign in to comment.