Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorosty committed May 4, 2024
0 parents commit c3e96cf
Show file tree
Hide file tree
Showing 33 changed files with 4,475 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

How to debug
===
- Run `node bin/debug`
- Visit `localhost:1234`


How to build
===
- Run `node bin/debug`
- To view, open the static standalone HTML file generated at `./docs/index.html`
7 changes: 7 additions & 0 deletions _isWorkerEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

exports.default = false




/**********/ exports.__esModule = true
6 changes: 6 additions & 0 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const fs = require('fs')
const utils = require('./utils')

utils.build(true).then(page =>
fs.writeFile('docs/index.html', page, () => console.log('done')))
15 changes: 15 additions & 0 deletions bin/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

const http = require('http')
const utils = require('./utils')

http.createServer(async (req, res) => {
try {
res.end(await utils.build())
} catch (e) {
console.log(new Date())
console.log(e)
res.end('error')
}
}).listen(1234)

console.log('running')
33 changes: 33 additions & 0 deletions bin/outdated.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

<h1>Outdated Browser</h1>
<div id="warning">
notice
<br>
<a id="upgrade" href="https://google.com/chrome" target="_blank">
<i class="fa fa-chrome"></i>
<span>cta</span>
</a>
</div>
<p>prompt</p>
<div id="browser-list">
<a class="browser chrome" href="https://google.com/chrome" target="_blank">
<i class="fa fa-chrome"></i>
<br>Chrome
</a>
<a class="browser firefox" href="https://mozilla.com/firefox" target="_blank">
<i class="fa fa-firefox"></i>
<br>FireFox
</a>
<a class="browser edge" href="https://microsoft.com/edge" target="_blank">
<i class="fa fa-edge"></i>
<br>Edge
</a>
<a class="browser safari" href="https://apple.com/safari" target="_blank">
<i class="fa fa-safari"></i>
<br>Safari
</a>
<a class="browser opera" href="https://opera.com" target="_blank">
<i class="fa fa-opera"></i>
<br>Opera
</a>
</div>
97 changes: 97 additions & 0 deletions bin/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!doctype html>
<html>
<head>
<title>Ali Dorosty | Front-End Engineer</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
#content {
position: fixed;
direction: ltr;
top: 0;
left: 0;
width: calc(100% + 100px);
height: calc(100% + 100px);
overflow: scroll;
}
#content a {
position: fixed;
display: block;
opacity: 0;
cursor: pointer;
}
#content a[href=''], #content a:not([href]) {
display: none;
}

#outdated {
font-family: sans-serif;
color: #fff;
text-align: center;
padding: 0;
margin: 0;
}
#outdated a { color: #fff; }
#outdated h1, #outdated p {
color: #444;
margin: 2rem;
padding: 0;
}
#outdated h1 {
font-size: 2rem;
font-weight: bold;
}
#warning {
background-color: #5b4346;
padding: 2rem;
}
#upgrade {
display: inline-block;
background-color: #1d7335;
margin-top: 2rem;
padding: 1rem 2rem;
text-decoration: none;
}
#upgrade i {
vertical-align: middle;
font-size: 4rem;
margin: 1rem 1rem 1rem 0;
}
#upgrade span {
display: inline-block;
vertical-align: middle;
font-size: 2rem;
}
#browser-list {
display: inline-block;
padding: 0 1rem 1rem;
}
.browser {
float: left;
width: 7rem;
padding: 2rem;
text-decoration: none;
}
.browser i {
font-size: 3rem;
padding-bottom: 1.5rem;
}
.chrome { background-color: #ffb31a; }
.firefox { background-color: #f78009; }
.edge { background-color: #33ccff; }
.safari { background-color: #0099ff; }
.opera { background-color: #ff4d4d; }
</style>
</head>
<body>
<script>
jsCode
</script>
</body>
</html>
53 changes: 53 additions & 0 deletions bin/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

const fs = require('fs')
const esbuild = require('esbuild')
const isWorkerEnabled = require('../_isWorkerEnabled').default

exports.build = async isProduction => {
const read = file => fs.promises.readFile(file).then(file => file.toString())

const build = async file => {
let { outputFiles: [{ text }] } = await esbuild.build({
entryPoints: [file],
target: 'es2015',
bundle: true,
write: false,
format: 'cjs',
minify: isProduction,
})
if (isProduction)
text = text.trim().replace(/\n/g, '\\n')
return text
}

const [
template,
outdatedTemplate,
mainCode,
workerCode,
] = await Promise.all([
read('bin/template.html'),
read('bin/outdated.html'),
build('src/index.js'),
build('src/worker.js'),
])

let workerCodeString = workerCode.replace(/\\/g, '\\\\')
workerCodeString = isProduction
? "'" + workerCodeString.replace(/\'/g, '\\\'') + "'"
: '`' + workerCodeString.replace(/\`/g, '\\\`').replace(/\$/g, '\\\$') + '`'

const outTemplateString = "'" + outdatedTemplate.replace(/\n */g, '') + "'"

let html = isProduction ? template.trim().replace(/\n */g, '') : template
html = html.replace(
'jsCode', isWorkerEnabled
? 'var workerCode = workerCodeString;mainCode'
: '(function(){workerCode})();(function(){mainCode})()'
)
.replace('mainCode', () => mainCode)
.replace('outdatedTemplate', () => outTemplateString)
return isWorkerEnabled
? html.replace('workerCodeString', () => workerCodeString)
: html.replace('workerCode', () => workerCode)
}
Binary file added docs/Ali Dorosty.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions docs/index.html

Large diffs are not rendered by default.

Loading

0 comments on commit c3e96cf

Please sign in to comment.