Skip to content

Commit

Permalink
added more shell content
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Nov 2, 2017
1 parent 5e8b30b commit 764f366
Show file tree
Hide file tree
Showing 202 changed files with 17,952 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
*~
dist/build
dist/plugins
*.log
node_modules
wskng.iml
app/.version
app/content/**/*.js.map
app/plugins/.pre-scanned
62 changes: 62 additions & 0 deletions .travis.yml
@@ -0,0 +1,62 @@
language: node_js
dist: trusty
sudo: false
node_js: 6
services:
- docker
addons:
apt:
sources:
- google-chrome
packages:
- dbus
- dbus-x11
- xvfb
- google-chrome-stable
- libnotify-cil-dev

install:
- Xvfb :99 -screen 0 1400x1050x24 > /dev/null 2>&1 &

env:
global:
- DISPLAY=":99.0"
- KEY_FROM_LAYER=true
- DO_NOT_SET_WSKPROPS=true
- WINDOW_WIDTH=1400
- WINDOW_HEIGHT=1050
- NO_DEBUGGER_BREAKPOINTS=true
- NO_NOTIFICATIONS=true
- NO_FIRST_TIMER=true
- UV_THREADPOOL_SIZE=64

script: echo "Running Tests!"

jobs:
include:
- stage: init
script: (./tools/travis/setup.sh;./tools/travis/build.sh)
- script: (cd app && npm install)
- script: (cd tests && npm install)
- script: (cd dist && npm install)

- stage: compile
script: (cd dist && ./compile.js)

- stage: test
script: (cd tests && npm run test)
env: LAYER=01
- script: (cd tests && npm run test)
env: LAYER=02
- script: (cd tests && npm run test)
env: LAYER=03
- script: (cd tests && npm run test)
env: LAYER=04
- script: (cd tests && npm run test)
env: LAYER=05
- script: (cd tests && npm run test)
env: LAYER=06
- script: (cd tests && npm run test)
env: LAYER=07
- script: (cd tests && npm run test)
env: LAYER=08
Binary file added assets/icons/icns/OpenWhisk-512x512.icns
Binary file not shown.
1 change: 1 addition & 0 deletions assets/icons/icns/README.md
@@ -0,0 +1 @@
Icons for MacOS
Binary file added assets/icons/icns/blue-dolphin-transparent.icns
Binary file not shown.
1 change: 1 addition & 0 deletions assets/icons/ico/README.md
@@ -0,0 +1 @@
Icons for Windows
Binary file added assets/icons/ico/blue-dolphin-transparent.ico
Binary file not shown.
Binary file added assets/icons/ico/favicon.ico
Binary file not shown.
Binary file added assets/icons/ico/openwhisk_512x512_jnb_icon.ico
Binary file not shown.
Binary file added assets/icons/png/OpenWhisk-512x512.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/activity-grid-icon-50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/activity-grid-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/activity-timeline-icon-50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/activity-timeline-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/blue-dolphin-transparent.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/cli-icon-50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/icon@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
155 changes: 155 additions & 0 deletions dist/build.sh
@@ -0,0 +1,155 @@
#!/usr/bin/env bash

PLATFORM=${1-all}
VERSION=`git rev-parse master`
BUILDDIR=build
APP_NAME="IBM Cloud Functions Shell"

# openwhisk icons
#ICON_MAC=../assets/icons/icns/OpenWhisk-512x512.icns
#ICON_WIN32=../assets/icons/ico/openwhisk_512x512_jnb_icon.ico

# dolphin icons
ICON_MAC=../assets/icons/icns/blue-dolphin-transparent.icns
ICON_WIN32=../assets/icons/ico/blue-dolphin-transparent.ico
ICON_LINUX=../assets/icons/png/blue-dolphin-transparent.png

function init {
# make the build directory
if [ ! -d $BUILDDIR ]; then
mkdir $BUILDDIR
if [ $? != 0 ]; then
exit 1
fi
fi

if [ ! -d node_modules ]; then
npm install
fi

# assemble plugins
UGLIFY=true ./compile.js

# minify the css
cp ../app/content/css/ui.css /tmp
./node_modules/.bin/minify /tmp/ui.css
cp /tmp/ui.min.css ../app/content/css/ui.css

VERSION=`cat ../app/package.json | jq --raw-output .version`
echo "$VERSION" > ../app/.version
}

function cleanup {
# rm ../app/plugins/.pre-scanned
rm ../app/.version

cp /tmp/ui.css ../app/content/css/ui.css

UGLIFY=true ./compile.js cleanup
}

function win32 {
if [ "$PLATFORM" == "all" ] || [ "$PLATFORM" == "win32" ] || [ "$PLATFORM" == "windows" ]; then
# create the bundles
./node_modules/.bin/electron-packager \
../app \
"$APP_NAME" \
--asar=true \
--build-version=$VERSION \
--out=$BUILDDIR \
--platform=win32 \
--icon=$ICON_WIN32 \
--protocol=wsk --protocol-name="Execute ${APP_NAME} commands" \
--overwrite \
--win32metadata.CompanyName="Apache" \
--win32metadata.ProductName="${APP_NAME}"

# CLI scripts
cp ../app/bin/fsh "$BUILDDIR/${APP_NAME}-win32-x64/fsh"
cp ../app/bin/fsh.bat "$BUILDDIR/${APP_NAME}-win32-x64"

#
# deal with win32 packaging
#
if [ -z "$NO_INSTALLER" ]; then
(cd $BUILDDIR && zip -q -r "${APP_NAME}-win32-x64" "${APP_NAME}-win32-x64" -x \*~)
fi
fi
}


#
# deal with darwin/macOS packaging
#
function mac {
if [ "$PLATFORM" == "all" ] || [ "$PLATFORM" == "mac" ] || [ "$PLATFORM" == "macos" ] || [ "$PLATFORM" == "darwin" ]; then
./node_modules/.bin/electron-packager \
../app \
"${APP_NAME}" \
--asar=true \
--build-version=$VERSION \
--ignore='~$' \
--out=$BUILDDIR \
--platform=darwin \
--icon=$ICON_MAC \
--protocol=wsk --protocol-name="Execute ${APP_NAME} commands" \
--overwrite

# use a custom icon for mac
cp $ICON_MAC "$BUILDDIR/${APP_NAME}-darwin-x64/${APP_NAME}.app/Contents/Resources/electron.icns"

# CLI script
cp ../app/bin/fsh "$BUILDDIR/${APP_NAME}-darwin-x64/${APP_NAME}.app/Contents/MacOS/"

# create the installers
if [ -n "$ZIP_INSTALLER" ]; then
(cd $BUILDDIR && zip -q -r "${APP_NAME}-darwin-x64" "${APP_NAME}-darwin-x64" -x \*~)

elif [ -z "$NO_INSTALLER" ]; then
./node_modules/.bin/electron-installer-dmg \
"$BUILDDIR/${APP_NAME}-darwin-x64/${APP_NAME}.app" \
"${APP_NAME}" \
--out=$BUILDDIR \
--icon=$ICON_MAC \
--icon-size=128 \
--overwrite
fi
fi
}

#
# deal with linux packaging
#
function linux {
if [ "$PLATFORM" == "all" ] || [ "$PLATFORM" == "linux" ]; then
./node_modules/.bin/electron-packager \
../app \
"${APP_NAME}" \
--asar=true \
--build-version=$VERSION \
--out=$BUILDDIR \
--platform=linux \
--protocol=wsk --protocol-name="Execute ${APP_NAME} commands" \
--icon=$ICON_LINUX \
--overwrite

# CLI script
cp ../app/bin/fsh "$BUILDDIR/${APP_NAME}-linux-x64"

if [ -z "$NO_INSTALLER" ]; then
(cd $BUILDDIR && zip -q -r "${APP_NAME}-linux-x64" "${APP_NAME}-linux-x64" -x \*~)
fi
fi
}


# line up the work
init
win32
mac
linux
cleanup

# TODO:
# upload to OS
# (cd ../prebuilt && npm version publish)
98 changes: 98 additions & 0 deletions dist/compile.js
@@ -0,0 +1,98 @@
#!/usr/bin/env node

const fs = require('fs-extra'),
path = require('path'),
events = require('events'),
mkdirp = require('mkdirp-promise'),
{ exec } = require('child_process'),
TMP = 'plugins' // we'll stash the original plugins here

global.plugins = require(path.join(__dirname, '../app/content/js/plugins'))
global.localStorage = { getItem: () => '{}' }
global.eventBus = new events.EventEmitter()
global.ui = {
startsWithVowel: () => false
}

/**
* Write the plugin list to the .pre-scanned file in app/plugins/.pre-scanned
*
*/
const writeToFile = modules => new Promise((resolve, reject) => {
fs.writeFile(path.join(__dirname, '..', 'app', 'plugins', '.pre-scanned'),
JSON.stringify(modules, undefined, 4),
err => {
if (err) reject(err)
else resolve()
})
})

/**
* Uglify the javascript
*
*/
const uglify = modules => modules.flat.map(module => new Promise((resolve, reject) => {
if (!process.env.UGLIFY) resolve()

const src = path.join(__dirname, '..', 'app', 'plugins', module.path),
target = src, // we'll copy it aside, and overwrite the original
tmpPath = path.join(TMP, module.path),
tmpDir = path.join(tmpPath, '..') // we want the name of the enclosing directory

//console.log(`uglifying ${module.route} ${src}`)

mkdirp(tmpDir)
.then(() => fs.copy(src, tmpPath).then(() => tmpPath))
.then(() => {
exec(`${path.join(__dirname, 'node_modules', '.bin', 'uglifyjs')} --compress --mangle -o "${target}" -- "${tmpPath}"`,
(err, stdout, stderr) => {
if (err) reject(err)
else resolve()
})
})
.catch(reject)
}))

/**
* Generic filesystem scanning routine
* Note that, when scanning for plugins, we ignore subdirectories named "helpers"
*
*/
const readDirRecursively = dir => path.basename(dir) !== 'helpers' && path.basename(dir) !== 'node_modules' && fs.statSync(dir).isDirectory()
? Array.prototype.concat(...fs.readdirSync(dir).map(f => readDirRecursively(path.join(dir, f))))
: dir

/**
* assemble the list of plugins, then minify the plugins, if we can,
* and write the list to the .pre-scanned file
*
*/
if (process.argv[2] === 'cleanup') {
// copy the TMP originals back in place
Promise.all(require('../app/content/js/plugins.js').scanForPlugins(TMP)
.map(pluginJsFile => {
const pluginRoot = path.join(__dirname, '..', 'app'),
originalLocation = path.join(pluginRoot, pluginJsFile)
return fs.copy(pluginJsFile, originalLocation)
}))
.then(() => process.exit(0))
.catch(err => {
console.error(err)
process.exit(1)
})

} else {
plugins.assemble()
.then(modules => Object.assign(modules, {
flat: modules.flat.map(module => Object.assign(module, {
// make the paths relative to the root directory
path: path.relative(path.join(__dirname, '..', 'app', 'plugins'), module.path)
}))
}))
.then(modules => Promise.all([writeToFile(modules), ...uglify(modules)]))
.then(() => process.exit(0))
.catch(err => {
console.error(err)
process.exit(1)
})
}

0 comments on commit 764f366

Please sign in to comment.