This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let envFilePlugin = { | |
name: 'env', | |
setup(build) { | |
function _findEnvFile(dir) { | |
if (!fs.existsSync(dir)) | |
return false; | |
let filePath = `${dir}/.env`; | |
if ((fs.existsSync(filePath))) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ENV } from 'env'; | |
import fs from 'fs'; | |
import path from 'path'; | |
let prefix = './config/'; | |
let configFile = 'config.local.json'; | |
if (ENV == 'production') { | |
configFile = 'config.prod.json'; | |
} else if (ENV == 'development') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// trigger upload dialog: | |
this.importFile.current.click(); | |
onFileImportChange = (e) => { | |
try { | |
const reader = new FileReader(); | |
reader.addEventListener('load', () => { | |
let data = JSON.parse(reader.result); | |
this.setState(data); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mkdirSync = function(dir) { | |
if (fs.existsSync(dir)) { | |
return; | |
} | |
try { | |
fs.mkdirSync(dir); | |
} catch(err){ | |
if(err.code == 'ENOENT'){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { getRedisClient } = require('./redis/redis') | |
redis = getRedisClient() | |
const EXPIRE_DEFAULT = 60*60; // seconds = 1hr | |
// App-wide cache. Just a wrapper for redis. | |
class Cache { | |
async get(id) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Response { | |
static success(res, data) { | |
const r = { | |
success: true | |
} | |
if (data) { | |
r.data = data | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bs = require('browser-sync').create(); | |
const url = require('url'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const PORT = 3300 | |
const OUTPUT_DIR = './build' | |
const DEFAULT_FILE = "index.html" | |
bs.watch(`${OUTPUT_DIR}/**/*.js`, function (event, file) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client: | |
onImagesAdded = (e) => { | |
try { | |
console.log('added', e) | |
Array.from(e.target.files).forEach(async (f: any) => { | |
let sUrl = await S3Service.getSignedUrl(f.name, f.type); | |
console.log('got signed url', sUrl) | |
let r = await this.sendFile(f, sUrl); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import LocalStorage from 'lib/utils/LocalStorage'; | |
export default class Store { | |
id: string; | |
items: any; | |
autoSave = true; | |
constructor(storeId, items = {}, autoSave = true) { | |
this.id = storeId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Usage: | |
// init: | |
this.db = new IDB(); | |
this.db.open(DBNAME); | |
this.db.addStore(DBNAME, { autoIncrement: true }, [ | |
{ name: 'id', key: 'id', params: { unique: true } }, | |
{ name: 'word, language', key: [ 'word', 'language' ], params: { unique: true } }, | |
]); |