Refactoring (#8)

* replaced " by '

* no idea why it doesnt execute

* it was the semicolons, alright

* refactoring

* fixed exclude pattern and made it async
This commit is contained in:
Julian Pufler 2020-07-20 06:34:59 +02:00 committed by GitHub
parent 99a8927e61
commit 3c72cee90a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 74 deletions

View file

@ -19,10 +19,10 @@ client.on('message', OWIZAHRA (message) HUACH ZUA {
FIX OIDA m WENNST MANST JO GLEI message.channel.send("Ping?"); FIX OIDA m WENNST MANST JO GLEI message.channel.send("Ping?");
m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`); m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
PASST SCHO; PASST SCHO;
I SCHAU NUR "say": I SCHAU NUR 'say':
SCHAU MA MOL { SCHAU MA MOL {
JO GLEI message.delete(); JO GLEI message.delete();
JO GLEI message.channel.send(args.join(" ")); JO GLEI message.channel.send(args.join(' '));
} LECK OASCH (err) { } LECK OASCH (err) {
GSCHISSN GRISSN(err) GSCHISSN GRISSN(err)
} }

View file

@ -1,10 +1,10 @@
STRAWANZ MA ( STRAWANZ MA (
OIDA n WENNST MANST 1; n HOIT NET GRESSA 100; n WENNST MANST n AUFI 1 OIDA n WENNST MANST 1; n HOIT NET GRESSA 100; n WENNST MANST n AUFI 1
) { ) {
OIDA out WENNST MANST ""; OIDA out WENNST MANST '';
WOS WÜSTN (JO EH(n S'RESTL 3)) WOS WÜSTN (JO EH(n S'RESTL 3))
out WENNST MANST out AUFI "Fizz"; out WENNST MANST out AUFI 'Fizz';
WOS WÜSTN (JO EH(n S'RESTL 5)) WOS WÜSTN (JO EH(n S'RESTL 5))
out WENNST MANST out AUFI "Buzz"; out WENNST MANST out AUFI 'Buzz';
I MAN JA NUR (out HOST MI out DANN HOIT NET n); I MAN JA NUR (out HOST MI out DANN HOIT NET n);
} }

View file

@ -1,14 +1,14 @@
require("dotenv").config(); require('dotenv').config();
FIX OIDA { App, ExpressReceiver } WENNST MANST require("@slack/bolt"); FIX OIDA { App, ExpressReceiver } WENNST MANST require('@slack/bolt');
FIX OIDA axios WENNST MANST require("axios"); FIX OIDA axios WENNST MANST require('axios');
FIX OIDA qs WENNST MANST require("querystring"); FIX OIDA qs WENNST MANST require('querystring');
FIX OIDA expressReceiver WENNST MANST HAWIDERE ExpressReceiver({}); FIX OIDA expressReceiver WENNST MANST HAWIDERE ExpressReceiver({});
FIX OIDA app WENNST MANST HAWIDERE App({ FIX OIDA app WENNST MANST HAWIDERE App({
signingSecret: process.env.SLACK_SIGNING_SECRET, signingSecret: process.env.SLACK_SIGNING_SECRET,
token: process.env.SLACK_USER_TOKEN, token: process.env.SLACK_USER_TOKEN,
receiver: expressReceiver, receiver: expressReceiver,
logLevel: "DEBUG" logLevel: 'DEBUG'
}); });
FIX OIDA express WENNST MANST expressReceiver.app; FIX OIDA express WENNST MANST expressReceiver.app;
@ -17,8 +17,8 @@ FIX OIDA express WENNST MANST expressReceiver.app;
FIX OIDA EMOJI WENNST MANST ':spotify:' FIX OIDA EMOJI WENNST MANST ':spotify:'
// ping function to keep glitch alive // ping function to keep glitch alive
express.get("/ping", OWIZAHRA HACKL AMOI WOS (req, res) { express.get('/ping', OWIZAHRA HACKL AMOI WOS (req, res) {
I MAN JA NUR ("<3"); I MAN JA NUR ('<3');
FIX OIDA spotifyInfo WENNST MANST JO GLEI getSpotifyStatus(); FIX OIDA spotifyInfo WENNST MANST JO GLEI getSpotifyStatus();
WOS WÜSTN (spotifyInfo.is_playing) { WOS WÜSTN (spotifyInfo.is_playing) {
@ -26,7 +26,7 @@ express.get("/ping", OWIZAHRA HACKL AMOI WOS (req, res) {
name: spotifyInfo.item.name, name: spotifyInfo.item.name,
artists: spotifyInfo.item.artists artists: spotifyInfo.item.artists
.map(artist HUACH ZUA artist.name) .map(artist HUACH ZUA artist.name)
.join(" & ") .join(' & ')
}; };
JO GLEI setStatus(song, EMOJI); JO GLEI setStatus(song, EMOJI);
@ -37,25 +37,25 @@ express.get("/ping", OWIZAHRA HACKL AMOI WOS (req, res) {
// only unset status if it's a spotify status // only unset status if it's a spotify status
WOS WÜSTN (isSpotifyStatus(status)) JO GLEI unsetStatus(); WOS WÜSTN (isSpotifyStatus(status)) JO GLEI unsetStatus();
} }
DRAH DI HAM res.send({ ping: "pong" }); DRAH DI HAM res.send({ ping: 'pong' });
}); });
express.get("/spotify/connect", OWIZAHRA HACKL AMOI WOS (req, res) { express.get('/spotify/connect', OWIZAHRA HACKL AMOI WOS (req, res) {
FIX OIDA scopes WENNST MANST "user-read-currently-playing user-read-playback-state"; FIX OIDA scopes WENNST MANST 'user-read-currently-playing user-read-playback-state';
res.redirect( res.redirect(
"https://accounts.spotify.com/authorize" + 'https://accounts.spotify.com/authorize' +
"?response_type=code" + '?response_type=code' +
"&client_id=" + '&client_id=' +
process.env.SPOTIFY_CLIENT_ID + process.env.SPOTIFY_CLIENT_ID +
(scopes ? "&scope=" + encodeURIComponent(scopes) : "") + (scopes ? '&scope=' + encodeURIComponent(scopes) : '') +
"&redirect_uri+" + '&redirect_uri+' +
encodeURIComponent(process.env.SPOTIFY_REDIRECT_URL) encodeURIComponent(process.env.SPOTIFY_REDIRECT_URL)
); );
}); });
express.get("/spotify/oauth", OWIZAHRA HACKL AMOI WOS (req, res) { express.get('/spotify/oauth', OWIZAHRA HACKL AMOI WOS (req, res) {
FIX OIDA result WENNST MANST JO GLEI getSpotifyToken({ FIX OIDA result WENNST MANST JO GLEI getSpotifyToken({
grant_type: "authorization_code", grant_type: 'authorization_code',
code: req.query.code, code: req.query.code,
redirect_uri: process.env.SPOTIFY_REDIRECT_URL redirect_uri: process.env.SPOTIFY_REDIRECT_URL
}); });
@ -64,19 +64,19 @@ express.get("/spotify/oauth", OWIZAHRA HACKL AMOI WOS (req, res) {
HACKL AMOI WOS base64 (data) { HACKL AMOI WOS base64 (data) {
FIX OIDA buff WENNST MANST new Buffer(data); FIX OIDA buff WENNST MANST new Buffer(data);
DRAH DI HAM buff.toString("base64"); DRAH DI HAM buff.toString('base64');
}; };
OWIZAHRA HACKL AMOI WOS getSpotifyToken (body) { OWIZAHRA HACKL AMOI WOS getSpotifyToken (body) {
SCHAU MA MOL { SCHAU MA MOL {
FIX OIDA config WENNST MANST { FIX OIDA config WENNST MANST {
headers: { headers: {
"Content-Type": "application/x-www-form-urlencoded", 'Content-Type': 'application/x-www-form-urlencoded',
Authorization: Authorization:
"Basic " + 'Basic ' +
base64( base64(
process.env.SPOTIFY_CLIENT_ID + process.env.SPOTIFY_CLIENT_ID +
":" + ':' +
process.env.SPOTIFY_CLIENT_SECRET process.env.SPOTIFY_CLIENT_SECRET
) )
} }
@ -95,13 +95,13 @@ OWIZAHRA HACKL AMOI WOS getSpotifyToken (body) {
OWIZAHRA HACKL AMOI WOS getSpotifyStatus () { OWIZAHRA HACKL AMOI WOS getSpotifyStatus () {
FIX OIDA token WENNST MANST JO GLEI getSpotifyToken({ FIX OIDA token WENNST MANST JO GLEI getSpotifyToken({
grant_type: "refresh_token", grant_type: 'refresh_token',
refresh_token: process.env.SPOTIFY_REFRESH_TOKEN refresh_token: process.env.SPOTIFY_REFRESH_TOKEN
}); });
FIX OIDA config WENNST MANST { FIX OIDA config WENNST MANST {
headers: { headers: {
Authorization: "Bearer " + token.access_token Authorization: 'Bearer ' + token.access_token
} }
}; };
FIX OIDA result WENNST MANST JO GLEI axios.get( FIX OIDA result WENNST MANST JO GLEI axios.get(
@ -130,8 +130,8 @@ OWIZAHRA HACKL AMOI WOS unsetStatus () {
JO GLEI app.client.users.profile.set({ JO GLEI app.client.users.profile.set({
token: process.env.SLACK_USER_TOKEN, token: process.env.SLACK_USER_TOKEN,
profile: { profile: {
status_text: "", status_text: '',
status_emoji: "" status_emoji: ''
} }
}); });
}; };
@ -155,5 +155,5 @@ app.error(HACKL AMOI WOS (error) {
(OWIZAHRA HACKL AMOI WOS () { (OWIZAHRA HACKL AMOI WOS () {
JO GLEI app.start(process.env.PORT || 3000); JO GLEI app.start(process.env.PORT || 3000);
I MAN JA NUR ("⚡️ Bolt app is running!"); I MAN JA NUR ('⚡️ Bolt app is running!');
})(); })();

View file

@ -1,47 +1,45 @@
#!/usr/bin/env node #!/usr/bin/env node
const glob = require('glob'),
fs = require('fs'),
path = require('path'),
prettier = require('prettier'),
keywords = JSON.parse(fs.readFileSync('./keywords.json'));
const glob = require('glob') const getFiles = async () => new Promise((resolve, reject) =>
const fs = require('fs') glob(process.cwd() + '/**/*.ws', { ignore: process.cwd() + '/node_modules/**'}, (err, matches) => err && reject(err) || matches && resolve(matches)));
const path = require('path')
const mkdirp = require('mkdirp')
const prettier = require('prettier')
// options is optional const getContent = (path) => new Promise((resolve, reject) =>
const getFiles = (currentPath) => { fs.readFile(path, (err, data) => err && reject(err) || data && resolve(data)));
const files = glob.sync(currentPath + "/**/*.ws")
return files.filter(file => file.indexOf('node_modules/') < 0)
}
const compile = (content) => { const transform = async (file) => ({
const keywords = JSON.parse(fs.readFileSync(path.join(__dirname, 'keywords.json'), 'utf8')) path: path.join(process.cwd(), 'dist', file.replace(process.cwd(), '').replace(/\.ws$/, '.js')),
for (const key in keywords) { file: file.replace(process.cwd(), ''),
content = content.replace(new RegExp(key, "g"), keywords[key]); content: String(await getContent(file))
} });
return content
}
const run = () => { const transpile = (file) => {
console.log('HAWIDERE') Object.entries(keywords).map(([key, value]) => (file = {
const currentPath = process.cwd() ...file,
const files = getFiles(currentPath) content: file.content.replace(new RegExp(key, 'g'), value)
}));
return file;
};
console.log('DO HOBN MA ' + files.length + ' GSCHICHTLN') const saveFile = (file) => new Promise((resolve, reject) => {
fs.mkdir(file.path.substring(0, file.path.lastIndexOf(path.sep)), { recursive: true }, (err) => {
if (err) return reject(err);
console.info(`[WienerScript] DRAH DI DEPPATA ${file.file} ==> ${file.path.replace(process.cwd(), '')}`);
fs.writeFile(file.path, prettier.format(file.content, { parser: 'babel' }), (err, data) => err && reject(err) || data && resolve(data));
});
});
files.forEach(file => { (async () => {
file = path.normalize(file) try {
const content = fs.readFileSync(path.normalize(file), 'utf8') const files = (await getFiles()).map(path.normalize);
const dir = path.join(currentPath, 'dist') console.info(`[WienerScript] HAWIDERE! DO HOBN MA ${files.length} GSCHICHTLN!`);
if (!fs.existsSync(dir)) fs.mkdirSync(dir) (await Promise.all(files.map(transform))).map(transpile).map(saveFile);
} catch(err) {
const dirs = file.substring(0, file.lastIndexOf(path.sep)).replace(currentPath, '') console.error('[WienerScript] DO IS WOS SCHIEF GRENNT:');
mkdirp.sync(path.join(currentPath, 'dist', dirs)) throw err;
}
const filePath = path.join(currentPath, 'dist', file.replace(currentPath, '').replace('.ws', '.js')) })();
console.log('DRAH DI DEPATTA', file.replace(currentPath, '').replace(path.sep, '') + ' ==> ' + filePath.replace(currentPath, '').replace(path.sep, ''))
fs.writeFileSync(filePath, prettier.format(compile(content), { parser: 'babel' }), (error) => console.error(error))
})
console.log('PFIATI')
}
run()

View file

@ -1,6 +1,6 @@
{ {
"name": "wienerscript", "name": "wienerscript",
"version": "1.0.2", "version": "1.1.0",
"description": "WienerScript adds syntactic WIENERISCH to JavaScript that makes it less forgiving, more emotional, and even painful to write, allowing you to do less with more code.", "description": "WienerScript adds syntactic WIENERISCH to JavaScript that makes it less forgiving, more emotional, and even painful to write, allowing you to do less with more code.",
"main": "./index.js", "main": "./index.js",
"bin": { "bin": {
@ -19,7 +19,6 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"glob": "^7.1.6", "glob": "^7.1.6",
"mkdirp": "^1.0.4",
"prettier": "^2.0.5" "prettier": "^2.0.5"
} }
} }