-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
89 lines (77 loc) · 2.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const express = require('express')
const webpack = require('webpack')
const webpackMiddleware =
require('webpack-dev-middleware')
const webpackHotMiddleware =
require('webpack-hot-middleware')
const path = require('path')
require('node-localstorage/register')
const { RUNNING_ON_DESKTOP } = require('./constants')
// not necessary yet! huzzah! 🥳
//const api = require('./api')
const dataPath = path.resolve(__dirname, 'data')
// Setup
const app = express();
const port = process.env['REACT_APP_PORT'] || 3001
const config = require('./webpack.config.js')({}, {})
const compiler = webpack(config);
const devMiddleware = webpackMiddleware(compiler, {
publicPath: config.output.publicPath,
serverSideRender: false,
watchOptions: {
// Due to iOS devices memory constraints
// disabling file watching is recommended
ignored: [
'dist/**',
'data/**',
/node_modules/,
],
//ignored: /.*/,
},
writeToDisk: true,
})
app.use(devMiddleware)
if (RUNNING_ON_DESKTOP) {
const hotMiddleware = webpackHotMiddleware(compiler, {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000,
})
app.use(hotMiddleware)
}
app.use('/data', express.static(dataPath))
app.get('/', (req, res) => {
res.sendFile('index.html', { root: __dirname })
})
// Launch app
app.listen(port, () => {
console.log(
'Launching app... http://localhost:' + port + '\n'
)
})
// Register app and middleware. Required for better
// performance when running from play.js
try {
typeof pjs === 'object' &&
pjs.register(app, devMiddleware)
} catch (error) {
console.error(error)
}
const allWords = require('fs')
.readFileSync('./data/all-words.txt')
.toString()
.split('\n')
const usefulLetters = /[mpfwb]/
const countUsefulLetters = w => Array.from(new Set(w))
.reduce(
(c, l) => c + Number(usefulLetters.test(l)),
0
)
const usefulWords = allWords
.filter(w => usefulLetters.test(w))
.map(w => [w, countUsefulLetters(w)])
.filter(([, c]) => c > 2)
.sort((a, b) => b[1] - a[1])
.map(x => x[0])
.join()
console.log('\n\n\n' + usefulWords + '\n\n\n')