Skip to content

Commit

Permalink
chore: add gitlab-ci pages demo
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiteng authored and dyingsunlight committed Jan 28, 2021
1 parent 63deaf1 commit 6b9e3df
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 109 deletions.
23 changes: 23 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
stages:
- test
- deploy

test:
stage: test
image: node:14.15.4-alpine
script:
- npm install
- npm run test

pages:
image: node:14.15.4-alpine
stage: deploy
only:
- master
script:
- npm install
- npm run build
- cp -Rp dist/umd/* public/
artifacts:
paths:
- public
59 changes: 59 additions & 0 deletions public/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>XMind Embed Viewer (Development)</title>
</head>
<body>
</body>
<script src="xmind-embed-viewer.js"></script>
<script>
const init = async () => {

const container = document.createElement('div')
document.body.append(container)
const res = await fetch('/test-1.xmind')
const viewer = new XMindEmbedViewer({
el: container,
file: await res.arrayBuffer(),
styles: {
'height': '500px',
'width': '100%'
}
})

const eventLogsElement = document.createElement('div')
eventLogsElement.style.height = '500px'
eventLogsElement.style.overflow = 'scroll'

const log = (type, message) => eventLogsElement.innerHTML += `<div style="margin-top: 8px">[${type}] ${typeof message === 'object' && message? JSON.stringify(message, null, 2) : message }</div>`

viewer.addEventListener('sheet-switch', payload => log('event: sheet-switch', payload))
viewer.addEventListener('zoom-scale-change', payload => log('event: zoom-scale-change', payload))
viewer.addEventListener('sheets-change', payload => log('event: sheets-change', payload))
viewer.addEventListener('map-ready', payload => log('event: map-ready', payload))

const loadFile1Button = document.createElement('button')
loadFile1Button.textContent = 'Load File 1'
loadFile1Button.addEventListener('click', async () => {
const res = await fetch('/test-1.xmind')
viewer.openFile(await res.arrayBuffer())
})

const loadFile2Button = document.createElement('button')
loadFile2Button.textContent = 'Load File 2'
loadFile2Button.addEventListener('click', async () => {
const res = await fetch('/test-2.xmind')
viewer.openFile(await res.arrayBuffer())
})

document.body.appendChild(loadFile1Button)
document.body.appendChild(loadFile2Button)
document.body.appendChild(eventLogsElement)

window.viewer = viewer
}

init()
</script>
</html>
59 changes: 59 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>XMind Embed Viewer (Development)</title>
</head>
<body>
</body>
<script src="xmind-embed-viewer.js"></script>
<script>
const init = async () => {

const container = document.createElement('div')
document.body.append(container)
const res = await fetch('/test-1.xmind')
const viewer = new XMindEmbedViewer({
el: container,
file: await res.arrayBuffer(),
styles: {
'height': '500px',
'width': '100%'
}
})

const eventLogsElement = document.createElement('div')
eventLogsElement.style.height = '500px'
eventLogsElement.style.overflow = 'scroll'

const log = (type, message) => eventLogsElement.innerHTML += `<div style="margin-top: 8px">[${type}] ${typeof message === 'object' && message? JSON.stringify(message, null, 2) : message }</div>`

viewer.addEventListener('sheet-switch', payload => log('event: sheet-switch', payload))
viewer.addEventListener('zoom-scale-change', payload => log('event: zoom-scale-change', payload))
viewer.addEventListener('sheets-change', payload => log('event: sheets-change', payload))
viewer.addEventListener('map-ready', payload => log('event: map-ready', payload))

const loadFile1Button = document.createElement('button')
loadFile1Button.textContent = 'Load File 1'
loadFile1Button.addEventListener('click', async () => {
const res = await fetch('/test-1.xmind')
viewer.openFile(await res.arrayBuffer())
})

const loadFile2Button = document.createElement('button')
loadFile2Button.textContent = 'Load File 2'
loadFile2Button.addEventListener('click', async () => {
const res = await fetch('/test-2.xmind')
viewer.openFile(await res.arrayBuffer())
})

document.body.appendChild(loadFile1Button)
document.body.appendChild(loadFile2Button)
document.body.appendChild(eventLogsElement)

window.viewer = viewer
}

init()
</script>
</html>
File renamed without changes.
File renamed without changes.
46 changes: 0 additions & 46 deletions statics/development.html

This file was deleted.

4 changes: 2 additions & 2 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"strict": true,
"sourceMap": true,
"target": "ES2015",
"target": "ESNext",
"moduleResolution": "node",
"module": "esnext",
"sourceRoot": "src",
Expand All @@ -15,4 +15,4 @@
"src"
],
"exclude": ["node_modules"]
}
}
123 changes: 62 additions & 61 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,72 @@ import * as path from 'path'
import { Configuration, EnvironmentPlugin } from 'webpack'

const commonConfig: Partial<Configuration> = {
devtool: 'source-map',
entry: './src/index.ts',
module: {
rules: [
{ test: /\.tsx?$/, loader: 'ts-loader' }
]
},
resolve: {
extensions: ['.js', '.ts'],
},
entry: './src/index.ts',
module: {
rules: [
{test: /\.tsx?$/, loader: 'ts-loader'}
]
},
resolve: {
extensions: ['.js', '.ts'],
},
}

const config: Configuration[] = [
{
...commonConfig,
name: 'dev',
mode: 'development',
output: {
library: 'XMindEmbedViewer',
libraryTarget: 'umd',
libraryExport: 'XMindEmbedViewer',
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
//
// https://github.com/webpack/webpack-dev-server/issues/2663
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
devServer: {
port: 9000,
static: [
path.resolve('./statics')
],
compress: true,
hot: true,
https: false,
},
plugins: [
new EnvironmentPlugin({
'EMBED_VIEWER_URL': process.env['EMBED_VIEWER_URL'] || 'http://localhost:8088/embed',
'EMBED_VIEWER_DOMAIN': process.env['EMBED_VIEWER_DOMAIN'] || 'http://localhost:8088'
})
]
{
...commonConfig,
name: 'dev',
mode: 'development',
devtool: 'inline-source-map',
output: {
library: 'XMindEmbedViewer',
libraryTarget: 'umd',
libraryExport: 'XMindEmbedViewer',
path: path.join(__dirname, 'dist'),
filename: 'xmind-embed-viewer.js'
},
//
// https://github.com/webpack/webpack-dev-server/issues/2663
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
devServer: {
port: 9000,
static: [
path.resolve('./public')
],
compress: true,
hot: true,
https: false,
},
plugins: [
new EnvironmentPlugin({
'EMBED_VIEWER_URL': process?.env['EMBED_VIEWER_URL'] || 'https://beta.xmind.net/embed',
'EMBED_VIEWER_DOMAIN': process?.env['EMBED_VIEWER_DOMAIN'] || 'https://beta.xmind.net'
})
]
},
{
...commonConfig,
name: 'prod-umd',
mode: 'production',
devtool: 'source-map',
output: {
library: 'XMindEmbedViewer',
libraryTarget: 'umd',
libraryExport: 'XMindEmbedViewer',
path: path.join(__dirname, 'dist/umd'),
filename: 'xmind-embed-viewer.js'
},
{
...commonConfig,
name: 'prod-umd',
mode: 'production',
output: {
library: 'XMindEmbedViewer',
libraryTarget: 'umd',
libraryExport: 'XMindEmbedViewer',
path: path.join(__dirname, 'dist/umd'),
filename: 'xmind-embed-viewer.js'
},
plugins: [
new EnvironmentPlugin({
'EMBED_VIEWER_URL': process.env['EMBED_VIEWER_URL'] || 'http://localhost:8088/embed',
'EMBED_VIEWER_DOMAIN': process.env['EMBED_VIEWER_DOMAIN'] || 'http://localhost:8088'
})
],
optimization: {
minimize: true
}
plugins: [
new EnvironmentPlugin({
'EMBED_VIEWER_URL': process?.env['EMBED_VIEWER_URL'] || 'https://beta.xmind.net/embed',
'EMBED_VIEWER_DOMAIN': process?.env['EMBED_VIEWER_DOMAIN'] || 'https://beta.xmind.net'
})
],
optimization: {
minimize: true
}
}
]

export default config
export default config

0 comments on commit 6b9e3df

Please sign in to comment.