Skip to content

Commit

Permalink
chore: sync template
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 8, 2024
1 parent 33c1a7f commit d6e6807
Show file tree
Hide file tree
Showing 16 changed files with 465 additions and 1,390 deletions.
65 changes: 6 additions & 59 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import { execSync } from "child_process";
import { config } from "dotenv";
import esbuild from "esbuild";
import { appendFileSync, readFileSync, writeFileSync } from "fs";

// CSS files in order
const cssFiles: string[] = [
"static/styles/rewards/pay.css",
"static/styles/rewards/background.css",
"static/styles/toast.css",
"static/styles/rewards/claim-table.css",
"static/styles/rewards/media-queries.css",
"static/styles/rewards/light-mode.css",
const typescriptEntries = ["static/main.ts"];
// const cssEntries = ["static/style.css"];
const entries = [
...typescriptEntries,
// ...cssEntries
];

// Output bundles file
const outputFilePath = "static/bundles/bundles.css";

const typescriptEntries = ["static/scripts/rewards/init.ts"];
export const entries = [...typescriptEntries];

export const esBuildContext: esbuild.BuildOptions = {
sourcemap: true,
entryPoints: entries,
Expand All @@ -32,28 +19,7 @@ export const esBuildContext: esbuild.BuildOptions = {
".ttf": "dataurl",
".svg": "dataurl",
},
outfile: "static/bundles/bundles.js",
entryNames: "bundles", // Ensure the CSS is named bundles.css
define: createEnvDefines(["SUPABASE_URL", "SUPABASE_ANON_KEY"], {
commitHash: execSync(`git rev-parse --short HEAD`).toString().trim(),
}),
plugins: [
{
name: "css-bundle",
setup(build) {
build.onEnd((result) => {
// Clear the file first
writeFileSync(outputFilePath, "", "utf8");

// Concatenate each file into the bundles file
cssFiles.forEach((file) => {
const data = readFileSync(file, "utf8");
appendFileSync(outputFilePath, data, "utf8");
});
});
},
},
],
outdir: "static/dist",
};

esbuild
Expand All @@ -65,22 +31,3 @@ esbuild
console.error(err);
process.exit(1);
});

function createEnvDefines(environmentVariables: string[], generatedAtBuild: Record<string, unknown>): Record<string, string> {
const defines: Record<string, string> = {};
config();
for (const name of environmentVariables) {
const envVar = process.env[name];
if (envVar !== undefined) {
defines[name] = JSON.stringify(envVar);
} else {
throw new Error(`Missing environment variable: ${name}`);
}
}
for (const key in generatedAtBuild) {
if (Object.prototype.hasOwnProperty.call(generatedAtBuild, key)) {
defines[key] = JSON.stringify(generatedAtBuild[key]);
}
}
return defines;
}
14 changes: 8 additions & 6 deletions build/esbuild-server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import esbuild from "esbuild";
import { esBuildContext } from "./esbuild-build";

startServer().catch((error) => {
console.error("Server startup error:", error);
(async () => {
await server();
})().catch((error) => {
console.error("Unhandled error:", error);
process.exit(1);
});

async function startServer() {
const context = await esbuild.context(esBuildContext);
const { port } = await context.serve({
export async function server() {
const _context = await esbuild.context(esBuildContext);
const { port } = await _context.serve({
servedir: "static",
port: 8080,
});
console.log(`Server running at http://localhost:${port}`);
console.log(`http://localhost:${port}`);
}
4 changes: 4 additions & 0 deletions build/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as dotenv from "dotenv";
// load environment variables (if you have them)
dotenv.config();
console.log("Welcome to ts-template");
6 changes: 1 addition & 5 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export default defineConfig({
setupNodeEvents() {
// implement node event listeners here
},
baseUrl: "http://localhost:8080",
experimentalStudio: true,
baseUrl: "http://localhost:8080",
},
viewportHeight: 900,
viewportWidth: 1440,
watchForFileChanges: false,
video: true,
});
12 changes: 12 additions & 0 deletions cypress/e2e/main.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe("Homepage tests", () => {
it("Console is cleared of errors and warnings", () => {
cy.visit("/", {
onBeforeLoad(win) {
cy.stub(win.console, "error").as("consoleError");
},
});
cy.get("@consoleError").should("not.be.called");
cy.get("body").should("exist");
cy.get("h1").should("exist");
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
34 changes: 9 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
{
"name": "pay.ubq.fi",
"name": "ts-template",
"version": "1.0.0",
"description": "Claim your UbiquityOS rewards.",
"description": "Template repository with TypeScript support.",
"main": "build/index.ts",
"author": "Ubiquity DAO",
"license": "MIT",
"engines": {
"node": "20.10.0"
"node": ">=20.10.0"
},
"scripts": {
"start": "run-s start:sign start:ui",
"watch": "nodemon -e ts,tsx --exec yarn start",
"watch:ui": "nodemon -e ts,tsx --exec yarn start:ui",
"start": "tsx build/esbuild-server.ts",
"build": "tsx build/esbuild-build.ts",
"format": "run-s format:lint format:prettier format:cspell",
"build": "run-s utils:build",
"start:ui": "tsx build/esbuild-server.ts",
"start:sign": "tsx scripts/typescript/generate-permit2-url.ts",
"utils:build": "tsx build/esbuild-build.ts",
"utils:get-invalidate-params": "forge script --via-ir scripts/solidity/GetInvalidateNonceParams.s.sol",
"format:lint": "eslint --fix .",
"format:prettier": "prettier --write .",
"format:cspell": "cspell **/*",
"postinstall": "git submodule update --init --recursive",
"test:anvil": "tsx cypress/scripts/anvil.ts",
"test:start": "yarn start",
"test:run": "cypress run",
"test:open": "cypress open",
"test:fund": "tsx cypress/scripts/funding.ts",
"knip": "knip --config .github/knip.ts",
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
"prepare": "husky install",
Expand All @@ -42,19 +30,17 @@
"open-source"
],
"dependencies": {
"@ethersproject/providers": "^5.7.2",
"@supabase/supabase-js": "^2.44.4",
"@ubiquibot/permit-generation": "1.4.1",
"@ubiquity-dao/rpc-handler": "^1.1.0",
"dotenv": "^16.4.4",
"ethers": "^5.7.2"
"dotenv": "^16.4.4"
},
"devDependencies": {
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@cspell/dict-node": "^4.0.3",
"@cspell/dict-software-terms": "^3.3.18",
"@cspell/dict-typescript": "^3.1.2",
"@jest/globals": "29.7.0",
"@mswjs/data": "0.16.1",
"@types/jest": "29.5.12",
"@types/node": "^20.11.19",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
Expand All @@ -66,14 +52,12 @@
"eslint-plugin-filename-rules": "^1.3.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-sonarjs": "^0.24.0",
"ethereum-protocol": "^1.0.1",
"husky": "^9.0.11",
"jest": "29.7.0",
"jest-junit": "16.0.0",
"jest-md-dashboard": "0.8.0",
"knip": "^5.0.1",
"lint-staged": "^15.2.2",
"nodemon": "^3.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"ts-jest": "29.1.2",
Expand Down
Loading

0 comments on commit d6e6807

Please sign in to comment.