Skip to content

Commit

Permalink
Get rid of babel-contracts, closes #770. Also, a bit of #773.
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jul 4, 2016
1 parent 34a6a1b commit c83bf14
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 206 deletions.
7 changes: 0 additions & 7 deletions .babelrc
Expand Up @@ -8,13 +8,6 @@
["transform-async-to-module-method", {
"module": "bluebird",
"method": "coroutine"
}],
["contracts", {
"env": {
"production": {
"strip": true
}
}
}]
],
"presets": [
Expand Down
10 changes: 5 additions & 5 deletions appsrc/components/interleave.js
@@ -1,4 +1,6 @@

import invariant from 'invariant'

const keyMirror = require('keymirror')
const State = keyMirror({
NORMAL: null,
Expand All @@ -7,11 +9,9 @@ const State = keyMirror({
})

function interleave (t, key, components, text_vars) {
pre: { // eslint-disable-line
typeof t === 'function'
typeof key === 'string'
typeof components === 'object'
}
invariant(typeof t === 'function', 'interleave has localizer instance')
invariant(typeof key === 'string', 'interleave has string key')
invariant(typeof components === 'object', 'interleave has object components')

if (typeof text_vars === 'undefined') {
text_vars = {}
Expand Down
3 changes: 3 additions & 0 deletions appsrc/reactors/index.js
Expand Up @@ -31,6 +31,7 @@ import tasks from './tasks'
import dialogs from './dialogs'
import report from './report'
import perf from './perf'
import packagingPolicy from './packaging-policy'

export default validateReactors({
_ALL: combine(i18n, session.catchAll, tray.catchAll, menu.catchAll,
Expand Down Expand Up @@ -142,6 +143,8 @@ export default validateReactors({
SELF_UPDATE_ERROR: combine(selfUpdate.selfUpdateError),
SHOW_AVAILABLE_SELF_UPDATE: combine(selfUpdate.showAvailableSelfUpdate),

SHOW_PACKAGING_POLICY: combine(packagingPolicy.showPackagingPolicy),

CLOSE_TAB_OR_AUX_WINDOW: combine(mainWindow.closeTabOrAuxWindow),
QUIT_WHEN_MAIN: combine(mainWindow.quitWhenMain),
QUIT_ELECTRON_APP: combine(mainWindow.quitElectronApp),
Expand Down
53 changes: 53 additions & 0 deletions appsrc/reactors/packaging-policy.js
@@ -0,0 +1,53 @@

import invariant from 'invariant'

import urls from '../constants/urls'

import {getUserMarket} from './market'
import fetch from '../util/fetch'

import localizer from '../localizer'
import {shell, dialog} from '../electron'

async function showPackagingPolicy (store, action) {
const {format, gameId} = action.payload
invariant(typeof format === 'string', 'showPackagingPolicy has string format')
invariant(typeof gameId === 'number', 'showPackagingPolicy has game id')

const i18n = store.getState().i18n
const t = localizer.getT(i18n.strings, i18n.lang)

const credentials = store.getState().session.credentials
const market = getUserMarket()

const game = await fetch.gameLazily(market, credentials, gameId)
if (!game) {
throw new Error(`unknown game id ${gameId}, can't show policy`)
}

const buttons = [
t('prompt.action.ok'),
t('prompt.packaging_policy.learn_more'),
t('prompt.packaging_policy.open_web_page', {title: game.title})
]

const dialogOpts = {
type: 'error',
buttons,
title: t(`prompt.${format}_policy.title`),
message: t(`prompt.${format}_policy.message`, {title: game.title}),
detail: t(`prompt.${format}_policy.detail`)
}

const callback = (response) => {
// not much to do anyway.
if (response === 1) {
shell.openExternal(urls[`${format}Policy`])
} else if (response === 2) {
shell.openExternal(game.url)
}
}
dialog.showMessageBox(dialogOpts, callback)
}

export default {showPackagingPolicy}
58 changes: 0 additions & 58 deletions appsrc/stores/policy-store.js

This file was deleted.

8 changes: 4 additions & 4 deletions appsrc/tasks/configure/html.js
@@ -1,4 +1,6 @@

import invariant from 'invariant'

import path from 'path'
import clone from 'clone'

Expand Down Expand Up @@ -34,10 +36,8 @@ const self = {
},

configure: async function (game, cavePath) {
pre: { // eslint-disable-line
typeof game === 'object'
typeof cavePath === 'string'
}
invariant(typeof game === 'object', 'html configure needs object game')
invariant(typeof cavePath === 'string', 'html configure needs string cavePath')

const gamePath = await self.getGamePath(cavePath)

Expand Down
20 changes: 9 additions & 11 deletions appsrc/tasks/install/core.js
@@ -1,4 +1,6 @@

import invariant from 'invariant'

import fnout from 'fnout'
import spawn from '../../util/spawn'
import mklog from '../../util/log'
Expand Down Expand Up @@ -50,19 +52,15 @@ const self = {
},

cacheType: function (opts, installerName) {
pre: { // eslint-disable-line
typeof opts === 'object'
typeof opts.globalMarket === 'object'
typeof opts.upload === 'object'
typeof opts.upload.id === 'number'
typeof installerName === 'string'
}

const {globalMarket, cave} = opts
const {globalMarket, cave, upload} = opts
if (!cave) return

invariant(typeof installerName === 'string', 'cacheType needs string installerName')
invariant(typeof upload === 'object', 'cacheType needs object upload')
invariant(typeof upload.id === 'number', 'cacheType needs int upload.id')

const installerCache = {}
installerCache[opts.uploadId] = installerName
installerCache[upload.id] = installerName
globalMarket.saveEntity('caves', cave.id, {installerCache})
},

Expand Down Expand Up @@ -91,7 +89,7 @@ const self = {
sniffType: async function (opts) {
const {archivePath} = opts
if (!archivePath) {
log(opts, 'no archive available, can\'t sniff type, going with "archive" uninstaller')
log(opts, 'no archive available, unable to sniff type, going with "archive" uninstaller')
return 'archive'
}

Expand Down
40 changes: 17 additions & 23 deletions appsrc/util/butler.js
@@ -1,4 +1,6 @@

import invariant from 'invariant'

import path from 'path'
import {partial} from 'underline'

Expand Down Expand Up @@ -33,11 +35,9 @@ const self = {

/* Downloads file at ${url} to ${dest} */
dl: async function (opts) {
pre: { // eslint-disable-line
typeof opts === 'object'
typeof opts.url === 'string'
typeof opts.dest === 'string'
}
invariant(typeof opts === 'object', 'opts is object')
invariant(typeof opts.url === 'string', 'opts.url is string')
invariant(typeof opts.dest === 'string', 'opts.dest is string')

let {emitter, url, dest} = opts
let err = null
Expand All @@ -58,12 +58,10 @@ const self = {

/* Apply a wharf patch at ${patchPath} in-place into ${outPath}, while checking with ${signaturePath} */
apply: async function (opts) {
pre: { // eslint-disable-line
typeof opts === 'object'
typeof opts.patchPath === 'string'
typeof opts.outPath === 'string'
typeof opts.signaturePath === 'string'
}
invariant(typeof opts === 'object', 'opts is object')
invariant(typeof opts.patchPath === 'string', 'opts.patchPath is string')
invariant(typeof opts.outPath === 'string', 'opts.outPath is string')
invariant(typeof opts.signaturePath === 'string', 'opts.signaturePath is string')

let {emitter, patchPath, outPath, signaturePath} = opts
let err = null
Expand All @@ -83,11 +81,9 @@ const self = {

/* Extracts tar archive ${archivePath} into directory ${destPath} */
untar: async function (opts) {
pre: { // eslint-disable-line
typeof opts === 'object'
typeof opts.archivePath === 'string'
typeof opts.destPath === 'string'
}
invariant(typeof opts === 'object', 'opts is object')
invariant(typeof opts.archivePath === 'string', 'opts.archivePath is string')
invariant(typeof opts.outPath === 'string', 'opts.outPath is string')

let {emitter, archivePath, destPath} = opts
let err = null
Expand All @@ -107,6 +103,8 @@ const self = {

/* rm -rf ${path} */
wipe: async function (path, opts = {}) {
invariant(typeof path === 'string', 'wipe has string path')

let err = null
let onerror = (e) => { err = e }

Expand All @@ -123,9 +121,7 @@ const self = {

/* mkdir -p ${path} */
mkdir: async function (path, opts = {}) {
pre: { // eslint-disable-line
typeof path === 'string'
}
invariant(typeof path === 'string', 'mkdir has string path')

let err = null
let onerror = (e) => { err = e }
Expand All @@ -143,10 +139,8 @@ const self = {

/* rsync -a ${src} ${dst} */
ditto: async function (src, dst, opts = {}) {
pre: { // eslint-disable-line
typeof src === 'string'
typeof dst === 'string'
}
invariant(typeof src === 'string', 'ditto has string src')
invariant(typeof dst === 'string', 'ditto has string dst')
let err = null
let onerror = (e) => { err = e }
let emitter = opts.emitter
Expand Down
7 changes: 3 additions & 4 deletions appsrc/util/cooldown.js
@@ -1,11 +1,10 @@

import invariant from 'invariant'
import Promise from 'bluebird'

let self = function (msBetweenRequests) {
pre: { // eslint-disable-line
typeof msBetweenRequests === 'number'
msBetweenRequests > 0
}
invariant(typeof msBetweenRequests === 'number', 'cooldown has number msBetweenRequests')
invariant(msBetweenRequests > 0, 'cooldown has positive msBetweenRequests')
let lastRequest = 0

return function cooldown () {
Expand Down
11 changes: 5 additions & 6 deletions appsrc/util/deploy.js
@@ -1,4 +1,6 @@

import invariant from 'invariant'

import {difference} from 'underline'
import bluebird from 'bluebird'

Expand All @@ -23,13 +25,10 @@ let self = {
* (that receipt will be used on next deploy)
*/
deploy: async (opts) => {
pre: { // eslint-disable-line
typeof opts === 'object'
typeof opts.stagePath === 'string'
typeof opts.destPath === 'string'
}

const {stagePath, destPath, onProgress = noop, onSingle = pnoop} = opts
invariant(typeof stagePath === 'string', 'deploy needs string stagePath')
invariant(typeof destPath === 'string', 'deploy needs string destPath')

const stageFiles = await sf.glob('**', {cwd: stagePath, dot: true, nodir: true, ignore: sf.globIgnore})

if (stageFiles.length === 1) {
Expand Down
11 changes: 4 additions & 7 deletions appsrc/util/extract.js
@@ -1,6 +1,7 @@

import {object} from 'underline'

import invariant from 'invariant'
import humanize from 'humanize-plus'
import path from 'path'
import fnout from 'fnout'
Expand Down Expand Up @@ -117,13 +118,9 @@ const self = {
},

extract: async (opts) => {
pre: { // eslint-disable-line
typeof opts === 'object'
typeof opts.archivePath === 'string'
typeof opts.destPath === 'string'
}

let archivePath = opts.archivePath
const {archivePath, destPath} = opts
invariant(typeof archivePath === 'string', 'extract needs string archivePath')
invariant(typeof destPath === 'string', 'extract needs string destPath')

let type = await fnout.path(archivePath)
if (type.ext === 'tar') {
Expand Down

0 comments on commit c83bf14

Please sign in to comment.