diff --git a/.github/workflows/sync-monorepo.mjs b/.github/workflows/sync-monorepo.mjs new file mode 100644 index 000000000..7cd12dec1 --- /dev/null +++ b/.github/workflows/sync-monorepo.mjs @@ -0,0 +1,11 @@ +import { syncfromGithubAction } from 'monorepo-sync'; + +syncfromGithubAction() + .then(() => { + console.log('Sync completed successfully'); + process.exit(0); + }) + .catch((error) => { + console.error('Error during sync:', error); + process.exit(1); + }); \ No newline at end of file diff --git a/.github/workflows/sync-pr-to-monorepo.yml b/.github/workflows/sync-pr-to-monorepo.yml new file mode 100644 index 000000000..7de261c08 --- /dev/null +++ b/.github/workflows/sync-pr-to-monorepo.yml @@ -0,0 +1,49 @@ +name: Sync Merged PR to Monorepo + +on: + pull_request: + types: [closed] + branches: + - main + - master + +jobs: + sync-to-monorepo: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.MONOREPO_SYNC_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + SOURCE_REPO_NAME: ${{ github.event.repository.name }} + MONOREPO_PACKAGE_LOCATION: packages/${{ github.event.repository.name }} + MONOREPO_PATH: ${{ github.workspace }}/monorepo + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Install dependencies + # Install project dependencies (including dev dependencies) + run: npm install + - name: Install zx + run: npm install zx + + - name: Install monorepo-sync package + run: npm install git+https://github.com/formio/monorepo-sync.git + - name: Clone Monorepo + run: | + gh repo clone formio/formio-monorepo monorepo -- --depth=1 + + - name: Sync to Monorepo + run: | + echo "Syncing PR #${PR_NUMBER}: ${PR_TITLE}" + node .github/workflows/sync-monorepo.mjs diff --git a/package.json b/package.json index 08029e0ef..8452c20c2 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "jest-transform-css": "^6.0.1", "jsdom": "^22.1.0", "prettier": "3.2.4", + "monorepo-sync": "git+https://github.com/johnformio/monorepo-sync.git", "react": "^19.0.0", "react-dom": "^19.0.0", "ts-jest": "^29.1.2", diff --git a/src/components/Form.tsx b/src/components/Form.tsx index cb87afa37..0db5c531f 100644 --- a/src/components/Form.tsx +++ b/src/components/Form.tsx @@ -252,7 +252,8 @@ const getEffectiveProps = (props: FormProps) => { export const Form = (props: FormProps) => { const renderElement = useRef(null); const currentFormJson = useRef(null); - const { formConstructor, formSource, formReadyCallback } = getEffectiveProps(props); + const { formConstructor, formSource, formReadyCallback } = + getEffectiveProps(props); const { src, form, @@ -295,9 +296,10 @@ export const Form = (props: FormProps) => { console.warn('Form source not found'); return; } - currentFormJson.current = formSource && typeof formSource !== 'string' - ? structuredClone(formSource) - : null; + currentFormJson.current = + formSource && typeof formSource !== 'string' + ? structuredClone(formSource) + : null; const instance = await createWebformInstance( formConstructor, currentFormJson.current || formSource, @@ -338,7 +340,8 @@ export const Form = (props: FormProps) => { useEffect(() => { let onAnyHandler = null; if (formInstance && Object.keys(handlers).length > 0) { - onAnyHandler = (...args: [string, ...any[]]) => onAnyEvent(handlers, ...args); + onAnyHandler = (...args: [string, ...any[]]) => + onAnyEvent(handlers, ...args); formInstance.onAny(onAnyHandler); } diff --git a/src/components/Report.jsx b/src/components/Report.jsx index a2ffbdc26..a170849a3 100644 --- a/src/components/Report.jsx +++ b/src/components/Report.jsx @@ -67,17 +67,19 @@ export const Report = (props) => { // eslint-disable-next-line no-undef if (report && !_isEqual(report, jsonReport.current)) { jsonReport.current = cloneDeep(report); - createReportInstance(report).then(() => { - if (formio) { - formio.form = { components: [], report }; - return formio; - } - }).catch((err) => { - console.error(err); - if (formio?.form?.report ) { - formio.form.report = {}; - } - }); + createReportInstance(report) + .then(() => { + if (formio) { + formio.form = { components: [], report }; + return formio; + } + }) + .catch((err) => { + console.error(err); + if (formio?.form?.report) { + formio.form.report = {}; + } + }); initializeFormio(); } }, [props.report]); diff --git a/yarn.lock b/yarn.lock index 15468abcb..e5b586cd4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3908,6 +3908,12 @@ moment@^2.29.4: resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae" integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how== +"monorepo-sync@git+https://github.com/johnformio/monorepo-sync.git": + version "1.0.0" + resolved "git+https://github.com/johnformio/monorepo-sync.git#7865350762a51f65be5a7c10314a18d0a1905f1e" + dependencies: + zx "^8.5.4" + ms@2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" @@ -5310,3 +5316,8 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + +zx@^8.5.4: + version "8.5.4" + resolved "https://registry.yarnpkg.com/zx/-/zx-8.5.4.tgz#1f5cc658ad69cf093aca1c5cfa943393e8db85f3" + integrity sha512-44oKea9Sa8ZnOkTnS6fRJpg3quzgnbB43nLrVfYnqE86J4sxgZMUDLezzKET/FdOAVkF4X+Alm9Bume+W+RW9Q==