Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #16 from brown-ccv/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
fernandogelin authored Jul 20, 2020
2 parents d0fde20 + ecd84fb commit 85a4e24
Show file tree
Hide file tree
Showing 9 changed files with 14,403 additions and 8,074 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build_at_home.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- 'src/**'
- '.github/workflows/main.yml'
- 'public/**'

jobs:
build:
Expand All @@ -26,12 +27,11 @@ jobs:
# install, test, build package
- name: npm install
run: npm install
- name: get git revision and branch
run: node version.js
- name: npm build
run: npm run build:win:home
- name: npm test
run: npm test
env:
CI: true
REACT_APP_AT_HOME: true

# Build electron app package installers
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
paths:
- 'src/**'
- '.github/workflows/main.yml'
- 'public/**'

jobs:
build:
Expand Down Expand Up @@ -32,10 +33,7 @@ jobs:
run: npm install
- name: npm build
run: npm run build
- name: npm test
run: npm test
env:
CI: true


# Build electron app package installers
- name: package electron - windows
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ yarn-debug.log*
yarn-error.log*

psiturkit/*_turk

public/config/version.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ This file contains all of the code relating to the electron app. This includes t

The `config` directory contains the config files needed for the electron app. This includes the event-marker details and event codes.

Note: the productId can be overwritten by the environment variable EVENT_MARKER_PRODUCT_ID
Note: the `comName` can be overwritten by the environment variable COMNAME.

### `src/`

Expand Down
22,402 changes: 14,352 additions & 8,050 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "[email protected]",
"url": "ccv.brown.edu"
},
"version": "1.1.0",
"version": "1.2.1",
"license": "MIT",
"private": true,
"main": "public/electron.js",
Expand All @@ -18,7 +18,8 @@
"cross-env": "^6.0.3",
"electron-log": "^3.0.9",
"electron-squirrel-startup": "^1.0.0",
"event-marker": "git+https://github.com/brown-ccv/event-marker.git#bump-version",
"event-marker": "git+https://github.com/brown-ccv/event-marker.git",
"execa": "^4.0.3",
"fs-extra": "^9.0.0",
"jquery": "^3.4.1",
"jspsych-react": "^0.2.2",
Expand Down Expand Up @@ -80,7 +81,8 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-standard": "^4.0.1",
"require-context.macro": "^1.1.1"
"require-context.macro": "^1.1.1",
"semantic-release": "^17.1.1"
},
"babel": {
"plugin": [
Expand Down
8 changes: 2 additions & 6 deletions public/config/trigger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Event trigger settings - used in both the react app (renderer) and the electron app (main)
const manufacturer = 'Teensyduino'
const vendorId = '16c0'
const productId = '0487'
const comName = 'COM3'

// Values to send to the 'USB event marker' arduino when an event happens.
// Make sure the 'open_resting_task' value doesn't conflict with any value sent
Expand Down Expand Up @@ -33,8 +31,6 @@ const eventCodes = {

// this is module.exports isntead of just exports as it is also imported into the electron app
module.exports = {
manufacturer,
vendorId,
productId,
comName,
eventCodes
}
17 changes: 10 additions & 7 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const log = require('electron-log');

const AT_HOME = (process.env.REACT_APP_AT_HOME === 'true')
// Event Trigger
const { eventCodes, manufacturer, vendorId, productId } = require('./config/trigger')
const { eventCodes, comName } = require('./config/trigger')

// Override product ID if environment variable set
const activeProductId = process.env.EVENT_MARKER_PRODUCT_ID || productId
log.info("Active product ID", activeProductId)
// Override comName if environment variable set
const activeComName = process.env.COMNAME || comName
log.info("Active comName", activeComName)

const { isPort, getPort, sendToPort } = require('event-marker')
const { getPort, sendToPort } = require('event-marker')
log.info(AT_HOME)

// Data Saving
Expand Down Expand Up @@ -83,7 +83,7 @@ let portAvailable
let SKIP_SENDING_DEV = false

const setUpPort = async () => {
p = await getPort(vendorId, activeProductId)
p = await getPort(activeComName)
if (p) {
triggerPort = p
portAvailable = true
Expand Down Expand Up @@ -150,6 +150,9 @@ ipc.on('trigger', (event, args) => {
}
})

// Read version file (git sha and branch)
var git = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'config/version.json')));

// INCREMENTAL FILE SAVING
let stream = false
let fileName = ''
Expand Down Expand Up @@ -181,7 +184,7 @@ ipc.on('data', (event, args) => {
}

//write the data
stream.write(JSON.stringify(args))
stream.write(JSON.stringify({...args, git}))

// Copy provocation images to patient's data folder
if (args.trial_type === 'image_keyboard_response') images.push(args.stimulus.slice(7))
Expand Down
26 changes: 26 additions & 0 deletions version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Get Git Commit SHA and Branch

const fs = require('fs-extra')
const execa = require('execa');

let git;

if (process.env.CI) {
const sha = process.env.GITHUB_SHA
const ref = process.env.GITHUB_REF
git = {sha, ref}
}
else {
const sha = execa.commandSync('git rev-parse HEAD').stdout
const ref = execa.commandSync('git branch --show-current').stdout
git = {sha, ref}
}


fs.writeFile('public/config/version.json', JSON.stringify(git))
.then(() => {
console.log(`Saved version file with rev: ${git.sha}, branch: ${git.ref}`);
})
.catch((err) => {
console.log(err);
});

0 comments on commit 85a4e24

Please sign in to comment.