Skip to content

Commit

Permalink
Apply JS linter
Browse files Browse the repository at this point in the history
  • Loading branch information
groenroos committed Apr 3, 2022
1 parent d8c07e1 commit 6bfb01a
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 249 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

/* Dependencies */

import { fileURLToPath } from 'node:url';
import { readFileSync as read, existsSync as exists } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'url';
import yargs from 'yargs';
/* eslint-disable-next-line node/file-extension-in-import */
import { hideBin } from 'yargs/helpers';
Expand Down Expand Up @@ -37,12 +37,12 @@ const app = new App();

const sirvSettings = {
maxAge: 1,
dev: process.env.NODE_ENV !== 'production'
dev: process.env.NODE_ENV !== 'production',
};

app.use(`/js`, sirv(path.join(__dirname, 'dist/js'), sirvSettings));
app.use(`/css`, sirv(path.join(__dirname, 'dist/css'), sirvSettings));
app.use(`/images`, sirv(path.join(__dirname, 'dist/images'), sirvSettings));
app.use('/js', sirv(path.join(__dirname, 'dist/js'), sirvSettings));
app.use('/css', sirv(path.join(__dirname, 'dist/css'), sirvSettings));
app.use('/images', sirv(path.join(__dirname, 'dist/images'), sirvSettings));


/* Data routes */
Expand Down
10 changes: 5 additions & 5 deletions routes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import { json } from 'milliparsec';


export default {
read: async (request, response) => {
async read(request, response) {
try {
response.json(await digest.call({
dir: process.cwd(),
opts: {}
opts: {},
}));
} catch (error) {
response.status(500).send(error);
}
},

write: async (request, response) => {
async write(request, response) {
/* Parse body */
await json()(request, response, (err) => void err && console.log(err));
await json()(request, response, error => void error && console.log(error));

const configFile = path.join(process.cwd(), 'config.json');
try {
Expand All @@ -39,5 +39,5 @@ export default {
console.log(error);
response.status(500).send(error);
}
}
},
};
18 changes: 9 additions & 9 deletions routes/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,50 @@ import dir from 'directory-tree';
function filterDirs(dirs, pos) {
let filteredDirs = [];

dirs.forEach((file) => {
for (const file of dirs) {
if (file.type === 'directory') {
const currentPath = path.join(pos || '', file.name);
filteredDirs.push(currentPath);
filteredDirs = filteredDirs.concat(filterDirs(file.children, currentPath));
}
});
}

return filteredDirs;
}

function filterFiles(files, pos) {
let filteredFiles = [];

files.forEach((file) => {
for (const file of files) {
const currentPath = path.join(pos || '', file.name);
if (file.type !== 'directory') {
filteredFiles.push(currentPath);
} else {
filteredFiles = filteredFiles.concat(filterFiles(file.children, currentPath));
}
});
}

return filteredFiles;
}

export default {
dirs: (request, response) => {
dirs(request, response) {
const dirs = dir(process.cwd(), {
exclude: /node_modules/,
attributes: ['type']
attributes: ['type'],
});

response.json(filterDirs(dirs.children));
},

files: (request, response) => {
files(request, response) {
const extension = request.params.extension || 'json';
const dirs = dir(process.cwd(), {
exclude: /node_modules/,
attributes: ['type'],
extensions: new RegExp(`\.${extension}$`)
extensions: new RegExp(`\.${extension}$`),
});

response.json(filterFiles(dirs.children));
}
},
};
9 changes: 4 additions & 5 deletions routes/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@

import process from 'node:process';

import getConfig from '../utils/getConfig.js';

import { digest } from '@sapling/sapling/core/loadModel.js';
import getConfig from '../utils/getConfig.js';


export default {
read: async (request, response) => {
async read(request, response) {
try {
response.json(await digest.call({
config: await getConfig(),
dir: process.cwd(),
opts: {}
opts: {},
}));
} catch (error) {
response.status(500).send(error);
}
}
},
};
41 changes: 26 additions & 15 deletions routes/responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import { createRequire } from 'node:module';
import path from 'node:path';
import process from 'node:process';

import { json } from 'milliparsec';
import exists from '../utils/exists.js';
import getConfig from '../utils/getConfig.js';

import { json } from 'milliparsec';


async function getResponseFile(file) {
const config = await getConfig();
Expand All @@ -23,11 +22,11 @@ async function getResponseFile(file) {
if (await exists(local)) {
const html = await fs.readFile(local);
return html.toString();
} else {
const require = createRequire(import.meta.url);
const html = await fs.readFile(require.resolve(`@sapling/sapling/static/response/${file}.${config.extension}`));
return html.toString();
}

const require = createRequire(import.meta.url);
const html = await fs.readFile(require.resolve(`@sapling/sapling/static/response/${file}.${config.extension}`));
return html.toString();
}

async function saveResponseFile(file, contents) {
Expand All @@ -43,30 +42,42 @@ async function saveResponseFile(file, contents) {


export default {
read: async (request, response) => {
async read(request, response) {
const responses = {
404: await getResponseFile('404'),
500: await getResponseFile('500'),
data: await getResponseFile('data'),
error: await getResponseFile('error')
error: await getResponseFile('error'),
};

response.json(responses);
},

write: async (request, response) => {
async write(request, response) {
/* Parse body */
await json()(request, response, (err) => void err && console.log(err));
await json()(request, response, error => void error && console.log(error));

try {
if ('404' in request.body) await saveResponseFile('404', request.body['404']);
if ('500' in request.body) await saveResponseFile('500', request.body['500']);
if ('data' in request.body) await saveResponseFile('data', request.body['data']);
if ('error' in request.body) await saveResponseFile('error', request.body['error']);
if ('404' in request.body) {
await saveResponseFile('404', request.body['404']);
}

if ('500' in request.body) {
await saveResponseFile('500', request.body['500']);
}

if ('data' in request.body) {
await saveResponseFile('data', request.body.data);
}

if ('error' in request.body) {
await saveResponseFile('error', request.body.error);
}

response.sendStatus(200);
} catch (error) {
console.log(error);
response.status(500).send(error);
}
}
},
};
4 changes: 2 additions & 2 deletions routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import isPortReachable from 'is-port-reachable';


export default {
ping: async (request, response) => {
async ping(request, response) {
const port = request.params.port || 3000;
const reachable = await isPortReachable(port, { host: 'localhost' });
response.json({ reachable });
}
},
};
26 changes: 13 additions & 13 deletions src/js/app.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
/* Dependencies */
import Vue from 'vue';
import { PrismEditor } from 'vue-prism-editor';
import App from './App.vue';

import router from './router.js';
import store from './store.js';

/* Config */
Vue.config.productionTip = false;

/* Components */
import modal from './components/elements/Modal.vue';
Vue.component("modal", modal);


/* Code editor */
import { PrismEditor } from 'vue-prism-editor';
import 'vue-prism-editor/dist/prismeditor.min.css';
Vue.component("prism-editor", PrismEditor);

import { highlight, languages } from 'prismjs/components/prism-core.js';
import 'prismjs/components/prism-clike.js';
Expand All @@ -25,11 +20,16 @@ import 'prismjs/components/prism-json.js';
import 'prismjs/components/prism-markup.js';
import 'prismjs/themes/prism-tomorrow.css';

/* Config */
Vue.config.productionTip = false;
Vue.component('modal', modal);
Vue.component('prism-editor', PrismEditor);

Vue.mixin({
data() {
return {
isScrolled: false
}
isScrolled: false,
};
},

methods: {
Expand All @@ -43,15 +43,15 @@ Vue.mixin({
return highlight(code, languages.markup);
},
scroll(e) {
const el = e.target;
this.isScrolled = el.scrollHeight - el.scrollTop === el.clientHeight;
}
}
const element = e.target;
this.isScrolled = element.scrollHeight - element.scrollTop === element.clientHeight;
},
},
});

/* Create app */
new Vue({
router,
store,
render: h => h(App)
render: h => h(App),
}).$mount('#app');
Loading

0 comments on commit 6bfb01a

Please sign in to comment.