Skip to content

Commit

Permalink
changed: switched to CommonJS, fixed HTML title,
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnR committed Aug 28, 2015
1 parent 93b6c33 commit cb4a007
Show file tree
Hide file tree
Showing 60 changed files with 4,794 additions and 4,874 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.sublime-workspace
node_modules
public/js/*.min.js
public/js/*-bundle.js
public/css/*.css
public/lib/enketo-core
public/lib/bower-components
Expand All @@ -10,4 +11,4 @@ config/config.json
.rebooted
.vagrant
.scratchpad

.nodemon-*
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "app/lib/enketo-core"]
path = app/lib/enketo-core
url = https://github.com/enketo/enketo-core.git
6 changes: 4 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"globals": {
"module": false,
"require": false,
"Promise": true
"Promise": true,
"indexedDB": true,
"define": true
},
"node": true,
"browser": false,
"browser": true,
"jquery": false,
"sub": true,
"esnext": true
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ language: node_js
node_js:
- "0.10"
before_script:
- npm install -g grunt-cli bower
- bower install
- npm install -g grunt-cli
- cp ./config/default-config.json ./config/config.json
- chmod 777 ./setup/redis/travis-redis.sh
- ./setup/redis/travis-redis.sh
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http:https://semver.org/).

[1.15.0] - 2015-08-28
------------------------
##### Changed
- switched to CommonJS modules (**WARNING: forks with custom client scripts, tests need to be updated)

##### Fixed
- HTML titles not populated

[1.14.4] - 2015-08-26
------------------------
##### Fixed
Expand Down
112 changes: 53 additions & 59 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use strict";

module.exports = function( grunt ) {
var JS_INCLUDE = [ "**/*.js", "!**/enketo-core/**", "!node_modules/**", "!test/**/*.spec.js", "!**/*.min.js", "!public/lib/**/*.js", "!app/lib/martijnr-foundation/**/*.js" ];
// show elapsed time at the end
var JS_INCLUDE = [ "**/*.js", "!node_modules/**", "!test/**/*.spec.js", "!public/lib/**/*.js", '!public/js/*-bundle.js', '!public/js/*-bundle.min.js' ];
var pkg = grunt.file.readJSON( 'package.json' );

require( 'time-grunt' )( grunt );
// load all grunt tasks
require( 'load-grunt-tasks' )( grunt );

grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
grunt.config.init( {
concurrent: {
develop: {
tasks: [ 'nodemon', 'watch' ],
Expand Down Expand Up @@ -50,7 +49,7 @@ module.exports = function( grunt ) {
},
watch: {
sass: {
files: [ '.rebooted', 'config/config.json', 'app/views/styles/**/*.scss', 'app/lib/enketo-core/src/**/*.scss', 'app/views/**/*.jade' ],
files: [ '.rebooted', 'config/config.json', 'app/views/styles/**/*.scss', 'app/views/**/*.jade' ],
tasks: [ 'sass' ],
options: {
spawn: true,
Expand All @@ -60,6 +59,14 @@ module.exports = function( grunt ) {
language: {
files: [ 'app/views/**/*.jade', 'app/controllers/**/*.js', 'app/models/**/*.js', 'public/js/src/**/*.js' ],
tasks: [ 'shell:translation' ]
},
js: {
files: JS_INCLUDE,
tasks: [ 'compile-dev' ],
options: {
spawn: true,
livereload: true
}
}
},
shell: {
Expand Down Expand Up @@ -90,7 +97,7 @@ module.exports = function( grunt ) {
options: {
jshintrc: ".jshintrc"
},
all: JS_INCLUDE
all: JS_INCLUDE,
},
// test server JS
mochaTest: {
Expand All @@ -116,43 +123,44 @@ module.exports = function( grunt ) {
},
browsers: {
configFile: 'test/client/config/browser-karma.conf.js',
browsers: [ 'Chrome', 'ChromeCanary', 'Firefox', 'Opera', /*'Safari'*/ ]
browsers: [ 'Chrome', 'ChromeCanary', 'Firefox', 'Opera' /*,'Safari'*/ ],
}
},
requirejs: {
options: {
//generateSourceMaps: true,
preserveLicenseComments: false,
baseUrl: "public/js/src/module",
mainConfigFile: [ "./public/js/src/require-config.js", "./public/js/src/require-build-config.js" ],
findNestedDependencies: true,
optimize: "uglify2",
done: function( done, output ) {
var duplicates = require( 'rjs-build-analysis' ).duplicates( output );

if ( duplicates.length > 0 ) {
grunt.log.subhead( 'Duplicates found in requirejs build:' );
grunt.log.warn( duplicates );
done( new Error( 'r.js built duplicate modules, please check the excludes option.' ) );
} else {
grunt.log.writeln( 'Checked for duplicates. All seems OK!' );
browserify: {
development: {
files: {
'public/js/enketo-webform-dev-bundle.js': [ 'public/js/src/main-webform.js' ],
'public/js/enketo-webform-edit-dev-bundle.js': [ 'public/js/src/main-webform-edit.js' ],
},
options: {
browserifyOptions: {
debug: true
}
done();
}
},
},
production: {
files: {
'public/js/enketo-webform-bundle.js': [ 'public/js/src/main-webform.js' ],
'public/js/enketo-webform-edit-bundle.js': [ 'public/js/src/main-webform-edit.js' ],
},
},
options: {
// ensure that enketo-config and widgets are overridden in **enketo-core**
transform: [
[ 'aliasify', {
aliases: pkg.aliasify.aliases,
global: true
} ]
]
},
"webform": getWebformCompileOptions(),
"webform-edit": getWebformCompileOptions( 'edit' )
},
symlink: {
core: {
files: [ {
overwrite: false,
expand: true,
cwd: 'app/lib/',
src: [ 'enketo-core' ],
dest: 'public/lib/'
} ]
}
uglify: {
all: {
files: {
'public/js/enketo-webform-bundle.min.js': [ 'public/js/enketo-webform-bundle.js' ],
'public/js/enketo-webform-edit-bundle.min.js': [ 'public/js/enketo-webform-edit-bundle.js' ],
},
},
},
env: {
test: {
Expand All @@ -161,22 +169,6 @@ module.exports = function( grunt ) {
}
} );

function getWebformCompileOptions( type ) {
// determine all widget js resources
var widgetResources = [].concat( require( './app/models/config-model' ).server.widgets );
widgetResources.forEach( function( widget, index, arr ) {
arr.push( 'text!' + widget.substr( 0, widget.lastIndexOf( '/' ) + 1 ) + 'config.json' );
} );
type = ( type ) ? '-' + type : '';
return {
options: {
name: "../main-webform" + type,
out: "public/js/webform" + type + "-combined.min.js",
include: [ '../../../../public/lib/bower-components/requirejs/require' ].concat( widgetResources )
}
};
}

grunt.registerTask( 'client-config-file', 'Temporary client-config file', function( task ) {
var clientConfigPath = "public/temp-client-config.json";
if ( task === 'create' ) {
Expand All @@ -189,8 +181,10 @@ module.exports = function( grunt ) {
}
} );

grunt.registerTask( 'default', [ 'symlink', 'compile' ] );
grunt.registerTask( 'compile', [ 'sass', 'client-config-file:create', 'requirejs', 'client-config-file:remove' ] );
grunt.registerTask( 'test', [ 'env:test', 'symlink', 'compile', 'mochaTest:all', 'karma:headless', 'jsbeautifier:test', 'jshint' ] );
grunt.registerTask( 'develop', [ 'concurrent:develop' ] );
grunt.registerTask( 'default', [ 'sass', 'compile', 'uglify' ] );
grunt.registerTask( 'compile', [ 'client-config-file:create', 'browserify:production', 'client-config-file:remove' ] );
grunt.registerTask( 'compile-dev', [ 'client-config-file:create', 'browserify:development', 'client-config-file:remove' ] );
grunt.registerTask( 'test', [ 'env:test', 'compile', 'mochaTest:all', 'karma:headless', 'jsbeautifier:test', 'jshint' ] );
grunt.registerTask( 'test-browser', [ 'env:test', 'client-config-file:create', 'karma:browsers', 'client-config-file:remove' ] );
grunt.registerTask( 'develop', [ 'compile-dev', 'concurrent:develop' ] );
};
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@ A light-weight node.js version of Enketo Smart Paper. Chock-full of [badass rock

#### Manually:

1. Install JS prerequisites: [Node.js 0.10.x](http:https://nodejs.org/) (newer version [not supported yet](https://github.com/albanm/node-libxslt/issues/18)), [Grunt Client](http:https://gruntjs.com), [Bower](http:https://bower.io/), and [Node-Gyp](https://github.com/TooTallNate/node-gyp)
1. Install JS prerequisites: [Node.js 0.10.x](http:https://nodejs.org/) (newer version [not supported yet](https://github.com/albanm/node-libxslt/issues/18)), [Grunt Client](http:https://gruntjs.com), and [Node-Gyp](https://github.com/TooTallNate/node-gyp)
2. Install [Redis](http:https://redis.io/topics/quickstart)
3. Install build-essential with `(sudo) apt-get install build-essential`
4. Clone this repository
5. Clone git submodules with `git submodule update --init --recursive` from project folder
6. Install dependencies with `npm install` and `bower install` from the project root
7. Create config/config.json to override values in the [default config](./config/default-config.json). Start with `cp config/default-config.json config/config.json`
3. Install build-essential (and libfontconfig to run tests) with `(sudo) apt-get install build-essential libfontconfig`
4. Install dependencies with `npm install` and `bower install` from the project root
5. Create config/config.json to override values in the [default config](./config/default-config.json). Start with `cp config/default-config.json config/config.json`
8. Build with `grunt` from the project root

#### Using vagrant:

This takes several shortcuts. Do not use for production!

1. Install [Vagrant](http:https://docs.vagrantup.com/v2/installation/index.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
2. Clone this repository
3. Clone git submodules with `git submodule update --init --recursive` from project folder
4. Run `vagrant up` and wait until it completes \*
5. Log in to the VM with `vagrant ssh` and run `cd /vagrant && npm start`
5. The app should now be running on [localhost:8006](http:https://localhost:8006). You can test the API in a different console window with:
2. Run `vagrant up` from project folder and wait until it completes \*
3. Log in to the VM with `vagrant ssh` and run `cd /vagrant && npm start`

The app should now be running on [localhost:8006](http:https://localhost:8006). You can test the API in a different console window with:
```curl --user enketorules: -d "server_url=https://ona.io/enketo&form_id=widgets" http:https://localhost:8006/api/v2/survey```.

_\* sometimes `vagrant up` fails for reasons beyond our control - e.g. if external resources are temporarily unavailable. Try running `vagrant reload --provision` to resolve this._
Expand Down Expand Up @@ -63,8 +60,8 @@ For a production server, we recommend using [pm2](https://github.com/unitech/pm2


### How to update
* update git repository with `git pull && git submodule update --init --recursive`
* update dependencies with `npm update && bower update`
* update git repository with `git pull`
* update dependencies with `npm update`
* re-build with `grunt`
* restart app

Expand Down
1 change: 0 additions & 1 deletion app/lib/enketo-core
Submodule enketo-core deleted from 0263a2
2 changes: 1 addition & 1 deletion app/views/styles/component/_fonts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@font-face {
font-family: 'enketo-icons';
src: url("/lib/enketo-core/build/fonts/enketo-icons-v2.woff") format("woff"), url("/lib/enketo-core/build/fonts/enketo-icons-v2.ttf") format("truetype"), url("/lib/enketo-core/build/fonts/enketo-icons-v2.svg#enketo-icons") format("svg");
src: url("/fonts/enketo-icons-v2.woff") format("woff"), url("/fonts/enketo-icons-v2.ttf") format("truetype"), url("/fonts/enketo-icons-v2.svg#enketo-icons") format("svg");
font-weight: normal;
font-style: normal;
}
4 changes: 2 additions & 2 deletions app/views/styles/component/_modal.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "../../../../public/lib/bower-components/vex/sass/vex";
@import "../../../../public/lib/bower-components/vex/sass/vex-theme-plain";
@import "../../../../node_modules/vex-js/sass/vex";
@import "../../../../node_modules/vex-js/sass/vex-theme-plain";

.vex.vex.vex-theme-plain {
h3 {
Expand Down
19 changes: 2 additions & 17 deletions app/views/styles/component/_widgets.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,2 @@
// Dynamically created list of widget stylesheets to import based on the content
// based on the content of config.json

@import "../../../lib/enketo-core/src/widget/note/note.scss";
@import "../../../lib/enketo-core/src/widget/select-desktop/selectpicker.scss";
@import "../../../lib/enketo-core/src/widget/select-mobile/selectpicker.scss";
@import "../../../lib/enketo-core/src/widget/geo/geopicker.scss";
@import "../../../lib/enketo-core/src/widget/table/tablewidget.scss";
@import "../../../lib/enketo-core/src/widget/radio/radiopicker.scss";
@import "../../../lib/enketo-core/src/widget/time/timepicker-extended.scss";
@import "../../../lib/enketo-core/src/widget/date/datepicker-extended.scss";
@import "../../../lib/enketo-core/src/widget/datetime/datetimepicker-extended.scss";
@import "../../../lib/enketo-core/src/widget/mediagrid/mediagridpicker.scss";
@import "../../../lib/enketo-core/src/widget/file/filepicker.scss";
@import "../../../lib/enketo-core/src/widget/select-likert/likertitem.scss";
@import "../../../lib/enketo-core/src/widget/distress/distresspicker.scss";
@import "../../../lib/enketo-core/src/widget/horizontal-choices/horizontalchoices.scss";
// no customizations, just the default enketo-core
@import "../../../../node_modules/enketo-core/src/sass/core/_widgets.scss";
18 changes: 9 additions & 9 deletions app/views/styles/error.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@import '../../lib/enketo-core/src/sass/core/fonts';
@import 'component/fonts';
@import '../../lib/enketo-core/src/sass/core/variables';
@import '../../lib/enketo-core/src/sass/core/mixins';
@import '../../lib/enketo-core/src/sass/formhub/mixins';
@import "../../../node_modules/enketo-core/src/sass/core/fonts";
@import "component/fonts";
@import "../../../node_modules/enketo-core/src/sass/core/variables";
@import "../../../node_modules/enketo-core/src/sass/core/mixins";
@import "../../../node_modules/enketo-core/src/sass/formhub/mixins";

body {
@include font-normal;
@include font-normal;
}

.error {
margin: 40px 20px 20px 20px;
padding: 20px;
border: 1px solid #F2616D;
margin: 40px 20px 20px 20px;
padding: 20px;
border: 1px solid #F2616D;
position: relative;
font-weight: normal;
min-height: 100px;
Expand Down
8 changes: 4 additions & 4 deletions app/views/styles/theme-formhub/_form_formhub.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "../../../lib/enketo-core/src/sass/core/main";
@import "../../../lib/enketo-core/src/sass/core/responsive";
@import "../../../../node_modules/enketo-core/src/sass/core/main";
@import "../../../../node_modules/enketo-core/src/sass/core/responsive";
@import "../component/widgets";
@import "../../../lib/enketo-core/src/sass/core/slider";
@import "../../../lib/enketo-core/src/sass/formhub/main";
@import "../../../../node_modules/enketo-core/src/sass/core/slider";
@import "../../../../node_modules/enketo-core/src/sass/formhub/main";
2 changes: 1 addition & 1 deletion app/views/styles/theme-formhub/theme-formhub.print.scss
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import "../../../lib/enketo-core/src/sass/formhub/formhub-print";
@import "../../../../node_modules/enketo-core/src/sass/formhub/formhub-print";
16 changes: 8 additions & 8 deletions app/views/styles/theme-formhub/theme-formhub.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

// variables
@import "variables";
@import "../../../lib/enketo-core/src/sass/formhub/variables";
@import "../../../lib/enketo-core/src/sass/core/variables";
@import "../../../../node_modules/enketo-core/src/sass/formhub/variables";
@import "../../../../node_modules/enketo-core/src/sass/core/variables";

// mixins, in the right order
@import "../../../lib/enketo-core/src/sass/core/mixins";
@import "../../../lib/enketo-core/src/sass/formhub/mixins";
@import "../../../../node_modules/enketo-core/src/sass/core/mixins";
@import "../../../../node_modules/enketo-core/src/sass/formhub/mixins";
@import "../component/mixins";

// reset
@import "../../../lib/enketo-core/src/sass/core/reset";
@import "../../../../node_modules/enketo-core/src/sass/core/reset";

// common styles
@import "../component/common";

// utilities
@import "../../../lib/enketo-core/src/sass/core/utilities";
@import "../../../../node_modules/enketo-core/src/sass/core/utilities";

// icons
@import "../component/icons";
Expand All @@ -27,8 +27,8 @@
@import "../component/buttons";

// layout
@import "../../../lib/enketo-core/src/sass/core/layout";
@import "../../../lib/enketo-core/src/sass/core/pages";
@import "../../../../node_modules/enketo-core/src/sass/core/layout";
@import "../../../../node_modules/enketo-core/src/sass/core/pages";

// components
@import "../component/side-slider";
Expand Down
8 changes: 4 additions & 4 deletions app/views/styles/theme-grid/_form-grid.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "../../../lib/enketo-core/src/sass/core/main";
@import "../../../lib/enketo-core/src/sass/core/responsive";
@import "../../../../node_modules/enketo-core/src/sass/core/main";
@import "../../../../node_modules/enketo-core/src/sass/core/responsive";
@import "../component/widgets";
@import "../../../lib/enketo-core/src/sass/core/slider";
@import "../../../lib/enketo-core/src/sass/grid/main";
@import "../../../../node_modules/enketo-core/src/sass/core/slider";
@import "../../../../node_modules/enketo-core/src/sass/grid/main";
Loading

0 comments on commit cb4a007

Please sign in to comment.