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

init #1

Merged
merged 32 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ad78fd6
set up project
ivibumblebee Dec 5, 2022
b46afb3
set up github
ivibumblebee Dec 5, 2022
332d235
fixed sub parsing
ivibumblebee Dec 5, 2022
38328a8
cleanup
ivibumblebee Dec 5, 2022
6db4aee
set up pr and deploy
ivibumblebee Dec 5, 2022
4f2fb1a
fixed wd
ivibumblebee Dec 5, 2022
0996d6b
updated yarn lock
ivibumblebee Dec 5, 2022
ac8e4e8
trying to publish
ivibumblebee Dec 5, 2022
cd20b64
fixed publish
ivibumblebee Dec 5, 2022
6c24a52
moved husky
ivibumblebee Dec 5, 2022
3be2282
trigger hooks
ivibumblebee Dec 5, 2022
151b6ca
triggering precommit
ivibumblebee Dec 5, 2022
af1feab
triggering precommit
ivibumblebee Dec 5, 2022
7eb06ec
fixed yarn
ivibumblebee Dec 5, 2022
0f5f580
fixed yarn for real
ivibumblebee Dec 5, 2022
7895ae4
first publish
ivibumblebee Dec 5, 2022
f0c016b
add login
ivibumblebee Dec 5, 2022
5f3aff4
adding registry
ivibumblebee Dec 5, 2022
20b9378
fixing env name??
ivibumblebee Dec 5, 2022
45d70f5
fixing scope
ivibumblebee Dec 5, 2022
b2210a7
fixing yarn lock
ivibumblebee Dec 5, 2022
6802c81
adding npmrc
ivibumblebee Dec 5, 2022
2f8f310
cleanup
ivibumblebee Dec 5, 2022
2cb136f
readme and fix publish
ivibumblebee Dec 5, 2022
e927054
fix line
ivibumblebee Dec 5, 2022
d09a1f1
Update README.md
ivibumblebee Dec 5, 2022
1417267
cleaned up dependencies
ivibumblebee Dec 5, 2022
d88c954
Merge branch 'f/init' of github.com:AES-Outreach/Express-React-PDF in…
ivibumblebee Dec 5, 2022
b3d8a9f
put express back in dependencies
ivibumblebee Dec 5, 2022
004770d
pushed readme
ivibumblebee Dec 5, 2022
9de7abd
cleanup
ivibumblebee Dec 12, 2022
ac5a913
clean up
ivibumblebee Dec 12, 2022
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
5 changes: 5 additions & 0 deletions .github/actions/spelling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# check-spelling/check-spelling configuration

| File | Purpose | Format | Info |
| ---------------------- | --------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [allow.txt](allow.txt) | Add words to the dictionary | one word per line (only letters and `'`s allowed) | [allow](https://github.com/check-spelling/check-spelling/wiki/Configuration#allow) |
3 changes: 3 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
isnan
outstem
Templating
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Purpose

What does this pull request hope to accomplish?

## Screenshot

UI change? Add a screenshot or a gif!

## Acceptance Criteria

- [ ] The user should be able to do ...
- [ ] Something should occur when ...

## Additional Notes

Any additional notes for developers to give greater context.
30 changes: 30 additions & 0 deletions .github/workflows/deploy-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Core Deployment

on:
push:
branches:
- master
paths:
- 'core/**'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.15
uses: actions/setup-node@v2
with:
node-version: 14.15
- name: Install dependencies
working-directory: ./core
run: yarn install
- name: Run production build
working-directory: ./core
run: yarn run build
- name: Push to NPM
working-directory: ./core
run: |
npm version "v1.0.${GITHUB_RUN_NUMBER}"
npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/pull-request-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Core Checks

on:
pull_request:
branches:
- master

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
test-and-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Uses Node.js 14.17
uses: actions/setup-node@v2
with:
node-version: 14.17
- name: Install dependencies
working-directory: ./core
run: yarn install
- name: Run prettier
working-directory: ./core
run: yarn prettier:check
- name: Linter
working-directory: ./core
run: yarn lint
- name: Spell check
working-directory: ./core
run: npx cspell "**/*.{md,js,ts,tsx}"
# - name: Run unit tests
# working-directory: ./core
# run: yarn test
Comment on lines +33 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be uncommented or is this because there currently are not tests??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there aren't currently tests, next dev day perhaps

- name: Run production build
working-directory: ./core
run: yarn build
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

echo '-----Core Precommit-----'
cd ./core && npx lint-staged
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# PDF-Express-Middleware
Middleware express using react-pdf to generate PDF files

## Project Structure

#### Core
Core contains the middleware builder and PDF wrapper, as well as the base root context

#### Prebuilt
Prebuilt contains additional prebuilt middleware that can be used, for example integrating i18Next
## Hooks
To set up precommit hooks with husky, run the following\
`npm install -g husky`\
`npx husky install .husky`
136 changes: 136 additions & 0 deletions core/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
const path = require("path");

module.exports = {
env: {
browser: true,
node: true,
es2021: true,
},
extends: [],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
},
plugins: ["react", "no-only-tests", "unused-imports", "prefer-arrow"],
overrides: [
{
files: ["*.ts", "*.tsx"],
parserOptions: {
sourceType: "module",
project: ["./tsconfig.test.json"],
tsconfigRootDir: __dirname,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:eslint-comments/recommended",
"prettier", // Make sure this is always last
],
rules: {
"no-only-tests/no-only-tests": "error",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-unused-vars": "error",
"eslint-comments/no-unused-disable": "error",
"eslint-comments/no-unlimited-disable": "error",
"eslint-comments/disable-enable-pair": [
"error",
{ allowWholeFile: true },
],
"unused-imports/no-unused-imports": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/dot-notation": "error",
"@typescript-eslint/explicit-member-accessibility": [
"off",
{
accessibility: "explicit",
},
],
"@typescript-eslint/no-require-imports": "error",
"id-blacklist": "off",
"id-match": "off",
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: false,
},
],
"no-restricted-properties": [
2,
{
object: "translate",
property: "getBrowserLang",
message: "Please use userCurrentLang instead.",
},
{
object: "t",
property: "getBrowserLang",
message: "Please use userCurrentLang instead.",
},
{
object: "translateService",
property: "getBrowserLang",
message: "Please use userCurrentLang instead.",
},
],
"no-underscore-dangle": "off",
"@typescript-eslint/member-ordering": "off",
"jsdoc/newline-after-description": "off",
"@typescript-eslint/ban-types": "error",
"no-var": "error",
"no-shadow": "off",
"prefer-arrow/prefer-arrow-functions": "error",
"prefer-const": "error",
"@typescript-eslint/no-unused-expressions": "error",
"use-isnan": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/naming-convention": [
"error",
// typeLike (class, interface, typeAlias, enum, typeParameter) should use StrictPascalCase
{ selector: ["typeLike"], format: ["PascalCase"] },
// Destructured variables should have no casing enforced
{
selector: ["variable"],
modifiers: ["destructured"],
format: null,
},
// Stand-alone variables should be camelCase or UPPER_CASE
{
selector: ["variable"],
format: ["camelCase", "UPPER_CASE"],
},
// Class properties and function parameters are only loosely enforced
{
selector: ["parameter", "accessor", "typeProperty"],
format: ["PascalCase", "snake_case", "camelCase", "UPPER_CASE"],
leadingUnderscore: "allow",
},
// Functions must use camelCase
{
selector: [
"function",
"variable",
"classMethod",
"typeMethod",
"classProperty",
"typeProperty",
],
// PascalCase is needed here for React components
format: ["camelCase", "PascalCase"],
types: ["function"], // To scope 'parameter', 'classProperty', 'typeProperty' and 'variable'
filter: { regex: "toJSON", match: false },
},
],
"@typescript-eslint/consistent-indexed-object-style": [
"error",
"record",
],
},
},
],
settings: {
react: {
version: "detect",
},
},
};
39 changes: 39 additions & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Dependency directories
node_modules/

# Optional eslint cache
.eslintcache

# Yarn Integrity file
.yarn-integrity

# compiled output
/deps
/dist

# dependencies
/node_modules

# IDE - VSCode
.vs/*
.vscode/*
.editorconfig

# misc
npm-debug.log
yarn-error.log

#Cspell Cache
.cspellcache

# Betterer Cache
.betterer.cache

# Yarn Berry
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions core/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
807 changes: 807 additions & 0 deletions core/.yarn/releases/yarn-3.3.0.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions core/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.3.0.cjs
75 changes: 75 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
## Base Root

For simple usage, a base root context element and it's associated middleware are provided as `BaseRootContext` and `basePDFGenerator`

### Usage

**Certificate Element**

```ts
import React from "react";
import { Page, View, Text } from "@react-pdf/renderer";

export const Certificate = ({ name, age }: CertificateProps) => {
return (
<Page size="A4" orientation="landscape">
<View>
<Text>
{name} - {age}
</Text>
</View>
</Page>
);
};
```

**Endpoint**

```ts
import { ProgramCertificate } from "./template";
import { basePDFGenerator } from "express-react-pdf";

router.get(
"/certificate",
basePDFGenerator(Certificate, (req) => ({
name: req.query.name,
age: req.query.age,
}))
);
```

## Builder

The `pdfMiddlewareBuilder` can be used to create react-pdf middleware for your express server. This supports defining a new root context, as well as how to extract data from your request to populate your root.

### Example - Integrating Other Frameworks

_Note: this will soon be published as a package_

Custom root contexts can be defined to integrate other frameworks, for example the i18Next translation library

**Root Context**

```ts
export const I18NextRootContext = ({
translate,
children,
}: I18NextRootContextProps & PropsWithChildren) => {
return (
<I18nextProvider i18n={translate}>
<Document>{children}</Document>
</I18nextProvider>
);
};
```

**Middleware**

```ts
export const i18NextPDFMiddleware = pdfMiddlewareBuilder(
I18NextRootContext,
(req) => ({
translate: req.i18n,
})
);
```
12 changes: 12 additions & 0 deletions core/cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.2",
"ignorePaths": ["./deps"],
"dictionaryDefinitions": [
{
"name": "allow",
"path": "../.github/actions/spelling/allow.txt",
"addWords": true
}
],
"dictionaries": ["allow"]
}
Loading