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
Small cleanups
  • Loading branch information
smithki committed Sep 2, 2021
commit e2ccc67b0dc6979ef06637502c653b434840694a
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"@types/react": "^16.9.34",
"@types/react-native": "^0.62.2",
"@types/rimraf": "^3.0.2",
"@types/tsc-watch": "^4.2.0",
"@types/whatwg-url": "^6.4.0",
"@typescript-eslint/eslint-plugin": "~3.4.0",
"auto": "^10.31.0",
"boxen-cli": "^1.0.0",
"chalk": "~4.1.2",
"eslint": "~7.3.1",
"eslint-import-resolver-typescript": "~2.0.0",
Expand Down
25 changes: 17 additions & 8 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import ora from 'ora';
import execa from 'execa';
import chalk from 'chalk';
import path from 'path';

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

function handleExecaError<TResult = never>(spinner?: ora.Ora, message?: string): CatchFn<TResult>;
function handleExecaError<TResult = never>(message?: string): CatchFn<TResult>;
function handleExecaError<TResult = never>(messageOrSpinner?: ora.Ora | string, message?: string): CatchFn<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') {
Expand All @@ -31,7 +32,7 @@ async function getTSConfigs() {
spinner.succeed('Found TypeScript projects to build!');
return subprocess.stdout.split('\n');
})
.catch(handleExecaError(spinner, 'Failed to discover TypeScript projects to build.'));
.catch(handleError(spinner, 'Failed to discover TypeScript projects to build.'));

return tsconfigs;
}
Expand All @@ -42,7 +43,7 @@ async function compileTypeScripts(tsconfigs: string[]) {
.then(() => {
spinner.succeed('TypeScripts successfully compiled!');
})
.catch(handleExecaError(spinner, 'TypeScripts failed to compile.'));
.catch(handleError(spinner, 'TypeScripts failed to compile.'));
}

async function bundleForCDN() {
Expand All @@ -51,12 +52,12 @@ async function bundleForCDN() {
stdio: 'inherit',
})
.then(() => console.log())
.catch(handleExecaError('CDN bundles failed to build.'));
.catch(handleError('CDN bundles failed to build.'));
}

async function injectENV() {
const spinner = ora('Injecting environment variables...').start();
const onCatch = handleExecaError(spinner, 'Failed to inject environment variables.');
const onCatch = handleError(spinner, 'Failed to inject environment variables.');
const allPkgs = await execa('yarn', ['--silent', 'paths'])
.then((subprocess) => subprocess.stdout.split('\n'))
.catch(onCatch);
Expand All @@ -72,7 +73,15 @@ async function main() {
const tsconfigs = await getTSConfigs();

console.log(
tsconfigs.reduce((prev, next) => `${prev}\n - ${next}`, ''),
tsconfigs
.slice()
.sort()
.map((cfgPath) => {
const prefix = 'packages/';
const basename = `/${path.basename(cfgPath)}`;
return cfgPath.replace(prefix, chalk`{gray ${prefix}}`).replace(basename, chalk`{gray ${basename}}`);
})
.reduce((prev, next) => chalk`${prev}\n {gray -} ${next}`, ''),
'\n',
);

Expand Down
33 changes: 27 additions & 6 deletions scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
import ora from 'ora';
import execa from 'execa';
import TscWatchClient from 'tsc-watch/client';
import chalk from 'chalk';
import path from 'path';

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);
}
}

function handleExecaError(spinner?: ora.Ora, message?: string) {
return (err?: any) => {
if (spinner) spinner.fail(message);
if (err) console.error(err);
process.exit(1);
};
Expand All @@ -26,14 +39,14 @@ async function getTSConfigs() {
spinner.succeed('Found TypeScript projects to build for development!');
return res;
})
.catch(handleExecaError(spinner, 'Failed to discover TypeScript project to build.'));
.catch(handleError(spinner, 'Failed to discover TypeScript project to build.'));

return { tsconfigs, allPkgs };
}

async function injectENV(allPkgs: string[]) {
await execa(`${process.env.INIT_CWD}/scripts/inject-env.ts`, [...allPkgs]).then(() => {
console.log('Injected environment variables.');
console.log('Environment variables successfully injected!');
});
}

Expand Down Expand Up @@ -67,7 +80,15 @@ async function main() {
const { tsconfigs, allPkgs } = await getTSConfigs();

console.log(
tsconfigs.reduce((prev, next) => `${prev}\n - ${next}`, ''),
tsconfigs
.slice()
.sort()
.map((cfgPath) => {
const prefix = 'packages/';
const basename = `/${path.basename(cfgPath)}`;
return cfgPath.replace(prefix, chalk`{gray ${prefix}}`).replace(basename, chalk`{gray ${basename}}`);
})
.reduce((prev, next) => chalk`${prev}\n {gray -} ${next}`, ''),
'\n',
);

Expand Down
16 changes: 5 additions & 11 deletions scripts/inject-env.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#!/usr/bin/env ts-node-script

/*
eslint-disable

global-require,
import/no-dynamic-require,
@typescript-eslint/no-var-requires
*/
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */

import { replaceInFile } from 'replace-in-file';
import path from 'path';

/**
* Environment variables to be interpolated into the built files. Interpolations
* occur where `"%VARIABLE_NAME%"` is found.
* occur where `%VARIABLE_NAME%` is found.
*
* (FYI: it's best to encapsulate the interpolation as a string).
* (FYI: it's best to encapsulate the interpolation as a string, i.e.: `"%VARIABLE_NAME%"`).
*/
const environment = {
WEB_VERSION: require(path.resolve(__dirname, '../packages/magic-sdk/package.json')).version,
Expand All @@ -32,7 +28,5 @@ Object.keys(environment).forEach(async (envVar) => {
to: environment[envVar],
allowEmptyPaths: true,
}).catch(console.error);

console.log(`Injected ENV variable \`${envVar}\``);
}
});
65 changes: 9 additions & 56 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3650,6 +3650,13 @@
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.0.tgz#fef1904e4668b6e5ecee60c52cc6a078ffa6697d"
integrity sha512-I99sngh224D0M7XgW1s120zxCt3VYQ3IQsuw3P3jbq5GG4yc79+ZjyKznyOGIQrflfylLgcfekeZW/vk0yng6A==

"@types/tsc-watch@^4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@types/tsc-watch/-/tsc-watch-4.2.0.tgz#5a9553c4652e8feffdb3735e75f78b5191384acc"
integrity sha512-hND5B6WVQcO9QdgSdRHeougv4EAEeg5UYMrVACbFfFJ/EaEbdJgYd+mHtIVwgrHSf1eucQRxuFQ9b2jIlnsT7A==
dependencies:
"@types/node" "*"

"@types/whatwg-url@^6.4.0":
version "6.4.0"
resolved "https://registry.yarnpkg.com/@types/whatwg-url/-/whatwg-url-6.4.0.tgz#1e59b8c64bc0dbdf66d037cf8449d1c3d5270237"
Expand Down Expand Up @@ -3930,13 +3937,6 @@ anser@^1.4.9:
resolved "https://registry.yarnpkg.com/anser/-/anser-1.4.9.tgz#1f85423a5dcf8da4631a341665ff675b96845760"
integrity sha512-AI+BjTeGt2+WFk4eWcqbQ7snZpDBt8SaLlj0RT2h5xfdWaiy51OjYvqwMrNzJLGy8iOAL6nKDITWO+rd4MkYEA==

ansi-align@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-2.0.0.tgz#c36aeccba563b89ceb556f3690f0b1d9e3547f7f"
integrity sha1-w2rsy6VjuJzrVW82kPCx2eNUf38=
dependencies:
string-width "^2.0.0"

ansi-colors@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-1.1.0.tgz#6374b4dd5d4718ff3ce27a671a3b1cad077132a9"
Expand Down Expand Up @@ -4643,29 +4643,6 @@ bottleneck@^2.15.3:
resolved "https://registry.yarnpkg.com/bottleneck/-/bottleneck-2.19.5.tgz#5df0b90f59fd47656ebe63c78a98419205cadd91"
integrity sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==

boxen-cli@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boxen-cli/-/boxen-cli-1.0.0.tgz#ad3eebad0a634a26cdd21bf4c0840e9cbc84f865"
integrity sha1-rT7rrQpjSibN0hv0wIQOnLyE+GU=
dependencies:
boxen "^1.0.0"
get-stdin "^5.0.1"
indent-string "^3.0.0"
meow "^3.7.0"

boxen@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/boxen/-/boxen-1.3.0.tgz#55c6c39a8ba58d9c61ad22cd877532deb665a20b"
integrity sha512-TNPjfTr432qx7yOjQyaXm3dSR0MH9vXp7eT1BFSl/C51g+EFnOR9hTg1IreahGBmDNCehscshe45f+C1TBZbLw==
dependencies:
ansi-align "^2.0.0"
camelcase "^4.0.0"
chalk "^2.0.1"
cli-boxes "^1.0.0"
string-width "^2.0.0"
term-size "^1.2.0"
widest-line "^2.0.0"

[email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/bplist-creator/-/bplist-creator-0.0.8.tgz#56b2a6e79e9aec3fc33bf831d09347d73794e79c"
Expand Down Expand Up @@ -4983,7 +4960,7 @@ camelcase@^2.0.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f"
integrity sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8=

camelcase@^4.0.0, camelcase@^4.1.0:
camelcase@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
integrity sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=
Expand Down Expand Up @@ -5142,11 +5119,6 @@ clean-stack@^2.0.0:
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==

cli-boxes@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143"
integrity sha1-T6kXw+WclKAEzWH47lCdplFocUM=

cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
Expand Down Expand Up @@ -7650,11 +7622,6 @@ get-stdin@^4.0.1:
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
integrity sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=

get-stdin@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398"
integrity sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=

get-stdin@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
Expand Down Expand Up @@ -10328,7 +10295,7 @@ [email protected]:
type-fest "^0.18.0"
yargs-parser "^20.2.3"

meow@^3.3.0, meow@^3.7.0:
meow@^3.3.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb"
integrity sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=
Expand Down Expand Up @@ -14458,13 +14425,6 @@ [email protected]:
os-tmpdir "^1.0.0"
rimraf "~2.2.6"

term-size@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/term-size/-/term-size-1.2.0.tgz#458b83887f288fc56d6fffbfad262e26638efa69"
integrity sha1-RYuDiH8oj8Vtb/+/rSYuJmOO+mk=
dependencies:
execa "^0.7.0"

terminal-link@^2.0.0, terminal-link@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/terminal-link/-/terminal-link-2.1.1.tgz#14a64a27ab3c0df933ea546fba55f2d078edc994"
Expand Down Expand Up @@ -15509,13 +15469,6 @@ wide-align@^1.1.0:
dependencies:
string-width "^1.0.2 || 2"

widest-line@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-2.0.1.tgz#7438764730ec7ef4381ce4df82fb98a53142a3fc"
integrity sha512-Ba5m9/Fa4Xt9eb2ELXt77JxVDV8w7qQrH0zS/TWSJdLyAwQjWoOzpzj5lwVftDz6n/EOu3tNACS84v509qwnJA==
dependencies:
string-width "^2.1.1"

windows-release@^3.1.0:
version "3.3.1"
resolved "https://registry.yarnpkg.com/windows-release/-/windows-release-3.3.1.tgz#cb4e80385f8550f709727287bf71035e209c4ace"
Expand Down