From e249e031bac823396de644d6ed642a08b4502879 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 7 Nov 2023 14:37:24 +0100 Subject: [PATCH 1/2] stop tracking dist --- .gitignore | 3 +- dist/PDFPreviewer.d.ts | 29 ------- dist/PDFPreviewer.d.ts.map | 1 - dist/PDFPreviewer.js | 157 ------------------------------------- dist/index.d.ts | 7 -- dist/index.d.ts.map | 1 - dist/index.js | 12 --- dist/styles.d.ts | 18 ----- dist/styles.d.ts.map | 1 - dist/styles.js | 20 ----- dist/types.d.ts | 15 ---- dist/types.d.ts.map | 1 - dist/types.js | 2 - 13 files changed, 1 insertion(+), 266 deletions(-) delete mode 100644 dist/PDFPreviewer.d.ts delete mode 100644 dist/PDFPreviewer.d.ts.map delete mode 100644 dist/PDFPreviewer.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.d.ts.map delete mode 100644 dist/index.js delete mode 100644 dist/styles.d.ts delete mode 100644 dist/styles.d.ts.map delete mode 100644 dist/styles.js delete mode 100644 dist/types.d.ts delete mode 100644 dist/types.d.ts.map delete mode 100644 dist/types.js diff --git a/.gitignore b/.gitignore index 25ca7af..9990850 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,7 @@ # node.js node_modules/ npm-debug.log -# It is a temporary solution until we push the package to NPM -# dist/ +dist/ # NPM file created by GitHub actions .npmrc diff --git a/dist/PDFPreviewer.d.ts b/dist/PDFPreviewer.d.ts deleted file mode 100644 index 5294a30..0000000 --- a/dist/PDFPreviewer.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; -import type { CSSProperties } from 'react'; -import PropTypes from 'prop-types'; -import 'react-pdf/dist/Page/AnnotationLayer.css'; -import 'react-pdf/dist/Page/TextLayer.css'; -type Props = { - file: string; - pageMaxWidth: number; - isSmallScreen: boolean; - containerStyle?: CSSProperties; - contentContainerStyle?: CSSProperties; -}; -declare function PDFPreviewer({ pageMaxWidth, isSmallScreen, file, containerStyle, contentContainerStyle }: Props): React.JSX.Element; -declare namespace PDFPreviewer { - var propTypes: { - file: PropTypes.Validator; - pageMaxWidth: PropTypes.Validator; - isSmallScreen: PropTypes.Validator; - containerStyle: PropTypes.Requireable; - contentContainerStyle: PropTypes.Requireable; - }; - var defaultProps: { - containerStyle: {}; - contentContainerStyle: {}; - }; -} -declare const _default: React.MemoExoticComponent; -export default _default; -//# sourceMappingURL=PDFPreviewer.d.ts.map \ No newline at end of file diff --git a/dist/PDFPreviewer.d.ts.map b/dist/PDFPreviewer.d.ts.map deleted file mode 100644 index 0b0dbca..0000000 --- a/dist/PDFPreviewer.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"PDFPreviewer.d.ts","sourceRoot":"","sources":["../src/PDFPreviewer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6D,MAAM,OAAO,CAAC;AAClF,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAEzC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,OAAO,yCAAyC,CAAC;AACjD,OAAO,mCAAmC,CAAC;AAK3C,KAAK,KAAK,GAAG;IACT,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,qBAAqB,CAAC,EAAE,aAAa,CAAC;CACzC,CAAC;AA4DF,iBAAS,YAAY,CAAC,EAAC,YAAY,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,EAAE,qBAAqB,EAAC,EAAE,KAAK,qBA6HtG;kBA7HQ,YAAY;;;;;;;;;;;;;;AAkIrB,wBAAkC"} \ No newline at end of file diff --git a/dist/PDFPreviewer.js b/dist/PDFPreviewer.js deleted file mode 100644 index 5bedd87..0000000 --- a/dist/PDFPreviewer.js +++ /dev/null @@ -1,157 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const react_1 = __importStar(require("react")); -const times_1 = __importDefault(require("lodash/times")); -const prop_types_1 = __importDefault(require("prop-types")); -const react_window_1 = require("react-window"); -const react_pdf_1 = require("react-pdf"); -require("react-pdf/dist/Page/AnnotationLayer.css"); -require("react-pdf/dist/Page/TextLayer.css"); -const styles_1 = __importDefault(require("./styles")); -/** - * Each page has a default border. The app should take this size into account - * when calculates the page width and height. - */ -const PAGE_BORDER = 9; -/** - * Pages should be more narrow than the container on large screens. The app should take this size into account - * when calculates the page width. - */ -const LARGE_SCREEN_SIDE_SPACING = 40; -// TODO: Comment -const DEFAULT_DOCUMENT_OPTIONS = { - cMapUrl: 'cmaps/', - cMapPacked: true, -}; -// TODO: Comment -const DEFAULT_EXTERNAL_LINK_TARGET = '_blank'; -/** - * Sets attributes to list container. - * It unblocks a default scroll by keyboard of browsers. - */ -const setListAttributes = (ref) => { - if (!ref) { - return; - } - /** - * Useful for elements that should not be navigated to directly using the "Tab" key, - * but need to have keyboard focus set to them. - */ - // eslint-disable-next-line no-param-reassign - ref.tabIndex = -1; -}; -const propTypes = { - file: prop_types_1.default.string.isRequired, - pageMaxWidth: prop_types_1.default.number.isRequired, - isSmallScreen: prop_types_1.default.bool.isRequired, - // eslint-disable-next-line react/forbid-prop-types - containerStyle: prop_types_1.default.object, - // eslint-disable-next-line react/forbid-prop-types - contentContainerStyle: prop_types_1.default.object, -}; -const defaultProps = { - containerStyle: {}, - contentContainerStyle: {}, -}; -// @ts-expect-error - It is a recommended step for import worker - https://github.com/wojtekmaj/react-pdf/blob/main/packages/react-pdf/README.md#import-worker-recommended -react_pdf_1.pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.js', import.meta.url).toString(); -function PDFPreviewer({ pageMaxWidth, isSmallScreen, file, containerStyle, contentContainerStyle }) { - const [pageViewports, setPageViewports] = (0, react_1.useState)([]); - const [numPages, setNumPages] = (0, react_1.useState)(0); - const [containerWidth, setContainerWidth] = (0, react_1.useState)(0); - const [containerHeight, setContainerHeight] = (0, react_1.useState)(0); - const containerRef = (0, react_1.useRef)(null); - /** - * Calculates a proper page width. - * It depends on a screen size. Also, the app should take into account the page borders. - */ - const calculatePageWidth = (0, react_1.useCallback)(() => { - const pageWidthOnLargeScreen = Math.min(containerWidth - LARGE_SCREEN_SIDE_SPACING * 2, pageMaxWidth); - const pageWidth = isSmallScreen ? containerWidth : pageWidthOnLargeScreen; - return pageWidth + PAGE_BORDER * 2; - }, [containerWidth, pageMaxWidth, isSmallScreen]); - /** - * Calculates a proper page height. The method should be called only when there are page viewports. - * It is based on a ratio between the specific page viewport width and provided page width. - * Also, the app should take into account the page borders. - */ - const calculatePageHeight = (0, react_1.useCallback)((pageIndex) => { - if (pageViewports.length === 0) { - return 0; - } - const pageWidth = calculatePageWidth(); - const { width: pageViewportWidth, height: pageViewportHeight } = pageViewports[pageIndex]; - const scale = pageWidth / pageViewportWidth; - return pageViewportHeight * scale + PAGE_BORDER * 2; - }, [pageViewports, calculatePageWidth]); - /** - * Upon successful document load, combine an array of page viewports, - * set the number of pages on PDF, - * hide/reset PDF password form, and notify parent component that - * user input is no longer required. - */ - const onDocumentLoadSuccess = (pdf) => { - Promise.all((0, times_1.default)(pdf.numPages, (index) => { - const pageNumber = index + 1; - return pdf.getPage(pageNumber).then((page) => page.getViewport({ scale: 1 })); - })).then((viewports) => { - setPageViewports(viewports); - setNumPages(pdf.numPages); - // TODO: Implement behaviour - // shouldRequestPassword: false, - // isPasswordInvalid: false, - }, () => { }); - }; - /** - * Render a specific page based on its index. - * The method includes a wrapper to apply virtualized styles. - */ - const renderPage = (0, react_1.useCallback)( - // eslint-disable-next-line react/no-unused-prop-types - ({ index, style }) => { - const pageWidth = calculatePageWidth(); - return (react_1.default.createElement("div", { style: style }, - react_1.default.createElement(react_pdf_1.Page, { key: `page_${index}`, width: pageWidth, pageIndex: index, - // This needs to be empty to avoid multiple loading texts which show per page and look ugly - // See https://github.com/Expensify/App/issues/14358 for more details - loading: "" }))); - }, [calculatePageWidth]); - (0, react_1.useLayoutEffect)(() => { - var _a, _b, _c, _d; - setContainerWidth((_b = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) !== null && _b !== void 0 ? _b : 0); - setContainerHeight((_d = (_c = containerRef.current) === null || _c === void 0 ? void 0 : _c.clientHeight) !== null && _d !== void 0 ? _d : 0); - }, []); - return (react_1.default.createElement("div", { ref: containerRef, style: Object.assign(Object.assign({}, styles_1.default.container), containerStyle) }, - react_1.default.createElement(react_pdf_1.Document, { file: file, options: DEFAULT_DOCUMENT_OPTIONS, externalLinkTarget: DEFAULT_EXTERNAL_LINK_TARGET, error: react_1.default.createElement("p", null, "Failed to load the PDF file :("), loading: react_1.default.createElement("p", null, "Loading..."), onLoadSuccess: onDocumentLoadSuccess, - // TODO: Implement behaviour - onPassword: () => { } }, pageViewports.length > 0 && (react_1.default.createElement(react_window_1.VariableSizeList, { style: Object.assign(Object.assign({}, styles_1.default.list), contentContainerStyle), outerRef: setListAttributes, width: containerWidth, height: containerHeight, itemCount: numPages, itemSize: calculatePageHeight, estimatedItemSize: calculatePageHeight(0) }, renderPage))))); -} -PDFPreviewer.propTypes = propTypes; -PDFPreviewer.defaultProps = defaultProps; -exports.default = (0, react_1.memo)(PDFPreviewer); diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 493e18e..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import PDFPreviewer from './PDFPreviewer'; -export { PDFPreviewer }; -declare const _default: { - PackageName: string; -}; -export default _default; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map deleted file mode 100644 index 360f58c..0000000 --- a/dist/index.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,OAAO,EAAC,YAAY,EAAC,CAAC;;;;AAEtB,wBAEE"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index f534807..0000000 --- a/dist/index.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PDFPreviewer = void 0; -const PDFPreviewer_1 = __importDefault(require("./PDFPreviewer")); -exports.PDFPreviewer = PDFPreviewer_1.default; -const PACKAGE_NAME = 'react-fast-pdf'; -exports.default = { - PackageName: PACKAGE_NAME, -}; diff --git a/dist/styles.d.ts b/dist/styles.d.ts deleted file mode 100644 index b0d9698..0000000 --- a/dist/styles.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -declare const styles: { - container: { - width: string; - height: string; - /** - * It's being used on Web/Desktop only to vertically center short PDFs, - * while preventing the overflow of the top of long PDF files. - */ - display: string; - }; - list: { - readonly overflowX: "hidden"; - readonly boxShadow: "none"; - readonly outline: "none"; - }; -}; -export default styles; -//# sourceMappingURL=styles.d.ts.map \ No newline at end of file diff --git a/dist/styles.d.ts.map b/dist/styles.d.ts.map deleted file mode 100644 index f7931fe..0000000 --- a/dist/styles.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM;;;;QAIJ;;;WAGG;;;;;;;;CASV,CAAC;AAEF,eAAe,MAAM,CAAC"} \ No newline at end of file diff --git a/dist/styles.js b/dist/styles.js deleted file mode 100644 index be09979..0000000 --- a/dist/styles.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const styles = { - container: { - width: '100%', - height: '100%', - /** - * It's being used on Web/Desktop only to vertically center short PDFs, - * while preventing the overflow of the top of long PDF files. - */ - display: 'grid', - }, - list: { - overflowX: 'hidden', - // There properties disable "focus" effect on list - boxShadow: 'none', - outline: 'none', - }, -}; -exports.default = styles; diff --git a/dist/types.d.ts b/dist/types.d.ts deleted file mode 100644 index a9c5f2a..0000000 --- a/dist/types.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -type Page = { - getViewport: ({ scale }: { - scale: number; - }) => PageViewport; -}; -type PDFDocument = { - numPages: number; - getPage: (pageNumber: number) => Promise; -}; -type PageViewport = { - height: number; - width: number; -}; -export type { PDFDocument, PageViewport }; -//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/types.d.ts.map b/dist/types.d.ts.map deleted file mode 100644 index 1bba36a..0000000 --- a/dist/types.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,GAAG;IACR,WAAW,EAAE,CAAC,EAAC,KAAK,EAAC,EAAE;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,KAAK,YAAY,CAAC;CAC3D,CAAC;AAEF,KAAK,WAAW,GAAG;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,YAAY,EAAC,WAAW,EAAE,YAAY,EAAC,CAAC"} \ No newline at end of file diff --git a/dist/types.js b/dist/types.js deleted file mode 100644 index c8ad2e5..0000000 --- a/dist/types.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); From 820216848390c51ec9eb6d731d877d97f3813b60 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 7 Nov 2023 16:20:19 +0100 Subject: [PATCH 2/2] add publish workflow --- .github/workflows/ publish.yml | 87 ++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/ publish.yml diff --git a/.github/workflows/ publish.yml b/.github/workflows/ publish.yml new file mode 100644 index 0000000..3b69523 --- /dev/null +++ b/.github/workflows/ publish.yml @@ -0,0 +1,87 @@ +name: Publish package to npmjs + +# This workflow runs when code is pushed to `main` (i.e: when a pull request is merged) +on: + push: + branches: [main] + +# Ensure that only once instance of this workflow executes at a time. +# If multiple PRs are merged in quick succession, there will only ever be one publish workflow running and one pending. +concurrency: ${{ github.workflow }} + +jobs: + version: + runs-on: ubuntu-latest + + # OSBotify will update the version on `main`, so this check is important to prevent an infinite loop + if: ${{ github.actor != 'OSBotify' }} + + steps: + - uses: actions/checkout@v3 + with: + ref: main + + - name: Decrypt & Import OSBotify GPG key + run: | + cd .github + gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output OSBotify-private-key.asc OSBotify-private-key.asc.gpg + gpg --import OSBotify-private-key.asc + env: + LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }} + + - name: Set up git for OSBotify + run: | + git config --global user.signingkey 367811D53E34168C + git config --global commit.gpgsign true + git config --global user.name OSBotify + git config --global user.email infra+osbotify@expensify.com + + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + + - name: Generate branch name + run: echo "BRANCH_NAME=OSBotify-bump-version-$(uuidgen)" >> $GITHUB_ENV + + - name: Create branch for version-bump pull request + run: git checkout -b ${{ env.BRANCH_NAME }} + + - name: Install npm packages + run: npm ci + + - name: Update npm version + run: npm version patch + + - name: Set new version in GitHub ENV + run: echo "NEW_VERSION=$(jq '.version' package.json)" >> $GITHUB_ENV + + - name: Push branch and publish tags + run: git push --set-upstream origin ${{ env.BRANCH_NAME }} && git push --tags + + - name: Create pull request + run: | + gh pr create \ + --title "Update version to ${{ env.NEW_VERSION }}" \ + --body "Update version to ${{ env.NEW_VERSION }}" + sleep 5 + env: + GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }} + + - name: Auto-approve pull request + run: gh pr review --approve ${{ env.BRANCH_NAME }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Auto-merge pull request + run: gh pr merge --merge --delete-branch ${{ env.BRANCH_NAME }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Build package + run: npm run build + + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}