Skip to content

Commit

Permalink
format sources
Browse files Browse the repository at this point in the history
mostly white space changes only

    biome format --fix
  • Loading branch information
pirxpilot committed Jan 20, 2025
1 parent 78ac391 commit 595f40a
Show file tree
Hide file tree
Showing 190 changed files with 938 additions and 995 deletions.
17 changes: 8 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ const logger = require('morgan');
const errorHandler = require('errorhandler');
const renderer = require('connect-renderer');

const app = module.exports = connect();
const app = (module.exports = connect());

process.env.PORT ??= 3000;
process.env.SITE_URL ??= `http://localhost:${process.env.PORT}`;
process.env.NODE_ENV ??= 'development';

const root = path.join(__dirname, 'public');
const {
SITE_URL: siteUrl,
LIFTIE_STATIC_HOST: staticHost = ''
} = process.env;
const { SITE_URL: siteUrl, LIFTIE_STATIC_HOST: staticHost = '' } = process.env;

const cachify = cachifyStatic(root);

Expand All @@ -36,10 +33,12 @@ app.locals = {
}
};

app.use(renderer(`${__dirname}/views`).engine('jade', {
compile: require('@pirxpilot/jade-core').compile,
options: { compileDebug: process.env.NODE_ENV !== 'production' }
}));
app.use(
renderer(`${__dirname}/views`).engine('jade', {
compile: require('@pirxpilot/jade-core').compile,
options: { compileDebug: process.env.NODE_ENV !== 'production' }
})
);

app.use(logger('dev'));
app.use(cookieParser());
Expand Down
2 changes: 1 addition & 1 deletion lib/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ function checkNames(requested, valid, all) {
if (typeof requested === 'string') {
requested = requested.split(',');
}
return requested.filter((item) => valid[item]);
return requested.filter(item => valid[item]);
}
5 changes: 1 addition & 4 deletions lib/cli/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ function fetchExample(resortId) {
}
}

program
.arguments('<resort-id>')
.action(fetchExample)
.parse(process.argv);
program.arguments('<resort-id>').action(fetchExample).parse(process.argv);

if (!done) {
program.outputHelp();
Expand Down
5 changes: 1 addition & 4 deletions lib/cli/for-each-resort.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ function forEachResort(fn) {
console.error(err);
process.exit(1);
}
dirents
.filter(dirent => dirent.isDirectory())
.forEach(({ name }) => fn(name));
dirents.filter(dirent => dirent.isDirectory()).forEach(({ name }) => fn(name));
});

}
10 changes: 4 additions & 6 deletions lib/cli/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const curl = require('./curl');
const dirs = require('./dirs');

let fname;
const schema = [{
const schema = [
{
name: 'id',
description: 'Short name of the resort [acme]',
type: 'string',
Expand Down Expand Up @@ -51,9 +52,7 @@ const schema = [{
}
];

program
.option('-j, --json <file>', 'JSON file with resort data', String)
.parse(process.argv);
program.option('-j, --json <file>', 'JSON file with resort data', String).parse(process.argv);

if (program.json) {
fname = path.resolve(program.json);
Expand Down Expand Up @@ -106,7 +105,6 @@ function generate(resort) {
curl(json.url, resort.id);
}


function write(dst, json) {
console.log('Generating %s...', dst);
fs.writeFileSync(dst, JSON.stringify(json, null, 2));
Expand Down Expand Up @@ -135,7 +133,7 @@ function execute(conf) {
schema[2].before = splitHost;
conf = conf || {};
prompt.override = conf;
prompt.addProperties(conf, schema, (err) => {
prompt.addProperties(conf, schema, err => {
if (err) {
console.error(err);
process.exit(-1);
Expand Down
27 changes: 17 additions & 10 deletions lib/cli/noaa.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@ function noaaForResort(resortId, { overwrite }) {
superagent(url)
.accept('application/geo+json')
.set('User-Agent', userAgent)
.then((res) => {
const { body: { properties: { gridId, gridX, gridY } } } = res;
const noaa = `${gridId}/${gridX},${gridY}`;
if (overwrite) {
descriptor.noaa = noaa;
writeDescriptor(resortId, descriptor);
.then(
res => {
const {
body: {
properties: { gridId, gridX, gridY }
}
} = res;
const noaa = `${gridId}/${gridX},${gridY}`;
if (overwrite) {
descriptor.noaa = noaa;
writeDescriptor(resortId, descriptor);
}
console.log(resortId, noaa);
},
e => {
console.error('Cannot find NOAA station for:', resortId, e.response.text);
}
console.log(resortId, noaa);
}, (e) => {
console.error('Cannot find NOAA station for:', resortId, e.response.text);
});
);
}

function descriptorPath(resortId, absolute) {
Expand Down
11 changes: 7 additions & 4 deletions lib/client/boot/height.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ function notify() {
if (!widget) {
return;
}
window.parent.postMessage({
height: widget.scrollHeight,
resort: window.location.pathname.split('/').pop()
}, '*');
window.parent.postMessage(
{
height: widget.scrollHeight,
resort: window.location.pathname.split('/').pop()
},
'*'
);
}

function postHeight() {
Expand Down
14 changes: 7 additions & 7 deletions lib/client/resort/lifts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ const states = ['open', 'hold', 'scheduled', 'closed'];
function renderStatus(node, status) {
dom.removeAllChildren(node);
if (status) {
node.innerHTML = Object.keys(status).map(name => {
const klass = `status ls-${status[name]}`;
return `<li class="lift"><span class="name">${name}</span><span class="${klass}"></span></li>`;
}).join('');
node.innerHTML = Object.keys(status)
.map(name => {
const klass = `status ls-${status[name]}`;
return `<li class="lift"><span class="name">${name}</span><span class="${klass}"></span></li>`;
})
.join('');
}
}

function renderStats(node, stats) {
states.forEach(s =>
node.querySelector(`.ls-${s}`).innerHTML = stats ? stats[s] : 0
);
states.forEach(s => (node.querySelector(`.ls-${s}`).innerHTML = stats ? stats[s] : 0));
}

function renderColorBar(node, percentage) {
Expand Down
2 changes: 0 additions & 2 deletions lib/client/resort/webcams.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports.type = 'webcams';

const DELAY = 15 * 60 * 1000; // update every 15 minutes


function swiper(el) {
const ui = {
swipe: swipe(el.swipe),
Expand Down Expand Up @@ -45,7 +44,6 @@ function swiper(el) {
};
}


function render(div, webcams) {
let cams;
let timer;
Expand Down
8 changes: 2 additions & 6 deletions lib/client/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ function state(nodes, st, keys) {
state[id] = classList.contains(st);
});

const selected = Object.keys(state)
.filter(id => state[id]);
const selected = Object.keys(state).filter(id => state[id]);

write(selected);
return selected;
}


function save() {
const selected = nodes
.filter(n => n.classList.contains(st))
.map(n => n.dataset.resort);
const selected = nodes.filter(n => n.classList.contains(st)).map(n => n.dataset.resort);

write(selected);
return selected;
Expand Down
4 changes: 1 addition & 3 deletions lib/client/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ function stats() {
const data = JSON.parse(pie.dataset.stats);
let ac = 0;
const { style } = pie;
Object.entries(data.percentage).forEach(
([key, value]) => style.setProperty(`--${key}`, `${ac += value}%`)
);
Object.entries(data.percentage).forEach(([key, value]) => style.setProperty(`--${key}`, `${(ac += value)}%`));
}
13 changes: 6 additions & 7 deletions lib/embed/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/*global document, window */

function el(attrs) {
const attrStr = Object.keys(attrs).map((attr) => `${attr}="${attrs[attr]}"`).join(' ');
const attrStr = Object.keys(attrs)
.map(attr => `${attr}="${attrs[attr]}"`)
.join(' ');

return ['<iframe ',
attrStr,
'></iframe>'
].join('');
return ['<iframe ', attrStr, '></iframe>'].join('');
}

function addWidget(parent, resort, style) {
const query = style ? `?style=${encodeURIComponent(style)}` : '';
let html = el({
'class': `lift-status ${resort}`,
class: `lift-status ${resort}`,
src: `https://liftie.info/widget/resort/${resort}${query}`,
scrolling: 'no'
});
Expand All @@ -39,7 +38,7 @@ function embed() {
let i;
const els = document.querySelectorAll('.liftie-widget[data-resort]');
if (els.length) {
window.addEventListener("message", receiveMessage, false);
window.addEventListener('message', receiveMessage, false);
}
for (i = 0; i < els.length; i++) {
addWidget(els[i], els[i].getAttribute('data-resort'), els[i].getAttribute('data-style'));
Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getRequestFnAndUrl(resort) {
url: resort.dataUrl
};
}
if (typeof (resort.getUrl) === 'function') {
if (typeof resort.getUrl === 'function') {
return {
fn: pipe,
url: resort.getUrl()
Expand All @@ -46,7 +46,7 @@ function fetch(resort, fn) {
if (!resort._parseFn) {
resort._parseFn = getParseFn(resort.id);
}
debug("Fetch lift status for %s", resort.id);
debug('Fetch lift status for %s', resort.id);
const rfau = resort._rfau;
rfau.fn(rfau.url, resort._parseFn, (_err, data) => {
Promise.resolve(data).then((data, err) => {
Expand Down
2 changes: 0 additions & 2 deletions lib/lifts/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const debug = require('debug')('liftie:lifts');

module.exports = getParseFn;


/**
* catch exceptions thrown by parse
*/
function getParseFn(resortId) {

const descriptor = require(`../resorts/${resortId}`);
const parse = typeof descriptor === 'function' ? descriptor : collectParse;

Expand Down
3 changes: 1 addition & 2 deletions lib/lifts/parser.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { nextTick } = require('node:process');
const { DomHandler, Text } = require('domhandler');
const { ElementType } = require('domelementtype');
const { WritableStream } = require("htmlparser2/WritableStream");
const { WritableStream } = require('htmlparser2/WritableStream');

module.exports = parserStream;

parserStream.html = parseHtml;


function parseHtml(html, parse, fn) {
const stream = parserStream(parse, fn);
stream.write(html);
Expand Down
1 change: 0 additions & 1 deletion lib/lifts/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const superagent = require('superagent');
const userAgent = 'Mozilla/5.0 (compatible; Liftie/1.0; +https://liftie.info)';

module.exports = ({ host, pathname, query, http2 }) => {

const req = superagent
.agent()
.get(host + pathname)
Expand Down
11 changes: 3 additions & 8 deletions lib/lifts/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module.exports = rest;
function rest(url, parse, fn) {
const fullUrl = url.host + url.pathname;

const request = url.body ?
superagent.post(fullUrl).send(url.body) :
superagent.get(fullUrl);
const request = url.body ? superagent.post(fullUrl).send(url.body) : superagent.get(fullUrl);

if (url.query) {
request.query(url.query);
Expand All @@ -18,13 +16,10 @@ function rest(url, parse, fn) {
request.http2(true);
}

request
.set('User-Agent', userAgent)
.set('Accept', 'application/json')
.on('error', fn);
request.set('User-Agent', userAgent).set('Accept', 'application/json').on('error', fn);

request.then(
(res) => {
res => {
let { body, text } = res;
if (url.html) {
return parseHtml(body, parse, fn);
Expand Down
4 changes: 2 additions & 2 deletions lib/lifts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function percentage(status) {
}
return states.reduce((memo, s) => {
//console.log('status', s, status[s]);
memo[s] = Math.floor(status[s] * 1000 / all) / 10;
memo[s] = Math.floor((status[s] * 1000) / all) / 10;
return memo;
}, empty());
}
Expand All @@ -36,7 +36,7 @@ function summary(arr) {
if (!s) {
return sum;
}
states.forEach((state) => {
states.forEach(state => {
sum[state] += s[state] || 0;
});
return sum;
Expand Down
14 changes: 6 additions & 8 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ module.exports = load;

async function load() {
const names = await fs.readdir(`${__dirname}/resorts`);
const entries = names.map(
id => [
const entries = names.map(id => [
id,
{
id,
{
id,
...require(`./resorts/${id}/resort.json`)
}
]
);
...require(`./resorts/${id}/resort.json`)
}
]);
return Object.fromEntries(entries);
}
4 changes: 1 addition & 3 deletions lib/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ function register(loader) {
}

function appendResorts(data, resorts) {
Object.entries(resorts).forEach(
([id, resort]) => data[id] ||= resort
);
Object.entries(resorts).forEach(([id, resort]) => (data[id] ||= resort));
return data;
}

Expand Down
Loading

0 comments on commit 595f40a

Please sign in to comment.