Skip to content

Commit

Permalink
Auto copy the manifest.xml in dist and replace localhost:3000
Browse files Browse the repository at this point in the history
Replace localhost:3000 both in `manifest.xml` and `api.js`
when environment variable is set at build time with the command
npm run-script build  -- --env.DOMAIN=MYDOMAIN:8080`
  • Loading branch information
Florimond committed Sep 1, 2020
1 parent e48c245 commit 7be1549
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
4 changes: 3 additions & 1 deletion outlook/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ typings/
.next

# VS CODE
.vscode/*
.vscode/
*.code-workspace

dist/
7 changes: 2 additions & 5 deletions outlook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@

- cd to the addin-in sources directory
- `npm install`
- `npm run-script build`
- copy the `manifest.xml` to the `dist` directory
- open the `manifest.xml` and replace all `https://localhost:3000` instances with the actual address
- do the same operation with `api.js`
- serve
- `npm run-script build -- --env.DOMAIN=127.0.0.1:8080` (replace `127.0.0.1:8080` with the actual domain)
- serve the dist folder
2 changes: 1 addition & 1 deletion outlook/src/taskpane/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const api = {
loginPage: "/web/login", // Should be the usual Odoo login page.
authCodePage: "/mail_client_extension/auth", // The page where to allow or deny access. You get an auth code.
getAccessToken: "/mail_client_extension/auth/access_token", // The address where to post to exchange an auth code for an access token.
addInRedirect: "https://localhost:3000/taskpane.html", // The address of the outlook add-in to redirect to at the end of the auth flow.
addInRedirect: "https://" + __DOMAIN__ + "/taskpane.html", // The address of the outlook add-in to redirect to at the end of the auth flow. See the webpack.config.js for the __DOMAIN__ variable.
outlookScope: "outlook",
outlookFriendlyName: "Outlook",
};
Expand Down
34 changes: 24 additions & 10 deletions outlook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const webpack = require('webpack');

module.exports = async (env, options) => {
const dev = options.mode === "development";
let domain = "localhost:3000";
if (env && env.DOMAIN) {
domain = env.DOMAIN;
}
const config = {
devtool: "source-map",
entry: {
Expand Down Expand Up @@ -57,10 +61,29 @@ module.exports = async (env, options) => {
{
to: "taskpane.css",
from: "./src/taskpane/taskpane.css"
}
},
{
from: './assets',
to: 'assets',
globOptions: {
ignore: ['*.scss'],
}
},
{
to: "manifest.xml",
from: "./manifest.xml",
transform(content) {
return content
.toString()
.replace(/localhost:3000/g, domain);
},
},
]
}
),
new webpack.DefinePlugin({
__DOMAIN__: JSON.stringify(domain)
}),
new ExtractTextPlugin('[name].[hash].css'),
new HtmlWebpackPlugin({
filename: "taskpane.html",
Expand All @@ -71,15 +94,6 @@ module.exports = async (env, options) => {
filename: "dialog.html",
template: "./src/taskpane/components/Login/dialog.html"
}),
new CopyWebpackPlugin({ patterns: [
{
from: './assets',
to: 'assets',
globOptions: {
ignore: ['*.scss'],
}
}
]}),
new webpack.ProvidePlugin({
Promise: ["es6-promise", "Promise"]
})
Expand Down

0 comments on commit 7be1549

Please sign in to comment.