Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factor build scripts to TypeScript #202

Merged
merged 23 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d7c26fd
Re-factor scripts for building, development, linting, and cleaning to…
smithki Sep 1, 2021
7fa7da1
Remove remnants of old test runner (ava)
smithki Sep 1, 2021
a210f1b
Re-factor scripts for unit testing to TypeScript
smithki Sep 1, 2021
e2ccc67
Small cleanups
smithki Sep 1, 2021
d258eeb
Refactor to merge `ViewController` and `PayloadTransport` classes (#203)
smithki Sep 2, 2021
9a59d3f
Make script code more DRY
smithki Sep 2, 2021
d12760f
Update TypeScript & make scripts more DRY
smithki Sep 2, 2021
94efcb4
Fix typo and add 'printSeparator' script utility
smithki Sep 2, 2021
a2325a2
Fix 'inject-env.ts' script following re-organization of code
smithki Sep 2, 2021
d5e2f35
Remove outdated / unused dependencies from root PackageJSON
smithki Sep 8, 2021
a858d16
Progress towards integrating microbundle
smithki Sep 9, 2021
69d343f
Update build scripts to bundle all packages via microbundle
smithki Sep 10, 2021
50a0a03
Remove unnecessary console statement
smithki Sep 10, 2021
e8c7fde
Run pre-commit hooks against all packages
smithki Sep 10, 2021
2e0e32c
Add more memory for tasks spawned via 'wsrun'
smithki Sep 10, 2021
3e28ee0
Raise the resource class in CI
smithki Sep 10, 2021
66a3346
Try to fix ENOMEM errors in CI by limiting concurrency
smithki Sep 10, 2021
89a4660
Replace 'p-limit' dependency with prior version (new version is ESM-o…
smithki Sep 10, 2021
b529dd4
Better caching in CircleCI
smithki Sep 10, 2021
f80e463
Update test script to work with Yarn 2
smithki Sep 10, 2021
494fe08
Fix tests related to ViewController refactor
smithki Sep 10, 2021
f1066f4
Reduce the CircleCI resource class back to medium
smithki Sep 10, 2021
62b4874
Fix tests related to ViewController refactor
smithki Sep 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make script code more DRY
  • Loading branch information
smithki committed Sep 2, 2021
commit 9a59d3fad32e0649eae714ed9ec623c9e2077229
20 changes: 1 addition & 19 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,7 @@ import execa from 'execa';
import chalk from 'chalk';
import path from 'path';
import { runAsyncProcess } from './utils/run-async-process';

type CatchFn<TResult = never> = (reason: any) => TResult | PromiseLike<TResult>;

function handleError<TResult = never>(spinner?: ora.Ora, message?: string): CatchFn<TResult>;
function handleError<TResult = never>(message?: string): CatchFn<TResult>;
function handleError<TResult = never>(messageOrSpinner?: ora.Ora | string, message?: string): CatchFn<TResult> {
return (err: any) => {
if (messageOrSpinner) {
if (typeof messageOrSpinner === 'string') {
console.error(messageOrSpinner);
} else {
messageOrSpinner.fail(message);
}
}

if (err) console.error(err);
process.exit(1);
};
}
import { handleError } from './utils/handle-script-error';

async function getTSConfigs() {
const spinner = ora('Determining TypeScript projects to build...').start();
Expand Down
5 changes: 2 additions & 3 deletions scripts/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ async function main() {
spinner.fail('Failed!');
if (err) console.error(err);
process.exit(1);
}
};

await Promise.all(concurrent.map((p) => p()))
.catch(handleError)
await Promise.all(concurrent.map((p) => p())).catch(handleError);

await new Promise<void>((resolve, reject) => {
sequential
Expand Down
20 changes: 1 addition & 19 deletions scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,7 @@ import TscWatchClient from 'tsc-watch/client';
import chalk from 'chalk';
import path from 'path';
import { runAsyncProcess } from './utils/run-async-process';

type CatchFn<TResult = never> = (reason: any) => TResult | PromiseLike<TResult>;

function handleError<TResult = never>(spinner?: ora.Ora, message?: string): CatchFn<TResult>;
function handleError<TResult = never>(message?: string): CatchFn<TResult>;
function handleError<TResult = never>(messageOrSpinner?: ora.Ora | string, message?: string): CatchFn<TResult> {
return (err: any) => {
if (messageOrSpinner) {
if (typeof messageOrSpinner === 'string') {
console.error(messageOrSpinner);
} else {
messageOrSpinner.fail(message);
}
}

if (err) console.error(err);
process.exit(1);
};
}
import { handleError } from './utils/handle-script-error';

async function getTSConfigs() {
const spinner = ora('Determining TypeScript projects to build for development...').start();
Expand Down
1 change: 0 additions & 1 deletion scripts/inject-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ async function main() {
}

runAsyncProcess(main);

27 changes: 27 additions & 0 deletions scripts/utils/handle-script-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ora from 'ora';

type CatchFn<TResult = never> = (reason: any) => TResult | PromiseLike<TResult>;

/**
* Used to handle errors that occur during script execution.
*
* Optionally accepts an Ora spinner instance, which will be set to a failed
* state with the given `message`. Otherwise, the message is logged to
* `process.stderr` and the process exits with a non-zero exit code.
*/
export function handleError<TResult = never>(spinner?: ora.Ora, message?: string): CatchFn<TResult>;
export function handleError<TResult = never>(message?: string): CatchFn<TResult>;
export function handleError<TResult = never>(messageOrSpinner?: ora.Ora | string, message?: string): CatchFn<TResult> {
return (err: any) => {
if (messageOrSpinner) {
if (typeof messageOrSpinner === 'string') {
console.error(messageOrSpinner);
} else {
messageOrSpinner.fail(message);
}
}

if (err) console.error(err);
process.exit(1);
};
}
8 changes: 4 additions & 4 deletions scripts/wsrun/resolve-paths.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env ts-node-script

import { relative, join } from 'path';
import path from 'path';
import { existsSync } from 'fs';
import { runAsyncProcess } from '../utils/run-async-process';

async function main() {
const args = process.argv.slice(2);
if (!args.length) args.push(''); // We need a minimum of one `args` element

const root = join(__dirname, '..', '..');
const absResults = args.map((a) => join(process.cwd(), a ?? ''));
const relResults = absResults.map((a) => relative(root, a));
const root = path.join(__dirname, '..', '..');
const absResults = args.map((a) => path.join(process.cwd(), a ?? ''));
const relResults = absResults.map((a) => path.relative(root, a));

relResults.forEach((result, i) => {
if (existsSync(absResults[i])) console.log(result);
Expand Down