Skip to content

Commit

Permalink
Basic go version
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jan 27, 2018
1 parent b5b8646 commit ea90b9c
Show file tree
Hide file tree
Showing 37 changed files with 2,114 additions and 93 deletions.
6 changes: 6 additions & 0 deletions .autoenv.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

test -f alfredenv.sh && {
source alfredenv.sh
} || {
echo ./alfredenv.sh not found >&2
}
11 changes: 11 additions & 0 deletions .autoenv_leave.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

unset alfred_workflow_bundleid
unset alfred_workflow_version
unset alfred_workflow_name
unset alfred_workflow_data
unset alfred_workflow_cache

unset INTERVAL_FIND
unset INTERVAL_MDFIND
unset INTERVAL_LOCATE

100 changes: 9 additions & 91 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,98 +1,16 @@

# Created by https://www.gitignore.io/api/python,sublimetext,vim

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
*.dist-info/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache
# build and dist directories
/build
/dist

# Scrapy stuff:
.scrapy
# compiled binary
/alfsubl

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
# vendor stuff
/vendor
Gopkg.lock

# Created by https://www.gitignore.io/api/python,sublimetext,vim

### SublimeText ###
# cache files for sublime text
Expand Down
43 changes: 43 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/BurntSushi/toml"
version = "0.3.0"

[[constraint]]
name = "github.com/deanishe/awgo"
version = "0.13.2"

[[constraint]]
name = "github.com/docopt/docopt.go"
# version = "0.6.2"
revision = "ee0de3bc6815ee19d4a46c7eb90f829db0e014b1"

[[constraint]]
name = "github.com/gobwas/glob"
version = "0.2.2"

# [[override]]
# name = "github.com/docopt/docopt-go"
# revision = "ee0de3bc6815ee19d4a46c7eb90f829db0e014b1"
2 changes: 1 addition & 1 deletion LICENCE → LICENCE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Dean Jackson <[email protected]>
Copyright (c) 2014–2018 Dean Jackson <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 24 additions & 0 deletions alfredenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# When sourced, creates an Alfred-like environment needed by modd
# and ./bin/build (which sources the file itself)

# getvar <name> | Read a value from info.plist
getvar() {
local v="$1"
/usr/libexec/PlistBuddy -c "Print :$v" info.plist
}

# stuff in info.plist
export alfred_workflow_bundleid=$( getvar "bundleid" )
export alfred_workflow_version=$( getvar "version" )
export alfred_workflow_name=$( getvar "name" )

export INTERVAL_FIND=$( getvar "variables:INTERVAL_FIND" )
export INTERVAL_MDFIND=$( getvar "variables:INTERVAL_MDFIND" )
export INTERVAL_LOCATE=$( getvar "variables:INTERVAL_LOCATE" )

# workflow data and cache directories
export alfred_workflow_data="${HOME}/Library/Application Support/Alfred 3/Workflow Data/${alfred_workflow_bundleid}"
export alfred_workflow_cache="${HOME}/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Data/${alfred_workflow_bundleid}"

177 changes: 177 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#!/usr/bin/env zsh

# Path to this script's directory (i.e. workflow root)
here="$( cd "$( dirname "$0" )"; pwd )"
root="$( cd "$here/../"; pwd )"
builddir="${root}/build"
distdir="${root}/dist"

source "${root}/alfredenv.sh"

verbose=false
devmode=true
runtests=false
force=false

# log <arg>... | Echo arguments to STDERR
log() {
echo "$@" >&2
}

# info <arg>.. | Write args to STDERR if VERBOSE is true
info() {
$verbose && log $(print -P "%F{blue}.. %f") "$@"
return 0
}

# success <arg>.. | Write green "ok" and args to STDERR if VERBOSE is true
success() {
$verbose && log $(print -P "%F{green}ok %f") "$@"
return 0
}

# error <arg>.. | Write red "error" and args to STDERR
error() {
log $(print -P '%F{red}err%f') "$@"
}

# fail <arg>.. | Write red "error" and args to STDERR, then exit with status 1
fail() {
error "$@"
exit 1
}

# cleanup | Delete build files
cleanup() {
info "cleaning up ..."
test -d "$builddir" && rm -rf $verbose "${builddir}/"*
}

# usage | Show usage message
usage() {
cat <<EOS
build [-h] [-d] [-t] [-f] [-v]
Build workflow in ./build directory from source code.
Use -d to also build an .alfredworkflow file in ./dist.
Usage:
build [-d] [-t] [-f] [-v]
build -h
Options:
-d Distribution. Also build .alfredworkflow file.
-f Force. Overwrite existing files.
-t Also run unit tests.
-h Show this message and exit.
-v Verbose.
EOS
}

# -------------------------------------------------------
# CLI options
while getopts ":dfhtv" opt; do
case $opt in
d)
devmode=false
;;
f)
force=true
;;
h)
usage
exit 0
;;
t)
runtests=true
;;
v)
verbose=true
;;
\?)
log "Invalid option: -$OPTARG"
exit 1
;;
esac
done
shift $((OPTIND-1))

test -z "$root" && fatal "couldn't find workflow directory"

$verbose && v=-v

pushd "$root" &> /dev/null
# -------------------------------------------------------
# Run unit tests
$runtests && {
info "running unit tests ..."
go test $v . || exit 1
success "unit tests"
}

# -------------------------------------------------------
# Build
test -d "${builddir}" && {
info "cleaning build directory ..."
cleanup
success "cleaned build"
}

info "building executable(s) ..."

go build $v -o ./alfsubl .

# $devmode && { sym="-s" }

info "linking assets to build directory ..."
# mkdir -vp "$builddir"
# mkdir -p $v "${builddir}/scripts/"{tab,url}
mkdir -p $v "${builddir}/icons"

pushd "$builddir" &> /dev/null

ln $v ../*.html .
ln $v ../info.plist .
ln $v ../icons/icon.png .
ln $v ../alfsubl .
ln $v ../README.md .
ln $v ../LICENCE.txt .
ln $v ../icons/*.png ./icons/
# ln $v scripts/tab/* "${builddir}/scripts/tab/"
# ln $v scripts/url/* "${builddir}/scripts/url/"
popd &> /dev/null

# -------------------------------------------------------
# Build .alfredworkflow file
$devmode || {
test -f "${outpath}" && {
$force && {
rm $v "${outpath}"
} || {
fatal "destination file already exists (use --force to overwrite)"
}
}

test -d "$distdir" || mkdir -p "$distdir"

info "building .alfredworkflow file ..."

zipname="Google-Calendar-View-${alfred_workflow_version}.alfredworkflow"
outpath="${distdir}/${zipname}"

pushd "$builddir" &> /dev/null

zip -9 -r "${outpath}" ./*
ST_ZIP=$?
test "$ST_ZIP" -ne 0 && {
error "zip failed (${ST_ZIP}) while creating .alfredworkflow file."
popd &> /dev/null
popd &> /dev/null
exit $ST_ZIP
}

popd &> /dev/null
success "wrote '${zipname}' file in '${distdir}'"
}

popd &> /dev/null
Loading

0 comments on commit ea90b9c

Please sign in to comment.