Skip to content

Commit

Permalink
feat: update build setup, deps, and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Oct 21, 2021
1 parent c8526a4 commit 72b0bdb
Show file tree
Hide file tree
Showing 23 changed files with 19,777 additions and 4,254 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Lint code
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release

on:
workflow_run:
branches: ["main"]
workflows: ["CI"]
types: [completed]

jobs:
release:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Release
run: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"*.ts": ["eslint -f codeframe --fix", "prettier --write"],
"*.ts": ["eslint --fix", "prettier --write"],
"*{.js,.json,.md,.yml,rc}": ["prettier --write"]
}
8 changes: 5 additions & 3 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"include": ["src/**/*"],
"reporter": ["text", "lcov"],
"include": ["src/**/*.{ts,marko}"],
"exclude": ["**/__tests__"]
"extension": [".ts", ".marko"],
"exclude": ["**/__tests__", "**/*.d.ts"],
"parserPlugins": ["objectRestSpread", "typescript"]
}
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
.nyc_output
package.json
package-lock.json
CHANGELOG.md
node_modules
coverage
dist
*.marko.js
__snapshots__
3 changes: 3 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"branches": ["main"]
}
96 changes: 0 additions & 96 deletions CHANGELOG.md

This file was deleted.

40 changes: 22 additions & 18 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
import fs from "fs";
import path from "path";
import glob from "globby";
import { build } from "esbuild";
import glob from "fast-glob";
import { build, BuildOptions } from "esbuild";

(async () => {
const assets = [];
const entryPoints = [];
const srcdir = path.resolve("src");
const outdir = path.resolve("dist");
const files = await glob(["**", "!*.d.ts", "!**/__tests__"], {
const files = glob.stream(["**", "!*.d.ts", "!**/__tests__"], {
cwd: srcdir,
});
}) as AsyncIterable<string>;

for (const file of files) {
for await (const file of files) {
if (path.extname(file) === ".ts") {
entryPoints.push(path.resolve(srcdir, file));
} else {
assets.push(file);
const outfile = path.join(outdir, file);
await fs.promises.mkdir(path.dirname(outfile), { recursive: true });
await fs.promises.copyFile(path.join(srcdir, file), outfile);
}
}

const opts: BuildOptions = {
outdir,
entryPoints,
outbase: srcdir,
platform: "node",
target: ["es2019"],
};

await Promise.all([
Promise.all(
assets.map(async (file) => {
const outfile = path.join(outdir, file);
await fs.promises.mkdir(path.dirname(outfile), { recursive: true });
await fs.promises.copyFile(path.join(srcdir, file), outfile);
})
),
build({
outdir,
entryPoints,
...opts,
format: "cjs",
outbase: srcdir,
target: ["es2019"],
}),
build({
...opts,
format: "esm",
outExtension: { ".js": ".mjs" },
}),
]);
})().catch((err) => {
Expand Down
Loading

0 comments on commit 72b0bdb

Please sign in to comment.