Skip to content

Commit

Permalink
Checkpoint for webui
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydw committed Feb 20, 2021
1 parent 7a66963 commit 3d9ca18
Show file tree
Hide file tree
Showing 12 changed files with 7,432 additions and 3,174 deletions.
10,459 changes: 7,287 additions & 3,172 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"scripts": {
"check": "gts check",
"clean": "gts clean",
"compile": "tsc",
"compile": "tsc; webpack --config webpack.common.js --mode development",
"copy": "cpx 'src/static/**' 'dist/src/static'",
"dev:start": "npm run copy; npm run compile",
"dev": "nodemon --watch src -e ts --exec npm run dev:start",
Expand All @@ -40,14 +40,26 @@
"@types/js-yaml": "^3.12.5",
"@types/mime-types": "^2.1.0",
"@types/node": "^14.14.16",
"@types/webpack": "^4.41.26",
"ava": "^3.14.0",
"cpx": "^1.5.0",
"file-loader": "^6.2.0",
"glob": "^7.1.6",
"gts": "^3.0.3",
"nodemon": "^2.0.6",
"preact-material-components": "^1.6.1",
"preact-router": "^3.2.1",
"preact": "^10.4.4",
"sass": "^1.32.4",
"sass-loader": "^10.1.1",
"ts-loader": "^8.0.12",
"ts-node": "^9.1.1",
"typedoc": "^0.19.2",
"typescript": "^4.1.3"
"typescript": "^4.1.3",
"webpack-cli": "^3.3.11",
"webpack-merge": "^5.7.3",
"webpack": "^4.43.0",
"webpack-stream": "^5.2.1"
},
"dependencies": {
"@google-cloud/datastore": "^6.3.1",
Expand Down
Empty file added src/index.js
Empty file.
4 changes: 4 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export function createApp(siteId: string, branchOrRef: string) {

const app = express();
app.disable('x-powered-by');
app.use('/fileset/static/', express.static('./dist/'));
app.all('/fileset/', async (req: express.Request, res: express.Response) => {
res.sendFile(fsPath.join(__dirname, './static/', 'webui.html'));
});
app.all('/*', async (req: express.Request, res: express.Response) => {
const envFromHostname = parseHostname(
req.hostname,
Expand Down
12 changes: 12 additions & 0 deletions src/static/webui.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fileset</title>
<link rel="stylesheet" href="/fileset/static/webui.min.css">
</head>
<body>
<div class="webui">container</div>
<script src="/fileset/static/webui.min.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import {asyncify, mapLimit} from 'async';

import {Datastore} from '@google-cloud/datastore';
import {Storage} from '@google-cloud/storage';
import {Type} from 'js-yaml';
import {entity} from '@google-cloud/datastore/build/src/entity';

const NUM_CONCURRENT_UPLOADS = 64;

const EntityType = {
Ref: 'ref',
Branch: 'branch',
};

function getBlobPath(siteId: string, hash: string) {
return `fileset/sites/${siteId}/blobs/${hash}`;
}
Expand Down Expand Up @@ -161,12 +167,15 @@ async function finalize(
'Fileset2Manifest',
`${manifest.site}:ref:${manifest.shortSha}`,
]);
const modified = new Date();
await saveManifestEntity(datastore, key, {
branch: manifest.branch,
modified: modified,
paths: manifestPaths,
redirects: manifest.redirects,
ref: manifest.ref,
site: manifest.site,
type: EntityType.Ref,
});

// Create branch mapping, so a branch name can be used to lookup filesets.
Expand All @@ -178,10 +187,12 @@ async function finalize(
]);
await saveManifestEntity(datastore, branchKey, {
branch: manifest.branch,
modified: modified,
paths: manifestPaths,
redirects: manifest.redirects,
ref: manifest.ref,
site: manifest.site,
type: EntityType.Branch,
});
}

Expand Down
20 changes: 20 additions & 0 deletions src/webui/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Component, h, render} from 'preact';

interface MainState {
currentPath: string;
}

class Main extends Component<unknown, MainState> {
constructor() {
super();
this.state = {
currentPath: window.location.pathname,
};
}
render() {
return <div>hello world!</div>;
}
}

const container = document.querySelector('.webui');
render(<Main />, container);
2 changes: 2 additions & 0 deletions src/webui/sass/webui.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
body
background: seablue
21 changes: 21 additions & 0 deletions src/webui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"jsx": "react",
"jsxFactory": "h",
"declaration": false,
"removeComments": true,
"allowJs": true,
"strict": true,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true
},
"lib": [
"dom",
"es2018"
],
"exclude": [
"node_modules"
]
}
47 changes: 47 additions & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const glob = require('glob');
const path = require('path');

module.exports = env => {
return {
entry: ['./src/webui/main.tsx'].concat(
glob.sync('./src/webui/sass/**/*.sass', {
ignore: ['./src/webui/sass/**/_*'],
})
),
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
mode: 'development',
plugins: [],
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, './src/webui/tsconfig.json'),
},
include: [path.resolve(__dirname, './src/webui/')],
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/i,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].min.css',
},
},
'sass-loader',
],
},
],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].min.js',
},
};
};
7 changes: 7 additions & 0 deletions webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const {merge} = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
});
7 changes: 7 additions & 0 deletions webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const {merge} = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
mode: 'production',
devtool: 'inline-source-map',
});

0 comments on commit 3d9ca18

Please sign in to comment.