From ce88ef1cc93efee6b2013ef8a04f2bbc5874b5ec Mon Sep 17 00:00:00 2001 From: mickmister <6913320+mickmister@users.noreply.github.com> Date: Wed, 1 Nov 2023 02:34:12 -0400 Subject: [PATCH 1/3] set up repo to be bare --- webapp/package-lock.json | 2 +- webapp/package.json | 12 +++++++- webapp/postinstall.js | 38 +++++++++++++++++++++++++ webapp/src/index.tsx | 61 +++++++--------------------------------- webapp/webpack.config.js | 2 +- 5 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 webapp/postinstall.js diff --git a/webapp/package-lock.json b/webapp/package-lock.json index a72d6b2..34590a4 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -4,7 +4,7 @@ "requires": true, "packages": { "": { - "name": "webapp", + "hasInstallScript": true, "dependencies": { "core-js": "3.22.8", "mattermost-redux": "5.33.1", diff --git a/webapp/package.json b/webapp/package.json index 653fb79..b44796f 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -10,7 +10,17 @@ "test": "jest --forceExit --detectOpenHandles --verbose", "test:watch": "jest --watch", "test-ci": "jest --forceExit --detectOpenHandles --maxWorkers=2", - "check-types": "tsc" + "check-types": "tsc", + "postinstall": "node postinstall.js" + }, + "submodule": { + "gitRepo": "https://github.com/mattermost/mattermost-plugin-google-calendar.git", + "gitTag": "master" + }, + "customModule": { + "name": "mattermost-plugin-google-calendar", + "repo": "https://github.com/mattermost/mattermost-plugin-google-calendar.git", + "commit": "master" }, "devDependencies": { "@babel/cli": "7.16.8", diff --git a/webapp/postinstall.js b/webapp/postinstall.js new file mode 100644 index 0000000..1e2a084 --- /dev/null +++ b/webapp/postinstall.js @@ -0,0 +1,38 @@ +const {execSync} = require('child_process'); +const fs = require('fs'); +const path = require('path'); +const packageJson = require('./package.json'); +const {chdir} = require('process'); + +const moduleName = packageJson.customModule.name; +const moduleRepo = packageJson.customModule.repo; +const commitHash = packageJson.customModule.commit; +const modulePath = path.join(__dirname, 'node_modules', moduleName); + +if (!moduleRepo || !commitHash) { + console.error('Module repo or commit hash not specified in package.json'); + process.exit(1); +} + +// Clone repo directory if not exists +try { + if (!fs.existsSync(modulePath)) { + execSync(`git clone ${moduleRepo} ${modulePath}`); + console.log(`Successfully cloned ${moduleName} into node_modules.`); + } +} catch (error) { + console.error(`Error cloning repo during postinstall: ${error}`); + process.exit(1); +} + + +// Checkout the specific commit and npm indtall +try { + chdir(modulePath); + execSync(`git checkout ${commitHash}`); + execSync(`cd webapp && npm i`); + chdir(`../..`); +} catch (error) { + console.error(`Error during postinstall: ${error}`); + process.exit(1); +} diff --git a/webapp/src/index.tsx b/webapp/src/index.tsx index d839a65..d2f823a 100644 --- a/webapp/src/index.tsx +++ b/webapp/src/index.tsx @@ -1,60 +1,19 @@ -import React, {useEffect} from 'react'; - import {Store, Action} from 'redux'; import {GlobalState} from '@mattermost/types/lib/store'; -import {PluginRegistry} from '@/types/mattermost-webapp'; - -import {PluginId} from './plugin_id'; - -import Hooks from './plugin_hooks'; -import reducer from './reducers'; - -import CreateEventModal from './components/modals/create_event_modal'; -import {getProviderConfiguration, handleConnectChange, openCreateEventModal} from './actions'; - -// eslint-disable-next-line @typescript-eslint/no-empty-function -export default class Plugin { - public async initialize(registry: PluginRegistry, store: Store>>) { - registry.registerReducer(reducer); - - const hooks = new Hooks(store); - registry.registerSlashCommandWillBePostedHook(hooks.slashCommandWillBePostedHook); - - const setup = async () => { - // Retrieve provider configuration so we can access names and other options in messages to use in the frontend. - await store.dispatch(getProviderConfiguration()); +import {id} from '@/manifest'; - registry.registerChannelHeaderMenuAction( - {'Create calendar event'}, - async (channelID) => { - if (await hooks.checkUserIsConnected()) { - store.dispatch(openCreateEventModal(channelID)); - } - }, - ); - - registry.registerRootComponent(CreateEventModal); - - registry.registerWebSocketEventHandler(`custom_${PluginId}_connected`, handleConnectChange(store)); - registry.registerWebSocketEventHandler(`custom_${PluginId}_disconnected`, handleConnectChange(store)); - }; - - registry.registerRootComponent(() => ); - - // reminder to set up site url for any API calls - // and i18n - } -} +import {PluginRegistry} from '@/types/mattermost-webapp'; -const SetupUI = ({setup}) => { - useEffect(() => { - setup(); - }, []); +import Plugin from 'mattermost-plugin-google-calendar/webapp/src/index.tsx'; - return null; -}; +// export default class Plugin { +// // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function +// public async initialize(registry: PluginRegistry, store: Store>>) { +// // @see https://developers.mattermost.com/extend/plugins/webapp/reference/ +// } +// } declare global { interface Window { @@ -62,4 +21,4 @@ declare global { } } -window.registerPlugin(PluginId, new Plugin()); +window.registerPlugin(id, new Plugin()); diff --git a/webapp/webpack.config.js b/webapp/webpack.config.js index c11ac22..d441aab 100644 --- a/webapp/webpack.config.js +++ b/webapp/webpack.config.js @@ -55,7 +55,7 @@ const config = { rules: [ { test: /\.(js|jsx|ts|tsx)$/, - exclude: /node_modules/, + exclude: /node_modules\/(?!mattermost-plugin-google-calendar)/, use: { loader: 'babel-loader', options: { From 3b19e97c480fb4b44a3f737f934e1db5994c46bb Mon Sep 17 00:00:00 2001 From: mickmister <6913320+mickmister@users.noreply.github.com> Date: Wed, 1 Nov 2023 02:50:17 -0400 Subject: [PATCH 2/3] change commit of gcal import --- webapp/package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/webapp/package.json b/webapp/package.json index b44796f..d644562 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -13,14 +13,10 @@ "check-types": "tsc", "postinstall": "node postinstall.js" }, - "submodule": { - "gitRepo": "https://github.com/mattermost/mattermost-plugin-google-calendar.git", - "gitTag": "master" - }, "customModule": { "name": "mattermost-plugin-google-calendar", "repo": "https://github.com/mattermost/mattermost-plugin-google-calendar.git", - "commit": "master" + "commit": "webapp-relative-paths" }, "devDependencies": { "@babel/cli": "7.16.8", From 14e7924d2f8ebf0d0ae693f94a248afe3df503d2 Mon Sep 17 00:00:00 2001 From: mickmister <6913320+mickmister@users.noreply.github.com> Date: Wed, 1 Nov 2023 03:08:47 -0400 Subject: [PATCH 3/3] fix lint --- webapp/package.json | 4 ++-- webapp/postinstall.js | 9 +++++---- webapp/src/index.tsx | 15 +-------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/webapp/package.json b/webapp/package.json index d644562..0b7c0f7 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -5,8 +5,8 @@ "build:watch": "webpack --mode=production --watch", "debug": "webpack --mode=none", "debug:watch": "webpack --mode=development --watch", - "lint": "eslint --ignore-pattern node_modules --ignore-pattern dist --ext .js --ext .jsx --ext tsx --ext ts . --quiet --cache", - "fix": "eslint --ignore-pattern node_modules --ignore-pattern dist --ext .js --ext .jsx --ext tsx --ext ts . --quiet --fix --cache", + "lint": "eslint --ignore-pattern node_modules --ignore-pattern dist --ignore-pattern postinstall.js --ext .js --ext .jsx --ext tsx --ext ts . --quiet --cache", + "fix": "eslint --ignore-pattern node_modules --ignore-pattern dist --ignore-pattern postinstall.js --ext .js --ext .jsx --ext tsx --ext ts . --quiet --fix --cache", "test": "jest --forceExit --detectOpenHandles --verbose", "test:watch": "jest --watch", "test-ci": "jest --forceExit --detectOpenHandles --maxWorkers=2", diff --git a/webapp/postinstall.js b/webapp/postinstall.js index 1e2a084..be4feeb 100644 --- a/webapp/postinstall.js +++ b/webapp/postinstall.js @@ -1,9 +1,11 @@ const {execSync} = require('child_process'); const fs = require('fs'); const path = require('path'); -const packageJson = require('./package.json'); + const {chdir} = require('process'); +const packageJson = require('./package.json'); + const moduleName = packageJson.customModule.name; const moduleRepo = packageJson.customModule.repo; const commitHash = packageJson.customModule.commit; @@ -25,13 +27,12 @@ try { process.exit(1); } - // Checkout the specific commit and npm indtall try { chdir(modulePath); execSync(`git checkout ${commitHash}`); - execSync(`cd webapp && npm i`); - chdir(`../..`); + execSync('cd webapp && npm i'); + chdir('../..'); } catch (error) { console.error(`Error during postinstall: ${error}`); process.exit(1); diff --git a/webapp/src/index.tsx b/webapp/src/index.tsx index d2f823a..f382bdc 100644 --- a/webapp/src/index.tsx +++ b/webapp/src/index.tsx @@ -1,19 +1,6 @@ -import {Store, Action} from 'redux'; - -import {GlobalState} from '@mattermost/types/lib/store'; - -import {id} from '@/manifest'; - -import {PluginRegistry} from '@/types/mattermost-webapp'; - import Plugin from 'mattermost-plugin-google-calendar/webapp/src/index.tsx'; -// export default class Plugin { -// // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function -// public async initialize(registry: PluginRegistry, store: Store>>) { -// // @see https://developers.mattermost.com/extend/plugins/webapp/reference/ -// } -// } +import {id} from '@/manifest'; declare global { interface Window {