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

Sync branch to template #4

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
66 changes: 6 additions & 60 deletions build/esbuild-build.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { execSync } from "child_process";
import { config } from "dotenv";
import esbuild from "esbuild";
import { readFileSync, appendFileSync, writeFileSync } from "fs";
import { join } from "path";

// 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 @@ -33,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 @@ -66,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;
}
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");
13 changes: 4 additions & 9 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { defineConfig } from "cypress";
import { config } from "dotenv";

config();

export default defineConfig({
e2e: {
setupNodeEvents() {},
baseUrl: "http://localhost:8080",
setupNodeEvents() {
// implement node event listeners here
},
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"
}
10 changes: 10 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"roots": ["./tests"],
"coveragePathIgnorePatterns": ["node_modules", "mocks"],
"collectCoverage": true,
"coverageReporters": ["json", "lcov", "text", "clover", "json-summary"],
"reporters": ["default", "jest-junit", "jest-md-dashboard"],
"coverageDirectory": "coverage"
}
45 changes: 16 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
{
"name": "pay.ubq.fi",
"name": "ts-template",
"version": "1.0.0",
"description": "Claim your DevPool rewards.",
"description": "Template repository with TypeScript support.",
"main": "build/index.ts",
"author": "Ubiquity DAO",
"license": "MIT",
"engines": {
"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 **/*",
"prepare": "husky install",
"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",
"test": "jest --setupFiles dotenv/config --coverage",
"cy:open": "cypress open",
"cy:run": "cypress run"
},
Expand All @@ -41,46 +30,44 @@
"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",
"npm-run-all": "^4.1.5"
"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",
"@types/ethereum-protocol": "^1.0.5",
"@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",
"cspell": "^8.4.0",
"cypress": "13.7.0",
"cypress": "13.6.6",
"esbuild": "^0.20.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-filename-rules": "^1.3.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-sonarjs": "^0.24.0",
"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",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
},
"lint-staged": {
"*.ts": [
"yarn prettier --write",
"eslint --fix",
"bash .github/workflows/scripts/kebab-case.sh"
"eslint --fix"
],
"src/**.{ts,json}": [
"cspell"
Expand Down
Loading
Loading